I have written a custom directshow filter which read's images and outputs them as RGB. This currently works fine.
I want to add the option of outputting in YUV. I'm still having some issues in the negotiation phase. IMO the explanations on the specific functions of DirectShow is just horrible, especially for source filters.
From my understanding, I propose which media types I support with GetMediaType(). Afterwards, when a specific type is chosen, CheckMediaType() validates the negotiated media type.
With this logic, I updated GetMediaType() to return a YUV media type. I couldn't find examples of how to create a yuv media type and ended up using the pushsource RGB example with some changes.
HRESULT CreateYUVVideoType(CMediaType *pMediaType, long Width, long Height, double Fps)
{
if (Width < 0)
{
return E_INVALIDARG;
}
FreeMediaType(*pMediaType);
VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));
if (pvi == 0)
{
return(E_OUTOFMEMORY);
}
ZeroMemory(pvi, sizeof(VIDEOINFO));
pvi->AvgTimePerFrame = Fps2FrameLength(Fps);
BITMAPINFOHEADER *pBmi = &(pvi->bmiHeader);
pBmi->biSize = sizeof(BITMAPINFOHEADER);
pBmi->biWidth = Width;
pBmi->biHeight = Height;
pBmi->biPlanes = 1;
pBmi->biBitCount = 16;
pBmi->biCompression = MAKEFOURCC('Y','U','Y','2');
pMediaType->SetSubtype(&MEDIASUBTYPE_YUY2);
pvi->bmiHeader.biSizeImage = DIBSIZE(pvi->bmiHeader);
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
return S_OK;
}
1) Is this the correct way to create a YUV (4:2:2) media type?
2) Also, when I render the pin, it connects the VMR with an AVI Decompressor in between? Why ?
3) Do I need to override any other functions besides GetMediaType and CheckMediaType in order to support multiple output media types?
Thanks