bool EnsureLibs() { static bool sInitDone = false; static bool sInitOk = false; if (!sInitDone) { sInitOk = LinkMfplat() && !!GetModuleHandleA(WMFDecoderDllNameFor(AAC)) && !!GetModuleHandleA(WMFDecoderDllNameFor(H264)); sInitDone = true; } return sInitOk; }
HRESULT WMFAACDecoder::Init(int32_t aChannelCount, int32_t aSampleRate, BYTE* aAACAudioSpecificConfig, UINT32 aAudioConfigLength) { HRESULT hr; // AAC decoder is in msauddecmft on Win8, and msmpeg2adec in earlier versions. hr = CreateMFT(CLSID_CMSAACDecMFT, WMFDecoderDllNameFor(AAC), mDecoder); if (FAILED(hr)) { hr = CreateMFT(CLSID_CMSAACDecMFT, WMFDecoderDllNameFor(AAC), mDecoder); if (FAILED(hr)) { LOG("Failed to create AAC decoder\n"); return E_FAIL; } } BYTE* userData = nullptr; UINT32 userDataLength; hr = AACAudioSpecificConfigToUserData(aAACAudioSpecificConfig, aAudioConfigLength, &userData, &userDataLength); ENSURE(SUCCEEDED(hr), hr); hr = SetDecoderInputType(aChannelCount, aSampleRate, userData, userDataLength); delete userData; ENSURE(SUCCEEDED(hr), hr); hr = SetDecoderOutputType(); ENSURE(SUCCEEDED(hr), hr); hr = SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0); ENSURE(SUCCEEDED(hr), hr); hr = SendMFTMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0); ENSURE(SUCCEEDED(hr), hr); hr = mDecoder->GetInputStreamInfo(0, &mInputStreamInfo); ENSURE(SUCCEEDED(hr), hr); hr = mDecoder->GetOutputStreamInfo(0, &mOutputStreamInfo); ENSURE(SUCCEEDED(hr), hr); return S_OK; }