根據數字識別輸入
[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 Source Reader 和 Sink Writer已取代它。 來源讀取器 和 接收寫入器 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 來源讀取器 和 接收寫入器,而不是 Windows Media Format 11 SDK。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
您傳遞給寫入器的每個範例都必須與輸入編號相關聯。 每個輸入編號都會對應至寫入器用來寫入檔案之配置檔中的一或多個數據流。 在個人檔案中,媒體來源會以連線名稱來識別。 當您設定寫入器的設定檔時,寫入器會將輸入編號與每個連接名稱產生關聯。 您必須先判斷每個輸入所期望的數據,才能將樣本交給作者。 您無法假設輸入的順序會與配置檔中的數據流相同,即使這種情況經常如此。 因此,比對輸入與數據流的唯一可靠方法是比較輸入的連接名稱與數據流的連接名稱。
若要識別載入設定檔的連接名稱和對應的輸入編號,請執行下列步驟:
- 建立寫入器物件,並設定要使用的配置檔。 如需在編輯器中配置設定檔的詳細資訊,請參閱 使用設定檔與編輯器。 您應該知道設定檔中資料流所使用的連接名稱。 您可以從設定檔中取得連線名稱,方法是取得每個資料流的數據流組態物件,並呼叫 IWMStreamConfig::GetConnectionName。 如需有關設定檔與資料流組態物件的更多資訊,請參見 使用設定檔。
- 呼叫 IWMWriter::GetInputCount來擷取輸入總數。
- 循環執行所有輸入,針對每個輸入執行下列步驟。
- 透過呼叫 IWMWriter::GetInputProps以擷取輸入的 IWMInputMediaProps 介面。
- 呼叫 IWMInputMediaProps::GetConnectionName,以擷取對應至輸入號碼的連接名稱。 擁有連接名稱之後,您就會知道與寫入器指派之輸入編號相關聯的數據流。
下列範例程式代碼會顯示每個輸入的連接名稱。 如需使用此程式碼的詳細資訊,請參閱 使用程式碼範例。
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;
}
相關主題