How can I reverse engineer a DirectShow graph?

2019-01-04 13:54发布

I have a DirectShow graph to render MPEG2/4 movies from a network stream. When I assemble the graph by connecting the pins manually it doesn't render. But when I call Render on the GraphBuilder it renders fine.

Obviously there is some setup step that I'm not performing on some filter in the graph that GraphBuilder is performing.

Is there any way to see debug output from GraphBuilder when it assembles a graph?

Is there a way to dump a working graph to see how it was put together?

Any other ideas for unraveling the mystery that lives in the DirectShow box?

Thanks! -Z

7条回答
放我归山
2楼-- · 2019-01-04 14:16

IGraphBuilder::SetLogFile (see http://msdn.microsoft.com/en-us/library/dd390091(v=vs.85).aspx) will give you lots of useful diagnostic information about what happens during graph building. Pass in a file handle (e.g. opened by CreateFile) and cast it to a DWORD_PTR. Call again with NULL to finish logging before you close the file handle.

The code in the following blog post for dumping a graph will give you some extra information to interpret the numbers in the log file.

http://rxwen.blogspot.com/2010/04/directshow-debugging-tips.html

查看更多
Anthone
3楼-- · 2019-01-04 14:19

You need to:

  1. Register you filter graph to the "Running Objects Table" - ROT - Using the code below
  2. Connect to your filter graph using GraphEdit (File->Connect to Remote Graph) or even better - With GraphEditPlus

To register your filter graph as a "connectable" graph, call this with your filter graph:

void AddToROT( IUnknown *pUnkGraph, DWORD *pdwRegister ) 
{
    IMoniker * pMoniker;
    IRunningObjectTable *pROT;
    WCHAR wsz[128];
    HRESULT hr;

    if (FAILED(GetRunningObjectTable(0, &pROT)))
        return;

    wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph, GetCurrentProcessId());

    hr = CreateItemMoniker(L"!", wsz, &pMoniker);
    if (SUCCEEDED(hr)) 
    {
        hr = pROT->Register(0, pUnkGraph, pMoniker, pdwRegister);
        pMoniker->Release();
    }

    pROT->Release();
}

And call this before you release the graph:

void RemoveFromROT(DWORD pdwRegister)
{
    IRunningObjectTable *pROT;

    if (SUCCEEDED(GetRunningObjectTable(0, &pROT))) 
    {
        pROT->Revoke(pdwRegister);
        pROT->Release();
    }
}

`

查看更多
Anthone
4楼-- · 2019-01-04 14:23
够拽才男人
5楼-- · 2019-01-04 14:25

You could "save" the graph (serialize it) to a .grf graphedit file, possibly: https://stackoverflow.com/a/10612735/32453

Also it appears that graphedit can "remote attach" to a running graph? http://rxwen.blogspot.com/2010/04/directshow-debugging-tips.html

查看更多
别忘想泡老子
6楼-- · 2019-01-04 14:32

Older versions of DirectX, I belive 9a, but not 9b had a "debug mode" for dshow. It would output logs of debug info into the debug console.

So download an older version, set it to debug. then open up debugview or load graphedt.exe in visual studio to see the debug info.

查看更多
够拽才男人
7楼-- · 2019-01-04 14:34

You can watch the graph you created using GraphEdit, a tool from the DirectShow SDK. In GraphEdit, select File->Connect to remote Graph...

In order to find your graph in the list, you have to register it in the running object table:

void AddToRot( IUnknown *pUnkGraph, DWORD *pdwRegister ) 
{
    IMoniker* pMoniker;
    IRunningObjectTable* pROT;
    GetRunningObjectTable( 0, &pROT );

    WCHAR wsz[256];     
    swprintf_s( wsz, L"FilterGraph %08p pid %08x", (DWORD_PTR)pUnkGraph, GetCurrentProcessId() );
    CreateItemMoniker( L"!", wsz, &pMoniker );

    pROT->Register( 0, pUnkGraph, pMoniker, pdwRegister );

    // Clean up any COM stuff here ...
}

After destroying your graph, you should remove it from the ROT by calling IRunningObjectTable::Revoke

查看更多
登录 后发表回答