Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipewire Audio Driver #23939

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Pipewire Audio Driver #23939

wants to merge 9 commits into from

Conversation

rtbo
Copy link
Contributor

@rtbo rtbo commented Aug 6, 2024

Resolves (on linux): #18701

This is a new audio driver for Linux, that uses the Pipewire API, (and therefore will only be used when Pipewire is installed and running).
For system that do not have pipewire, it will fallback to ALSA automatically.

Pipewire performs a setup negotiation to match what is requested by the app and what is setup on the system.
So the buffer size is more a request for a certain latency rather than something imperative.
I've added support for "System default" buffer size where we don't request anything specific to pipewire.

In general, pipewire will handle gracefully all sorts of corner cases.
My observations are for a low latency playback, free of any glitch, in all situations.

Pipewire also provides the devices available, so the user can choose any playback device available, including bluetooth.
I didn't test yet with USB external device.

Relates to #23439

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@rtbo rtbo mentioned this pull request Aug 6, 2024
8 tasks
@rtbo rtbo force-pushed the pw_audio branch 7 times, most recently from e4dc473 to fea0b81 Compare August 9, 2024 12:22
@rtbo rtbo marked this pull request as draft August 10, 2024 21:46
@rtbo rtbo force-pushed the pw_audio branch 11 times, most recently from a9ce01a to c26c45d Compare August 11, 2024 16:03
CMakeLists.txt Outdated Show resolved Hide resolved
@RomanPudashkin
Copy link
Contributor

Great job, thank you so much! I asked @DmitryArefiev to test it. @MarcSabatella could you also test it? Thanks!

@DmitryArefiev
Copy link
Contributor

@rtbo Tried on my LinuxUbuntu 22.04. The build doesn't run..

Here is terminal output:

dima@dima-VivoBook-ASUSLaptop-X415JAB-X415JA:~$ '/home/dima/Desktop/MU4_242241603_Lin_23939_Pipewire Audio Driver(1)/MuseScore-Studio-4.4.0.242241603-x86_64.AppImage' -d 
/lib/x86_64-linux-gnu/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[D] pw.context [pipewire.c:231 load_spa_handle()] load lib:'support/libspa-support' factory-name:'support.log'
[D] pw.context [pipewire.c:115 open_plugin()] can't load /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: cannot open shared object file: Permission denied
[D] pw.context [pipewire.c:231 load_spa_handle()] load lib:'support/libspa-support' factory-name:'support.cpu'
[D] pw.context [pipewire.c:115 open_plugin()] can't load /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: cannot open shared object file: Permission denied
[I] pw.context [pipewire.c:647 pw_init()] version 1.0.4
[D] pw.thread-loop [thread-loop.c:146 loop_new()] 0x62c279642400: new name:pw-driver-loop
[D] pw.context [pipewire.c:231 load_spa_handle()] load lib:'support/libspa-support' factory-name:'support.system'
[D] pw.context [pipewire.c:115 open_plugin()] can't load /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: /root/build_tools/pw-1.0.4/lib/spa-0.2/support/libspa-support.so: cannot open shared object file: Permission denied
[E] pw.loop [loop.c:67 pw_loop_new()] 0x62c2796a2ba0: can't make support.system handle: No such file or directory
/tmp/.mount_MuseScTyp4NK/AppRun: line 26:  3320 Segmentation fault      (core dumped) "${APPDIR}/bin/mscore4portabledev" "$@"

@MarcSabatella
Copy link
Contributor

Same.

@rtbo
Copy link
Contributor Author

rtbo commented Aug 14, 2024

Thanks for the code review and the tests.
I have difficulties to make the AppImage work. I'm currently running local tests to see which PW plugins must be included.
I'm nearly done with it, I will let you know.

@rtbo rtbo force-pushed the pw_audio branch 4 times, most recently from b732239 to 12a1581 Compare August 15, 2024 20:16
@rtbo rtbo marked this pull request as ready for review August 15, 2024 21:33
@rtbo
Copy link
Contributor Author

rtbo commented Aug 15, 2024

AppImage should work now.
It will use the pipewire shared object from your system. If pipewire is not installed, it will load the SO packaged in the AppImage and fallback to ALSA gracefully because of missing plugins.

@DmitryArefiev have you installed pipewire on your ubuntu-22.04? (installed by default starting 22.10). If not you should see the same as the master branch.
@MarcSabatella for you the choppy sound should be gone, and you can choose a playback device in the audio preferences.

@MarcSabatella
Copy link
Contributor

MarcSabatella commented Aug 15, 2024

Sounds promising! Unfortunately, segfault at startup, just after the splash screen. Log file attached from a run with "-F -d":

log.txt

@rtbo
Copy link
Contributor Author

rtbo commented Aug 16, 2024

Unfortunately I don't have enough info to debug the issue. Please repeat with the last build.

@MarcSabatella
Copy link
Contributor

Here you go:

log.txt

@rtbo
Copy link
Contributor Author

rtbo commented Aug 17, 2024

Thank you it should be OK now. There was a stupid typo in the code.
Your device recognition doesn't seem to work same as mine.
Please see if you have relevant device names in the preferences.
Bluetooth and USB hotplug should normal work as well.

@MarcSabatella
Copy link
Contributor

Crash is gone indeed, and I do see a drop-down for device, although it doesn't tell me anything particularly useful - I've never heard of whatever it is showing me as the only option. But I assume that's something set up by the ChromeOS audio system.

Behavior is decent, with good playback at 48 or 44.1 and buffer sizes about 104. Buffer sizes below are problematic in a new way: no sound at all during note input, and on playback, when stopping, the last note played gets extended for a very long time:

Screen.recording.2024-08-18.10.52.13.AM.webm

Nothing interesting is printed to console at that time, but I've attached a log anyhow:

log.txt

@@ -30,11 +30,11 @@
#include "audiodeviceslistener.h"

namespace muse::audio {
class LinuxAudioDriver : public IAudioDriver, public async::Asyncable
class AlsaAudioDriver : public IAudioDriver, public async::Asyncable
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to rename MUSE_AUDIO_LINUXAUDIODRIVER_H :) But you can also replace it with #pragma once

@RomanPudashkin
Copy link
Contributor

Buffer sizes below are problematic in a new way

@rtbo regarding this issue: can we limit the min size to this constant MINIMUM_BUFFER_SIZE (audiotypes.h)?

@DmitryArefiev
Copy link
Contributor

Tested on LinuxUbuntu 22.04.4 LTS (Wayland)

@rtbo Now it doesn't crash, but I don't have a sound during note input and playback doesn't start

MuseScore_240819_120345.log

@DmitryArefiev have you installed pipewire on your ubuntu-22.04? (installed by default starting 22.10). If not you should see the same as the master branch.

I think not. I still have 22.04.4 LTS after installing all updates

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