tramhao / termusic

Music Player TUI written in Rust
GNU General Public License v3.0
1.14k stars 46 forks source link

Can't overlap audio output at the same time involving ALSA #127

Open dummyy1 opened 1 year ago

dummyy1 commented 1 year ago

I can't watch YouTube videos or output any kind of audio outside of Termusic when is open, regardless if it's playing or not. I got this unspecified error loop: an error occurred on output stream: A backend-specific error has occurred: ALSA function 'snd_pcm_poll_descriptors' failed with error 'UnknownErrno: Unknown errno' If I close Termusic then I can output audio without problems. I also have Pipewire and PulseAudio installed. I installed Termusic using Cargo and it automatically installed the binaries at /root/.cargo/bin/termusic so when I run it by alias I need superuser privileges to access the /root/ folder, maybe it has something to do because some time ago I build it instead and this error didn't occurred.

tramhao commented 1 year ago

Seems strange. I can play youtube videos via brave browser and also playing termusic in the background.
My sound setup is Pipewire and pulseaudio. I didn't have pipewire-alsa installed but I have pulseaudio-alsa installed. When I'm playing, within pavucontrol, I can see termusic as an alsa-plugin. Would you please check your configuration? Seems something related to alsa.

plum commented 8 months ago

Well, I must say what a nicely envisioned cli, and neatly featured. I've enjoyed settin git up and using it, with music and in particlar, podcast streams and searching. Thankyou.

I have this output problem too. I am using pipewire-alsa. I also use pavu and wireviz, with pipewire's pseudo--pulse feature.

The main problems caused by this are switching sound applications whilst keeping termusic open.

I get no output from any other player, even when termusic isn't playing, but only when I close termusic. 1. wirevize showing the connections .

I'm attatching two screenshots with brave/youube plahing simultaenously with termusic, and gpodder/mpv; In this case I only get termusic output. screenshot_2024-03-09_02-34-50_780050743 screenshot_2024-03-09_02-36-35_515863983

Screenshots:

  1. wireviz
  2. pulseaudio-volume-control

3 telling points about the screenshots: NOTE 1: on the pavuvtl playback tab you can see output from brave to 'built in analogue stereo', but no sound is heard! NOTE 2: On th ewireviz diagram you see that gpodder/mpv is 'attached' to the output, although there is no sound. NOTE 3: termmusic doesn't appear wireviz at all, although it does output to the analogue stereo and is heard.

John

archlinux lts termusic, 0.7.11-4

hasezoey commented 8 months ago

i am running termusic (rusty(alsa), mpv, gstreamer) with pipewire 1.0.3 and have not had any problems (aside from sound stopping when gdb pausing termusic in rusty(alsa) backend).

could this be reconfirmed with latest master (currently at 3560924113989c6a17616ea2143c7f3d79fb87c9)? also please provide extra information like what sound system you use (alsa, pipewire, pulseaudio) and their versions and which backend in termusic is used (rusty(alsa), mpv, gstreamer)

manjaro 23.1.3

PS: please note that 0.7.11 is quite old and way behind

plum commented 8 months ago

i am running termusic (rusty(alsa), mpv, gstreamer) with pipewire 1.0.3 and have not had any problems (aside from sound stopping when gdb pausing termusic in rusty(alsa) backend).

