如何在运行时添加/删除一些过滤器以图形化? [英] How to add/remove some filters to graph at runtime?

查看:96
本文介绍了如何在运行时添加/删除一些过滤器以图形化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时将Compressor,Avi Muxer和File Writer添加到我的图形中。
我已经在图中添加了一个InfTee,如下所示:

I want to add Compressor, Avi Muxer, and File Writer to my graph, at runtime. I`ve added an InfTee to my graph like this:

            IBaseFilter sourceTee = (IBaseFilter)new InfTee();
            graphBuilder.AddFilter(sourceTee, "Infinite Tee");
            outPin = DsFindPin.ByDirection(theVideoDevice, PinDirection.Output, 0);
            inPin = DsFindPin.ByDirection(sourceTee, PinDirection.Input, 0);
            hr = graphBuilder.Connect(outPin, inPin); 

但是当我尝试在按钮上获取输出时,如下面的代码所示,出现错误。

But when I try to get output on a button click like the below code, I get an error.

    private void button1_Click(object sender, EventArgs e)
    {

        IPin outPin, inPin;
        int hr;


        // Connect To Compressor
        outPin = DsFindPin.ByDirection(Preview_Class.smartTeeFilter, PinDirection.Output ,1);
        inPin = DsFindPin.ByDirection(Preview_Class.theVideoCompressor, PinDirection.Input, 0);
        hr = Preview_Class.graphBuilder.Connect(outPin, inPin);
        DsError.ThrowExceptionForHR(hr);
        // etc
        }

我必须注意我得到了输出在预览时将我的视频渲染器固定为0,但是我想通过单击按钮来添加录制功能。

I must note that I am getting an output pin 0 for my video renderer at preview time, but I want to add recording feature by clicking a button.

任何帮助将不胜感激。

推荐答案

简短答案



运行过滤器图时,无法添加/删除过滤器,无法连接/断开引脚。无法执行此操作的原因在于,这些操作假定过滤器处于停止状态,而过滤器图形状态转换假定该图中的所有过滤器都随图形本身更改状态。

Short answer

When filter graph is running, you cannot add/remove filters, you cannot connect/disconnect pins. The reason behind your inability to do it, is that the actions assume stopped state of the filters, and filter graph state transitions assume that all filters in the graph change state with the graph itself.

MSDN / DirectShow在使用动态重新连接方法。虽然算法定义得很好,但是股票过滤器和第三方过滤器很少实现它。也就是说,DirectShow的整个部分向开发人员提供了一个提示:如果您渴望的话,如何在自己的过滤器中自己实现。

MSDN/DirectShow adds flexibility of changing topology while running using Dynamic Reconnection approach. While the algorithm is defined pretty well, stock filters and third party filters rarely implement it. That is, this entire section of DirectShow is more a hint to developers "how you can implement it yourself in your own filter if you long for that".

C#代码是DirectShow技术的使用者,并处理事实可用的内容,而不是动态重新连接。一种典型的方法是桥接(请参见上面的Wimmel的评论,并搜索论坛-它是

C# code is the consumer of DirectShow technology and deals with what is de facto available, and it is not the dynamic reconnection. A typical approach would be bridging (see Wimmel's comment above, and search the forum - it is mentioned many times).

另请参见:

  • Reconnect Directshow Filter Pin
  • Directshow continious capture
  • GMFBridge usage in DirectShow

这篇关于如何在运行时添加/删除一些过滤器以图形化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