BlueStrat BlueStrat - 1 year ago 95
C++ Question

Should I still pool IMFMediaBuffer objects?

The DirectX Media Objects(DMO) documentation advised that, for sake of efficiency, buffers holding media samples (supporting the

interface) should be pooled instead of being constantly created/destroyed:

The simplest solution is to allocate a new buffer for each sample, although doing so is inefficient.

A better solution is to implement an object to manage a pool of
To do this, write code in the Release method of your
IMediaBuffer implementation that calls a method of your buffer manager
(instead of deleting itself) when the reference count drops to zero.
The buffer manager can then maintain a list of pointers to allocated
buffer objects. Create a method in your buffer manager to check the
list of free buffers and return a pointer so that your application can
access buffers when needed.

Now that DMO has been superseded by Media Foundation Transforms (MFT), I can't find the same advice in the documentation. Is this pooling strategy something that should still be considered when managing the equivalent buffer objects (this time implementing the

Answer Source

The pooling strategy still reduces overall performance overhead but there are a few important things to keep in mind:

  1. The importance of pooling reduced with time as impact of not pooling gets smaller and smaller even on such performance sensitive APIs as real time video processing
  2. Media Foundation implements pooling on its side for function level APIs like MFCreateSample: the API returns a new sample created on API-managed internal pool of sample objects

That is, even if you not pool, you still get some pooling for free and the API itself helps you with small things like this. Your reasonable approach for accurate resource management still makes sense and would not hurt, of course, especially that documentation is not so much detailed on how it is doing the optimizations on its end.

Also, a good example of COM object pool implementation is DirectShow's CMemAllocator implementation contained in Windows SDK 7.x samples in \Samples\multimedia\directshow\baseclasses\amfilter.h

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download