media-keys/gvc: don't abort when the active port is missing from the port list

Launchpad bug: https://bugs.launchpad.net/bugs/2175446

Summary

gvc_mixer_stream_get_port() in the embedded gvc copy (plugins/media-keys/gvc/) calls g_assert_not_reached() when the active port of a stream is not in its port list. With PipeWire this happens with Bluetooth headsets, and it kills unity-settings-daemon.

Symptom

With PipeWire + WirePlumber 0.5 and a Bluetooth headset supporting A2DP and HFP, choosing the headset's Handsfree output in Sound Settings (or any A2DP ↔️ HFP profile switch) aborts unity-settings-daemon:

Gvc:ERROR:gvc-mixer-stream.c:534:gvc_mixer_stream_get_port: code should not be reached

Media keys, volume OSD and other plugins go away until the daemon is restarted.

Steps to reproduce

  1. Unity session with PipeWire (tested: PipeWire 1.4.11, WirePlumber 0.5.13).
  2. Connect a Bluetooth headset that supports A2DP and HFP and play some audio through it.
  3. System Settings › Sound › Output → select Handsfree → unity-settings-daemon gets SIGABRT.

Cause

Under PipeWire the headset is a single sink bluez_output.<MAC> in every profile; only its ports change (headset-output for A2DP, headset-hf-output for HFP). While the profile changes, the sink's active port can be missing from its port list (the list changes underneath gvc, see https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/5053). One path where it fires (also seen in distribution crash reports for the GNOME copy) is on_default_sink_port_notify() → gvc_mixer_control_lookup_device_from_stream() → gvc_mixer_stream_get_port().

Fix

Replace the assert with a g_debug() and return NULL, and guard the three callers that dereference the result (port ? port->port : NULL). Upstream libgnome-volume-control made the same change in commit 806b8e2 ("mixer-stream: Allow ports to not exist", https://gitlab.gnome.org/GNOME/libgnome-volume-control/-/merge_requests/31).

The same fix is proposed for unity-control-center, which has its own copy of gvc (plus a second fix for the profile switch in the Sound panel).

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

  * media-keys/gvc: don't abort when the active port is missing from the
    port list, as happens with Bluetooth headsets under PipeWire
    (LP: #2175446)

Testing

Built as a local package on Ubuntu 22.04 (15.04.1+21.10.20220207, PipeWire 1.4.11, WirePlumber 0.5.13) and tested with a real Bluetooth headset: switching Speakers → Handsfree → Headset no longer crashes the daemon, and media keys keep working. 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.

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