I am trying to create an instance of an audio renderer with a given GUID by calling MFCreateAudioRenderer
with the attributes pointer set. I've set all the required values, but the call returns E_INVALIDARG
and mftrace.exe
shows
13808,33E0 15:09:52.27643 CMFAttributesDetours::GetUnknown @014C4550 - enter
13808,33E0 15:09:52.27644 CMFAttributesDetours::GetUnknown @014C4550 attribute not found guidKey = {1082E6C2-7660-4945-8E78-228A3B3329F6}
13808,33E0 15:09:52.27644 CMFAttributesDetours::GetUnknown @014C4550 - exit (failed hr=0xC00D36E6 MF_E_ATTRIBUTENOTFOUND)
I can't find this GUID anywhere and don't know what to set. Any advices?
Minimal sample to reproduce:
#include <atlbase.h>
#include <atlcom.h>
#include <Mfidl.h>
#include <Mfapi.h>
#include <Mmdeviceapi.h>
#include <string>
#include <vector>
#include <map>
#include <Functiondiscoverykeys_devpkey.h>
#include <Audioclient.h>
#include <Codecapi.h>
#include <Audiopolicy.h>
#pragma comment(lib, "Mfplat.lib")
#pragma comment(lib, "Mf.lib")
int main(int argc, char** argv)
{
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
CComPtr<IMMDeviceEnumerator> pMMDeviceEnumerator;
pMMDeviceEnumerator.CoCreateInstance(__uuidof(MMDeviceEnumerator));
std::map<std::wstring, CComPtr<IMMDevice>> Devices;
if (pMMDeviceEnumerator)
{
CComPtr<IMMDeviceCollection> pMMDeviceCollection;
if (SUCCEEDED(pMMDeviceEnumerator->EnumAudioEndpoints(EDataFlow::eRender, DEVICE_STATE_ACTIVE, &pMMDeviceCollection)))
{
UINT nDeviceCount = 0;
if (SUCCEEDED(pMMDeviceCollection->GetCount(&nDeviceCount)))
{
UINT nDeviceIndex = 0;
while (nDeviceIndex < nDeviceCount)
{
CComPtr<IMMDevice> pMMDevice;
if (SUCCEEDED(pMMDeviceCollection->Item(nDeviceIndex, &pMMDevice)))
{
CComPtr<IPropertyStore> pPropertyStore;
if (SUCCEEDED(pMMDevice->OpenPropertyStore(STGM_READ, &pPropertyStore)))
{
PROPVARIANT Variant;
PropVariantInit(&Variant);
if (SUCCEEDED(pPropertyStore->GetValue(PKEY_Device_FriendlyName, &Variant)))
{
wchar_t* pId = nullptr;
if (SUCCEEDED(pMMDevice->GetId(&pId)))
{
Devices.emplace(pId, pMMDevice);
CoTaskMemFree(pId);
}
}
}
}
++nDeviceIndex;
}
}
}
}
std::vector<CComPtr<IMFMediaSink>> MediaSinks;
for (const auto& Device : Devices)
{
CComPtr<IMFAttributes> pAttributes;
MFCreateAttributes(&pAttributes, 0);
CComPtr<IMFMediaSink> pAudioRenderer;
HRESULT hResult = pAttributes->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, Device.first.c_str());
hResult = pAttributes->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE, ERole::eMultimedia);
hResult = pAttributes->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_STREAM_CATEGORY, AUDIO_STREAM_CATEGORY::AudioCategory_BackgroundCapableMedia);
hResult = pAttributes->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_FLAGS, 0);
hResult = pAttributes->SetGUID(MF_AUDIO_RENDERER_ATTRIBUTE_SESSION_ID, GUID_NULL);
hResult = MFCreateAudioRenderer(pAttributes, &pAudioRenderer);
if (SUCCEEDED(hResult))
{
MediaSinks.push_back(pAudioRenderer);
}
}
CoUninitialize();
}
Related MSDN bit is:
...If you specify a device role, the SAR uses whatever audio device has been assigned for that role. To specify the device role, set the
MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE
attribute.
You identify the device by either ID or ROLE, the two are mutually exclusive, hence E_INVALIDARG
when you provide both at a time.
User contributions licensed under CC BY-SA 3.0