Skip to content

Migrate pulseaudio to pipewire (New)#826

Merged
Hook25 merged 6 commits intocanonical:mainfrom
hanhsuan:migrate_pulseaudio_to_pipewire
Jan 12, 2024
Merged

Migrate pulseaudio to pipewire (New)#826
Hook25 merged 6 commits intocanonical:mainfrom
hanhsuan:migrate_pulseaudio_to_pipewire

Conversation

@hanhsuan
Copy link
Copy Markdown
Contributor

@hanhsuan hanhsuan commented Nov 16, 2023

Description

  1. using check_audio_deamon.sh to check what environment is under testing to use right function for testing
  2. Under pipewire, using pw-dump and wpctl to replace pactl command to collect information and settings.
  3. the output of pw-dump is json format, therefore pactl.py isn't needed a alternative for pipewire.
  4. audio_settings.py is buggy for selecting right device, change to use show_default_audio_device.sh to show the default device and let user to check.
  5. using wpctl status to replace audio_settings.py store command

Resolved issues

#327
After Ubuntu 22.04, the audio will change from pulseaudio to pipewire. Therefore, the old test case should be migrated from pulseaudio to pipewire.

JIRA

Documentation

Tests

Jira Card CQT-2396

@Hook25
Copy link
Copy Markdown
Collaborator

Hook25 commented Nov 16, 2023

/canonical/self-hosted-runners/run-workflows 94ea095

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 18, 2023

Codecov Report

Attention: 47 lines in your changes are missing coverage. Please review.

Comparison is base (120bb96) 34.83% compared to head (10ceb84) 37.23%.
Report is 114 commits behind head on main.

Files Patch % Lines
providers/base/bin/pipewire_test.py 91.16% 14 Missing and 11 partials ⚠️
providers/base/bin/pipewire_utils.py 90.98% 9 Missing and 13 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #826      +/-   ##
==========================================
+ Coverage   34.83%   37.23%   +2.40%     
==========================================
  Files         302      304       +2     
  Lines       34165    34774     +609     
  Branches     5909     6000      +91     
==========================================
+ Hits        11901    12949    +1048     
+ Misses      21698    21226     -472     
- Partials      566      599      +33     
Flag Coverage Δ
provider-base 10.19% <91.08%> (+7.06%) ⬆️

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.

1. using `check_audio_deamon.sh` to check what environment is under
   testing to use right function for testing
2. Under pipewire, using `pw-dump` and `wpctl` to replace `pactl`
   command to collect information and settings.
3. the output of `pw-dump` is json format, therefore `pactl.py`
   isn't needed a alternative for pipewire.
4. `audio_settings.py` is buggy for selecting right device, change to use
   `show_default_audio_device.sh` to show the default device and let user
   to check.
5. using `wpctl status` to replace `audio_settings.py store` command
@hanhsuan hanhsuan force-pushed the migrate_pulseaudio_to_pipewire branch from 4eb393d to 306f4c1 Compare November 23, 2023 07:34
@hanhsuan hanhsuan force-pushed the migrate_pulseaudio_to_pipewire branch from a4b4a71 to 4b0a8df Compare November 25, 2023 13:02
@hanhsuan hanhsuan marked this pull request as ready for review November 26, 2023 00:13
@hanhsuan hanhsuan requested review from diohe0311 and pieqq November 26, 2023 00:14
@diohe0311
Copy link
Copy Markdown
Contributor

/canonical/self-hosted-runners/run-workflows a48b4b2

@diohe0311
Copy link
Copy Markdown
Contributor

audio_settings.py is buggy for selecting right device

Can you tell more about this issue? in which env?

@hanhsuan
Copy link
Copy Markdown
Contributor Author

For DP, HDMI and Thunderbolt monitor, the name shows in OS are the same with only index different. Therefore, audio_settings.py will never know which one is correct then force to select one that might not the right one. If the validator isn't noticed this issue, the validator might make the wrong judgement.

@diohe0311
Copy link
Copy Markdown
Contributor

For DP, HDMI and Thunderbolt monitor, the name shows in OS are the same with only index different. Therefore, audio_settings.py will never know which one is correct then force to select one that might not the right one. If the validator isn't noticed this issue, the validator might make the wrong judgement.

Is this the only issue you have with audio_settings.py?
If audio_settings.py can provide more information, would you still need show_default_audio_device.sh?
It seems that the scripts have overlapping functionalities, perhaps instead of introducing a new script, we could work on improving the existing one?
@Hook25 @kissiel Do you have any suggestions?

@hanhsuan
Copy link
Copy Markdown
Contributor Author

Other functions depend on pulseaudio that couldn't work on pipewire.

@diohe0311
Copy link
Copy Markdown
Contributor

Other functions depend on pulseaudio that couldn't work on pipewire.

I'm not familiar with PulseAudio and Pipewire, just start to learning it because of this PR :)
I found Pipewire has a pipewire-pulse.service, it supports PulseAudio applications.
https://wiki.archlinux.org/title/PipeWire

We can discuss more once I figure out how to use it.

@hanhsuan
Copy link
Copy Markdown
Contributor Author

  1. pactl is not installed by default after lunar
  2. The output format of pactl info is different between pulseaudio and pipewire with pipewire-pulse, it makes the pactl.py parsing failed.

