共用方式為


使用數據流優先順序

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

串流優先順序可讓您更好地掌控內容的播放,方法是讓您指定設定檔中串流的優先順序。 當讀取器和串流伺服器在播放期間遇到頻寬短缺時,可能需要捨棄範例以提供不間斷的播放。 如果您在配置文件中指定流優先級對象的優先順序,樣本將首先從最低優先級的數據流中移除。

不同於頻寬共用和互斥對象,數據流優先順序物件不會使用 IWMStreamList 介面來追蹤數據流清單。 相反地,您必須使用 WM_STREAM_PRIORITY_RECORD 結構的陣列。 結構必須依優先順序的遞減順序組織在陣列中。 除了保有數據流編號之外,數據流優先順序結構也可讓您指定數據流是否為必要專案。 不論其在清單中的位置為何,必須的串流都不會被移除。

下列範例程式代碼示範如何在配置檔中包含數據流優先順序。 此配置檔適用於教室簡報,其中包含講師演講的音訊串流、講師的視訊串流,以及擷取簡報投影片的視訊串流。 音訊串流是最重要的,而且是強制性的。 簡報投影片的優先順序會最低,因為影像會相當固定,因此偶爾損失幾幀不會造成太大的影響。

IWMProfileManager*       pProfileMgr = NULL;
IWMProfile*              pProfileTmp = NULL;
IWMProfile3*             pProfile    = NULL;
IWMStreamPrioritization* pPriority   = NULL;

WM_STREAM_PRIORITY_RECORD StreamArray[3];
HRESULT hr = S_OK;

// Initialize COM.
hr = CoInitialize(NULL);

// Create a profile manager object.
hr = WMCreateProfileManager(&pProfileMgr);

// Create an empty profile.
hr = pProfileMgr->CreateEmptyProfile(WMT_VER_9_0, &pProfileTmp)

// Get the IWMProfile3 for the new profile, then release the old one.
hr = pProfileTmp->QueryInterface(IID_IWMProfile3, (void**)&pProfile);
pProfileTmp->Release();
pProfileTmp = NULL;

// Give the new profile a name and description.
hr = pProfile->SetName(L"Prioritization_Example");
hr = pProfile->SetDescription(L"Only for use with example code.");

// Create the first stream.
hr = pProfile->CreateNewStream(WMMEDIATYPE_Audio, &pStream);

// TODO: configure the stream as needed for the scenario.

// Set the stream number.
hr = pStream->SetStreamNumber(1);

// Give the stream a name for clarity.
hr = pStream->SetStreamName(L"Lecturer_Audio");

// Include the new stream in the profile.
hr = pProfile->AddStream(pStream);

// Release the stream configuration interface.
pStream->Release();
pStream = NULL;

// Repeat for the other two streams.
hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStream);

// TODO: configure the stream as needed for the scenario.
hr = pStream->SetStreamNumber(2);
hr = pStream->SetStreamName(L"Lecturer_Video");
hr = pProfile->AddStream(pStream);
pStream->Release();
pStream = NULL;

hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStream);

// TODO: configure the stream as needed for the scenario.
hr = pStream->SetStreamNumber(3);
hr = pStream->SetStreamName(L"Slide_Video");
hr = pProfile->AddStream(pStream);
pStream->Release();
pStream = NULL;

// Create a stream prioritization object.
hr = pProfile->CreateNewStreamPrioritization(&pPriority);

// Fill the array with data.
StreamArray[0].wStreamNum = 1;
StreamArray[0].fMandatory = TRUE;

StreamArray[1].wStreamNum = 2;
StreamArray[1].fMandatory = FALSE;

StreamArray[2].wStreamNum = 3;
StreamArray[2].fMandatory = FALSE;

// Assign the stream array to the stream prioritization object.
hr = pPriority->SetPriorityRecords(StreamArray, 3);

// Add the stream prioritization to the profile.
hr = pProfile->SetStreamPrioritization(pPriority);

// Release the stream prioritization object.
pPriority->Release();
pPriority = NULL;

// TODO: Save the profile to a string, and save the string to a file.
// For more information, see To Save a Custom Profile.

// Release the remaining interfaces.
pProfile->Release();
pProfile = NULL;

pProfileMgr->Release();
pProfileMgr = NULL;

使用配置檔