使用流优先顺序

[与此页面关联的功能 Windows Media Format 11 SDK 是一项旧功能。 它已被源读取器和接收器编写器取代。 源读取器和接收器编写器已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用源读取器和接收器编写器,而不是 Windows Media 格式 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;

使用配置文件