Microsoft DirectX 8.1 (C++) |
In buffering mode, the Sample Grabber stores a copy of every sample that it receives. To retrieve the buffer, call the ISampleGrabber::GetCurrentBuffer method. This method fills an array of bytes allocated by the caller. To determine the required buffer size, call the method with a NULL pointer for the array:
long cbBuffer = 0;
hr = pGrabber->GetCurrentBuffer(&cbBuffer, NULL);
char *pBuffer = new char[cbBuffer];
if (!pBuffer)
{
return E_OUTOFMEMORY;
}
hr = pGrabber->GetCurrentBuffer(&cbBuffer,
reinterpret_cast<long*>(pBuffer));
Use the ISampleGrabber::GetConnectedMediaType method to find the format of the buffer. For example, if the buffer is an uncompressed video frame, the format is defined by a VIDEOINFOHEADER structure. (The Sample Grabber does not support VIDEOINFOHEADER2.)
AM_MEDIA_TYPE mt;
hr = pGrabber->GetConnectedMediaType(mt);
VIDEOINFOHEADER *pVih;
if (mt.formattype == FORMAT_VideoInfo)
pVih = reinterpret_cast<VIDEOINFOHEADER*>(mt.pbFormat);
else
return VFW_E_INVALIDMEDIATYPE; // Something went wrong
// pVih->bmiHeader is the BITMAPINFOHEADER for the frame.
// Free the format block when you are done:
FreeMediaType(mt);