共用方式為


建立轉換節點

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

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

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

從 MFT 建立轉換節點

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

  1. 建立 MFT 的實例,並取得 MFT IMFTransform 介面的指標。
  2. 呼叫 MFCreateTopologyNode 並使用 MF_TOPOLOGY_TRANSFORM_NODE 旗標以建立轉換節點。
  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 的 CLSID(例如,如果您實作自己的自定義 MFT)。
  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 媒體音訊 (WMA) 編碼器的啟用物件。 確切的功能取決於 MFT。 並非所有 MFT 都提供啟用物件。 如需詳細資訊,請參閱 Activation Objects

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

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

  1. 建立啟用物件,並取得啟用物件的 IMFActivate 介面指標。
  2. 呼叫 MFCreateTopologyNode,並使用 MF_TOPOLOGY_TRANSFORM_NODE 旗標來建立轉換節點。
  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