IMFTransform::ProcessOutput returns E_INVALIDARG

IMFTransform::ProcessOutput returns E_INVALIDARG

问题

我正在尝试调用 ProcessOutput 以从我的解码器获取解码数据并收到以下错误:

E_INVALIDARG One or more arguments are invalid.

我试过的

由于 ProcessOutput 有很多参数,我试图查明可能是什么错误。 Documentation for ProcessOutput does not mention E_INVALIDARG. However, the documentation for MFT_OUTPUT_DATA_BUFFER,参数之一的数据类型,在其备注部分提到:

Any other combinations are invalid and cause ProcessOutput to return E_INVALIDARG

它谈论的是如何设置 MFT_OUTPUT_DATA_BUFFER 结构。因此,错误的设置 MFT_OUTPUT_DATA_BUFFER 可能会导致该错误。但是,我已尝试正确设置它。

通过调用 GetOutputStreamInfo,我发现我需要分配发送到 ProcessOutput 的样本,这就是我所做的。我使用的方法与用于 ProcessInput 的方法几乎相同,所以我不知道我在这里做错了什么。

我也试图确保其他论点,从逻辑上讲,他们也应该能够引起 E_INVALIDARG。它们对我来说看起来不错,但我无法找到任何其他线索来证明我对 ProcessOutput 的哪些论点可能无效。

密码

我已尝试 post 仅对下面代码的相关部分进行修改。为了简洁起见,我删除或缩短了许多错误检查。请注意,我使用的是纯 C。

"Prelude"

...
hr = pDecoder->lpVtbl->SetOutputType(pDecoder, dwOutputStreamID, pMediaOut, dwFlags);
...
// Send input to decoder
hr = pDecoder->lpVtbl->ProcessInput(pDecoder, dwInputStreamID, pSample, dwFlags);
if (FAILED(hr)) { /* did not fail */ }

所以在下面有趣的代码之前,我已经成功地设置了一些东西(我希望如此)并将它们发送到没有失败的 ProcessInput。我有 1 个输入流和 1 个输出流,AAC 输入,PCM 输出。

直接导致错误的代码

// Input has now been sent to the decoder
// To extract a sample from the decoder we need to create a strucure to hold the output
// First we ask the OutputStream for what type of output sample it will produce and who should allocate it
// Then we create both the sample in question (if we should allocate it that is) and the MFT_OUTPUT_DATA_BUFFER
// which holds the sample and some other information that the decoder will fill in.

#define SAMPLES_PER_BUFFER 1 // hardcoded here, should depend on GetStreamIDs results, which right now is 1

MFT_OUTPUT_DATA_BUFFER pOutputSamples[SAMPLES_PER_BUFFER];
DWORD *pdwStatus = NULL;

// There are different allocation models, find out which one is required here.
MFT_OUTPUT_STREAM_INFO streamInfo = { 0,0,0 };
MFT_OUTPUT_STREAM_INFO *pStreamInfo = &streamInfo;

hr = pDecoder->lpVtbl->GetOutputStreamInfo(pDecoder, dwOutputStreamID, pStreamInfo);
if (FAILED(hr)) { ... }

if (pStreamInfo->dwFlags == MFT_OUTPUT_STREAM_PROVIDES_SAMPLES) { ... }
else if (pStreamInfo->dwFlags == MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES) { ... }
else {  
    // default, the client must allocate the output samples for the stream
    IMFSample *pOutSample = NULL;
    DWORD minimumSizeOfBuffer = pStreamInfo->cbSize;
    IMFMediaBuffer *pBuffer = NULL;

    // CreateMediaSample is explained further down. 
    hr = CreateMediaSample(minimumSizeOfBuffer, sampleDuration, &pBuffer, &pOutSample);
        if (FAILED(hr)) {
            BGLOG_ERROR("error");
        }

    pOutputSamples[0].pSample = pOutSample;
}

// since GetStreamIDs return E_NOTIMPL then dwStreamID does not matter
// but its recomended that it is set to the array index, 0 in this case.
// dwOutputStreamID will be 0 when E_NOTIMPL is returned by GetStremIDs
pOutputSamples[0].dwStreamID = dwOutputStreamID; // = 0
pOutputSamples[0].dwStatus = 0;
pOutputSamples[0].pEvents = NULL; // have tried init this myself, but MFT_OUTPUT_DATA_BUFFER documentation says not to.

hr = pDecoder->lpVtbl->ProcessOutput(pDecoder, dwFlags, outputStreamCount, pOutputSamples, pdwStatus);
if (FAILED(hr)) {
    // here E_INVALIDARG is found.
}
代码中使用的

CreateMediaSample 来自 an example 官方文档,但修改为调用 SetSampleDuration 和 SetSampleTime。虽然我没有设置这两个,但我得到了同样的错误,所以它应该是导致问题的其他原因。

发送到 ProcessOutput 的一些实际数据

以防我可能遗漏了一些从实际数据中很容易看出的东西:

hr = pDecoder->lpVtbl->ProcessOutput(
    pDecoder, // my decoder
    dwFlags, // 0
    outputStreamCount, // 1 (from GetStreamCount)
    pOutputSamples, // se comment below
    pdwStatus // NULL
);
// pOutputSamples[0] holds this struct:
// dwStreamID = 0, 
// pSample = SampleDefinedBelow 
// dwStatus = 0, 
// pEvents = NULL

// SampleDefinedBelow:
// time = 0
// duration = 0.9523..
// buffer = with max length set correctly 
// attributes[] = NULL

问题

所以有人对我做错了什么或者我如何进一步调试有任何想法吗?

ProcessOutput 需要一个有效的指针作为最后一个参数,所以这不起作用:

DWORD *pdwStatus = NULL;
pDecoder->lpVtbl->ProcessOutput(..., pdwStatus);

没关系:

DWORD dwStatus;
pDecoder->lpVtbl->ProcessOutput(..., &dwStatus);

关于进一步 E_FAIL - 总的来说,您上面的发现看起来不错。这不是我看到的明显的东西,而且错误代码也不表明问题出在 MFT 数据流上。也许它可能是错误的数据或与媒体类型集不匹配的数据。