Share via


Registrazione ed enumerazione di MFP

Questa sezione descrive come enumerare le trasformazioni di Media Foundation e come registrare un MFT personalizzato in modo che le applicazioni possano individuarla.

Enumerazione delle MFP

Per individuare le MFP registrate nel sistema, un'applicazione può chiamare la funzione MFTEnumEx.

Nota

Questa funzione richiede Windows 7. Prima di Windows 7, le applicazioni devono usare invece la funzione MFTEnum.

 

Questa funzione accetta le informazioni seguenti come input:

  • Categoria di MFT da enumerare, ad esempio decodificatore video o decodificatore audio.
  • Formato di input o output corrispondente.
  • Flag che specificano condizioni di ricerca aggiuntive.

La funzione restituisce una matrice di puntatori IMFActivate , ognuno dei quali rappresenta un MFT che corrisponde ai criteri di enumerazione.

Ad esempio, il codice seguente enumera i decodificatori Di Windows Media Video:

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

Per impostazione predefinita, alcuni tipi di MFT vengono esclusi dall'enumerazione, tra cui MGT asincrone, MGT hardware e MFT con restrizioni sul campo d'uso. Questi sono esclusi perché tutti richiedono una gestione speciale di qualche tipo. Usare il parametro Flags di MFTEnumEx per modificare il valore predefinito. Ad esempio, per includere le MFP hardware nei risultati dell'enumerazione, impostare il flag di MFT_ENUM_FLAG_HARDWARE :

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

Registrazione di MFP

Quando si registra una trasformazione Media Foundation (MFT), vengono scritti due tipi di informazioni nel Registro di sistema:

  • CLSID di MFT, in modo che i client possano chiamare CoCreateInstance o CoGetClassObject per creare un'istanza di MFT. Questa voce del Registro di sistema segue il formato standard per le class factory COM. Per altre informazioni, vedere la documentazione di Windows SDK per Component Object Model (COM).
  • Informazioni che consentono a un'applicazione di enumerare le MFP per categoria funzionale.

Per creare le voci di enumerazione MFT nel Registro di sistema, chiamare la funzione MFTRegister. È possibile includere le informazioni seguenti su MFT:

  • Categoria del MFT, ad esempio decodificatore video o codificatore video. Per un elenco di categorie, vedere MFT_CATEGORY.
  • Elenco di formati di input e output supportati da MFT. Ogni formato è definito da un tipo principale e da un sottotipo. Per ottenere informazioni di formato più dettagliate, il client deve creare MFT e chiamare Metodi IMFTransform . Il caricatore della topologia usa queste informazioni quando risolve una topologia parziale.

Per rimuovere le voci dal Registro di sistema, chiamare MFTUnregister.

Il codice seguente illustra come registrare un MFT. In questo esempio si presuppone che MFT sia un effetto video che supporti gli stessi formati sia per l'input che per l'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;
}

Campo delle restrizioni per l'utilizzo

Trasformazioni di Media Foundation