locked
IMFSourceReaderCallback hrStatus = MF_E_INVALIDMEDIATYPE despite IMFSourceReader::SetCurrentMediaType success RRS feed

  • Question

  • I'm using the Logitech B990 HD Webcam and essentially the SDK Media Foundation sample for SourceReader. 

    The camera supports H264 compressed output over USB2.0. 

    I would like to capture the data in H264 format, but I'm getting an error on the IMFSourceReaderCallback of MF_E_INVALIDMEDIATYPE.

    I use IMFSourceReader::SetCurrentMediaType to make sure I'm capturing in H264, and that function returns successfully.

    As a debug step, I even go through all naively supported formats to make sure H264 is one of them.

    Any idea of what might be going wrong?

    pseudo code:

    IMFSourceReader *m_pReader;

    for(UINT32 index=0;;index++)
    {
     hr=m_pReader->GetNativeMediaType(
      (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
      index, // Type index
      &pCaptureType);
      
     GUID subtype = {0};
     hr = pCaptureType->GetGUID(MF_MT_SUBTYPE, &subtype);

     if(subtype == MFVideoFormat_H264)
      break;

     // stop when there are no more native types
     if (FAILED(hr)) { goto done; }
    }

    //pCaptureType has MF_MT_SUBTYPE = MFVideoFormat_H264

    hr = m_pReader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,NULL,pCaptureType);
    //hr = S_OK

    hr = m_pReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pType);
    //hr = S_OK

    GUID subtype = {0};
    hr = pType->GetGUID(MF_MT_SUBTYPE, &subtype);

    // subtype = MFVideoFormat_H264

    =============================================

    //IMFSourceReaderCallback method
    HRESULT CCapture::OnReadSample(
        HRESULT hrStatus,
        DWORD /*dwStreamIndex*/,
        DWORD /*dwStreamFlags*/,
        LONGLONG llTimeStamp,
        IMFSample *pSample      // Can be NULL
        )
    {
     //hrStatus = MF_E_INVALIDMEDIATYPE
    }


    NOTE: The same process works without any error for getting MJPEG data from the Logitech C910 camera.
    • Edited by sjbaran Friday, August 5, 2011 4:46 PM
    Thursday, August 4, 2011 11:47 PM

Answers

  • The device capture source does not actually set the media type on the device until the source is started. This means that if there is a failure setting the media type, you will not see the failure when you initially set the media type but when you first try and read samples from the source. This error you see in the trace is just the device saying the media type is unsupported.

    Advertising a media type that then gets rejected is usually a faulty behavior. It is possible that the device is looking for configuration parameters to be set on the media type, but I cannot say exactly what it might be looking for.

    • Marked as answer by sjbaran Tuesday, October 11, 2011 5:03 PM
    Friday, September 30, 2011 5:44 PM

