locked
Sometimes failing to get OnReadSample callback after successful call to ReadSample RRS feed

  • Question

  • Can anyone explain why the OnReadSample callback would never be invoked after a successful call to ReadSample?  My app is using this mechanism to capture frames from a webcam.  This failure mode is rare, but it always happens the first time after unplugging the webcam and plugging it back in (while the app is not running).  I see the callback being called once (with a null sample) but the next call to ReadSample never generates an invocation of OnReadSample.

    I used MFTrace to capture the reader events in the good and bad cases, but they don't seem to indicate anything useful.  Here are the relevant excerpts:

    Good:

    1372,B64 15:50:28.05871 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @SourceReader_ReadSample_Begin
    1372,100 15:50:28.06997 Microsoft-Windows-MediaFoundation-Performance Stop  @State Change to Stop Tag=CAPS Object=0x0000000020C95BC8
    1372,D4C 15:50:28.07010 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaSourceEvent
    1372,D4C 15:50:28.07012 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaSourceEvent
    1372,EC4 15:50:28.07013 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    1372,EC4 15:50:28.07013 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    1372,EC4 15:50:28.07015 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    1372,EC4 15:50:28.07015 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_RequestSample
    1372,EC4 15:50:28.07015 Microsoft-Windows-MediaFoundation-Performance Input  @Buffer Input Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=9223372036854775807 Clock=0x0000000000000000 Sample=0x0000000000000000 Buffer Size=0 Sample Size=0 Sample Duration=0
    1372,EC4 15:50:28.07016 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    1372,EC4 15:50:28.07016 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    1372,EC4 15:50:28.07016 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    1372,EC4 15:50:28.07016 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    1372,EC4 15:50:28.07017 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @SourceReader_ReadSample_End

    1372,EC4 15:50:28.07028 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @SourceReader_ReadSample_Begin
    1372,EC4 15:50:28.07036 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    1372,100 15:50:28.42629 Microsoft-Windows-MediaFoundation-Performance @Capture Source Start Tag=CAPS Object=0x0000000020C95950 Duration=<unknown TDH type 21>
    1372,100 15:50:28.42630 Microsoft-Windows-MediaFoundation-Performance Queued  @Buffer Queued Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=8420563654 Clock=0x0000000000000000 Sample=0x0000000020BB4D20 Buffer Size=1572864 Sample Size=22472 Sample Duration=333333
    1372,100 15:50:28.42630 Microsoft-Windows-MediaFoundation-Performance Output  @Buffer Output Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=8420563654 Clock=0x0000000000000000 Sample=0x0000000020BB4D20 Buffer Size=1572864 Sample Size=22472 Sample Duration=333333
    1372,EC4 15:50:28.42632 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    1372,EC4 15:50:28.42633 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @Transform_ProcessInput
    1372,EC4 15:50:28.43117 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @Transform_ProcessOutput
    1372,EC4 15:50:28.43120 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @SourceReader_ReadSample_End


    1372,EC4 15:50:28.43136 Microsoft-Windows-MediaFoundation-Performance Input  @ProcessInput Tag=Resz Object=0x000000002A25F3B0 Object Category=8 Sample=0x0000000045075AD0 Buffer Size=1572864 Sample Time=0 Processing Time=4
    1372,EC4 15:50:28.43230 Microsoft-Windows-MediaFoundation-Performance Output  @ProcessOutput Tag=Resz Object=0x000000002A25F3B0 Object Category=8 Sample=0x0000000045C7B3E0 Buffer Size=1572864 Sample Time=0 Processing Time=933

    1372,EC4 15:50:28.50238 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @SourceReader_ReadSample_Begin
    1372,EC4 15:50:28.50242 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    1372,EC4 15:50:28.50243 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_RequestSample
    1372,EC4 15:50:28.50243 Microsoft-Windows-MediaFoundation-Performance Input  @Buffer Input Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=9223372036854775807 Clock=0x0000000000000000 Sample=0x0000000000000000 Buffer Size=0 Sample Size=0 Sample Duration=0
    1372,100 15:50:28.63444 Microsoft-Windows-MediaFoundation-Performance @Capture Source Ready Queue Empty Tag=CAPS Object=0x000000002A250F90 Duration=<unknown TDH type 21>
    1372,100 15:50:28.63444 Microsoft-Windows-MediaFoundation-Performance Queued  @Buffer Queued Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=8422644559 Clock=0x0000000000000000 Sample=0x0000000020BB4D80 Buffer Size=1572864 Sample Size=22376 Sample Duration=333333
    1372,100 15:50:28.63445 Microsoft-Windows-MediaFoundation-Performance Output  @Buffer Output Tag=CAPS Object=0x000000002A250F90 Object Category=27 Stream=0x000000002A250F90 Timestamp=8422644559 Clock=0x0000000000000000 Sample=0x0000000020BB4D80 Buffer Size=1572864 Sample Size=22376 Sample Duration=333333
    1372,EC4 15:50:28.63452 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    1372,EC4 15:50:28.63454 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @Transform_ProcessInput
    1372,EC4 15:50:28.63845 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @Transform_ProcessOutput
    1372,EC4 15:50:28.63848 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @SourceReader_ReadSample_End

    (pattern repeats)


    Bad:


    3544,728 15:51:21.41710 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @SourceReader_ReadSample_Begin
    3544,1114 15:51:21.43114 Microsoft-Windows-MediaFoundation-Performance Stop  @State Change to Stop Tag=CAPS Object=0x000000002A10B358
    3544,6E8 15:51:21.43127 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaSourceEvent
    3544,6E8 15:51:21.43129 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaSourceEvent
    3544,12DC 15:51:21.43131 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,12DC 15:51:21.43132 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,12DC 15:51:21.43134 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    3544,12DC 15:51:21.43134 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_RequestSample
    3544,12DC 15:51:21.43135 Microsoft-Windows-MediaFoundation-Performance Input  @Buffer Input Tag=CAPS Object=0x000000002A048660 Object Category=27 Stream=0x000000002A048660 Timestamp=9223372036854775807 Clock=0x0000000000000000 Sample=0x0000000000000000 Buffer Size=0 Sample Size=0 Sample Duration=0
    3544,12DC 15:51:21.43135 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    3544,12DC 15:51:21.43136 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_MediaStreamEvent
    3544,12DC 15:51:21.43136 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,12DC 15:51:21.43136 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    3544,12DC 15:51:21.43137 Microsoft-Windows-MediaFoundation-MFReadWrite Stop  @SourceReader_ReadSample_End
    3544,12DC 15:51:21.43172 Microsoft-Windows-MediaFoundation-MFReadWrite Start  @SourceReader_ReadSample_Begin
    3544,12DC 15:51:21.43176 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessOutputError
    3544,728 15:51:21.90556 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,728 15:51:21.90556 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,728 15:51:21.90556 Microsoft-Windows-MediaFoundation-MFReadWrite @Transform_ProcessMessage
    3544,12DC 15:51:21.94581 Microsoft-Windows-MediaFoundation-MFReadWrite @SourceReader_Error
    Thursday, May 5, 2011 7:51 PM

All replies

  • I'm still looking for help with the issue described in the post below.  Does anyone have any insights?

     

       Thanks,

       Mike

     

    http://social.msdn.microsoft.com/Forums/en-US/mediafoundationdevelopment/thread/4b4ce70e-ba11-491f-96f9-d681d9d39a63/

    Tuesday, August 2, 2011 8:06 PM
  • As noted in the trace, the source reader hit an error.  The error code is likely contained within the hrStatus argument of the OnReadSample callback you got with a null sample.  Once the source reader has hit an error, it cannot coninue.  You should recreate the source reader, and probably the source as well. 
    Thursday, September 1, 2011 7:03 PM
  • Then if even for the first time the readsample() cannot invoke a onreadsample(), what can i do? And the hr = .readsample() returns S_OK. Then where in the code and when need i recreate the source reader or the source?
    Thursday, August 14, 2014 10:40 AM