hresult configureaudiostream( imfsourcereader *preader, // pointer to the source reader. imfmediatype **pppcmaudio // receives the audio format. ) { imfmediatype *puncompressedaudiotype = null; imfmediatype *ppartialtype = null; // select the first audio stream, and deselect all other streams. hresult hr = preader->setstreamselection( (dword)mf_source_reader_all_streams, false); if (succeeded(hr)) { hr = preader->setstreamselection( (dword)mf_source_reader_first_audio_stream, true); } // create a partial media type that specifies uncompressed pcm audio. hr = mfcreatemediatype(&ppartialtype); if (succeeded(hr)) { hr = ppartialtype->setguid(mf_mt_major_type, mfmediatype_audio); } if (succeeded(hr)) { hr = ppartialtype->setguid(mf_mt_subtype, mfaudioformat_pcm); } // set this type on the source reader. the source reader will // load the necessary decoder. if (succeeded(hr)) { hr = preader->setcurrentmediatype( (dword)mf_source_reader_first_audio_stream, null, ppartialtype); } // get the complete uncompressed format. if (succeeded(hr)) { hr = preader->getcurrentmediatype( (dword)mf_source_reader_first_audio_stream, &puncompressedaudiotype); } // ensure the stream is selected. if (succeeded(hr)) { hr = preader->setstreamselection( (dword)mf_source_reader_first_audio_stream, true); } // return the pcm format to the caller. if (succeeded(hr)) { *pppcmaudio = puncompressedaudiotype; (*pppcmaudio)->addref(); } saferelease(&puncompressedaudiotype); saferelease(&ppartialtype); return hr; }