lathajee

Could somebody help me in understanding ,How the filter state transition done

I read filter state transitions done in upstream order. Starting from renderer to source filter.

Initially graph will be in which state Paused

i have Source filter->Transform Filter-> Renderer

In graphedit when we run the graph, the filter graph manager will dispatch Run to all filters in the graph simultaneously

I have overrided Run method in Transform Filter, just to give some pop up.

Source filter has sent the media sample and delivered it to transform filter's input pin after this Run method has called.

I expected source filter's and transform filter's Run methods will be called at the same time.But it's not.

How the filter graph manager does dispatching states



Re: DirectShow Development Filter States

Chris P.

The Filter Graph manager notifies the filters in reverse starting with the renderer as you mentioned. The process is sequential and syncronous and if any of the filters reject the state change the graph will not run. The reason for doing things backwards is to make sure that no samples will be delivered by the source filter until the state change has completed.

The inital state of the graph after creation is stopped. On "run" the graph is first transistioned to a "paused" state before going to run. Most filters should treat paused and run as the same as samples are allowed to flow in the paused state to the limit that the renderer allows.

The actual notification occurs via the IMediaFilter interface, the graph manager gets this interface from each filter and calls Run(), Pause() or Stop(). The CBaseFilter translates this into a call to Active() or Inactive() for each pin.




Re: DirectShow Development Filter States

Thore Karlsen

In addition to what Chris said, there's some more information in the MSDN:

http://msdn2.microsoft.com/en-us/library/ms783675.aspx





Re: DirectShow Development Filter States

lathajee

Is this state transition done in different thread than the usual flow of data

so, at the state transition the thread which takes care of the data flow and the thread responsible for state transition will be running simultaneously or that time only one thread is running





Re: DirectShow Development Filter States

Thore Karlsen

Once the graph is started there will be a separate thread (or multiple threads depending on the filters in the graph) that handle the streaming data. Here is more information:

http://msdn2.microsoft.com/en-us/library/ms787724.aspx





Re: DirectShow Development Filter States

lathajee

Thanks for the replies.

I am still facing problem with the filter's Run State.

file source -> Splitter -> My Filter -> Decoder ->Renderer

This is the snapshot of the graph. I have overwritten my filter's RUN method. I Just clicked Run on the graphedt.

The Filter's RUN method is not at all executing. It's going only to input pin's receive method.

But I want my filter's Run method is to be called before the receive method. How can I do this

Why the state of filter is not changing

In the Run method, I am just popping up one message and calling CBaseFilter's Run method.

So I thought to manually check the filter state in the receive method, if it is not in running state, i called filter's run method. In this case Run method was executing twice.

Your help is much appreciated.

Thanks!!





Re: DirectShow Development Filter States

Thore Karlsen

Your Run() method shouldn't have to be called before Receive(). When you call Run() on the filter graph, the filter will go through the paused state before it goes to the running state. While the filters are in the paused state they can receive samples. Perhaps you should consider putting your code in Pause() instead of Run().





Re: DirectShow Development Filter States

lathajee

I want to put some code such that It should be called only one time that to when I press Run button in the graphedt, If I put it in Pause whenever state change happens it will be executed, I dont want this behaviour.





Re: DirectShow Development Filter States

Thore Karlsen

Then put the code in a separate method in your filter and call that method from Run() and from Receive(). You shouldn't call Run() from Receive().





Re: DirectShow Development Filter States

Thore Karlsen

By the way, if you just pause the graph that code will be called anyway, because Receive() will be called even in the paused state.





Re: DirectShow Development Filter States

Chris P.

For transform filters your usually best of using Active() and Inactive() as Stop() and Run() already have default handlers and overriding the default handlers may have undesirable behaviour unless you reimplement the base class behaviour.






Re: DirectShow Development Filter States

Thore Karlsen

Active()/Inactive() is what I typically use. I guess it should be pointed out that Active() is called when the filter is paused, not only when it's run. By the way it's easy enough to override Run() and Stop() and just call the base class implementation before you do any of your own initialization. There's no need to copy/paste code unless there's some fundamental change.





Re: DirectShow Development Filter States

lathajee

Are you talking about active()/Inactive() of Pin's

Thore, I had problem by putting in Run()itsef, It's not at all called

my Receive &Run method data flow is as follow

Receive()

{

if ( filter is in runnig state)

{

WaitforsingleObject()

CBasePin::Receive();

Deliver()

}

else

{

Deliver some dummy data

}
}

Run()

{

MyFun(); ///My own function

CBaseFilter::Run()
}

This is the case. When I click Run,I am always going to else part of Receive method. That's it. No Run method execution





Re: DirectShow Development Filter States

Thore Karlsen

Is Receive() called multiple times I would expect Receive() to be called before Run(), but Run() should be called right after the first Receive().





Re: DirectShow Development Filter States

lathajee

Yes, Receive() called multiple times. Even I did expect Run after first receive().