could this be reconfirmed with latest master (currently at [3560924]

PS: please note that 0.7.11 is quite old and way behind

@hasezoey Thank you for kind reply. I shall report back then, after checking out the latest version; the installaiton was from the arch user repo (aur repository). I shall use git.

I am gong to look into ensuring I use mpv - I don't beleive it is in termusic's config; When checking dependencies for current installation, I saw gstreamer but not mpv; perhaps that is the aur's package config.

BTW: is there a way to search in the podcasts episode list? I don't beleive there is, and if not, has this ever been suggested as a new feature?

Shall report back shortly, in a couple of days.

John

hasezoey commented 8 months ago

I am gong to look into ensuring I use mpv - I don't beleive it is in termusic's config; When checking dependencies for current installation, I saw gstreamer but not mpv; perhaps that is the aur's package config.

termusic-git gets compiled with --all-features, whereas termusic only gets compiled with --features cover, and the only default backend is rusty (not mpv or gst). also note that in 0.7.11 the backends were mutually exclusive, but on current master (currently at 3560924113989c6a17616ea2143c7f3d79fb87c9), you can compile-in multiple backends and select between them using --backend (though not via config or env yet)

BTW: is there a way to search in the podcasts episode list? I don't beleive there is, and if not, has this ever been suggested as a new feature?

i dont see such a feature yet, but Library already has Playlist / Music directory search (via /), maybe it could be adapted. But this is unrelated to the current issue, so see #230 instead.

plum commented 8 months ago

Sorry for delay, I spent plenty of time checking out the bug, after ensuring the latest termusic from git was installed. I'll keep things as pointed and breif as possible, in order to be helpful; any further de-bug checks you may think useful, just ask.

My system v.0.7.11.r366.gc8f7988-1; install date: 12.03.2024 OS: Arch Linux x86_64 Kernel Release: 6.6.21-1-lts Processor Type: Intel(R) Core(TM) i5-4300M CPU @ 2.60GHz

Pipewire Version : 1:1.0.4-1

Description of Bug: When termusic is open, server running;

Some Error Reports follow, which show with the audio out conflict, when attempting to play from a second sourcee - i.e. termusic playing with audio out;

$ systemctl --user pipwire.pulse.service:

 mod.protocol-pulse: client 0x5f0dbb752020 [C* Music Player]: ERROR command:-1 (invalid) tag:4294967295 error:2>
Mar 17 10:20:22 arch-t440p pipewire-pulse[4289]: mod.protocol-pulse: client 0x5f0dbc3d8f30 [PulseAudio Volume Control]: ERROR command:-1 (invalid) tag:42949672>
lines 1-14/14 (END)

$ systemctl --user wireplumber.service Mar 17 10:40:03 arch-t440p wireplumber[270917]: 1 pending linkable(s) not activated in 20sec. This should never happen.

$ ytfzf [some you tube url] [ao] "Audio output esd not found!" "failed to start: "

CHeers John

hasezoey commented 8 months ago

pipewire plugins: gst-plugin-pipewire helvum pipewire-audio pipewire-jack pipewire-pulse $ systemctl --user pipwire.pulse.service:

just to confirm you dont have pipewire-alsa installed?

hasezoey commented 8 months ago

if you are using alsa via pipewire-pulse and have this issue, this sounds like a bug in pipewire-pulse and not much that can be done in termusic (aside from not using alsa i guess), at least i have no understanding of what is failing in pipewire-pulse for us to fix.

plum commented 8 months ago

if you are using alsa via pipewire-pulse and have this issue, this sounds like a bug in pipewire-pulse and not much that can be done in termusic (aside from not using alsa i guess), at least i have no understanding of what is failing in pipewire-pulse for us to fix.

I think you're quite correct, from my observation of the error messages. Yet all other audio players work OK together - this is unique to termusic. I use at around seven others from time to time. It may be due to fact that the server takes over; I intend to fire up mpd and try nmpcpp to see if it's the same result. As for alsa, I think I have to use alsa, that goes with the sound architecture at kernal level. Its pulse that is optional.

Whatever the case I see I have, in my patch diagram, output from 'pipewire ALSA[mpv]/ALSA Playback' I do have gstreamer on baord; how would switch to that insytead of mpv; Perhaps it would fare better;

q.1 Is it right mpv /gstreamer option selected at make, or is there a user config option?

Also, I notice the line, 'player_port = 50101' I wonder if that may have somehting to do with it, and perhaps that needs altering somehow;

q.2 Do you know how I might delve further into that quesiotn of ports?

I might be wise to consider ditching pipewire-pulse for now, and switch to pipwire-jack. It would beed careful patching manually but I know ardour works well with that, which is of course a multi-track audio suequencer.

tramhao commented 8 months ago

is this issue https://github.com/RustAudio/cpal/issues/634 related to the bug above?

hasezoey commented 8 months ago

q.1 Is it right mpv /gstreamer option selected at make, or is there a user config option?

to change the backend, you first need to compile it in via feature flags, or all via all-backends feature, then next you need to pass --backend yourChoice or TMS_BACKEND=yourChoice. possible backends (and features) are rusty(default feature) gst (gstreamer) and mpv.

You can verify which backend is used by looking into the server logs and looking for a line along of Using Backend ...

Also, I notice the line, 'player_port = 50101' I wonder if that may have somehting to do with it, and perhaps that needs altering somehow;

that is for the gRPC server, which is used as communication between server and TUI.

I might be wise to consider ditching pipewire-pulse for now, and switch to pipwire-jack. It would beed careful patching manually but I know ardour works well with that, which is of course a multi-track audio suequencer.

i dont know if that will be possible, termusic only supports ALSA on linux at the moment.

As for alsa, I think I have to use alsa, that goes with the sound architecture at kernal level. Its pulse that is optional.

i dont know how it works in the kernel, but i think a userspace app (like pipewire) can intercept it to handle it for itself, or have a virtual device that will be targeted (and created by the app (like pipewire)).


is this issue https://github.com/RustAudio/cpal/issues/634 related to the bug above?

maybe, but i think the problem here is outputting to the same device termusic targets, not other devices which have been iterated

plum commented 8 months ago

@hasezoey Thanks for kind reply, some usefu information there.

I can confirm, from prior knowledge when getting to grips with pipewire, that Linux as currently built by Arch - and ineed all linux so far as I am aware, does require Alsa for ALL sound at kernal level, and it is therefore built into the kernal; however you dont have to use alsa in user space, but can opt for pule or jack; nontheless Alsa will be running at kernal level. Pipewire intercepts from alsa, and negated that part of alsa that is used for user space config.

Best wishes. John

plum commented 8 months ago

Good news, progress made, and I have it sorted: termusic when up, no longer blocks playing another sound source; all sound sources play well together, from mpv, or through browser , or directly through cmus/alsa.

In short, pipewire-pulse was the culprit.

What I did was remove pipewire-pulse ('pulseaudio' itself was not installed, it being replaced by pipewire), and ensured pipewire-audio was installed (it was already). I also removed pavuctl, becuase it is now redundant.

Pipewrire audio is also a session manager, and works instead of pulse. It has no --user service file, unlike pipewire-pulse; It runs with pipewire.service.

All is working; there is more to do in regard to configuring wireplumber with alsa; Bcause wireplumber appears to come configured to work with pipewire-pulse, and so reveals no patch connections or players, THAT IS,

The alsa mixer shows nothing unusual. Mpris through dbus is working fine alongside. Neither Cmus nor mpv need any special configuration; I commented all out, and default values work fine. Brave browers and qutebrowser worked - they find the right audio sink on restart.

Aurora Music studio mixing/sequencing software works fine as usual (it takes over from alsa in kernal through jack).

I am now a full-on termusic user!

The raiotnal behind removing pipewire-pulse, apart form the fact that it was a suspected culprit, is that it is only required as a session manager for those who wish to play software that is dedicated to using pulse, (like Musiccube, if I'm not mistaken). I dont. It was advised by many to install a smatterof course, and in order to retain pavuctl, which is thought to be a neat. user sounbd configutaion panel for selcting audio inputs and outputs, rather like Mac OSx's.

Pipewire has its own session manager, and the pulse plugin runs on top, it being likely at times to make mishcheif therefore. Configuration for user space, is not necessary. Wireplumber could be useful for more specialised needs - like recording multitrack along with a digital mixer.

Cheers, John

hasezoey commented 8 months ago

just to confirm what distro are you using?

i am using Manjaro 23.1.3 and have the following installed, without any problems:

$ pacman -Ss "pipewire*" | grep installed
extra/gst-plugin-pipewire 1:1.0.3-1 [installed]
extra/kpipewire 5.27.11-1 (plasma) [installed]
extra/libpipewire 1:1.0.3-1 [installed]
extra/libwireplumber 0.4.17-1 [installed]
extra/manjaro-pipewire 20231009-1 [installed]
extra/pipewire 1:1.0.3-1 [installed]
extra/pipewire-alsa 1:1.0.3-1 [installed]
extra/pipewire-audio 1:1.0.3-1 [installed]
extra/pipewire-jack 1:1.0.3-1 [installed]
extra/pipewire-pulse 1:1.0.3-1 [installed]
extra/pipewire-zeroconf 1:1.0.3-1 [installed]
extra/qemu-audio-pipewire 8.2.2-1 [installed]
extra/wireplumber 0.4.17-1 [installed]

also as far as i know, i am basically using default pipewire configuration and have not manually changed anything.

also pipewire for me works in user mode and not system mode:

$ ps -aux | grep pipewire                
hasezoey    1832  0.0  0.1 114404 16948 ?        S<sl 12:43   0:02 /usr/bin/pipewire
hasezoey    1958  0.1  0.1 114980 17944 ?        S<Lsl 12:43   0:04 /usr/bin/pipewire-pulse

$ systemctl --user status pipewire.service
● pipewire.service - PipeWire Multimedia Service
     Loaded: loaded (/usr/lib/systemd/user/pipewire.service; disabled; preset: enabled)
     Active: active (running) since Tue 2024-03-19 12:43:20 CET; 55min ago
TriggeredBy: ● pipewire.socket
   Main PID: 1832 (pipewire)
      Tasks: 3 (limit: 19065)
     Memory: 9.8M (peak: 11.6M)
        CPU: 2.086s
     CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pipewire.service
             └─1832 /usr/bin/pipewire

Mar 19 12:43:20 Meicoo-Manjaro systemd[1412]: Started PipeWire Multimedia Service.

$ systemctl --user status wireplumber.service
● wireplumber.service - Multimedia Service Session Manager
     Loaded: loaded (/usr/lib/systemd/user/wireplumber.service; enabled; preset: enabled)
     Active: active (running) since Tue 2024-03-19 12:43:20 CET; 1h 7min ago
   Main PID: 1833 (wireplumber)
      Tasks: 7 (limit: 19065)
     Memory: 25.8M (peak: 27.4M)
        CPU: 281ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/wireplumber.service
             └─1833 /usr/bin/wireplumber

Mar 19 12:43:20 Meicoo-Manjaro systemd[1412]: Started Multimedia Service Session Manager.

Pipewrire audio is also a session manager, and works instead of pulse. It has no --user service file, unlike pipewire-pulse; It runs with pipewire.service.

i dont know which distro you are on, but at least in arch / manjaro pipewire-audio is just a library, not a session manager, the only session managers i am aware of are pipewire-media-session(legacy) and wireplumber(recommended). another source than my system and knowledge


PS: just to ask again, as i have not seen a answer, did you already try pipewire-alsa?

plum commented 8 months ago

@tramhao

also pipewire for me works in user mode and not system mode

Agreed.

just to confirm what distro are you using?

i dont know which distro you are on, but at least in arch / manjaro pipewire-audio is just a library, not a session manager, the only session managers i am aware of are pipewire-media-session(legacy) and wireplumber(recommended). another source than my system and knowledge

You're correct; wireplumber is the session manager; pipewire-media-session and pipewire-pulse are alternatives.

PS: just to ask again, as i have not seen a answer, did you already try pipewire-alsa?

Yes , I always had it installed, only removed pipwire-pulse; I am using pipewire-alsa exclusively now, with wireplumber, as follows:

My system:

OS: Arch Linux x86_64 Kernel Release: 6.6.21-1-lts Processor Type: Intel(R) Core(TM) i5-4300M CPU @ 2.60GHz

Pipewire and Plugins installed: Pipewire Version : 1:1.0.4-1 pipewire plugins: gst-plugin-pipewire, pipewire-alsa, pipewire-audio pipewire-jack pipewire-pulse Wireplumber Version : 0.4.17-1.16

ps -aux | grep pipewire  
chuee       1328  0.1  0.1 199016 10192 ?        R<sl 04:46   1:40 /usr/bin/pipewire
chuee      57645  0.0  0.0   6932  2552 pts/2    S+   19:50   0:00 grep --color=auto --exclude-dir=.svn 

To correct myself then, pipewire-pulse and pipwire-media session are redundant for me, when relying upon wireplumber, and because i do not use any player that inists upon pulse.

And, to re-iterate, removal of pipewire-pulse has cleared the problem of termusic blocking other audio output. Now, Having said that, I always had wireplumber installed and running; it is possible that the two, pipwire-pulse and wireplumber did not play well together for me when running termusic.

Note, also - I aways had pipewrire-alsa installed too; Unlike pipewire-pulse, it does not have a systemd service file.

hasezoey commented 8 months ago

You're correct; wireplumber is the session manager; pipewire-media-session and pipewire-pulse are alternatives.

Note, also - I aways had pipewrire-alsa installed too; Unlike pipewrie-pulse, it does not have a systemd service file.

to my knowledge pipewire-pulse is not a replacement for a pipewire session, it just creates a pulse server that translates to pipewire, that is required because of how pulseaudio works, and alsa (and maybe jack) have no server requirement and so can work without one being started (via a service file)

And, to re-iterate, removal of pipewire-pulse has cleared the problem of ternusic blocking other audio output.

great to hear


so assuming @dummyy1 does not report back to still have problems with the latest master (and verify their setup), i think this issue could be closed (and just a new one created if it should ever pop-up again or ask in discussions)

plum commented 8 months ago

@tramhao

great to hear

Yes, it is good, thanks very much for you help. I hope this discussion helps others too.

so assuming @dummyy1 does not report back to still have problems with the latest master (and verify their setup), i think this issue could be closed (and just a new one created if it should ever pop-up again or ask in discussions)

I would say so, unless you want this particular issue is to include the issue of termusic-server blocking itself from audio output after wake from sleep; I cant remember if I saw it reported as a seperate issue or not, somehwhere - I almost believe I did.