void SetSampleMetaData(IMFSourceReader *pReader, DWORD streamIndex, PyObject *out) { //Set meta data in output object IMFMediaType *pCurrentType = NULL; LONG plStride = 0; GUID majorType=GUID_NULL, subType=GUID_NULL; UINT32 width = 0; UINT32 height = 0; HRESULT hr = pReader->GetCurrentMediaType(streamIndex, &pCurrentType); if(!SUCCEEDED(hr)) cout << "Error 3\n"; BOOL isComp = FALSE; hr = pCurrentType->IsCompressedFormat(&isComp); PyDict_SetItemStringAndDeleteVar(out, "isCompressed", PyBool_FromLong(isComp)); hr = pCurrentType->GetGUID(MF_MT_MAJOR_TYPE, &majorType); LPCWSTR typePtr = GetGUIDNameConst(majorType); if(!SUCCEEDED(hr)) cout << "Error 4\n"; hr = pCurrentType->GetGUID(MF_MT_SUBTYPE, &subType); if(!SUCCEEDED(hr)) cout << "Error 5\n"; int isVideo = (majorType==MFMediaType_Video); if(isVideo) { GetDefaultStride(pCurrentType, &plStride); hr = MFGetAttributeSize(pCurrentType, MF_MT_FRAME_SIZE, &width, &height); if(!SUCCEEDED(hr)) cout << "Error 20\n"; } LPCWSTR subTypePtr = GetGUIDNameConst(subType); //if(subTypePtr!=0) wcout << "subtype\t" << subTypePtr << "\n"; PyDict_SetItemStringAndDeleteVar(out, "isCompressed", PyBool_FromLong(isComp)); if(typePtr!=NULL) PyDict_SetItemStringAndDeleteVar(out, "type", PyUnicode_FromWideChar(typePtr, wcslen(typePtr))); if(subTypePtr!=NULL) PyDict_SetItemStringAndDeleteVar(out, "subtype", PyUnicode_FromWideChar(subTypePtr, wcslen(subTypePtr))); if(!isComp) PyDict_SetItemStringAndDeleteVar(out, "stride", PyInt_FromLong(plStride)); PyDict_SetItemStringAndDeleteVar(out, "width", PyInt_FromLong(width)); PyDict_SetItemStringAndDeleteVar(out, "height", PyInt_FromLong(height)); }
HRESULT CASFManager::SetupStreamDecoder (WORD wStreamNumber, GUID* pguidCurrentMediaType) { if (! m_pContentInfo) { return MF_E_NOT_INITIALIZED; } if (wStreamNumber == 0) { return E_INVALIDARG; } IMFASFProfile* pProfile = NULL; IMFMediaType* pMediaType = NULL; IMFASFStreamConfig *pStream = NULL; GUID guidMajorType = GUID_NULL; GUID guidSubType = GUID_NULL; GUID guidDecoderCategory = GUID_NULL; BOOL fIsCompressed = TRUE; CLSID *pDecoderCLSIDs = NULL; // Pointer to an array of CLISDs. UINT32 cDecoderCLSIDs = 0; // Size of the array. HRESULT hr = S_OK; //Get the profile object that stores stream information CHECK_HR(hr = m_pContentInfo->GetProfile(&pProfile)); //Get stream configuration object from the profile CHECK_HR(hr = pProfile->GetStreamByNumber(wStreamNumber, &pStream)); //Get the media type CHECK_HR(hr = pStream->GetMediaType(&pMediaType)); //Get the major media type CHECK_HR(hr = pMediaType->GetMajorType(&guidMajorType)); //Get the sub media type CHECK_HR(hr = pMediaType->GetGUID(MF_MT_SUBTYPE, &guidSubType)); //find out if the media type is compressed CHECK_HR(hr = pMediaType->IsCompressedFormat(&fIsCompressed)); if (fIsCompressed) { //get decoder category if (guidMajorType == MFMediaType_Video) { guidDecoderCategory = MFT_CATEGORY_VIDEO_DECODER; } else if (guidMajorType == MFMediaType_Audio) { guidDecoderCategory = MFT_CATEGORY_AUDIO_DECODER; } else { CHECK_HR(hr = MF_E_INVALIDMEDIATYPE); } // Look for a decoder. MFT_REGISTER_TYPE_INFO tinfo; tinfo.guidMajorType = guidMajorType; tinfo.guidSubtype = guidSubType; CHECK_HR(hr = MFTEnum( guidDecoderCategory, 0, // Reserved &tinfo, // Input type to match. (Encoded type.) NULL, // Output type to match. (Don't care.) NULL, // Attributes to match. (None.) &pDecoderCLSIDs, // Receives a pointer to an array of CLSIDs. &cDecoderCLSIDs // Receives the size of the array. )); // MFTEnum can return zero matches. if (cDecoderCLSIDs == 0) { hr = MF_E_TOPO_CODEC_NOT_FOUND; } else { //if the CDecoder instance does not exist, create one. if (!m_pDecoder) { CHECK_HR(hr = CDecoder::CreateInstance(&m_pDecoder)); } //Load the first MFT in the array for the current media type CHECK_HR(hr = m_pDecoder->Initialize(pDecoderCLSIDs[0], pMediaType)); } *pguidCurrentMediaType = guidMajorType; } else { // Not compressed. Don't need a decoder. CHECK_HR(hr = MF_E_INVALIDREQUEST); } TRACE((L"Stream decoder loaded.\n")); done: LOG_MSG_IF_FAILED(L"CASFManager::SetupStreamDecoder failed.\n", hr); SAFE_RELEASE(pProfile); SAFE_RELEASE(pMediaType); SAFE_RELEASE(pStream); CoTaskMemFree(pDecoderCLSIDs); return hr; }