我应该释放内部分配的MFT输出缓冲区的返回IMFSample吗? [英] Should I release the returned IMFSample of an internally allocated MFT output buffer?

查看:118
本文介绍了我应该释放内部分配的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;

pSample

指向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 文档:

输出缓冲区

MFT通过pSample成员返回流的输出数据 MFT_OUTPUT_DATA_BUFFER结构.该结构成员是 指向媒体样本的IMFSample接口的指针. (请参阅媒体 样本.)媒体样本是由调用方或由媒体分配的 MFT,具体取决于MFT的分配模型.查找分配 模型,调用IMFTransform::GetOutputStreamInfo并检查 MFT_OUTPUT_STREAM_INFO结构的dwFlags成员

The MFT returns output data for a stream through the pSample member of the MFT_OUTPUT_DATA_BUFFER structure. This structure member is a pointer to the IMFSample interface of a media sample. (See Media Samples.) The media sample is allocated either by the caller or by the MFT, depending on the MFT's allocation model. To find the allocation model, call IMFTransform::GetOutputStreamInfo and examine the dwFlags member of the MFT_OUTPUT_STREAM_INFO structure

...

如果pSampleNULL并且dwFlags不包含 MFT_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER,MFT提供了一个示例 用于输出数据. MFT将pSample设置为指向样本 它提供的. MFT可以分配新样本或重复使用 输入样本.

If pSample is NULL and dwFlags does not contain the MFT_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER, the MFT provides a sample for the output data. The MFT sets pSample to point to the sample that it provides. The MFT can either allocate a new sample or re-use an input sample.

文档中没有提及是否应释放在这种情况下返回的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结构文档:

pEvents

在调用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_OUTPUT_STREAM_PROVIDES_SAMPLES标志,则MFT将分配媒体样本.
  • 如果存在MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES标志,则调用者可以选择提供媒体样本.如果pSample为NULL,则MFT将分配媒体样本.
  • 如果这两个标志都不存在,则调用者必须分配媒体样本.
  • If the MFT_OUTPUT_STREAM_PROVIDES_SAMPLES flag is present, the MFT allocates the media sample.
  • If the MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES flag is present, the caller can optionally provide a media sample. If pSample is NULL, the MFT will allocate the media sample.
  • If neither of these two flags is present, the caller must allocate the media sample.

请注意,文档中没有提到调用方提供示例指针,而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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