RTWorkQ/RTWQ
2024-03-22
14
0
在微软的音频技术中,WASAPI(Windows 音频会话API)是一组用于音频流程管理的API。
RTWorkQ(Real-Time Work Queue)是WASAPI中的一个重要组件,它用于处理实时音频数据流的高优先级操作。
RTWorkQ主要用于处理音频数据的实时采集和播放,确保音频数据在实时性要求下能够高效地被处理。
通过专门的实时工作队列,RTWorkQ可以确保音频数据在传输过程中不会出现延迟或丢失,从而提高了音频处理的稳定性和性能。
RTWQ是在Win 8.1中引入的。
const HMODULE rtwq_module = GetModuleHandle(L"RTWorkQ.dll");
struct win_version_info win1703 = {};
win1703.major = 10;
win1703.minor = 0;
win1703.build = 15063;
win1703.revis = 0;
struct win_version_info ver;
get_win_ver(&ver);
if (win_version_compare(&ver, &win1703) >= 0)
rtwq_supported = rtwq_module != NULL;
if (rtwq_supported)
{
rtwq_unlock_work_queue =PFN_RtwqUnlockWorkQueue)GetProcAddress(rtwq_module,RtwqUnlockWorkQueue");
rtwq_lock_shared_work_queue =(PFN_RtwqLockSharedWorkQueue)GetProcAddress(rtwq_module, "RtwqLockSharedWorkQueue");
rtwq_create_async_result =
(PFN_RtwqCreateAsyncResult)GetProcAddress(
rtwq_module, "RtwqCreateAsyncResult");
rtwq_put_work_item = (PFN_RtwqPutWorkItem)GetProcAddress(
rtwq_module, "RtwqPutWorkItem");
rtwq_put_waiting_work_item =
(PFN_RtwqPutWaitingWorkItem)GetProcAddress(
rtwq_module, "RtwqPutWaitingWorkItem");
try {
hr = rtwq_create_async_result(nullptr, &startCapture,
nullptr,
&startCaptureAsyncResult);
if (FAILED(hr)) {
throw HRError(
"Could not create startCaptureAsyncResult",
hr);
}
hr = rtwq_create_async_result(nullptr, &sampleReady,
nullptr,
&sampleReadyAsyncResult);
if (FAILED(hr)) {
throw HRError(
"Could not create sampleReadyAsyncResult",
hr);
}
hr = rtwq_create_async_result(nullptr, &restart,
nullptr,
&restartAsyncResult);
if (FAILED(hr)) {
throw HRError(
"Could not create restartAsyncResult",
hr);
}
DWORD taskId = 0;
DWORD id = 0;
hr = rtwq_lock_shared_work_queue(L"Capture", 0, &taskId,
&id);
if (FAILED(hr)) {
throw HRError("RtwqLockSharedWorkQueue failed",
hr);
}
startCapture.SetQueueId(id);
sampleReady.SetQueueId(id);
restart.SetQueueId(id);
} catch (HRError &err) {
blog(LOG_ERROR, "RTWQ setup failed: %s (0x%08X)",
err.str, err.hr);
rtwq_supported = false;
}
}