Heap Corruption, Creating Push Source Filter to read YUV Frame

Heap Corruption, Creating Push Source Filter to read YUV Frame

Post by nathanfros » Sun, 22 Jun 2008 08:47:13


Hello,
I have been working with the PushSource example from the sdk. I
modified the code to read a YV12 frame instead of a BMP. Most of my
modifications have been in the GetMediaType function. I am able to
insert the filter into GraphEdit, but when I render the pin I get this
error in VS2005:

"Windows has triggered a breakpoint in graphedt.exe.
This may be due to a corruption of the heap, and indicates a bug in
graphedt.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information"

I am unable to track where this happens but it is after
CEnumMediaTypes::Next returns.

I have been working with DirectShow for about a week now. I am trying
to make a viewer that reads raw yuv formats. If you have any
suggestions on how to do this I would appreciate that.

Thank you very much,
Nate

Windows XP SP2
MICROSOFT PLATFORM SOFTWARE DEVELOPMENT KIT FOR MICROSOFT WINDOWS
SERVER 2003 SERVICE PACK 1
Microsoft DirectX SDK (March 2008)
VisualStudio2005

code:
HRESULT CPushPinBitmap::GetMediaType(CMediaType *pMediaType)
{
CAutoLock cAutoLock(m_pFilter->pStateLock());

CheckPointer(pMediaType, E_POINTER);

// If the bitmap file was not loaded, just fail here.
if (!m_pImage)
return E_FAIL;

// Allocate enough room for the VIDEOINFOHEADER and the color
tables
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER*)pMediaType-
if (pvi == 0)
return(E_OUTOFMEMORY);

ZeroMemory(pvi, pMediaType->cbFormat);
pvi->AvgTimePerFrame = m_rtFrameLength;

// Copy the header info
memcpy(&(pvi->bmiHeader), m_pBmi, m_cbBitmapInfo);
pvi->bmiHeader.biWidth = FRAMEWIDTH;
pvi->bmiHeader.biHeight = FRAMEHEIGHT;
pvi->bmiHeader.biPlanes = 1;
pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
pvi->bmiHeader.biBitCount = 16;
pvi->bmiHeader.biSizeImage = FRAMESIZE;
pvi->bmiHeader.biXPel *** eter = FRAMEWIDTH;
pvi->bmiHeader.biYPel *** eter = FRAMEHEIGHT;
pvi->bmiHeader.biClrImportant = 0;
pvi->bmiHeader.biClrUsed = 0;
pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); ;



// Set image size for use in FillBuffer
// pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader);

// Clear source and target rectangles
SetRectEmpty(&(pvi->rcSource)); // we want the whole image area
rendered
SetRectEmpty(&(pvi->rcTarget)); // no particular destination
rectangle

pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
//pMediaType->SetFormat((BYTE*)pvi, sizeof(pvi));
pMediaType->SetTemporalCompression(FALSE);

// Work out the GUID for the subtype from the header info.
//const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&MEDIASUBTYPE_YV12);

//FRAME SIZE SET HERE I think
pMediaType->SetSampleSize(FRAMESIZE);

return S_OK;
}
 
 
 

Heap Corruption, Creating Push Source Filter to read YUV Frame

Post by TWlrZSBXYX » Wed, 25 Jun 2008 04:27:03


This doesn't allocate enough room for the VIDEOINFOHEADER structure.
SIZE_PREHEADER is only the first 48 bytes of the structure. You want:

VIDEOINFOHEADER *pvi =
(VIDEOINFOHEADER*)pMediaType->AllocFormatBuffer(VIDEOINFOHEADER);

- Mike