我还应该合并 IMFMediaBuffer 对象吗?

Should I still pool IMFMediaBuffer objects?

DirectX 媒体对象 (DMO) documentation 建议,为了提高效率,保存媒体样本(支持 IMediaBuffer 接口)的缓冲区应该合并而不是经常 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 buffers. 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.

既然 DMO 已被 Media Foundation Transforms (MFT) 取代,我在文档中找不到相同的建议。 在管理等效缓冲区对象(这次实现 IMFMediaBuffer 接口)时是否仍应考虑这种池化策略?

池化策略仍然可以降低整体性能开销,但需要牢记一些重要事项:

  1. 池化的重要性随着时间的推移而降低,因为不池化的影响越来越小,即使在实时视频处理这样的性能敏感 APIs 上也是如此
  2. Media Foundation 在其一侧实现功能级别 APIs 的池化,例如 MFCreateSample:API returns 在 API 上创建的新示例-样本对象的托管内部池

也就是说,即使您不使用池,您仍然可以免费获得一些池,API 本身可以帮助您处理此类小事情。您用于准确资源管理的合理方法仍然有意义并且不会造成伤害,当然,尤其是文档没有详细说明它如何进行优化。

此外,COM 对象池实现的一个很好的例子是 DirectShow 的 CMemAllocator 实现包含在 Windows SDK 7.x 示例中 \Samples\multimedia\directshow\baseclasses\amfilter.h

观看此网络广播:Introduction to Windows Media Architecture

您将在 MediaFoundation 内部了解有关内存管理的更多信息。

根据我使用 MediaFoundation 的经验,MediaFoundation 池策略非常好。