How can I reverse engineer a DirectShow graph?

£可爱£侵袭症+ 提交于 2019-12-17 04:09:53

问题


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


回答1:


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




回答2:


Roman Ryltsov has created a DirectShow Filter Graph Spy tool (http://alax.info/blog/777), a wrapper COM dll over the FilterGraph interface, which logs all the calls to FilterGraph methods.

Also it will add all the created graphs into Running Object Table (ROT) which you can then visualize using tools like GraphEdit or GraphStudio. Very useful when you need to see how a Windows Media Player graph looks like.




回答3:


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




回答4:


There is a detailed MSDN entry on this. http://msdn.microsoft.com/en-us/library/windows/desktop/dd390650(v=vs.85).aspx




回答5:


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();
    }
}

`




回答6:


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:


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



来源:https://stackoverflow.com/questions/27832/how-can-i-reverse-engineer-a-directshow-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!