Gary G.
Gary G.

Reputation: 338

Should I release the buffers within IMFSample before I release the IMFSample object?

I can't find any information about a requirement to release the buffers within an IMFSample before actually releasing the IMFSample itself. If I do just release the IMFSample does that automatically release it's buffers? I'm writing a video player app and I'm receiving a sample from IMFSourceReader::ReadSample. While I see the code running I see a small increase in memory usage in VS2017 and I'm not sure if it's a leak yet. The code I'm using is based on the sample code in this post. Media Foundation webcam video H264 encode/decode produces artifacts when played back

I found the IMFSample::RemoveAllBuffers method that may or may not release the buffers, it doesn't specify in the documentation. Maybe this needs to be used before releasing the IMFSample? https://msdn.microsoft.com/en-us/library/windows/desktop/ms703108(v=vs.85).aspx

(I also run across another related post in my research but I don't think it applies to my question:) Should I release the returned IMFSample of an internally allocated MFT output buffer?

Thanks!

Upvotes: 0

Views: 1086

Answers (3)

ToKa
ToKa

Reputation: 98

Last but not least.

According to Microsoft you have to release the buffers (before- or afterward doesn't matter). See: Decode the audio

Upvotes: 0

mofo77
mofo77

Reputation: 1515

Just to echo from what Roman said, if you just handle an IMFSample, you just need to release this IMFSample. If you AddBuffer on the IMFSample, you have to remove it (i agree it's not clear, but if buffers are removed at this time, this will create problems with the component who handles IMFSample, and it will not find buffers after). that said, this design can cause problems if no one calls RemoveAllBuffers at the right time.

Differents components are not supposed to use AddBuffer on the same IMFSample. But it is possible to do it.

This is bad design for memory management. You have to deal with it.

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69642

Regular COM interface pointer management rules apply: you just release IMFSample pointer and that's it.

In certain cases your release of a sample pointer does not lead to actual freeing of memory because samples might be pooled: the released sample object is returned to its parent pool and is ready for reuse.

Upvotes: 2

Related Questions