According to CBaseInputPin.Receive method,
Question1: Yes, If the pin uses a worker thread to process the sample, add a reference count to the sample inside this method. After the method returns, the upstream pin releases the sample. When the sample's reference count reaches zero, the sample returns to the allocator for re-use.
Question2: DirectShow should not call Receive again when previous Receive blocking. But If the Receive method might block, the upstream filter might decide to use a worker thread that buffers data. See the COutputQueue class for an implementation of this strategy.
How can I pass data from CRenderedInputPin::Receive to another thread
My DirectShow filter (derived from CRenderedInputPin) must receive data (MyInputPin::Receive(IMediaSample *pSample)) from it’s upstream and write it to a file or network. Writing (to file/net) procedure may be not very fast, so I am going to place it to a separate writing thread. I would like to pass data from *pSample buffer immediately to writing procedure to avoid unnecessarily data copying.
Question1: How can I guarantee that after MyInputPin::Receive() exited, *pSample buffer will not be released. Is it enough to call pSample->AddRef() to block releasing and to call pSample->Release() in the writing thread to force buffer release ?
Question2: If I will not place the writing procedure to the separate thread, will or not DS call Receive for the next data portion (I will return ReceiveCanBlock== S_OK) ?
-
Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
2022-06-20T03:20:32.807+00:00