建立轉換節點

轉換節點代表媒體基礎轉換 (MFT) ,例如解碼器或編碼器。 有數種不同的方式可以初始化轉換節點:

  • 從 MFT 的指標。
  • 從 MFT 的 CLSID。
  • 從 MFT 啟用物件的指標。

如果您要在受保護的媒體路徑內載入拓撲, (PMP) ,您必須使用 CLSID 或啟用物件,以便在受保護的程式中建立 MFT。 第一種方法 (使用 MFT) 指標不適用於 PMP。

從 MFT 建立轉換節點

若要從 MFT 建立轉換節點,請執行下列動作:

  1. 建立 MFT 的實例,並取得 MFT 之 IMFTransform 介面的指標。
  2. 使用MF_TOPOLOGY_TRANSFORM_NODE旗標呼叫MFCreateTopologyNode,以建立轉換節點。
  3. 呼叫 IMFTopologyNode::SetObject 並傳入 IMFTransform 指標。
  4. 呼叫 IMFTopology::AddNode ,將節點新增至拓撲。

下列範例會從 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;
}

從 CLSID 建立轉換節點

若要從 CLSID 建立轉換節點,請執行下列動作:

  1. 尋找 MFT 的 CLSID。 您可以使用 MFTEnum 函式依類別尋找 MFT 的 CLSID,例如解碼器或編碼器。 例如,如果您實作自己的自訂 MFT () ,您可能也會知道您想要使用之特定 MFT 的 CLSID。
  2. 使用MF_TOPOLOGY_TRANSFORM_NODE旗標呼叫MFCreateTopologyNode,以建立轉換節點。
  3. 在節點上設定 MF_TOPONODE_TRANSFORM_OBJECTID 屬性。 屬性值是 CLSID。
  4. 呼叫 IMFTopology::AddNode ,將節點新增至拓撲。

下列範例會從 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;
}

從啟用物件建立轉換節點

某些 MFT 提供啟用物件。 例如, MFCreateWMAEncoderActivate 函式會傳回 Windows Media Audio (WMA) 編碼器的啟用物件。 確切的函式取決於 MFT。 並非所有 MFT 都提供啟用物件。 如需詳細資訊,請參閱 啟用物件

您也可以藉由呼叫 MFTEnumEx 函式來取得 MFT 啟用物件。

若要從啟用物件建立轉換節點,請執行下列動作:

  1. 建立啟用物件,並取得啟用物件的 IMFActivate 介面指標。
  2. 使用MF_TOPOLOGY_TRANSFORM_NODE旗標呼叫MFCreateTopologyNode,以建立轉換節點。
  3. 呼叫 IMFTopologyNode::SetObject 並傳入 IMFActivate 指標。
  4. 呼叫 IMFTopology::AddNode ,將節點新增至拓撲。

下列範例會從啟用物件建立和初始化轉換節點。

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

建立拓撲

拓撲

IMFTopologyNode