locked
IMFSourceReader.ReadSample never hitting callback after reading on stream index 1. Calls to Stream index 0 work fine. RRS feed

  • Question

  • So background im working on reworking an application that was using direct show to use Windows Media Foundation. in Directshow i have UVC camera still pins working fine. however when i switched to using a SourceReader in WMF i have stream 0 (the live video stream) however when i use the same interface to try and request samples on Stream1 i dont receive anything. This is with the following call.
                        hr = StreamReader.ReadSample(1,
                                MediaFoundation.ReadWrite.MF_SOURCE_READER_CONTROL_FLAG.None,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                IntPtr.Zero
                                );

    if i switch it to 

                        hr = StreamReader.ReadSample(1,
                                MediaFoundation.ReadWrite.MF_SOURCE_READER_CONTROL_FLAG.Drain,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                IntPtr.Zero
                                );

    i receive only null IMFSamples. ive checked the state of hr and it is always S_OK. During this time i am also running the same call but on stream 0 and it is working fine. The only error or flag i get is StreamTick on the first frame on stream 0.

    Im not entirely sure where to go from here if anyone has suggestions im open

    Wednesday, June 24, 2020 3:20 PM

All replies

  • Hello ThisIsAnAmazingName,

    Since you mentioned callback I assume that you use IMFSourceReader::ReadSample in asynchronous mode. If this is true, the method returns immediately. If an error occurs, the method can fail either synchronously or asynchronously. Check the return value of ReadSample, and also check the hrStatus parameter of IMFSourceReaderCallback::OnReadSample. You can refer to this document for error checking:

    	while (SUCCEEDED(hr))
    	{
    		BOOL bEOS;
    		hr = pCallback->Wait(INFINITE, &bEOS);
    		if (FAILED(hr) || bEOS)
    		{
    			break;
    		}
    		hr = pReader->ReadSample(1,
    			MF_SOURCE_READER_CONTROLF_DRAIN, NULL, NULL, NULL, NULL);
    	}

    And usually, a media file contains either a single audio stream, or exactly one video stream and one audio stream. If you get error 0xc00d36b3 (The stream number provided was invalid.) maybe there is only one audio/video stream. At this time you can try MF_SOURCE_READER_ANY_STREAM as 

    dwStreamIndex and check the dwStreamIndex in OnReadSample call to get the actual stream index.

    Please let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 25, 2020 8:07 AM
  • Evening sorry for the late response the call doesnt fail synchronously either it returns S_OK and reads correctly for 1 read returning a null media sample before attempting a second read ( and also receiveing S_OK) but then never returning
    Monday, June 29, 2020 6:23 PM
  • Hello ThisIsAnAmazingName,

    Thanks for confirmation.

    Could you show a mini, complete and reproducible sample? So I can do a further investigation.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 30, 2020 4:38 AM