I've asked a very similar question before for a video renderer filter.
See here: Custom DirectShow Video Renderer Filter - Dynamic Resolution Change
But this time, I need a solution for a source filter. This source filter connects directly to the video renderer. Decoder is embedded.
I'm able to get the resolution changes from the stream. I also resize the buffers when I get a new resolution. But I don't know how to notify my new resolution through the pin. Should I somehow create an instance from CMediaType
, fill in the new values and call pin's SetMediaType()
method or what is the proper solution? I'm currently doing this.
if(nWidth * nHeight * 3 != reader->m_RGB24BufferSize) { // if resolution changed
reader->m_RGB24BufferSize = nWidth * nHeight * 3;
reader->m_RGB24Buffer = (BYTE*)malloc(reader->m_RGB24BufferSize);
reader->m_pin->m_bmpInfo.biWidth = nWidth;
reader->m_pin->m_bmpInfo.biHeight = nHeight;
reader->m_pin->m_bmpInfo.biSizeImage = GetBitmapSize(&reader->m_pin->m_bmpInfo);
// Now what? How to notify the video renderer?
}
m_pin
is the only output pin of the source filter here which is declared like;
class MyPin : public CSourceStream { ... };
I know the answer should be simple and there should be many examples around but since I'm a little bit confused about these subjects, I prefer a nice explanation besides the example.
You can have output pin derived from CDynamicOutputPin
and perform the following when you need to send notification downstream (to the renderer) about the format change:
hr = StartUsingOutputPin();
if (SUCCEEDED(hr))
{
hr = ChangeMediaType(&m_mt);
StopUsingOutputPin();
}
There is an implementation of CDynamicSourceStream
and matching CDynamicSource
in DirectShow samples from Windows SDK that you may find helpful.
From MSDN Dynamic Format Changes:
QueryAccept (Downstream) is used when If an output pin proposes a format change to its downstream peer, but only if the new format does not require a larger buffer.
ReceiveConnection is used when an output pin proposes a format change to its downstream peer, and the new format requires a larger buffer.
Did you have a chance to try any of these two?
来源:https://stackoverflow.com/questions/8805705/custom-directshow-source-filter-dynamic-resolution-change