Copy link
Copy Markdown
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.

Allow me to endorse this comment: #826 (comment)

Looking at the changes from audio_test.py -> pipewire_test.py, it looks very clear to me that the two should be merged and use inheritance to obtain the result that we need.

Let me be more explicit, we have a super class here that is VolumeController, this class should contain all common functionality and the interface.

def run_retry(command):
    # Since the audio system may return a failure if the audio layer is not 
    # yet initialized, we will try running a few times in case of failure. 
    # Do not use this if your command is not "idempotent", 
    # repeating them should not have any bad effects.
    for attempt in range(0, 3):
        try:
            return subprocess.check_output(
                command,
                universal_newlines=True
            )
        except (subprocess.CalledProcessError):
            time.sleep(5)

class VolumeController:
    def __init__(self, controller_type, logger=None):
        self.controller_type = controller_type
        self.logger = logger
    def set_volume(self, volume): pass
    def get_volume(self): pass
    def set_mute(self, mute): pass

Then we have two subclasses, one for pipewire and one for pulseaudio

class PulseVolumeController(VolumeController):
    ... # this is the one from audio_test.py with minor edits

class PipewireVolumeController(VolumeController):
    ... # this is from pipewire_test.py

The main function is basically the same for the two modules (but the warning message, that should be moved inside the PulseVolumeController class. To select the audio system we want to test we can add a new cli argument with two possible choiches (pipewire, pulseaudio), and we initialize the correct instance in main depending on this argument value.

This kind of design should also make it trivial to add a new audio system or remove an old one, for example, if we ever deprecate testing pulseaudio systems via checkbox, we can just remove the argument and the class, and everything else will remain the same.

I did read most of this PR but I feel like the comments by @diohe0311 are correct, once those are addressed I can give some additional comments (I don't want them to overlap, lets do one review at the time!)

@diohe0311
Copy link
Copy Markdown
Contributor

diohe0311 commented Jan 9, 2024

@hanhsuan Hi! we have updated the code review criteria

I changed my formatting related comments to suggestions, @Hook25 Hanhsuan mentioned you guys will have a review meeting for this, just want to let you know that the mock input in test_pipewire_utils.py is highly identical(some of them is the same), but I'm not sure if it worth to do something to simplify it or just leave it be.

2. Replacing regex to simplier method
3. Some minor fixes
2. Remove useless try catch in the unit test
Copy link
Copy Markdown
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.

+1, this is probably going to need a followup but its a good base to work on. Thank you

@Hook25 Hook25 dismissed diohe0311’s stale review January 12, 2024 14:17

Fixed by the latest commits

@Hook25 Hook25 merged commit 228b716 into canonical:main Jan 12, 2024
LiaoU3 pushed a commit to LiaoU3/checkbox that referenced this pull request Mar 20, 2024
* Migrate pulseaudio to pipewire
1. using `check_audio_deamon.sh` to check what environment is under
   testing to use right function for testing
2. Under pipewire, using `pw-dump` and `wpctl` to replace `pactl`
   command to collect information and settings.
3. the output of `pw-dump` is json format, therefore `pactl.py`
   isn't needed a alternative for pipewire.
4. `audio_settings.py` is buggy for selecting right device, change to use
   `show_default_audio_device.sh` to show the default device and let user
   to check.
5. using `wpctl status` to replace `audio_settings.py store` command

* Add more unit tests

* Remove assertLog to make code simplier

* 1. Migrate show_default_audio_device.sh to pipewire_utils.py show
2. Replacing regex to simplier method
3. Some minor fixes

* Add unit test for pipewire_utils show function

* 1. Add logs
2. Remove useless try catch in the unit test
binli pushed a commit to binli/checkbox that referenced this pull request Mar 22, 2024
* Migrate pulseaudio to pipewire
1. using `check_audio_deamon.sh` to check what environment is under
   testing to use right function for testing
2. Under pipewire, using `pw-dump` and `wpctl` to replace `pactl`
   command to collect information and settings.
3. the output of `pw-dump` is json format, therefore `pactl.py`
   isn't needed a alternative for pipewire.
4. `audio_settings.py` is buggy for selecting right device, change to use
   `show_default_audio_device.sh` to show the default device and let user
   to check.
5. using `wpctl status` to replace `audio_settings.py store` command

* Add more unit tests

* Remove assertLog to make code simplier

* 1. Migrate show_default_audio_device.sh to pipewire_utils.py show
2. Replacing regex to simplier method
3. Some minor fixes

* Add unit test for pipewire_utils show function

* 1. Add logs
2. Remove useless try catch in the unit test
hanhsuan added a commit to hanhsuan/checkbox that referenced this pull request Mar 25, 2024
This test case is missed to migrate in the canonical#826
hanhsuan added a commit to hanhsuan/checkbox that referenced this pull request Mar 26, 2024
This test case is missed to migrate in the canonical#826
pieqq pushed a commit that referenced this pull request Mar 29, 2024
…1106)

migrate from pulseaudio to pipewire

This test case is missed to migrate in the #826
LiaoU3 pushed a commit to LiaoU3/checkbox that referenced this pull request Apr 17, 2024
…anonical#1106)

migrate from pulseaudio to pipewire

This test case is missed to migrate in the canonical#826
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