Media Foundation Transform objects (MFT) may implement an output buffer allocation model where the buffers are allocated internally by the MFT object.
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.
From the MFT_OUTPUT_DATA_BUFFER structure documentation:
typedef struct _MFT_OUTPUT_DATA_BUFFER {
DWORD dwStreamID;
IMFSample *pSample;
DWORD dwStatus;
IMFCollection *pEvents;
} MFT_OUTPUT_DATA_BUFFER;
pSample
Pointer to the
IMFSampleinterface. Before callingProcessOutput, set this member equal to a validIMFSamplepointer orNULL. See Remarks for more information.
From the IMFTransform::ProcessOutput documentation:
Output Buffers
The MFT returns output data for a stream through the
pSamplemember of theMFT_OUTPUT_DATA_BUFFERstructure. This structure member is a pointer to theIMFSampleinterface 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, callIMFTransform::GetOutputStreamInfoand examine thedwFlagsmember of theMFT_OUTPUT_STREAM_INFOstructure
...
If
pSampleisNULLanddwFlagsdoes not contain theMFT_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER, the MFT provides a sample for the output data. The MFT setspSampleto point to the sample that it provides. The MFT can either allocate a new sample or re-use an input sample.
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.
From the MFT_OUTPUT_DATA_BUFFER structure documentation:
pEvents
Before calling
ProcessOutput, set this member toNULL. On output, the MFT might set this member to a validIMFCollectioninterface pointer. The pointer represents a collecton that contains zero or more events. To get each event, callIMFCollection::GetElementand query the returnedIUnknownpointer for theIMFMediaEventinterface. When theProcessOutputmethod returns, the caller is responsible for releasing theIMFCollectionpointer if the pointer is notNULL.
Can somebody confirm if the returned IMFSample interface should be released or not?
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.