Ejemplo n.º 1
0
        /// <summary>
        /// Worker thread.
        /// </summary>
        ///
        private void WorkerThread( )
        {
            ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.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++;
                    bytesReceived += bitmap.Width * bitmap.Height *
                                     (Bitmap.GetPixelFormatSize(bitmap.PixelFormat) >> 3);

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

                    // free image
                    bitmap.Dispose( );

                    // check current position
                    if (aviReader.Position >= stopPosition)
                    {
                        reasonToStop = ReasonToFinishPlaying.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;

                        if ((msec > 0) && (stopEvent.WaitOne(msec, false)))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (VideoSourceError != null)
                {
                    VideoSourceError(this, new VideoSourceErrorEventArgs(exception.Message));
                }
            }

            aviReader.Dispose( );
            aviReader = null;

            if (PlayingFinished != null)
            {
                PlayingFinished(this, reasonToStop);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Worker thread.
        /// </summary>
        /// 
        private void WorkerThread( )
		{
            ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.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++;
                    bytesReceived += bitmap.Width * bitmap.Height *
                        ( Bitmap.GetPixelFormatSize( bitmap.PixelFormat ) >> 3 );

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

					// free image
					bitmap.Dispose( );

                    // check current position
                    if ( aviReader.Position >= stopPosition )
                    {
                        reasonToStop = ReasonToFinishPlaying.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;

                        if ( ( msec > 0 ) && ( stopEvent.WaitOne( msec, false ) ) )
                            break;
                    }
				}
			}
			catch ( Exception exception )
			{
                // provide information to clients
                if ( VideoSourceError != null )
                {
                    VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) );
                }
			}

			aviReader.Dispose( );
			aviReader = null;

            if ( PlayingFinished != null )
            {
                PlayingFinished( this, reasonToStop );
            } 
		}