none
How to add/remove audio endpoints in a custom audio endpoint enumerator dynamically? RRS feed

  • Question

  • Hello experts,

    Is there any example or code snippet to show how to add/remove audio endpoints in a "custom audio endpoint enumerator" dynamically? In a remote RDS session, can we create/remove audio endpoints during session connection? Looks the "mstsc.exe" have this ability but we don't know how it does.

    I've checked the guide for "custom audio endpoint enumerator" and other documents from Google/MSDN, such as:

    https://docs.microsoft.com/en-us/windows/desktop/TermServ/implementing-an-audio-endpoint-enumerator

    But I couldn't get any clue to add/remove audio endpoints dynamically.

    I think it should be OK to create a dedicated thread in the "custom audio endpoint enumerator" and wait for a signal to create audio endpoints. But how to let the system or application be aware of this? My understanding is the function "GetTSAudioEndpointEnumeratorForSession" needs to be called if any audio endpoint is created or removed thus others could know it. But how to re-trigger this function call for other applications?

    Great thanks in advance for any suggestion!

    Monday, June 3, 2019 5:28 AM

All replies

  • I don't know, but I'm willing to take a guess... does your custom IMMDeviceEnumerator implementation have a IMMDeviceEnumerator::RegisterEndpointNotificationCallback method?

    Matthew van Eerde

    Monday, June 3, 2019 2:00 PM
    Moderator
  • Thank you for diving into this discussion thread, Matt!

    As we are implementing the custom audio endpoint enumerator, we will be responsible to add/remove audio endpoints inside the enumerator.

    That's to say, the upper callers(or the consumers of this enumerator) could call this function to register the notificaiton event when there is any endpoint added/removed. But it is the enumerator's rsponsibility to add/remove endpoints, thus others could be notified.

    So things go back to my original question.

    Please let me know if you have further idea. Thanks very much!

    Tuesday, June 4, 2019 12:36 AM
  • Um... you didn't answer my question.

    Does your custom implementation of IMMDeviceEnumerator implement the RegisterEndpointNotificationCallback?

    If so, does Windows call it?


    Matthew van Eerde

    Tuesday, June 4, 2019 5:59 PM
    Moderator
  • Yes, we implemented this function.

    Its prototype is:

    HRESULT RegisterEndpointNotificationCallback(
      IMMNotificationClient *pClient
    );

    https://docs.microsoft.com/en-us/windows/desktop/api/mmdeviceapi/nf-mmdeviceapi-immdeviceenumerator-registerendpointnotificationcallback

    We stored the input parameter pClient.

    Take the following scenario as an example:

    On windows 2016, when we click audio icon from the sys-tray, then click the "Recording devices", the UI to list all recording devices will be shown, and this function will be called.

    We hard-coded some logic to manually created/removed the IMMDevice instance, and called the following functions with pClient:

    IMMNotificationClient::OnDeviceStateChanged
    IMMNotificationClient::OnDeviceAdded
    IMMNotificationClient::OnDeviceRemoved

    The calls all succeeded. But there is no change in the recording device list UI. (I expected the should be change to the list after adding/removing devices).

    So I think there should be some hidden points that I don't make out.

    This is my second question: how to notify others or the Windows OS to let them know the device list has been changed thus the relevant UIs have chance to change?

    Thanks.

    Monday, June 10, 2019 4:04 AM
  • OK, so, to be sure I understand:

    1. You are implementing IMMDeviceEnumerator::RegisterEndpointNotificationCallback
    2. Windows is calling this and passing IMMNotificationClient pointers
    3. You are calling IMMNotificationClient::OnDeviceAdded, OnDeviceRemoved, and OnDeviceStateChanged on all registered IMMNotificationClient pointers
    4. And yet, the Sound control panel isn't updating itself

    Is that correct?


    Matthew van Eerde

    Monday, June 10, 2019 4:00 PM
    Moderator
  • Yes, Matt!

    For #3, all the return values are S_OK.

    For #4, the sound UI didn't update itself to reflect the actual devices. I've expected those added devices would be shown in the UI in real-time, and those removed devices would be removed from the UI in real-time. But actually they didn't.

    Thanks Matt!
    Tuesday, June 11, 2019 1:53 AM
  • OK, then as far as I can tell you're doing everything right, and either you're running into a lack-of-feature, or there's a bug in Windows, or there's a bug in your custom IMMDeviceEnumerator implementation.

    Matthew van Eerde

    Tuesday, June 11, 2019 10:08 AM
    Moderator
  • Hi Matt, really thank you very much for taking time on this discussion thread!

    The custom IMMDeviceEnumerator only created one audio endpoint device. It worked fine in other apps(such as skype, zoom, ...). So I don't know whether there is any bug in our current implementation.

    Do you have further suggestion that I could move ahead?

    Thanks, Matt!

    Thursday, June 13, 2019 9:16 AM
  • Huh? First you said you want to add and remove endpoints dynamically. Now you're saying you only create one audio endpoint device. Which is it?

    If there's a bug in your implementation, you should fix it.

    Let's start over. Please answer these three questions:

    1. What are you doing exactly?
    2. What do you expect to happen?
    3. What actually happens?

    Matthew van Eerde

    Monday, June 17, 2019 3:37 PM
    Moderator
  • Hi Matthew,

    Sorry to confused you.

    When I said "The custom IMMDeviceEnumerator only created one audio endpoint device", I meant the original implementation.

    NOW I want to a). create more device dynamically, and b). let the system to be notified when they are created.

    And your original summary is exactly correct:

      • You are implementing IMMDeviceEnumerator::RegisterEndpointNotificationCallback
      • Windows is calling this and passing IMMNotificationClient pointers
      • You are calling IMMNotificationClient::OnDeviceAdded, OnDeviceRemoved, and OnDeviceStateChanged on all registered IMMNotificationClient pointers
    •       And yet, the Sound control panel isn't updating itself

    Please let me know if I missed anything. Thanks.


    • Edited by B0L Friday, June 28, 2019 1:12 AM Format
    Thursday, June 27, 2019 12:50 PM
  • OK, then it would seem you have found a bug. Please file a problem report in Feedback Hub with "recreate my problem" logs of the problem in action. Once filed, share a link to the problem report.

    Matthew van Eerde

    Wednesday, July 3, 2019 7:53 PM
    Moderator
  • OK, thank you very much, Matt! I will do that.
    Friday, July 12, 2019 9:43 AM