Custom DirectShow Source Filter - Dynamic Resolution Change

萝らか妹 提交于 2019-12-07 17:58:37

问题


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.


回答1:


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.




回答2:


From MSDN Dynamic Format Changes:

  1. 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.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!