private void nestedVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// don't even try doing something if there are no clients
if (NewFrame == null)
return;
if (skipFramesIfBusy)
{
if (!isProcessingThreadAvailable.WaitOne(0, false))
{
// return in the case if image processing thread is still busy and
// we are allowed to skip frames
return;
}
}
else
{
// make sure image processing thread is available in the case we cannot skip frames
isProcessingThreadAvailable.WaitOne();
}
// pass the image to processing frame and exit
lastVideoFrame = CloneImage(eventArgs.Frame);
isNewFrameAvailable.Set();
}