Search code examples
c++ms-media-foundation

How to use a custom heap with IMFSourceReader


In our application we are using an IMFSourceReader to handle the decode of a .mp4 file for us to play.

What we would like to do is reserve an amount of memory in the application and then configure the IMFSourceReader to use this reserved memory as its heap when it allocates the IMFSampleObjects.

I am wondering what might be the best way to try an achieve this. I believe that we will need to implement a custom media source as suggested in this documentation https://learn.microsoft.com/en-us/windows/win32/medfound/writing-a-custom-media-source#generating-source-data and use the MFCreateSourceReaderFromMediaSource method. Is that correct?

Additionally I am still unclear on exactly where we would do the memory allocations. Will we need to create a new IMFMediaBuffer object as well?


Solution

  • I do not think it is realistic to supply custom memory heap without re-implementing Media Foundation primitives behind your source reader media pipeline (also, in the context of the question it would be worth mentioning its details).

    More importantly though, I suppose there is no real need or advantage in doing things this way. If you see increased memory pressure, it is highly unlikely that potential enormous effort in customization of memory allocator for primitives inside the source reader improves the situation. This is one of the reasons the feature does not exist in first place.