All replies

  • MFTrace info:

    3332,1C0 16:18:41.76136 CMFPlatExportDetours::MFStartup @ Version=0x00020070, dwFlags=0x00000000
    3332,1C0 16:18:41.80754 CMFExportDetours::MFEnumDeviceSources @ MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE=MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
    3332,1C0 16:18:41.80755 CMFPlatExportDetours::MFTEnumEx @ Category: CLSID_VideoInputDeviceCategory, Flags: 0x00000004, input MT: <NULL>, output MT: <NULL>
    3332,1C0 16:18:41.80847 COle32ExportDetours::CoCreateInstance @ Created {62BE5D10-60EB-11D0-BD3B-00A0C911CE86} System Device Enumerator (C:\Windows\system32\devenum.dll) @0075DE98 - traced interfaces:
    3332,1C0 16:18:41.80868 COle32ExportDetours::CoCreateInstance @ Created {860BB310-5D01-11D0-BD3B-00A0C911CE86} VFW Capture Class Manager (C:\Windows\system32\devenum.dll) @0033C3E0 - traced interfaces:
    3332,1C0 16:18:41.80875 COle32ExportDetours::CoCreateInstance @ Created {62BE5D10-60EB-11D0-BD3B-00A0C911CE86} System Device Enumerator (C:\Windows\system32\devenum.dll) @0075DF00 - traced interfaces:
    3332,1C0 16:18:41.81419 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @0025B2C0, MF_TRANSFORM_CATEGORY_Attribute=CLSID_VideoInputDeviceCategory;MFT_TRANSFORM_CLSID_Attribute=MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID;MF_TRANSFORM_FLAGS_Attribute=4;MFT_ENUM_HARDWARE_URL_Attribute=\\?\usb#vid_046d&pid_0828&mi_00#6&15198992&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global;MFT_FRIENDLY_NAME_Attribute=USB Video Device;MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 55 59 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 55 59 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ...
    3332,1C0 16:18:41.81424 CMFExportDetours::MFEnumDeviceSources @ Source activate 00 @0025B318, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY=CLSID_VideoInputDeviceCategory;MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_HW_SOURCE=4;MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK=\\?\usb#vid_046d&pid_0828&mi_00#6&15198992&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global;MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME=USB Video Device;MF_DEVSOURCE_ATTRIBUTE_MEDIA_TYPE=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 55 59 32 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE=MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
    3332,1C0 16:18:41.81766 COle32ExportDetours::CoCreateInstance @ New MFT @002E29C0, MF_TRANSFORM_ASYNC=1
    3332,1C0 16:18:41.81768 COle32ExportDetours::CoCreateInstance @ Created {8AC3587A-4AE7-42D8-99E0-0A6013EEF90F} Device Proxy MFT (C:\Windows\System32\mf.dll) @002E29C0 - traced interfaces: IMFTransform @002E29C0,
    3332,1C0 16:18:41.81852 COle32ExportDetours::CoCreateInstance @ Created {720D4AC0-7533-11D0-A5D6-28DB04C10000} KsTopologyInfo Class (C:\Windows\system32\vidcap.ax) @0033A7F8 - traced interfaces:
    3332,1C0 16:18:41.81989 COle32ExportDetours::CoCreateInstance @ Created {C6E13344-30AC-11D0-A18C-00A0C9118956} IAMDroppedFrames (C:\Windows\system32\kswdmcap.ax) @0033C3E0 - traced interfaces:
    3332,1C0 16:18:41.82012 COle32ExportDetours::CoCreateInstance @ Created {6A2E0670-28E4-11D0-A18C-00A0C9118956} IAMVideoControl (C:\Windows\system32\kswdmcap.ax) @0033AB38 - traced interfaces:
    3332,1C0 16:18:41.82032 COle32ExportDetours::CoCreateInstance @ Created {C6E13360-30AC-11D0-A18C-00A0C9118956} IAMVideoProcAmp (C:\Windows\system32\kswdmcap.ax) @0033AB58 - traced interfaces:
    3332,1C0 16:18:41.82052 COle32ExportDetours::CoCreateInstance @ Created {C6E13370-30AC-11D0-A18C-00A0C9118956} IAMCameraControl (C:\Windows\system32\kswdmcap.ax) @0033C430 - traced interfaces:
    3332,1C0 16:18:41.82309 CMFActivateDetours::ActivateObject @0025B318 New MFT @002E29C0
    3332,1C0 16:18:41.82310 CMFActivateDetours::ActivateObject @0025B318 New source @002F15B0
    3332,1C0 16:18:41.82314 CMFMediaSourceDetours::TracePD @002F15B0 Stream 0 (ID 0): selected 1, MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_YUY2;MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_DEFAULT_STRIDE=1280;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_SAMPLE_SIZE=614400;MF_MT_AVG_BITRATE=147456000;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_AM_FORMAT_TYPE=FORMAT_VideoInfo;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_FRAME_RATE_RANGE_MIN=21474836481 (5,1)
    3332,1C0 16:18:46.52577 CMFActivateDetours::ActivateObject @0025B318 New MFT @002E29C0
    3332,1C0 16:18:46.52578 CMFActivateDetours::ActivateObject @0025B318 New source @002F15B0
    3332,1C0 16:18:46.52587 CMFMediaSourceDetours::TracePD @002F15B0 Stream 0 (ID 0): selected 1, MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_YUY2;MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_DEFAULT_STRIDE=1280;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_SAMPLE_SIZE=614400;MF_MT_AVG_BITRATE=147456000;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_AM_FORMAT_TYPE=FORMAT_VideoInfo;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_FRAME_RATE_RANGE_MIN=21474836481 (5,1)
    3332,1C0 16:18:46.52590 CMFReadWriteExportDetours::MFCreateSourceReaderFromMediaSource @ Source @002F15B0, MF_SOURCE_READER_ASYNC_CALLBACK=@004B3F38
    3332,1C0 16:18:46.52594 CMFReadWriteExportDetours::MFCreateSourceReaderFromByteStream @ Bytestream @002F15B0, MF_SOURCE_READER_ASYNC_CALLBACK=@004B3F38
    3332,1C0 16:18:46.52651 COle32ExportDetours::CoCreateInstance @ Created {48E2ED0F-98C2-4A37-BED5-166312DDD83F} MFReadWrite Class Factory (C:\Windows\System32\mfreadwrite.dll) @002D022C - traced interfaces: IMFReadWriteClassFactory @002D022C,
    3332,1C0 16:18:46.52652 CMFReadWriteClassFactoryDetours::CreateInstanceFromObject @002D022C Object @002F15B0, MF_SOURCE_READER_ASYNC_CALLBACK=@004B3F38
    3332,1C0 16:18:46.52660 CMFReadWriteClassFactoryDetours::HandleObject @ New source reader @055489B0
    3332,FF8 16:18:46.53040 CMFTransformDetours::SetOutputType @002E29C0 Failed MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MEDIASUBTYPE_H264;MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_SAMPLE_SIZE=614400;MF_MT_AVG_BITRATE=147456000;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_AM_FORMAT_TYPE=FORMAT_VideoInfo;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_FRAME_RATE_RANGE_MIN=21474836481 (5,1)
    3332,FF8 16:18:46.53042 CMFMediaSourceDetours::EndGetEvent @002F15B0 Met=205 MENewStream, value @002F96A8,
    3332,FF8 16:18:46.53047 CMFMediaSourceDetours::HandleEvent @002F15B0 New stream @002F96A8 (ID 0), MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MEDIASUBTYPE_H264;MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_SAMPLE_SIZE=614400;MF_MT_AVG_BITRATE=147456000;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_AM_FORMAT_TYPE=FORMAT_VideoInfo;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_FRAME_RATE_RANGE_MIN=21474836481 (5,1)
    3332,FF8 16:18:46.53051 CMFMediaSourceDetours::EndGetEvent @002F15B0 Met=201 MESourceStarted, value (empty), failed HrStatus=C00D36B4 MF_E_INVALIDMEDIATYPE,


    Friday, August 5, 2011 4:21 PM
  • Anyone have any idea about what might be going wrong?

    The trace indicates that SetOutputType failed, but in the code I did not get a failure returned to HRESULT. How would this happen?

    Anyone use the Logitech B990 HD Webcam to capture H.264 directly from the camera (not a decoded format)?

    Friday, September 9, 2011 6:33 PM
  • The device capture source does not actually set the media type on the device until the source is started. This means that if there is a failure setting the media type, you will not see the failure when you initially set the media type but when you first try and read samples from the source. This error you see in the trace is just the device saying the media type is unsupported.

    Advertising a media type that then gets rejected is usually a faulty behavior. It is possible that the device is looking for configuration parameters to be set on the media type, but I cannot say exactly what it might be looking for.

    • Marked as answer by sjbaran Tuesday, October 11, 2011 5:03 PM
    Friday, September 30, 2011 5:44 PM
  • My conclusion is that either the camera has faulty behavior (with regards to supporting H264 with Media Foundation) or it expects some other (undocumented?) configuration.

    If anyone has any information on how to capture H264 frames (with the Logitech B990 HD Webcam or other camera with built-in H264 encoder) using Media Foundation (or other method if necessary) then I would be interested in the details.

    Tuesday, October 11, 2011 5:07 PM
  • FYI,

    the Logitech B990 HD Webcam works with graphedit (DirectShow) with H264 as an output, but not Topoedit (Media Foundation)

    Friday, October 21, 2011 8:03 PM
  • Hi,

    did you finally get the webcam to work with h264?

    I bought a Logitech C920 with h264 support as well but I get MF_E_INVALIDMEDIATYPE after calling ReadSample.

    Regards,

    Sergio.

    Thursday, January 10, 2013 1:06 PM
  •  UVC 1.5 (supported by the Logitech C920) has H.264 support.  It is included in Windows 8 but not Windows 7.

    So if you use Windows 8 and the UVC driver with the Logitech camera (and not the Logitech driver), the IMFSourceReaderCallback method returns successfully and provides the H264 buffer.

    Monday, February 4, 2013 10:27 PM