Création de nœuds de transformation

Un nœud de transformation représente une transformation Media Foundation (MFT), telle qu’un décodeur ou un encodeur. Il existe plusieurs façons d’initialiser un nœud de transformation :

  • À partir d’un pointeur vers le MFT.
  • À partir d’un CLSID pour MFT.
  • À partir d’un pointeur vers un objet d’activation pour MFT.

Si vous envisagez de charger la topologie à l’intérieur du chemin d’accès multimédia protégé (PMP), vous devez utiliser le CLSID ou un objet d’activation, afin que le MFT puisse être créé à l’intérieur du processus protégé. La première approche (à l’aide d’un pointeur vers le MFT) ne fonctionne pas avec le PMP.

Création d’un nœud de transformation à partir d’un MFT

Pour créer un nœud de transformation à partir d’un MFT, procédez comme suit :

  1. Créez un instance du MFT et obtenez un pointeur vers l’interface IMFTransform de MFT.
  2. Appelez MFCreateTopologyNode avec l’indicateur MF_TOPOLOGY_TRANSFORM_NODE pour créer le nœud de transformation.
  3. Appelez IMFTopologyNode::SetObject et passez le pointeur IMFTransform .
  4. Appelez IMFTopology::AddNode pour ajouter le nœud à la topologie.

L’exemple suivant crée et initialise un nœud de transformation à partir d’un MFT.

HRESULT AddTransformNode(
    IMFTopology *pTopology,     // Topology.
    IMFTransform *pMFT,         // MFT.
    IMFTopologyNode **ppNode    // Receives the node pointer.
    )
{
    *ppNode = NULL;

    IMFTopologyNode *pNode = NULL;
    
    // Create the node.
    HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &pNode);

    // Set the object pointer.
    if (SUCCEEDED(hr))
    {
        hr = pNode->SetObject(pMFT);
    }

    // Add the node to the topology.
    if (SUCCEEDED(hr))
    {
        hr = pTopology->AddNode(pNode);
    }

    // Return the pointer to the caller.
    if (SUCCEEDED(hr))
    {
        *ppNode = pNode;
        (*ppNode)->AddRef();
    }

    SafeRelease(&pNode);
    return hr;
}

Création d’un nœud de transformation à partir d’un CLSID

Pour créer un nœud de transformation à partir d’un CLSID, procédez comme suit :

  1. Recherchez le CLSID du MFT. Vous pouvez utiliser la fonction MFTEnum pour rechercher les CLSID des MFT par catégorie, tels que les décodeurs ou les encodeurs. Vous pouvez également connaître le CLSID d’un MFT particulier que vous souhaitez utiliser (par exemple, si vous avez implémenté votre propre MFT personnalisé).
  2. Appelez MFCreateTopologyNode avec l’indicateur MF_TOPOLOGY_TRANSFORM_NODE pour créer le nœud de transformation.
  3. Définissez l’attribut MF_TOPONODE_TRANSFORM_OBJECTID sur le nœud. La valeur de l’attribut est le CLSID.
  4. Appelez IMFTopology::AddNode pour ajouter le nœud à la topologie.

L’exemple suivant crée et initialise un nœud de transformation à partir d’un CLSID.

HRESULT AddTransformNode(
    IMFTopology *pTopology,     // Topology.
    const CLSID& clsid,         // CLSID of the MFT.
    IMFTopologyNode **ppNode    // Receives the node pointer.
    )
{
    *ppNode = NULL;

    IMFTopologyNode *pNode = NULL;
    
    // Create the node.
    HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &pNode);

    // Set the CLSID attribute.

    if (SUCCEEDED(hr))
    {
        hr = pNode->SetGUID(MF_TOPONODE_TRANSFORM_OBJECTID, clsid);
    }

    // Add the node to the topology.
    if (SUCCEEDED(hr))
    {
        hr = pTopology->AddNode(pNode);
    }

    // Return the pointer to the caller.
    if (SUCCEEDED(hr))
    {
        *ppNode = pNode;
        (*ppNode)->AddRef();
    }

    SafeRelease(&pNode);
    return hr;
}

Création d’un nœud de transformation à partir d’un objet d’activation

Certains MFT fournissent des objets d’activation. Par exemple, la fonction MFCreateWMAEncoderActivate retourne un objet d’activation pour l’encodeur Windows Media Audio (WMA). La fonction exacte dépend de la MFT. Toutes les MFT ne fournissent pas d’objet d’activation. Pour plus d’informations, consultez Activation Objects.

Vous pouvez également obtenir un objet d’activation MFT en appelant la fonction MFTEnumEx .

Pour créer un nœud de transformation à partir d’un objet d’activation, procédez comme suit :

  1. Créez l’objet d’activation et obtenez un pointeur vers l’interface IMFActivate de l’objet d’activation.
  2. Appelez MFCreateTopologyNode avec l’indicateur MF_TOPOLOGY_TRANSFORM_NODE pour créer le nœud de transformation.
  3. Appelez IMFTopologyNode::SetObject et passez le pointeur IMFActivate .
  4. Appelez IMFTopology::AddNode pour ajouter le nœud à la topologie.

L’exemple suivant crée et initialise un nœud de transformation à partir d’un objet d’activation.

HRESULT AddTransformNode(
    IMFTopology *pTopology,     // Topology.
    IMFActivate *pActivate,     // MFT activation object.
    IMFTopologyNode **ppNode    // Receives the node pointer.
    )
{
    *ppNode = NULL;

    IMFTopologyNode *pNode = NULL;
    
    // Create the node.
    HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &pNode);

    // Set the object pointer.
    if (SUCCEEDED(hr))
    {
        hr = pNode->SetObject(pActivate);
    }

    // Add the node to the topology.
    if (SUCCEEDED(hr))
    {
        hr = pTopology->AddNode(pNode);
    }

    // Return the pointer to the caller.
    if (SUCCEEDED(hr))
    {
        *ppNode = pNode;
        (*ppNode)->AddRef();
    }

    SafeRelease(&pNode);
    return hr;
}

Création de topologies

Topologies

IMFTopologyNode