How do I identify DirectShow audio renderer filters uniquely?
As I just found out the hard way, friendly names are not guaranteed to be unique. Bonus points if I can inst开发者_JAVA百科antiate the filter from that identifier without having to enumerate them.
Renderer filters wrapping WaveOut devices can be identified by WaveOutId. Those wrapping DirectSound devices can be identified by DSGuid.
ICreateDevEnum* devices;
if (CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (LPVOID*)&devices) == S_OK)
{
IEnumMoniker* enumerator;
if (devices->CreateClassEnumerator(CLSID_AudioRendererCategory, &enumerator, 0) == S_OK)
{
IMoniker* moniker;
while (enumerator->Next(1, &moniker, NULL) == S_OK)
{
IPropertyBag* properties;
if (moniker->BindToStorage(NULL, NULL, IID_IPropertyBag, (void**)&properties) == S_OK)
{
VARIANT variant;
VariantInit(&variant);
if (properties->Read(L"WaveOutId", &variant, NULL) == S_OK)
{
// variant.lVal now contains the id of the wrapped WaveOut device.
}
else if (properties->Read(L"DSGuid", &variant, NULL) == S_OK)
{
// variant.bstrVal now contains an uppercase GUID.
// It's the same GUID you would get from DirectSoundEnumerate.
}
VariantClear(&variant);
properties->Release();
}
moniker->Release();
}
enumerator->Release();
}
devices->Release();
}
精彩评论