Registering and Enumerating MFTs

This section describes how to enumerate Media Foundation transforms, and how to register a custom MFT so that applications can discover it.

Enumerating MFTs

To discover MFTs that are registered on the system, an application can call the MFTEnumEx function.

Note

This function requires to Windows 7. Prior to Windows 7, applications should use the MFTEnum function instead.

 

This function takes the following information as input:

  • The category of MFT to enumerate, such as video decoder or audio decoder.
  • An input or output format to match.
  • Flags that specify additional search conditions.

The function returns an array of IMFActivate pointers, each of which represents an MFT that matches the enumeration criteria.

For example, the following code enumerates Windows Media Video decoders:

HRESULT hr = S_OK;
UINT32 count = 0;

IMFActivate **ppActivate = NULL;    // Array of activation objects.
IMFTransform *pDecoder = NULL;      // Pointer to the decoder.

// Match WMV3 video.
MFT_REGISTER_TYPE_INFO info = { MFMediaType_Video, MFVideoFormat_WMV3 };

UINT32 unFlags = MFT_ENUM_FLAG_SYNCMFT  | 
                 MFT_ENUM_FLAG_LOCALMFT | 
                 MFT_ENUM_FLAG_SORTANDFILTER;

hr = MFTEnumEx(
    MFT_CATEGORY_VIDEO_DECODER,
    unFlags,
    &info,      // Input type
    NULL,       // Output type
    &ppActivate,
    &count
    );


if (SUCCEEDED(hr) && count == 0)
{
    hr = MF_E_TOPO_CODEC_NOT_FOUND;
}

// Create the first decoder in the list.

if (SUCCEEDED(hr))
{
    hr = ppActivate[0]->ActivateObject(IID_PPV_ARGS(&pDecoder));
}

for (UINT32 i = 0; i < count; i++)
{
    ppActivate[i]->Release();
}
CoTaskMemFree(ppActivate);

By default, some types of MFT are excluded from the enumeration, including asynchronous MFTs, hardware MFTs, and MFTs with field-of-use restrictions. These are excluded because they all require special handling of some kind. Use the Flags parameter of MFTEnumEx to change the default. For example, to include hardware MFTs in the enumeration results, set the MFT_ENUM_FLAG_HARDWARE flag:

UINT32 unFlags = MFT_ENUM_FLAG_HARDWARE |
                 MFT_ENUM_FLAG_SYNCMFT  | 
                 MFT_ENUM_FLAG_LOCALMFT | 
                 MFT_ENUM_FLAG_SORTANDFILTER;
hr = MFTEnumEx(
    MFT_CATEGORY_VIDEO_DECODER,
    unFlags,
    &info,      // Input type
    NULL,       // Output type
    &ppActivate,
    &count
    );

Registering MFTs

When you register a Media Foundation transform (MFT), two types of information are written to the registry:

  • The CLSID of the MFT, so that clients can call CoCreateInstance or CoGetClassObject to create an instance of the MFT. This registry entry follows the standard format for COM class factories. For more information, see the Windows SDK documentation for the Component Object Model (COM).
  • Information that enables an application to enumerate MFTs by functional category.

To create the MFT enumeration entries in the registry, call the MFTRegister function. You can include the following information about the MFT:

  • The category of the MFT, such as video decoder or video encoder. For a list of categories, see MFT_CATEGORY.
  • A list of input and output formats that the MFT supports. Each format is defined by a major type and a subtype. (To get more detailed format information, the client must create the MFT and call IMFTransform methods.) The topology loader uses this information when it resolves a partial topology.

To remove the entries from the registry, call MFTUnregister.

The following code shows how to register an MFT. This example assumes that the MFT is a video effect that supports the same formats for both input and output.

// CLSID of the MFT.
extern const GUID CLSID_MyVideoEffectMFT;

// DllRegisterServer: Creates the registry entries.
STDAPI DllRegisterServer()
{
    HRESULT hr = S_OK;

    // Array of media types.
    MFT_REGISTER_TYPE_INFO aMediaTypes[] =
    {
        {   MFMediaType_Video, MFVideoFormat_NV12 },
        {   MFMediaType_Video, MFVideoFormat_YUY2 },
        {   MFMediaType_Video, MFVideoFormat_UYVY },
    };

    // Size of the array.
    const DWORD cNumMediaTypes = ARRAY_SIZE(aMediaTypes);

    hr = MFTRegister(
        CLSID_MyVideoEffectMFT,     // CLSID.
        MFT_CATEGORY_VIDEO_EFFECT,  // Category.
        L"My Video Effect",         // Friendly name.
        0,                          // Reserved, must be zero.
        cNumMediaTypes,             // Number of input types.
        aMediaTypes,                // Input types.
        cNumMediaTypes,             // Number of output types.
        aMediaTypes,                // Output types.
        NULL                        // Attributes (optional).
        );

    if (SUCCEEDED(hr))
    {
        // Register the CLSID for CoCreateInstance (not shown).
    }
    return hr;
}

// DllUnregisterServer: Removes the registry entries.
STDAPI DllUnregisterServer()
{
    HRESULT hr = MFTUnregister(CLSID_MyVideoEffectMFT);

    // Unregister the CLSID for CoCreateInstance (not shown).

    return hr;
}

Field of Use Restrictions

Media Foundation Transforms