DirectShow - About the Capture Graph Builder

原文:http://msdn.microsoft.com/en-us/library/ms778829(v=vs.85).aspx

A filter graph that performs video or audio capture is called a capture graph. Capture graphs are often more complicated than file playback graphs. To make it easier for applications to build capture graphs, DirectShow provides a helper object called the Capture Graph Builder. The Capture Graph Builder exposes the ICaptureGraphBuilder2 interface, which contains methods for building and controlling a capture graph.

一个能够抓取video或者audio的filter graph就称为capture graph。 capture graphs 比 file playback graphs 要复杂。为了使程序创建起来更简单,DirectShow 提供了Capture Graph Builder 。Capture Graph Builder 提供 ICaptureGraphBuilder2  接口,里面包含创建和控制 capture graph 的方法。

DirectShow - About the Capture Graph Builder_第1张图片

Start by calling CoCreateInstance to create new instances of the Capture Graph Builder and the Filter Graph Manager. Then initialize the Capture Graph Builder by calling ICaptureGraphBuilder2::SetFiltergraph with a pointer to the Filter Graph Manager's IGraphBuilder interface.
用 CoCreateInstance  来创建  Capture Graph Builder 和  Filter Graph Manager 的实例,然后使用 ICaptureGraphBuilder2::SetFiltergraph 将 Capture Graph Builder 初始化。

DirectShow - About the Capture Graph Builder_第2张图片

The following code shows a helper function to perform these steps:
下面的代码演示了这个创建并初始化过程:

HRESULT InitCaptureGraphBuilder(
  IGraphBuilder **ppGraph,  // Receives the pointer.
  ICaptureGraphBuilder2 **ppBuild  // Receives the pointer.
)
{
    if (!ppGraph || !ppBuild)
    {
        return E_POINTER;
    }
    IGraphBuilder *pGraph = NULL;
    ICaptureGraphBuilder2 *pBuild = NULL;

    // Create the Capture Graph Builder.
    HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, 
        CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pBuild );
    if (SUCCEEDED(hr))
    {
        // Create the Filter Graph Manager.
        hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,
            IID_IGraphBuilder, (void**)&pGraph);
        if (SUCCEEDED(hr))
        {
            // Initialize the Capture Graph Builder.
            pBuild->SetFiltergraph(pGraph);

            // Return both interface pointers to the caller.
            *ppBuild = pBuild;
            *ppGraph = pGraph; // The caller must release both interfaces.
            return S_OK;
        }
        else
        {
            pBuild->Release();
        }
    }
    return hr; // Failed
}

你可能感兴趣的:(windows,VS2010,Studio,Visual,2010,directshow)