i***@gmail.com
2013-03-24 05:30:48 UTC
I am writing a source filter that output yv12 data(704x576 in pixel) to vmr9 directly,
the connection is good when the graph run, but the display is so horrible.
I am wondering how to fill media sample data in SourceStream::FillBuffer(), do I need to scale the yv12 data to the dimension as vmr9 required(1024x576), or I just need to padding it, and if padding is needed, how to do it?
The memory layout of yv12 data that source filter got is like this:
low memory address ........... high memory address
yyyy-yyyy-vv-uu
Does someone knows how to handle this dynamic format change?
I have read this topic:
http://us.generation-nt.com/answer/vmr-9-changes-resolution-during-start-streaming-help-27523272.html
But the author did not point out how did he resolve it.
The media type proposed to vmr9 when it call SourceStream::GetMediaType() is as below:
pmt->SetType(&MEDIATYPE_Video);
pmt->SetSubtype(&MEDIASUBTYPE_YV12);
pmt->SetFormatType(&FORMAT_VideoInfo);
pmt->SetTemporalCompression(FALSE);
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
memset(vih, 0, sizeof(VIDEOINFOHEADER));
vih->AvgTimePerFrame = m_AvgTimePerFrame;
vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
vih->bmiHeader.biWidth = 704;
vih->bmiHeader.biHeight = 576;
vih->bmiHeader.biPlanes = 1;
vih->bmiHeader.biBitCount = 12;
vih->bmiHeader.biCompression = '21VY';
vih->bmiHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth * abs(vih->bmiHeader.biHeight) * vih->bmiHeader.biBitCount >> 3;
pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
The vmr9 proposed its media type when call QueryAccept() on my output pin:
[format change]
WxH = 1024x576
rcSource = {0,0,704,576}
rcTarget = {0,0,704,540}
And the source filter just accept this format change by call SourceStream::CheckMediaType():
if (pmt->majortype == MEDIATYPE_Video
&& pmt->subtype == MEDIASUBTYPE_YV12
&& pmt->formattype == FORMAT_VideoInfo) {
return S_OK;
}
the connection is good when the graph run, but the display is so horrible.
I am wondering how to fill media sample data in SourceStream::FillBuffer(), do I need to scale the yv12 data to the dimension as vmr9 required(1024x576), or I just need to padding it, and if padding is needed, how to do it?
The memory layout of yv12 data that source filter got is like this:
low memory address ........... high memory address
yyyy-yyyy-vv-uu
Does someone knows how to handle this dynamic format change?
I have read this topic:
http://us.generation-nt.com/answer/vmr-9-changes-resolution-during-start-streaming-help-27523272.html
But the author did not point out how did he resolve it.
The media type proposed to vmr9 when it call SourceStream::GetMediaType() is as below:
pmt->SetType(&MEDIATYPE_Video);
pmt->SetSubtype(&MEDIASUBTYPE_YV12);
pmt->SetFormatType(&FORMAT_VideoInfo);
pmt->SetTemporalCompression(FALSE);
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
memset(vih, 0, sizeof(VIDEOINFOHEADER));
vih->AvgTimePerFrame = m_AvgTimePerFrame;
vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
vih->bmiHeader.biWidth = 704;
vih->bmiHeader.biHeight = 576;
vih->bmiHeader.biPlanes = 1;
vih->bmiHeader.biBitCount = 12;
vih->bmiHeader.biCompression = '21VY';
vih->bmiHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth * abs(vih->bmiHeader.biHeight) * vih->bmiHeader.biBitCount >> 3;
pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
The vmr9 proposed its media type when call QueryAccept() on my output pin:
[format change]
WxH = 1024x576
rcSource = {0,0,704,576}
rcTarget = {0,0,704,540}
And the source filter just accept this format change by call SourceStream::CheckMediaType():
if (pmt->majortype == MEDIATYPE_Video
&& pmt->subtype == MEDIASUBTYPE_YV12
&& pmt->formattype == FORMAT_VideoInfo) {
return S_OK;
}