本文介绍了我应该释放内部分配的MFT输出缓冲区的返回IMFSample吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

媒体基础转换对象(MFT)可以实现输出缓冲区分配模型,在该模型中,缓冲区是由MFT对象在内部分配的.

Media Foundation Transform objects (MFT) may implement an output buffer allocation model where the buffers are allocated internally by the MFT object.

在这种情况下,内部分配的缓冲区是通过MFT_OUTPUT_DATA_BUFFER结构的pSample成员返回的,该成员传递给IMFTransform::ProcessOutput()方法.

If this is the case, the internally allocated buffer is returned via the pSample member of an MFT_OUTPUT_DATA_BUFFER structure that is passed to the IMFTransform::ProcessOutput() method.

MFT_OUTPUT_DATA_BUFFER结构文档:

typedef struct _MFT_OUTPUT_DATA_BUFFER {
  DWORD         dwStreamID;
  IMFSample     *pSample;
  DWORD         dwStatus;
  IMFCollection *pEvents;
} MFT_OUTPUT_DATA_BUFFER;

指向IMFSample界面的指针.调用ProcessOutput之前, 将此成员设置为等于有效的IMFSample指针或NULL.看 备注以获取更多信息.

Pointer to the IMFSample interface. Before calling ProcessOutput, set this member equal to a valid IMFSample pointer or NULL. See Remarks for more information.

IMFTransform ::: ProcessOutput 文档:

输出缓冲区

...

文档中没有提及是否应释放在这种情况下返回的IMFSample接口.似乎不是这种情况,因为文档非常明确地表明任何事件都是通过同一接口返回的struct应该由调用者释放.

The documentation does not mention if the returned IMFSample interface in this case should be released. It seems this is not the case, since the documentation is very explicit that any events returned via the same struct should be released by the caller.

MFT_OUTPUT_DATA_BUFFER结构文档:

在调用ProcessOutput之前,将此成员设置为NULL.在输出时, MFT可能将此成员设置为有效的IMFCollection 接口指针.指针代表一个包含以下内容的收集器 零个或多个事件.要获取每个事件,请致电 IMFCollection::GetElement并查询返回的IUnknown指针 用于IMFMediaEvent界面. 使用ProcessOutput方法时 返回时,调用方负责释放IMFCollection 指针,如果指针不是NULL.

Before calling ProcessOutput, set this member to NULL. On output, the MFT might set this member to a valid IMFCollection interface pointer. The pointer represents a collecton that contains zero or more events. To get each event, call IMFCollection::GetElement and query the returned IUnknown pointer for the IMFMediaEvent interface. When the ProcessOutput method returns, the caller is responsible for releasing the IMFCollection pointer if the pointer is not NULL.

有人可以确认是否应该释放返回的IMFSample接口吗?

Can somebody confirm if the returned IMFSample interface should be released or not?

我认为,如果我们不应该释放返回的接口,则应该对其进行明确记录,因为它违反了我们在使用完接口后就已经建立的COM释放接口的方式.

I think that If we should not release the returned interface, it should be documented explicitly, as it goes against the established COM way of releasing the interface once we have finished using it.

推荐答案

如果指针是由MFT使用非NULL值初始化的,则调用方负责释放样本(与调用方分配的缓冲区相反-in在这种情况下,MFT会使用它,但不需要在结构中添加引用.

The caller is responsible to release the sample if the pointer was initialized with a non-NULL value by the MFT (as opposed to buffer allocated by the caller - in which case the MFT uses it but does not need to AddRef it in the structure).

以下代码段适用于所有三种型号:

Code snippet below is good for all three models:

请注意,文档中没有提到调用方提供示例指针,而MFT用其自己的示例指针代替的情况.

Note that the documentation does not mention a scenario where caller provides a sample pointer, and MFT replaces it with its own.

(尽管代码不是完美的,只是参考计数的一个示例;如果有一个先验信息是样本是调用者的,那么就不需要执行Attach/Detach事情了,课程)

(the code is not to be perfect though, just an illustration of reference counting; if there is a priori information that samples are caller's then there is no need to do Attach/Detach thing, of course)

CComPtr<IMFSample> pSample;
// pSample is NULL or not
MFT_OUTPUT_DATA_BUFFER Buffer;
Buffer.pSample = pSample.Detach();
// ...
const HRESULT nResult = pTransform->ProcessOutput(..., &Buffer, ...);
pSample.Attach(Buffer.pSample);
// pSample holds a valid properly ref'fed pointer
// No need to use Buffer.pSample below

这篇关于我应该释放内部分配的MFT输出缓冲区的返回IMFSample吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:05
查看更多