Search code examples
audiodirectshowaudio-streamingvisual-c++-2010audio-processing

How Direcshow Filters exchange Media samples?


anybody know how directshow filters exchange media samples?

we know source filter grab sample (from MIC or Live) and pass it to next filter in graph.

clearly i want to know how filters pass samples to another filter?

is there a known pattern for this?

if i decide to implement audio processing filters without any third party component , is it possible to implement media sample exchange using muti producer/consumer Queue?

say source filter F1 is media captur filter and filter F2 is DSP filter.

F1 write to Multi Producer/Consumer queue and F2 consume captured samples enqueued by F1 if any sample available.(I think about Multi Producer/Consumer queue because in some cases one filter can have more than one output and more that one input and each filter has it's own thread). is there any better way?

*EDIT : our solution must looks like Publisher Subscriber pattern , but i think this not suitable for media processing.

thank u so much


Solution

  • MSDN provides a pretty detailed description here in Overview of Data Flow in DirectShow. You want the whole article, and this is the excerpt about specifically exchange of data between filters:

    [...] Whenever a filter needs to fill a buffer with data, it requests a sample from the allocator by calling IMemAllocator::GetBuffer. If the allocator has any samples that are not currently in use by another filter, the GetBuffer method returns immediately with a pointer to the sample. If all of the allocator's samples are in use, the method blocks until a sample becomes available. When the method does return a sample, the filter puts data into the buffer, sets the appropriate flags on the sample (typically including a time stamp), and delivers the sample downstream. [...]