Skip to content

Comments

Stop moving input devices#54

Merged
kinetiknz merged 1 commit intomozilla:devfrom
achronop:dont-move-devices
Apr 20, 2020
Merged

Stop moving input devices#54
kinetiknz merged 1 commit intomozilla:devfrom
achronop:dont-move-devices

Conversation

@achronop
Copy link
Contributor

Stop moving to a new device when the default device changes or when the current device is removed.

@kinetiknz kinetiknz self-requested a review April 16, 2020 13:53
@achronop achronop force-pushed the dont-move-devices branch from 10c5718 to cb8e94d Compare April 16, 2020 14:29
@achronop achronop changed the title Stop moving devices Stop moving input devices Apr 16, 2020
@achronop
Copy link
Contributor Author

This is needed for BMO 1628634. In Ubuntu PA is configured to make a new input device the system default. We don't want to switch to that new device because it is against the spec.

@kinetiknz
Copy link
Contributor

We've been discussing this change via PM. Changing the device switching behaviour of cubeb streams is fine, but we need a clear idea of the desired behaviour at the cubeb API level. With that in hand, we can address any behavioural inconsistencies existing in the various backends.

Currently:

  • PulseAudio always follows the default device (before this PR)
  • AudioUnit follows the default output device if cubeb_devid is null, but seems to follow the default input device only if the current input device has disappeared (even if a cubeb_devid was specified)
  • WASAPI follows the default device if cubeb_devid is null. If a cubeb_devid is specified, it's always used when (re)opening streams.

I think the WASAPI behaviour is closest to the original intent of the API: passing a valid cubeb_devid means the stream only ever uses that device and passing a null cubeb_devid allows the stream to follow that device type's OS default.

My proposal is to change the PulseAudio backend to match the current Windows behaviour, which means setting DONT_MOVE on an input or output stream only if a cubeb_devid was specified.

If we need to support a use case where the caller passes a null cubeb_devid but doesn't want the stream to follow the default device, the caller could indicate that by setting CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING during stream initialization. That pref is currently only implemented for WASAPI, but it'd be simple to add to the other backends.

@padenot
Copy link
Collaborator

padenot commented Apr 17, 2020

I think this plan is good, because it makes sense on an API level and allows us to implement the behaviour we need for the web.

I can take care of aligning the AudioUnit bit today if nobody is doing that.

@achronop
Copy link
Contributor Author

Thanks for summarizing our discussion. I totally agree and I will follow up on the implementation here. One thing I would like to mention explicitly is that the use of CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING pref will disable switching for all available sides which are both input and output in case of a duplex stream. This also windows current behavior.

@kinetiknz
Copy link
Contributor

One thing I would like to mention explicitly is that the use of CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING pref will disable switching for all available sides which are both input and output in case of a duplex stream. This also windows current behavior.

You're right that the WASAPI backend handles it that way. That's due to the very limited requirements of the existing use inside Gecko, and that is no longer needed due to sandboxing and AudioSession remoting. The flag is per-cubeb_stream_param, so backends can treat it per-side.

@ChunMinChang
Copy link
Member

For AudioUnit side, the input device will do its best to follow the cubeb_devid user defines. When the stream is reinitializing, we will try using the mic with the specified cubeb_devid. If that fails, then the mic becomes the default input device.

Set DONT_MOVE in input and output device if device id is specified or the CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING is set.
@achronop achronop force-pushed the dont-move-devices branch from cb8e94d to e69763b Compare April 20, 2020 17:06
Copy link
Contributor

@kinetiknz kinetiknz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kinetiknz kinetiknz merged commit 8375ed3 into mozilla:dev Apr 20, 2020
kinetiknz added a commit to mozilla/cubeb that referenced this pull request Apr 20, 2020
Following the discussion in mozilla/cubeb-pulse-rs#54
and elsewhere, document the interaction between cubeb_stream_init parameters
and cubeb's intended device switching policy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants