mozilla / cubeb

Cross platform audio library
ISC License
441 stars 125 forks source link

Disable automatic device switching if user doesn't follow the system default device #694

Open ChunMinChang opened 2 years ago

ChunMinChang commented 2 years ago

To unblock BMO 1735201 and BMO 1238038, we should disable automatic device switching by default unless users ask to follow the system default device. That should be the default behavior in Firefox.

ChunMinChang commented 2 years ago

To clarify a bit more, we should only switch devices automatically when user asks to use the system default device. Using the system default means that the users pass a NULL cubeb_devid in cubeb_stream_init. https://github.com/mozilla/cubeb/blob/5a2a20c6055d26e0a30fae8f1cf6f6cb975c5c97/include/cubeb/cubeb.h#L524 https://github.com/mozilla/cubeb/blob/5a2a20c6055d26e0a30fae8f1cf6f6cb975c5c97/include/cubeb/cubeb.h#L531

If users pass a non-NULL cubeb_devid, then it's not the default device, even if the device happens to be the current system default device. User must pass NULL explicitly to follow the system default.

In brief, switching device or not can be summarized into the following situations:

For input stream: device unplug input device unplug output device default input change default output change
default Yes N/A Yes N/A
non-default No N/A No N/A
For output stream: device unplug input device unplug output device default input change default output change
default N/A Yes N/A Yes
non-default N/A No N/A No
For duplex stream: device unplug input device unplug output device default input change default output change
default input, default output Yes Yes Yes Yes
default input, non-default output Yes No Yes No
non-default input, default output No Yes No Yes
non-default input, non-default output No No No No
ChunMinChang commented 2 years ago

I think it's a good time to revisit #167 again. I believe the WebRTC spec allow users to select the output device now: https://webrtc.github.io/samples/src/content/devices/input-output/, and Chrome has implemented that but we haven't. In addition, we need to support the setSinkId as well. We should check the WebRTC and setSinkId's spec and then think how we should handle the device-switching policy in cubeb. We also have a few special cases for the output device selection (e.g., Bluetooth Handsfree, Loopback). That's something we need to take into our consideration, and we need to document this policy somewhere.

nathanzachary commented 6 months ago

I think it's a good time to revisit #167 again. I believe the WebRTC spec allow users to select the output device now: https://webrtc.github.io/samples/src/content/devices/input-output/, and Chrome has implemented that but we haven't.

@ChunMinChang, Looking at the WebRTC link that you provided, I can confirm that I am able to switch input and output devices in Chromium, but not in Firefox. There are some related Mozilla bugs that could be resolved with this implementation as well:

https://bugzilla.mozilla.org/show_bug.cgi?id=1650131 https://bugzilla.mozilla.org/show_bug.cgi?id=1716249

Is there any roadmap tracking the progress of implementing this WebRTC specification in Firefox that we can vote on and/or contribute to?

nathanzachary commented 6 months ago

Firefox only shows the 'default' input source: firefox_webrtc_input_source

Chromium shows all four available input sources: chromium_webrtc_input_sources