How do I identify DirectShow audio renderer filters uniquely?

风格不统一 提交于 2019-12-10 21:28:54

问题


As I just found out the hard way, friendly names are not guaranteed to be unique. Bonus points if I can instantiate the filter from that identifier without having to enumerate them.


回答1:


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();
}


来源:https://stackoverflow.com/questions/6545539/how-do-i-identify-directshow-audio-renderer-filters-uniquely

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!