Bug 1212421

Summary: toggling audio_output do not affect immediately audio output through pipewire.socket
Product: [openSUSE] openSUSE Tumbleweed Reporter: Jimis Hol <hol.jimis>
Component: SoundAssignee: Antonio Larrosa <alarrosa>
Status: NEW --- QA Contact: E-mail List <qa-bugs>
Severity: Minor    
Priority: P5 - None CC: tiwai
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: openSUSE Tumbleweed   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jimis Hol 2023-06-15 19:35:43 UTC
I start mpd through mpd.socket in user space.
Almost always, I use httpd type of output, so i am not really sure if the behavior concerns pipewire only or pulseaudio too.
Recently I migrated to pipewire and wanted to test pipewire type of audio output.
I use ncmpcpp as a client.
On booting, pipewire.socket is active but pipewire.service is not.
Opening ncmpcpp makes mpd.service to start and pipewire.service too. But not immediate sound is out. There is no sound even if mpd starts with the ON option to pipewire type of output.
After 4 or 5 minutes the sound starts (maybe when a new song starts).
The easy workaround is to go to Show playlist and hit Enter to play the selected item. After that, toggling the pipewire output makes immediate respond to sound toggling as ON and OFF accordingly.
Another workaround is to restart mpd.service

I tried to edit mpd.service as Requires=pipewire.service and After=pipewire.service, with no success. (As I mentioned, pipewire.service seems to start normally). Anyway i would not like such a solution.

The expected behavior would be to hear immediate sound when mpd service starts, through ncmpcpp, and pipewire type of audio output is ON. Additionally, sound should toggle immediately after pipewire type of output is toggled.
Thank you.
Comment 1 Takashi Iwai 2023-06-16 08:04:06 UTC
Something for Antonio, I suppose.
Comment 2 Antonio Larrosa 2023-06-16 10:04:50 UTC
Thanks, Takashi. Yes, I guess this is for me.

Jimis, I don't have much experience with mpd, but I made a quick test and it doesn't seem to start playing automatically when it's started. I also did a web search and found the general solution to this is to run at some point "mpc play" to let mpd play. Did you try adding:

ExecStartPost=/usr/bin/mpc play

to the user mpd.service file ? (not the system one)

Btw, when you say "On booting, pipewire.socket is active but pipewire.service is not." You mean "On booting and logging in", right?

> The expected behavior would be to hear immediate sound when mpd service starts, 

The above addition for the service file should work for that, otherwise you have to give mpd the "play" command throught ncmpcpp (which at least here works fine). 

> through ncmpcpp, and pipewire type of audio output is ON. Additionally, sound 
> should toggle immediately after pipewire type of output is toggled.

As I said, I'm not familiar with mpd. How do you toggle outputs at runtime?
The mpd.conf file I used to test is:

===
audio_output {
    type     "pipewire"
    name     "PipeWire Sound Server"
    enabled  "yes"
}

db_file            "~/.config/mpd/database"
music_directory    "~/Music"
===
Comment 3 Jimis Hol 2023-06-16 19:23:02 UTC
> I also did a
> web search and found the general solution to this is to run at some point
> "mpc play" to let mpd play. Did you try adding:
> 
> ExecStartPost=/usr/bin/mpc play
> 
> to the user mpd.service file ? (not the system one)

I avoided to install mpc client, as I use ncmpcpp for the same job. I am sure that ExecStartPost would surely work, as it is an automatic equivalent to my workaround of "The easy workaround is to go to Show playlist and hit Enter to play the selected item." My thinking is that such a workaround should not be necessary.

> Btw, when you say "On booting, pipewire.socket is active but
> pipewire.service is not." You mean "On booting and logging in", right?

Yes, exactly. If, after loggining in, some application wants to produce sound, pipewire.socket activates pipewire.srvice normally. mpd.service do activate pipewire.service too, but needs an additional "play" command to produce sound through pipewire.

> As I said, I'm not familiar with mpd. How do you toggle outputs at runtime? 

I toggle through key 7 of Show output screen of ncmpcpp client. (On some ncmpcpp updates that option disappeared but it came back and on present version i can use that facility.) I can not tell how ncmpcpp achieves that but, i never need to edit my initial configuration of mpd.conf, that is same as yours except the 
enabled  "yes"
line.

That minor issue, if it is to be considered an issue, may have only theoretical significance for developers of pipewire and/or mpd, as to understand what differentiate mpd from other sound applications and mpd needs an additional "play" command to start to produce sound.
Comment 4 Jimis Hol 2023-06-16 19:26:36 UTC
I do not have 'enabled "yes" ' line.