【发布时间】:2014-07-17 04:11:48
【问题描述】:
我刚刚花了一整天的时间试图找到解决这个问题的方法,让我解释一下:
我正在使用 c++ 中的 Visual 2013、Qt、OpenGL 和 Media Foundation 在 Windows 上开发视频工具。 我有一个 IMFSourceReader,它正在抓取我在 QWindow 内使用 openGL 处理和显示的视频帧。
现在我想播放视频文件的音频流。 我知道如何获取音频样本(使用相同的源阅读器)。 我也知道如何枚举我所有的音频设备:
IMMDeviceEnumerator *pEnum = NULL; // Audio device enumerator.
IMMDeviceCollection *pDevices = NULL; // Audio device collection.
IMMDevice *pDevice = NULL; // An audio device.
IMFAttributes *pAttributes = NULL; // Attribute store.
IMFMediaSink *pSink = NULL; // Streaming audio renderer (SAR)
LPWSTR wstrID = NULL; // Device ID.
// Create the device enumerator.
hr = CoCreateInstance(
__uuidof(MMDeviceEnumerator),
NULL,
CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator),
(void**)&pEnum
);
// Enumerate the rendering devices.
if (SUCCEEDED(hr))
{
hr = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDevices);
}
// Get ID of the first device in the list.
if (SUCCEEDED(hr))
{
hr = pDevices->Item(0, &pDevice);
}
if (SUCCEEDED(hr))
{
hr = pDevice->GetId(&wstrID);
}
// Create an attribute store and set the device ID attribute.
if (SUCCEEDED(hr))
{
hr = MFCreateAttributes(&pAttributes, 2);
}
if (SUCCEEDED(hr))
{
hr = pAttributes->SetString(
MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID,
wstrID
);
}
// Create the audio renderer.
if (SUCCEEDED(hr))
{
hr = MFCreateAudioRenderer(pAttributes, &pSink);
}
SAFE_RELEASE(pEnum);
SAFE_RELEASE(pDevices);
SAFE_RELEASE(pDevice);
SAFE_RELEASE(pAttributes);
CoTaskMemFree(wstrID);
}
我想我必须选择a Streaming Audio Renderer,但仅此而已。我在网上找不到任何东西,我什至上了 Google 搜索的第 11 页...
你是我唯一的希望...
【问题讨论】:
标签: c++ qt audio ms-media-foundation