コード例 #1
0
ファイル: AVIFileVideoSource.cs プロジェクト: sclcwwl/Gimela
    /// <summary>
    /// Worker thread.
    /// </summary>
    /// 
    private void WorkerThread()
    {
      VideoSourceFinishedReasonType reasonToStop = VideoSourceFinishedReasonType.StoppedByUser;

      // AVI reader
      AVIReader aviReader = new AVIReader();

      try
      {
        // open file
        aviReader.Open(source);

        // stop positions
        int stopPosition = aviReader.Start + aviReader.Length;

        // frame interval
        int interval = (frameIntervalFromSource) ? (int)(1000 / aviReader.FrameRate) : frameInterval;

        while (!stopEvent.WaitOne(0, false))
        {
          // start time
          DateTime start = DateTime.Now;

          // get next frame
          Bitmap bitmap = aviReader.GetNextFrame();

          framesReceived++;

          if (NewFrame != null)
            NewFrame(this, new NewFrameEventArgs(bitmap, DateTime.Now));

          // free image
          bitmap.Dispose();

          // check current position
          if (aviReader.Position >= stopPosition)
          {
            reasonToStop = VideoSourceFinishedReasonType.EndOfStreamReached;
            break;
          }

          // wait for a while ?
          if (interval > 0)
          {
            // get frame extract duration
            TimeSpan span = DateTime.Now.Subtract(start);

            // miliseconds to sleep
            int msec = interval - (int)span.TotalMilliseconds;

            while ((msec > 0) && (stopEvent.WaitOne(0, true) == false))
            {
              // sleeping ...
              Thread.Sleep((msec < 100) ? msec : 100);
              msec -= 100;
            }
          }
        }
      }
      catch (Exception ex)
      {
        // provide information to clients
        if (VideoSourceException != null)
        {
          VideoSourceException(this, new VideoSourceExceptionEventArgs(ex.Message));
        }
      }

      aviReader.Dispose();
      aviReader = null;

      if (VideoSourceFinished != null)
      {
        VideoSourceFinished(this, new VideoSourceFinishedEventArgs(reasonToStop));
      }
    }
コード例 #2
0
        /// <summary>
        /// Worker thread.
        /// </summary>
        ///
        private void WorkerThread()
        {
            VideoSourceFinishedReasonType reasonToStop = VideoSourceFinishedReasonType.StoppedByUser;

            // AVI reader
            AVIReader aviReader = new AVIReader();

            try
            {
                // open file
                aviReader.Open(source);

                // stop positions
                int stopPosition = aviReader.Start + aviReader.Length;

                // frame interval
                int interval = (frameIntervalFromSource) ? (int)(1000 / aviReader.FrameRate) : frameInterval;

                while (!stopEvent.WaitOne(0, false))
                {
                    // start time
                    DateTime start = DateTime.Now;

                    // get next frame
                    Bitmap bitmap = aviReader.GetNextFrame();

                    framesReceived++;

                    if (NewFrame != null)
                    {
                        NewFrame(this, new NewFrameEventArgs(bitmap, DateTime.Now));
                    }

                    // free image
                    bitmap.Dispose();

                    // check current position
                    if (aviReader.Position >= stopPosition)
                    {
                        reasonToStop = VideoSourceFinishedReasonType.EndOfStreamReached;
                        break;
                    }

                    // wait for a while ?
                    if (interval > 0)
                    {
                        // get frame extract duration
                        TimeSpan span = DateTime.Now.Subtract(start);

                        // miliseconds to sleep
                        int msec = interval - (int)span.TotalMilliseconds;

                        while ((msec > 0) && (stopEvent.WaitOne(0, true) == false))
                        {
                            // sleeping ...
                            Thread.Sleep((msec < 100) ? msec : 100);
                            msec -= 100;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // provide information to clients
                if (VideoSourceException != null)
                {
                    VideoSourceException(this, new VideoSourceExceptionEventArgs(ex.Message));
                }
            }

            aviReader.Dispose();
            aviReader = null;

            if (VideoSourceFinished != null)
            {
                VideoSourceFinished(this, new VideoSourceFinishedEventArgs(reasonToStop));
            }
        }