views:

65

answers:

2

I'm messing around with the PushSource sample filter shipped with the DirectShow SDK and I'm having the following problem:

When I call IMediaControl::Run(), it returns S_FALSE which means "the graph is preparing to run, but some filters have not completed the transition to a running state". MSDN suggests to then call IMediaControl::GetState() and wait for the transition to finish.

And so, I call IMediaControl::GetState(INFINITE, ...) which is supposed to solve the problem.

However, to the contrary, it returns VFW_S_STATE_INTERMEDIATE even though I've specified an infinite waiting time.

I've tried all three variations (Bitmap, Bitmap Set and Desktop) and they all behave the same way, which initially lead me to believe there is a bug in there somewhere.

However, then, I tried using IFilterGraph::AddSourceFilter to do the same and it did the same thing, which must mean it's my rendering code that is the problem:

CoInitialize(0);

IGraphBuilder *graph = 0;
assert(S_OK == CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&graph));

IBaseFilter *pushSource = 0;
graph->AddSourceFilter(L"sample.bmp", L"Source", &pushSource);

IPin *srcOut = 0;
assert(S_OK == GetPin(pushSource, PINDIR_OUTPUT, &srcOut));
graph->Render(srcOut);



IMediaControl *c = 0;
IMediaEvent   *pEvent;
assert(S_OK == graph->QueryInterface(IID_IMediaControl, (void**)&c));
assert(S_OK == graph->QueryInterface(IID_IMediaEvent, (void**)&pEvent));

HRESULT hr = c->Run();
if(hr != S_OK)
{
    if(hr == S_FALSE)
    {
        OAFilterState state;
        hr = c->GetState(INFINITE, &state);

        assert(hr == S_OK );
    }

}

long code;
assert(S_OK == pEvent->WaitForCompletion(INFINITE, &code));

Anyone knows how to fix this?

A: 
IBaseFilter *pushSource = 0;
graph->AddSourceFilter(L"sample.bmp", L"Source", &pushSource);

AddSourceFilter adds a default source filter, I don't think it will add your pushsource samplefilter.

I would recommend to add the graph to the ROT, so you can inspect it with graphedit.

And what happens if you don't call GetState()?

hr = pMediaControl->Run();
if(FAILED(hr)) {
    /// handle error
}

long evCode=0;
while (evCode == 0) 
{
    pEvent->WaitForCompletion(1000, &evCode);
    /// other code
}
Wimmel
A: 

Open GraphEditPlus, add your filter, render its pin and press Run. Then you'll see states of each filter separately, so you'll see what filter didn't run and why.

Dee Mon