-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio device switching #167
Comments
Quick notes:
There are several types of changes we can signal:
For the cases where we can no longer use the current device, there are several reasons. Using WASAPI as an example:
The current enum values cover device disconnections, but don't have a way to signal that the same device may still be available but require reconfiguration to continue using. It's also probably worth considering how to address the issues raised in https://bugzilla.mozilla.org/show_bug.cgi?id=1198591 |
True. It's however possible. Worst case we're re-configuring a bit too much.
My thinking on this one was that you don't need to make any decision about which device to use if your policy is to let it switch to the new default device, so we can return from the callback and proceed. Also it's a rather common case (plugging in an USB headset on OSX changes the system default), and it let cubeb be faster about the switch. Choosing a particular device (or device pair) often requires re-enumerating the available devices (because it's likely the list changed), which can be blocking and/or require user intervention to pick the right one. At this point, it's best to kill the stream and make the software do something.
Agreed, that's very useful and I missed it. Firefox uses the information that the device changed to reset the AEC for example.
I think we only care about the transition available -> unavailable here.
Breaking the list down:
So, there is three reasons for getting the device notification:
An updated proposal typedef enum {
CUBEB_INPUT_DEVICE_CHANGED = 1 << 0;
CUBEB_OUTPUT_DEVICE_CHANGED = 1 << 1;
CUBEB_DEVICE_SWITCHED = 1 << 2;
CUBEB_DEVICE_RECONFIGURED = 1 << 3;
CUBEB_DEVICE_UNAVAILABLE = 1 << 4;
CUBEB_STREAM_ERROR = 1 << 5;
} cubeb_device_change_information;
typedef enum {
CUBEB_USE_DEFAULT_INPUT = 1 << 0;
CUBEB_USE_DEFAULT_OUTPUT = 1 << 1;
CUBEB_STOP_INPUT = 1 << 2;
CUBEB_STOP_OUTPUT = 1 << 3;
} cubeb_device_change_action;
typedef cubeb_device_change_action (* cubeb_device_changed_callback)(void * user_ptr, cubeb_device_change_information); |
We need to define the behaviour of what happens when users change devices, either via the audio configuration menu, or by plugging or unplugging a physical device.
Here is a proposal that allows implementing something flexible:
First, we need to implement the device change notification callback on all supported platforms.
Next, I propose that inside the audio backends, we call the user callback before changing the stream configuration. We also need to make sure that no audio callback will be called during the time where the device change callback is called.
Then, we can modify the signature of the callback, and make it like so:
If it's ok to switch to the default devices, the user can return
CUBEB_USE_DEFAULT_INPUT|CUBEB_USE_DEFAULT_OUTPUT
, and the switch will occur. If the user prefers to kill one side of the stream, passing the appropriate enum member turns the stream into an half-duplex stream, or stops the stream if bothCUBEB_STOP_INPUT
andCUBEB_STOP_OUTPUT
are or-ed and returned. Users can then react to the device change, for example by destroying this stream and creating a new one.It sounds a bit dangerous to allow calling cubeb APIs from the device change notification callback.
For gecko, this allows implementing the following:
getUserMedia
that uses the default device for the system, and continues across default device changes."ended"
event on theMediaStream
associated with thegetUserMedia
call, as specced, and stopping the capture. This informs the user that something has happened and thatgetUserMedia
should probably be called again.The text was updated successfully, but these errors were encountered: