Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all articles
Browse latest Browse all 1079

E_NOINTERFACE occur at MESessionTopoloySet event

$
0
0

I'm trying to play .mp4 file with MFT(Micorsoft H264 Video Decoder MFT) , based on the MF_ProtectedPlayback sample in the SDK.

I have created a topology. But I get a MESessionTopologySet event with E_NOINTERFACE in

IMFMediaEvent->GetStatus(&hrStatus));.

The source node is a default source node in the sample code, and the output node is default renderer node in the sample code. I am using the Micorsoft H264 Video Decoder MFT in between the source and the renderer.

Why do the error occur?

Please tell me the appropriate way to connect the MFT.

This is the code which I have written.

///////////////////////////////////////////////////////////////////////////////////

// AddBranch to Partial Topology (Video) 

AddBranchToPartialTopologyVideo(IMFTopology *pTopology, IMFPresentationDescriptor *pSourcePD, DWORD iStream)){

     TRACE((L"CPlayer::AddBranchToPartialTopologyVideo\n"));

     assert(pTopology != NULL);

    IMFStreamDescriptor* pSourceSD = NULL;
    IMFTopologyNode* pSourceNode = NULL;
    IMFTopologyNode* pOutputNode = NULL;
    IMFTopologyNode* pDecoderNode = NULL;
    BOOL fSelected = FALSE;

    HRESULT hr = S_OK;

    // Get the stream descriptor for this stream.
    CHECK_HR(hr = pSourcePD->GetStreamDescriptorByIndex(iStream, &fSelected, &pSourceSD));

    // Create the topology branch only if the stream is selected.
    // Otherwise, do nothing.
    if (fSelected)
    {
        // Create a source node for this stream.
        CHECK_HR(hr = CreateSourceStreamNode(m_pSource, pSourcePD, pSourceSD, &pSourceNode));

        // Create the output node for the renderer.
        CHECK_HR(hr = CreateOutputNode(pSourceSD, m_hwndVideo, &pOutputNode));

       // Create the MFT node for the decoder.
       CHECK_HR(hr = CreateDecoderNode(pSourceSD, m_hwndVideo, &pDecoderNode));

        // Add nodes to the topology.
        CHECK_HR(hr = pTopology->AddNode(pSourceNode));

        CHECK_HR(hr = pTopology->AddNode(pDecoderNode));

        CHECK_HR(hr = pTopology->AddNode(pOutputNode));


        // Connect the source node to the output node.
        CHECK_HR(hr = pSourceNode->ConnectOutput(0, pDecoderNode, 0));
        CHECK_HR(hr = pDecoderNode->ConnectOutput(0, pOutputNode, 0));

    }

done:
    // Clean up.
    SAFE_RELEASE(pSourceSD);
    SAFE_RELEASE(pSourceNode);
    SAFE_RELEASE(pDecoderNode);
    SAFE_RELEASE(pOutputNode);
    return hr;
}

// 

HRESULT CreateDecoderNode(
    IMFStreamDescriptor *pSourceSD,
    HWND hwndVideo,
    IMFTopologyNode **ppNode
    )
{  

    IMFTopologyNode *pNode = NULL;
    IMFMediaTypeHandler *pHandler = NULL;
    IMFTransform *pDecoder = NULL;

    GUID guidMajorType = GUID_NULL;
    HRESULT hr = S_OK;

    // Get the stream ID.
    DWORD streamID = 0;
    pSourceSD->GetStreamIdentifier(&streamID); // Just for debugging, ignore any failures.

    // Get the media type handler for the stream.
    CHECK_HR(hr = pSourceSD->GetMediaTypeHandler(&pHandler));
   
    // Get the major media type.
    CHECK_HR(hr = pHandler->GetMajorType(&guidMajorType));

    // Create a downstream node.
    CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &pNode));

    // Create an IMFActivate object for the renderer, based on the media type.
    if (MFMediaType_Video == guidMajorType)
    {
        GUID subtype;
        //  Get the video decoder.
         FindDecoderEx(subtype, FALSE, &pDecoder);
    }
    else
    {
        TRACE((L"Stream %d: Unknown format\n", streamID));
        CHECK_HR(hr = E_FAIL);
    }

    // Set the IActivate object on the MFT node.
    CHECK_HR(hr = pNode->SetObject(pDecoder));

    // Return the IMFTopologyNode pointer to the caller.
    *ppNode = pNode;
    (*ppNode)->AddRef();

done:
    SAFE_RELEASE(pNode);
    SAFE_RELEASE(pHandler);
   SAFE_RELEASE(pDecoder);
    return hr;
}

// Find the Decoder

HRESULT FindDecoderEx(
 const GUID& subtype,
 BOOL bAudio,
 IMFTransform **ppDecoder
 )
{
    HRESULT hr = S_OK;
    UINT32 count = 0;

    IMFActivate **ppActivate = NULL;

    MFT_REGISTER_TYPE_INFO info = {0};
    info.guidMajorType = MFMediaType_Video;
    info.guidSubtype = subtype;


    hr = MFTEnumEx(
       MFT_CATEGORY_VIDEO_DECODER,
       MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_LOCALMFT | MFT_ENUM_FLAG_SORTANDFILTER,
       NULL,
       //  &info,
       NULL,
       &ppActivate,
       &count
     );

    if(SUCCEEDED(hr) && count == 0){
        hr = MF_E_TOPO_CODEC_NOT_FOUND;
    }

    wchar_t ss[100];
    UINT32  len;
    GUID  guid;
    for(UINT j=0; j<count; j++){
       ppActivate[j]->GetString(MFT_FRIENDLY_NAME_Attribute, ss, 100, &len);
       ppActivate[j]->GetGUID(MFT_TRANSFORM_CLSID_Attribute, &guid);
       if(wcscmp(ss , _T("Microsoft H264 Video Decoder MFT")) == 0){
           hr = ppActivate[j]->ActivateObject(IID_PPV_ARGS(ppDecoder));
           break;
       }
    }

    for(UINT32 i=0; i<count; i++){
       ppActivate[i]->Release();
    }

    CoTaskMemFree(ppActivate);

    return hr;
}

                                                                                                                   


Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>