Share via


依數位識別輸入

[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 來源讀取器和接收寫入器已取代它。 來源讀取器和接收寫入器已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用來源讀取器和接收寫入器,而不是Windows 媒體格式 11 SDK。 Microsoft 建議使用舊版 API 的現有程式碼盡可能重寫為使用新的 API。

您傳遞至寫入器的每個範例都必須與輸入編號相關聯。 每個輸入編號都會對應至寫入器用來寫入檔案之設定檔中的一或多個資料流程。 在設定檔中,媒體來源會以連線名稱來識別。 當您設定寫入器的設定檔時,寫入器會將輸入編號與每個連接名稱產生關聯。 您必須先判斷每個輸入預期的資料,才能將範例傳遞至寫入器。 您無法假設輸入的順序與設定檔中的資料流程相同,即使這種情況通常也是如此。 因此,比對輸入與資料流程的唯一可靠方式,就是比較輸入的連接名稱與資料流程的連接名稱。

若要識別載入設定檔的連接名稱和對應的輸入編號,請執行下列步驟:

  1. 建立寫入器物件,並設定要使用的設定檔。 如需在寫入器中設定設定檔的詳細資訊,請參閱 To Use Profiles with the Writer>。 您應該知道設定檔中資料流程所使用的連接名稱。 您可以從設定檔內取得連線名稱,方法是取得每個資料流程的資料流程組態物件,並呼叫 IWMStreamConfig::GetConnectionName。 如需設定檔和資料流程組態物件的詳細資訊,請參閱 使用設定檔
  2. 呼叫 IWMWriter::GetInputCount來擷取輸入總數。
  3. 迴圈查看所有輸入,並針對每個輸入執行下列步驟。

下列範例程式碼會顯示每個輸入的連接名稱。 如需使用此程式碼的詳細資訊,請參閱 使用程式碼範例

HRESULT GetNamesForInputs(IWMWriter* pWriter)
{
    DWORD    cInputs  = 0;
    HRESULT  hr       = S_OK;
    WCHAR*   pwszName = NULL;
    WORD     cchName  = 0;

    IWMInputMediaProps* pProps = NULL;

    // Get the total number of inputs for the file.
    hr = pWriter->GetInputCount(&cInputs);
    GOTO_EXIT_IF_FAILED(hr);

    // Loop through all supported inputs.
    for (DWORD inputIndex = 0; inputIndex < cInputs; inputIndex++)
    {
        // Get the input properties for the input.
        hr = pWriter->GetInputProps(inputIndex, &pProps);  
        GOTO_EXIT_IF_FAILED(hr);

        // Get the size of the connection name.
        hr = pProps->GetConnectionName(0, &cchName);
        GOTO_EXIT_IF_FAILED(hr);

        if (cchName > 0)
        {
            // Allocate memory for the connection name.
            pwszName = new WCHAR[cchName];
            if (wszName == NULL)
            {
                hr = E_OUTOFMEMORY;
                goto Exit;
            }

            // Get the connection name.
            hr = pProps->GetConnectionName(pwszName, &cchName);
            GOTO_EXIT_IF_FAILED(hr);
            
            // Display the name.
            printf("Input # %d = %S\n", pwszName);
        } // end if

        // Clean up for next iteration.
        SAFE_ARRAY_DELETE(pwszName);
        SAFE_RELEASE(pProps);
    } // end for inputIndex

Exit:
    SAFE_ARRAY_DELETE(pwszName);
    SAFE_RELEASE(pProps);
    return hr;
}

IWMWriter 介面

撰寫 ASF 檔案