Search code examples
c++cwindowsdirectshow

DirectShow's SampleGrabber retrieves erroneous sample


Being a newbie to DS I needed a SampleGrabber that can handle VIDEOINFOHEADER2, which IMediaDet cannot.

So I took the SampleGrabber from DX8.1 samples which - in contrast to the stock grabber - allows all kind of media. I used the sample code quite as is, and grabbing one single frame everything seems to work fine: the graph is built without returning errorcodes etc. Then calling

    hr = pSeeking->SetPositions( 
        &Seek, 
        AM_SEEKING_AbsolutePositioning, 
        NULL, 
        AM_SEEKING_NoPositioning );

with Seek = 2

the callback is called:

HRESULT Callback( IMediaSample * pSample, REFERENCE_TIME * StartTime, REFERENCE_TIME * StopTime, BOOL TypeChanged )

The problem is with the buffer: It has the right size (GetSize () == 691200 = 3 Byte * 640 * 320) but its content is all "205", which cannot be (in which format ever).

Suspicious about it: The parameters of "Callback" are StartTime = 834168, StopTime = 1251251 and TypeChanged = 1.

I tried showing the Graph at GraphEdit https://msdn.microsoft.com/en-us/library/windows/desktop/dd390650%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 but wasn't successful ("application is busy" from GraphEdit).

Where might the problem be?


Solution

  • Found it (at last).

    In the callback I copied the delivered buffer, with memcpy, and confused source and destination. Very embarrassing.

    Thanks for the help. (Will try to delete this question in a few days after everybody has read, as it's of very limited use).