Answered DoRenderSample

  • Tuesday, January 17, 2012 5:22 PM
     
      Has Code

    What is the proper way of processing media samples? I have written a renderer filter that works fine on Windows XP 32-bit and Windows Vista 64-bit PCs with an external webcamera. It also works fine on a netbook with Windows XP with embedded webcamera, but it does not work on Windows 7 on a notebook with embedded webcamera, nor does it work on a tablet with two embedded webcameras running Windows 8 Developer Preview. On the tablet, I managed to find out that the biCompression field of the sample's BITMAPINFOHEADER is a large number, but the allowed constants are small numbers (one to five).

    In the CheckMediaType method, I just save the bmiHeader:

    if (pmt->formattype == FORMAT_VideoInfo)
    {
    	m_bitmapInfoHeader = ((VIDEOINFOHEADER*)pmt->pbFormat)->bmiHeader;
    	return S_OK;
    }
    return S_FALSE;
    

    In DoRenderSample, I get the data pointer and I set bitmapInfo.bmiColors to all zeros. Since biCompression is not false on Windows 7 and Windows 8, Bitmap::Save returns Status::InvalidParameter (error code: 2):

    BYTE *pBuffer;
    BITMAPINFO bitmapInfo;
    
    pMediaSample->GetPointer(&pBuffer);
    bitmapInfo.bmiHeader = m_bitmapInfoHeader;
    memset(&bitmapInfo.bmiColors, 0, sizeof(bitmapInfo.bmiColors));
    
    Bitmap *pBitmap = new Bitmap(&bitmapInfo, pBuffer);
    pBitmap->Save(FileName, &m_clsidBmpEncoder);
    
    

     

All Replies

  • Wednesday, January 18, 2012 10:46 PM
     
     Answered

    biCompression can be one of the defined BI_* consts or a FOURCC value, e.g. 'YV12', which appears as a long number (but print it out as a char[4] and you can read its real value: printf("%.4hs",&biCompression)).

    I don't know what you mean by "biCompression is not false", since biCompression is not a bool. If you mean it is not BI_RGB (that is, 0), that is common since many webcams capture in some YUV format or even some compressed format like MJPEG (and recently even H.264). With some webcams, the default format would be either MJPEG or YUV, but you can ask them to capture in RGB (which sometimes limits the capture resolution), with others RGB is not supported at all.


    <http://www.riseoftheants.com/mmx/faq.htm>
    • Marked As Answer by me5775 Thursday, January 19, 2012 7:21 PM
    •  
  • Thursday, January 19, 2012 7:23 PM
     
     
    Thank you very much for your reply, it's been very helpful to me. How do I ask the camera to capture in RGB mode? Is it possible with DirectShow?
    • Edited by me5775 Thursday, January 19, 2012 7:23 PM
    •  
  • Friday, January 20, 2012 3:59 AM
     
     Answered
    http://msdn.microsoft.com/en-us/Library/dd387907.aspx
    <http://www.riseoftheants.com/mmx/faq.htm>
    • Edited by Alessandro Angeli Friday, January 20, 2012 4:00 AM
    • Marked As Answer by me5775 Friday, January 20, 2012 7:37 PM
    •  
  • Friday, January 20, 2012 7:37 PM
     
     
    It works! Thanks again for your help.