Skip to content

Conversation

@p-gentili
Copy link
Collaborator

@p-gentili p-gentili commented Sep 26, 2025

Description

This PR introduces a new utility module in checkbox support to scan and control sources and sinks using both Pipewire and Pulseaudio in a transparent way.

The main functions explains a bit how to use it, but in general:

  1. List only the sinks / sources
  2. Iter on sinks / sources, and control it one by one

It's non trivial to control nodes outside of the iteration, especially with Pipewire: Nodes are ephemeral, and there's no identifier that is guaranteed to survive after changing device profile.

Resolved issues

N/A

Documentation

N/A

Tests

Run it as a script, and check if the sink on your machine changes.

NB: there are sinks that are available but not actually usable: your settings panel might not update the displayed value in this case.

@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 96.24329% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.35%. Comparing base (1c4f2c0) to head (9af0c29).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...ort/checkbox_support/helpers/audio_server_utils.py 92.30% 14 Missing and 3 partials ⚠️
...x_support/helpers/tests/test_audio_server_utils.py 98.81% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2131      +/-   ##
==========================================
+ Coverage   53.81%   54.35%   +0.54%     
==========================================
  Files         406      408       +2     
  Lines       43288    43847     +559     
  Branches     7997     8075      +78     
==========================================
+ Hits        23296    23834     +538     
- Misses      19179    19195      +16     
- Partials      813      818       +5     
Flag Coverage Δ
checkbox-ng 71.56% <ø> (ø)
checkbox-support 67.89% <96.24%> (+2.60%) ⬆️
provider-base 30.90% <ø> (ø)
provider-resource 39.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@p-gentili p-gentili changed the title [New] audio utils module (DRAFT) DRAFT: audio utils module (New) Sep 26, 2025
@p-gentili p-gentili force-pushed the audio-utils branch 2 times, most recently from 9f11017 to 93e736d Compare November 12, 2025 09:51
@p-gentili p-gentili changed the title DRAFT: audio utils module (New) Audio server utils module (New) Nov 12, 2025
@p-gentili p-gentili marked this pull request as ready for review November 12, 2025 13:47
@Hook25 Hook25 self-assigned this Nov 26, 2025
Copy link
Collaborator

@Hook25 Hook25 left a comment

Choose a reason for hiding this comment

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

This is ok, consider adding a bit more end 2 end tests.

Introduces a unified interface for working with PulseAudio and PipeWire
audio servers without requiring deep knowledge of either system.

Features:
- AudioServerUtils factory that auto-detects the running audio server
- PipewireUtils: Full support for PipeWire's device/profile/node hierarchy
- PulseaudioUtils: Support for PulseAudio sink/source management
- Node abstraction representing audio sinks and sources
- Methods to list, iterate, set default, and control volume of audio nodes
- CLI interface for listing and interactively selecting audio nodes

The iterator pattern (iter_sinks/iter_sources) automatically activates
profiles before yielding nodes, making them immediately usable.
Comprehensive test coverage for the audio_server_utils module:

- NodeTests: Basic Node class instantiation
- AudioServerUtilsTests: Factory pattern and server detection
- PipewireUtilsTests: PipeWire-specific functionality including
  pw-dump parsing, device/profile/node handling, and volume control
- PulseaudioUtilsTests: PulseAudio-specific functionality including
  pactl parsing, sink/source management, and volume control

Signed-off-by: Paolo Gentili <paolo.gentili@canonical.com>
Signed-off-by: Paolo Gentili <paolo.gentili@canonical.com>
Signed-off-by: Paolo Gentili <paolo.gentili@canonical.com>
Signed-off-by: Paolo Gentili <paolo.gentili@canonical.com>
@Hook25 Hook25 merged commit 761105c into main Jan 12, 2026
52 checks passed
@Hook25 Hook25 deleted the audio-utils branch January 12, 2026 09:27
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.

3 participants