问题
我试图调用 ProcessOutput
从解码器获取解码数据并收到以下错误:
E_INVALIDARG
One or more arguments are invalid.
我尝试过的
由于 ProcessOutput
有很多参数,我试图查明错误可能是什么。 Documentation for ProcessOutput
没有提及E_INVALIDARG
。然而,documentation for MFT_OUTPUT_DATA_BUFFER
,参数之一的数据类型,在其备注部分提到:
Any other combinations are invalid and cause
ProcessOutput
to returnE_INVALIDARG
它讨论的是如何设置MFT_OUTPUT_DATA_BUFFER
结构。因此,错误设置 MFT_OUTPUT_DATA_BUFFER
可能会导致该错误。不过我已经尝试正确设置它。
通过调用 GetOutputStreamInfo,我发现我需要分配发送到 ProcessOutput 的样本,这就是我所做的。我使用的方法与 ProcessInput 几乎相同,所以我不知道我在这里做错了什么。
我还尝试确保其他参数在逻辑上也应该能够导致 E_INVALIDARG
。它们对我来说看起来不错,但我无法找到任何其他导致我的 ProcessOutput
参数可能无效的原因。
代码
我尝试仅发布下面代码的相关部分。为了简洁起见,我删除或缩短了许多错误检查。请注意,我使用的是纯 C。
“前奏”
...
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 数据流上。也许它可能是坏数据或与媒体类型集不匹配的数据。
关于c - IMFTransform::ProcessOutput 返回 E_INVALIDARG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41983374/