locked
Adding a SampleGrabber to the MF_BasicPlayback example, No errors but SampleGrabber does not callback? RRS feed

  • Question

  • Hi,

    I have modified the MF_BasicPlayback example from the SDK to include the code from the Using the Sample Grabber Sink example.

    I have inserted a tee into the video stream so the source node feeds a tee which is connected to the renderer output node and the samplegrabber node.  The code runs and plays a video but the samplegrabber callback never gets called.

    I am struggling to find where the error is without the joys of Graphedit to see if it has correctly connected up.

    Any ideas?

    I have modifed AddBranchToPartialTopology with the below code, I use the provided SampleGrabberCB class from the Microsoft example.

    Thanks for any help.

    Mike

    if (majorType == MFMediaType_Video && fSelected) { // Configure the media type that the Sample Grabber will receive. // Setting the major and subtype is usually enough for the topology loader // to resolve the topology. CHECK_HR(hr = MFCreateMediaType(&pType)); CHECK_HR(hr = pType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video)); CHECK_HR(hr = pType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32));

    // Create the sample grabber sink. CHECK_HR(hr = SampleGrabberCB::CreateInstance(&m_pSampleGrabber)); CHECK_HR(hr = MFCreateSampleGrabberSinkActivate(pType, m_pSampleGrabber, &pSinkActivate)); // To run as fast as possible, set this attribute (requires Windows 7): //CHECK_HR(hr = pSinkActivate->SetUINT32(MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, TRUE)); DWORD streamID; pSourceSD->GetStreamIdentifier(&streamID); CHECK_HR(hr = AddOutputNode(pTopology, pSinkActivate, 0, &pSampleGrabberNode)); // if I put in StreamID it throws an error.

    CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_TEE_NODE, &pTeeNode)); CHECK_HR(hr = pTopology->AddNode(pTeeNode)); CHECK_HR(hr = pSourceNode->ConnectOutput(0, pTeeNode, 0)); CHECK_HR(hr = pTeeNode->ConnectOutput(0, pSampleGrabberNode, 0)); CHECK_HR(hr = pTeeNode->ConnectOutput(0, pOutputNode, 0)); } else { // Connect the source node to the output node. hr = pSourceNode->ConnectOutput(0, pOutputNode, 0); }


    Saturday, June 20, 2015 1:26 PM

Answers

  • Hi,

    I have sorted this problem now.  The problem was my lack of understanding of how the automatic topology resolving works in Media Foundation (it seems it does not do it too well!).  For future reference for anybody, the problem was the video format of the samplegrabber.

    It seems that you can only set the samplegrabber to a YUV format, the file source does not output any RGB types and it seems the topology does not figure out it needs to put in the Media Foundation equivalent of a Color Space Converter (if there is one).

    To further complicate matters if the source is WMV the supported format is YUY2, if it is H.264 the supported format is NV12 (or the other way round, I can't remember now).

    To further complicate matters, this only works if the renderer is not connected.  If the renderer (EVR I assume) is connected I could not get all 3 to agree, in this case, it renderers but the samplegrabber fails to callback (because I guess it is not connected).

    I never looked into what format the EVR settled on with the file source to see if I could match it in the samplegrabber as I just needed something quick and dirty to get decoded data out of a H.264 file, using the default Windows 7 components.  I.e. without installing some extra filters to get it going with Directshow.

    • Marked as answer by Mike Cameron Wednesday, June 24, 2015 4:07 PM
    Wednesday, June 24, 2015 4:07 PM