How can I pass data from CRenderedInputPin::Receive to another thread

STK STK 61 Reputation points
2022-06-17T19:40:38.437+00:00

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) ?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,736 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,856 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2022-06-20T03:20:32.807+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.