0

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
        }

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.

Any help would be appreciated.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Vahid K.
  • 440
  • 4
  • 14
  • You are not clear - `1` on runtime is "from code while running" or "when the graph is running"? `2` what error code you are getting? – Roman R. Sep 14 '14 at 15:37
  • seems to me the problem is not add/remove filters at runtime, but [to record without stopping preview](http://stackoverflow.com/q/22069432/33499). (short answer, use GMFBridge). – wimh Sep 14 '14 at 18:07
  • Roman, I mean while the graph is running. Wimmel, Thanks. – Vahid K. Sep 15 '14 at 06:59

1 Answers1

3

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.

Longer answer

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# 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).

See also:

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158