为什么IMFSourceReader :: ReadSample有缓冲区或全0?

时间:2014-10-29 21:17:07

标签: winapi audio aac ms-media-foundation

我的总体目标是从自定义文件系统中读取AAC数据包,解码为PCM并使用waveoutwrite进行播放。

作为中间步骤,我已经从中下载了alarm_antelope  http://download.wavetlan.com/SVV/Media/HTTP/http-aac.htm 并尝试使用IMFSourceReader进行读取和解码。 (最后我会让源阅读器给我原始样本,以便我可以使用解码器进行测试。)

问题是看起来我得到一个大缓冲区或所有零条目。

HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
    hr = MFStartup(MF_VERSION);

//need to read the data from a source somewhere.
IMFSourceReader *pSourceReader;
wchar_t* filename = L"F:\\PINTS\\Alarm_Antelope.aac"; //temp dir of file downloaded from above url
 hr = MFCreateSourceReaderFromURL(filename, NULL, &pSourceReader);
if (FAILED(hr)) {       
    return 0; 
}
DWORD dwStreamIndex = MF_SOURCE_READER_FIRST_AUDIO_STREAM;
IMFMediaType *pMediaType = NULL;
hr= MFCreateMediaType(&pMediaType);
pMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
pMediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);

hr= pSourceReader->SetCurrentMediaType(  dwStreamIndex, NULL,pMediaType);
if (FAILED(hr)) {
    return 0;
}
DWORD dwControlFlags = 0; //no control flag
DWORD pdwActualStreamIndex;
DWORD pdwStreamFlags;
LONGLONG pllTimestamp;
IMFSample *pSample=NULL;

BYTE* outputData = NULL;
DWORD outputSize = 0;
hr = pSourceReader->ReadSample(dwStreamIndex, dwControlFlags, &pdwActualStreamIndex, &pdwStreamFlags, &pllTimestamp, &pSample);
if (hr < 0) 
    return 0;

DWORD ttlLength = 0;
pSample->GetTotalLength(&ttlLength);
IMFMediaBuffer *pimpBufout;
pSample->ConvertToContiguousBuffer(&pimpBufout);
DWORD bufLen = 0;
pimpBufout->GetCurrentLength(&bufLen);

#pragma region experiment with direct source reader             
    BYTE *outData = NULL;
    DWORD outDataLen = 0;

    hr = pimpBufout->Lock(&outData, NULL, &outDataLen);
    printf("\nbefore copy");
    for (DWORD i = 0; i < outDataLen; i++)
    {
        printf("%x", outData[i]);
    }
    outputData = new BYTE[outDataLen];
    memcpy(outputData, outData, outDataLen);
    outputSize = outDataLen/2;//since this is supposed to be SHORTs

    hr = pimpBufout->Unlock();
    printf("\nAfter copy");
    for ( DWORD i = 0; i < outputSize; i++)
    {
        printf("%x", outputData[i]);
    }
#pragma endregion

两个印刷语句都填写全部为零。跟踪显示除了OK之外没有HR代码。为什么这会产生所有0x00? GetBufferByIndex产生相同的结果。

0 个答案:

没有答案