AsyncVideoSource Class |
Namespace: Accord.Video
The AsyncVideoSource type exposes the following members.
Name | Description | |
---|---|---|
AsyncVideoSource(IVideoSource) |
Initializes a new instance of the AsyncVideoSource class.
| |
AsyncVideoSource(IVideoSource, Boolean) |
Initializes a new instance of the AsyncVideoSource class.
|
Name | Description | |
---|---|---|
BytesReceived |
Received bytes count.
| |
FramesProcessed |
Processed frames count.
| |
FramesReceived |
Received frames count.
| |
IsRunning |
State of the video source.
| |
NestedVideoSource |
Nested video source which is the target for asynchronous processing.
| |
SkipFramesIfBusy |
Specifies if the object should skip frames from the nested video source when it is busy.
| |
Source |
Video source string.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
SignalToStop |
Signal video source to stop its work.
| |
Start |
Start video source.
| |
Stop |
Stop video source.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
WaitForStop |
Wait for video source has stopped.
|
Name | Description | |
---|---|---|
NewFrame |
New frame event.
| |
PlayingFinished |
Video playing finished event.
| |
VideoSourceError |
Video source error event.
|
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The class represents a simple proxy, which wraps the specified NestedVideoSource with the aim of asynchronous processing of received video frames. The class intercepts NewFrame event from the nested video source and fires it to clients from its own thread, which is different from the thread used by nested video source for video acquisition. This allows clients to perform processing of video frames without blocking video acquisition thread, which continue to run and acquire next video frame while current is still processed.
For example, let’s suppose that it takes 100 ms for the nested video source to acquire single frame, so the original frame rate is 10 frames per second. Also let’s assume that we have an image processing routine, which also takes 100 ms to process a single frame. If the acquisition and processing are done sequentially, then resulting frame rate will drop to 5 frames per second. However, if doing both in parallel, then there is a good chance to keep resulting frame rate equal (or close) to the original frame rate.
The class provides a bonus side effect - easer debugging of image processing routines, which are put into NewFrame event handler. In many cases video source classes fire their NewFrame event from a try/catch block, which makes it very hard to spot error made in user's code - the catch block simply hides exception raised in user’s code. The AsyncVideoSource does not have any try/catch blocks around firing of NewFrame event, so always user gets exception in the case it comes from his code. At the same time nested video source is not affected by the user's exception, since it runs in different thread.
Sample usage:
// usage of AsyncVideoSource is the same as usage of any // other video source class, so code change is very little // create nested video source, for example JPEGStream JPEGStream stream = new JPEGStream( "some url" ); // create async video source AsyncVideoSource asyncSource = new AsyncVideoSource( stream ); // set NewFrame event handler asyncSource.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source asyncSource.Start( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }