tanvon++

September 27, 2008

Inserting a DMO in the DirectShow Filter Graph

Filed under: DMO, DirectShow, System Device Enumerator — Tags: — tanvon malik @ 10:30 am

DirectX Media Objects (DMO) can be thought as light weight DirectShow filter with limited functionality, But are easier to develop, mostly used for audio video effects.

DMOs can be inserted in a filter graph through a wrapper filter, after DMOs insertion in the filter graph it is treated like a normal filter.

A DMO is a COM object. So wrapping means it is aggregated by the DMO Wrapper Filter.

DMO creation sequence is,

  1. Call CoCreateInstance to create DMO Wrapper Filter.
  2. Query the DMO Wrapper Filter for the IDMOWrapperFilter interface.
  3. Initialize the required DMO with IDMOWrapperFilter::Init.
// Create the DMO Wrapper filter.
IBaseFilter *pFilter;
HRESULT hr = CoCreateInstance(CLSID_DMOWrapperFilter, NULL,
    CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pFilter);

if (SUCCEEDED(hr))
{
    // Query for IDMOWrapperFilter.
    IDMOWrapperFilter *pDmoWrapper;
    hr = pFilter->QueryInterface(IID_IDMOWrapperFilter,
                                                (void**)&pDmoWrapper);

    if (SUCCEEDED(hr))
    {
        // Initialize the filter.
        hr = pDmoWrapper->Init(CLSID_MyDMO, DMOCATEGORY_VIDEO_EFFECT);
        pDmoWrapper->Release();

        if (SUCCEEDED(hr))
        {
            // Add the filter to the graph.
            hr = pGraph->AddFilter(pFilter, L"My DMO");
        }
    }
    pFilter->Release();
}

Inserting DMO in filter graph through System Device Enumerator

The other way to add a DMO in the filter graph is through System Device Enumerator. The System Device Enumerator can be used to enumerate the DMOs in various categories, and through System Device Enumerator it is easy to instantiate a DMO through IMoniker::BindToObject which automatically creates the DMO Wrapper filter and initializes it with the DMO.

Blog at WordPress.com.