locked
IMFSample::ReadSample asynchronous works but why not synchronous? RRS feed

  • Question

  • I'm a bit confused with why I can't get synchronous calls to ReadSample to work. I've followed the documentation as explained in http://msdn.microsoft.com/en-us/library/dd389281%28VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/dd374665%28VS.85%29.aspx but I wouldn't put it past me to have misread the information.

    Basically I'm trying to do something like

    DWORD dwActualStreamIndex;
    DWORD dwStreamFlags;
    LONGLONG llTimeStamp;
    IMFSample *pSample;

    hr = m_pReader->ReadSample(
                MF_SOURCE_READER_FIRST_VIDEO_STREAM,
                0,  // Control Flags
                &dwActualStreamIndex,
                &dwStreamFlags,
                &llTimeStamp,
                &pSample
            );

    but I keep getting hr = E_INVALIDARG

    If I instead set up a callback and use
    hr = m_pReader->ReadSample(
            MF_SOURCE_READER_FIRST_VIDEO_STREAM, //MF_SOURCE_READER_ANY_STREAM,
            0,  // Flags
            NULL,
            NULL,
            NULL,
            NULL
        );

    then it's fine.

    Can anyone shed some light on this for me?

    Cheers
    • Edited by The March Hare Wednesday, December 9, 2009 5:17 AM fix typo in title
    Wednesday, December 9, 2009 3:47 AM

Answers

  • Are you setting the callback (MF_SOURCE_READER_ASYNC_CALLBACK) when you create the source reader?

    If you set the callback but then call ReadSample using the synchronous semantics, the method returns E_INVALIDARG.

    (Conversely, if you do not set the callback and then call the method with async semantics, the method returns E_POINTER.)



    - Mike

    ----------------------------------------------------------------------------
    Mike Wasson, SDK Documentation
    This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use.

    (c) 2009 Microsoft Corporation. All rights reserved.

     


    Mike Wasson (SDK Documentation)
    • Marked as answer by GlennNZ Wednesday, December 9, 2009 8:26 PM
    Wednesday, December 9, 2009 6:06 AM

All replies

  • Are you setting the callback (MF_SOURCE_READER_ASYNC_CALLBACK) when you create the source reader?

    If you set the callback but then call ReadSample using the synchronous semantics, the method returns E_INVALIDARG.

    (Conversely, if you do not set the callback and then call the method with async semantics, the method returns E_POINTER.)



    - Mike

    ----------------------------------------------------------------------------
    Mike Wasson, SDK Documentation
    This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use.

    (c) 2009 Microsoft Corporation. All rights reserved.

     


    Mike Wasson (SDK Documentation)
    • Marked as answer by GlennNZ Wednesday, December 9, 2009 8:26 PM
    Wednesday, December 9, 2009 6:06 AM
  • Thanks Mike Wasson, that was it. The question now seems embarrassing because, yes, I'd forgotten to comment out...

    if (SUCCEEDED(hr))
    {
    hr = pAttributes->SetUnknown(
    MF_SOURCE_READER_ASYNC_CALLBACK,
    pCallback
    );
    }
    ...as I kept changing between the two different ReadSample methods/techniques.
    Wednesday, December 9, 2009 8:25 PM