Sound panel: don't abort on a missing port and switch card profile for PipeWire Bluetooth headsets

Launchpad bug: https://bugs.launchpad.net/bugs/2175446 Companion MR for unity-settings-daemon: unity-settings-daemon!4

Summary

Two fixes in the copy of libgnome-volume-control (gvc) embedded in panels/sound/:

  1. gvc_mixer_stream_get_port() no longer aborts when the active port of a stream is missing from its port list; callers that dereferenced the result now handle NULL.
  2. gvc_mixer_control_change_output() switches the card profile (not the sink port) when the selected output belongs to a profile that is not active. Without this, selecting a Bluetooth headset's A2DP output while it is in HFP mode does nothing under PipeWire.

The same first fix is proposed for unity-settings-daemon (plugins/media-keys/gvc/), which ships its own copy of these files.

Symptom

With PipeWire + WirePlumber 0.5, a Bluetooth headset with A2DP and HSP/HFP profiles:

  • In Sound Settings › Output, the headset shows two entries: "Headset" (A2DP) and "Handsfree" (HFP).
  • Choosing Handsfree while A2DP is active crashes the settings daemon:
    Gvc:ERROR:gvc-mixer-stream.c:534:gvc_mixer_stream_get_port: code should not be reached
    (unity-settings-daemon killed by SIGABRT; the panel's own gvc copy has the same assert.)
  • Once the crash is avoided, choosing Headset while HFP is active does nothing: the headset stays in HFP (low quality, mono).

Steps to reproduce

  1. Unity session with PipeWire as the sound server (tested: PipeWire 1.4.11, WirePlumber 0.5.13).
  2. Connect a Bluetooth headset that supports A2DP and HFP.
  3. Open System Settings › Sound › Output, select Handsfree → unity-settings-daemon aborts.
  4. With fix 1 applied, select Handsfree, then Headset → nothing happens.

Cause

Under PulseAudio, each Bluetooth profile had its own sink (bluez_sink.<MAC>.a2dp_sink, bluez_sink.<MAC>.headset_head_unit). Under PipeWire the headset is a single sink bluez_output.<MAC> that keeps its name in every profile; only its ports change:

headset-output     (part of profiles a2dp-sink*)
headset-hf-output  (part of profiles headset-head-unit*)
  • During a profile switch the sink's active port can be one that is not (yet) in its port list (the port list can change underneath gvc, see https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/5053), so the g_assert_not_reached() in gvc_mixer_stream_get_port() fires. Three callers then dereference the result without a check (gvc_mixer_control_lookup_device_from_stream(), gvc_mixer_control_change_output(), gvc_mixer_control_change_input()).
  • Both UI devices (Headset / Handsfree) now map to the same stream, so gvc_mixer_control_change_output() takes the "port change" path and calls gvc_mixer_stream_change_port(). The port of the other profile is not available on the sink while the current profile is active, so nothing happens. The card profile has to be changed instead, like for a device without a stream.

Fix

  1. gvc-mixer-stream.c: replace g_assert_not_reached() with a g_debug() and return NULL. Use port ? port->port : NULL in the three callers. This matches upstream libgnome-volume-control, which removed the same assert in commit 806b8e2 ("mixer-stream: Allow ports to not exist", part of https://gitlab.gnome.org/GNOME/libgnome-volume-control/-/merge_requests/31).
  2. gvc-mixer-control.c, gvc_mixer_control_change_output(): before the port comparison, if the output's card has an active profile that is not one of the output's supported profiles, call gvc_mixer_control_change_profile_on_selected_device(), make the stream the default sink if needed, and return.

Upstream GNOME addressed the second problem differently in the same MR (port list refresh and stream-id reset on UI devices, 18 commits). That series relies on several earlier gvc changes that the Unity copy does not have (e.g. 82fed08, 10a3c0a), so a targeted fix is proposed here instead of a backport.

No debian/changelog entry is included, since this repository is behind the archive (0ubuntu16); suggested entries for the uploader:

  * sound/gvc: don't abort when the active port is missing from the port
    list, as happens with Bluetooth headsets under PipeWire (LP: #2175446)
  * sound/gvc: switch the card profile instead of the sink port when the
    selected output needs another profile (Bluetooth headset A2DP/HFP
    under PipeWire) (LP: #2175446)

Testing

Built as local packages on Ubuntu 22.04 (unity-control-center 15.04.0+22.04.20220629, unity-settings-daemon 15.04.1+21.10.20220207, PipeWire 1.4.11, WirePlumber 0.5.13) and tested with a real Bluetooth headset:

  • Speakers → Handsfree: no crash, headset switches to HFP.
  • Handsfree → Headset: card switches back to A2DP.
  • Wired / internal outputs unaffected.

The gvc files are byte-identical in the current ubuntu/devel branch, so the diff applies unchanged; I have not run it on the development release itself.

Known limitation: see the note on row 3 below.

Expected end-to-end behaviour / test matrix

End-to-end tests ran on 20–21 November 2026 with a Poly Voyager Focus UC headset, Ubuntu 22.04 Unity, PipeWire 1.4.11 and WirePlumber 0.5.13.

This change covers only the rows owned by the "Unity Sound panel": choosing an output, switching Headset ↔️ Handsfree, and the crash that switching used to cause. The other rows depend on a local user service and a WirePlumber rule on the test machine, not on Unity. They are listed to show the full behaviour these fixes were checked against.

"Call" means a calling application is capturing the microphone: Teams, Slack, Telegram, Signal, Discord, Zoom, Element, or a web browser (Chrome, Firefox, Brave, Edge, which covers WhatsApp Web and Meet).

# Situation Audio output Microphone Playback Handled by
1 Headset switched on / connected → Headset automatically internal (unchanged) continues local service
2 Output changed manually (Speakers, Dock, Headset) the selected one unchanged continues Unity Sound panel
3 Handsfree selected manually, no call headset, telephone quality (HFP) unchanged continues Unity Sound panel (see note)
4 Call starts, headset on current output remembered → headset in Handsfree (HFP) headset paused local service + WirePlumber rule
5 Call starts, headset off internal speakers internal paused local service
6 Call ends back to the remembered output the previous one players paused by the call resume local service
7 Headset taken off the head, audio in the headset unchanged — paused, resumes when put back on local service
8 Headset taken off the head, audio on the speakers unchanged — continues local service
9 Headset switched off, audio in the headset → speakers (automatic) internal paused local service
10 Headset switched off, audio on the speakers speakers internal continues local service
11 Headset buttons — — play/pause, next/previous track, fast forward/rewind. Play keys are ignored during a call and for 4 s after it, and for 2 s around taking the headset off or putting it on: the headset sends key 201 by itself about 50 ms before its "don/doff" sensor event local service

Note on row 3 (known limitation): with fix 2, selecting Handsfree from Speakers switches the card to HFP, but the default sink is not always updated. Out of two tries, it worked once and failed once, while a video was playing. I have not found the cause. It may be related to the asynchronous profile change, because profile_swapping_device_id is handled later. On the test machine the local service makes the default output follow the headset, which hides this. Without that service the output may need to be selected again.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading