madhat1
madhat1

Reputation: 704

DirectShow.NET Controlling number of camera device buffers

I'm trying to debug a latency issue that i have when streaming frames from a USB Camera using DirectShow.NET.

I'm capturing frames using SampleGrabber and doing some algorithmic processing on them. The SampleGrabber is connected after an MJPEG decoder so the frames are decoded, and the stream is configured to 30 FPS. The problem I'm seeing is when my algorithm takes longer than 33ms to handle a frame. In that case, I'm seeing a latency effect - frames are not lost and frame rate is not decreased but merely arrive late. This indicates some kind of buffering mechanism inside the device's driver (generic USB camera = generic DirectShow?) with a large number of buffers, circa 16.

The question is, can someone shed some light on this issue and perhaps suggest a way to set the number of buffers in the device? I've found that the interface IMemAllocator allows changing the number of buffers via a member method: IMemAllocator::SetProperties, but how is this done in DirectShow.NET? Anyone has any experience with it?

Upvotes: 0

Views: 319

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69642

You are trying to control what you are not supposed to control. Allocator properties are scope of control of upstream connection of the Sample Grabber filter you are capturing video through. You in turn get your control in Sample Grabber's callback only (you should have been more specific about how exactly you get data, SampleCB or BufferCB), so you get what you get.

Basically, your options to manage incoming video stream are:

  1. to grab with SampleCB and process taking into consideration that before you return from SampleCB callback, the entire streaming thread is blocked
  2. to copy data into your internal buffer for asynchronous processing and return ASAP, to release streaming thread and let it go at maximal rate

For greater flexibility you are supposed to use your custom filter instead of Sample Grabber.

Upvotes: 1

Related Questions