3
votes

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

1
The media type looks good, however do you actually have your data in YUY2? Or you still have your data in RGB but you want to push it as YUY2? - Roman R.
i'm converting my currently RGB images to YUY2 (for simulation purposes, until I actually have data in YUY2) - Itsik
Well, it is still not clear what the problem is. What exactly "some issues in the negotiation phase" are? Unable to connect pin, any HRESULTs on the way. What is exactly MEDIATYPE and VIDEOINFOHEADER you are having (code snippet is good but what is the result). - Roman R.
I asked 3 specific questions, you answered q1. Q2 is regarding the AVI Decompressor. Q3 is general about Directshow source filters. - Itsik
3 - No, you're OK with that. 2 - the typical is that VMR requires that you support extended strides for YUY2 in order to make a direct connection, you possibly don't; also there might be still something with media type. - Roman R.

1 Answers

-1
votes

Set it also in GetStreamCaps function