openairplay / goplay2

Airplay 2 Receiver written in Go
Apache License 2.0
384 stars 20 forks source link

ALSA output #3

Closed noelhibbard closed 3 years ago

noelhibbard commented 3 years ago

I see this thing is hard coded for pcm.default for the ALSA output. It would be great to have a command line option for the ALSA output. A cmd line option for the listen port would also be great. I have a few 7.1 ch sound cards in my server and have an elaborate ALSA config that busts them up into several outputs and then I run several instances of shairport-sync and each one is on it's own port and set to output to different ALSA outputs. I would love to be able to do this with AirPlay 2.

AlbanSeurat commented 3 years ago

You are not the first to have a different Alsa configuration, I will add a parameter to change the default value (pcm.default)

noelhibbard commented 3 years ago

I'm actually not getting any output at all on a freshly loaded test machine running Debian.

This works perfect though: speaker-test -D pcm.default -c 2 -f 44100 -F S16_LE

AlbanSeurat commented 3 years ago

Do you have any error while starting the program ? I use my program on a Raspberry 1 with Raspbian. Any logs ?

noelhibbard commented 3 years ago

I uncommented setLog() so it would output to a file but there are no errors in there. I also changed pcm.default to gibberish and it still doesn't produce any errors.

AlbanSeurat commented 3 years ago

there should be some logs at startup :

goplay2 -i en0
2021/07/07 20:55:08 Device Pi: be3a23ed-3159-4336-8282-1c543ff13fc9, guid: a41f6742-7fbb-4c42-b983-6094836b5a12, Psi: 94865c70-52b3-4b05-ad72-f26d10184f57

Another example if you are running without sudo on a linux (port below 1024 are usually restricted):

pi@raspberrypi:~/goplay2$ ./goplay2
2021/07/07 19:57:29 Device Pi: 583c51cb-1408-4998-a36e-8194908a8be9, guid: df903751-a6d1-4621-9518-443fbf48528f, Psi: 62b7ea64-4082-4de6-9fea-01ca856dffab
2021/07/07 19:57:30 Error while listening port 320 listen udp :320: bind: permission denied

If you do not have a similar line, there is an error in the build. If PCM.default ist not found, an error should be logged. On ArchLinux i've got an error anyway

I need to update the documentation for Raspberry Pi

AlbanSeurat commented 3 years ago

You need to pair (iPhone in my case) and try to play to music to have the error like this one :

2021/07/07 20:06:33 request received : SETUP rtsp://192.168.0.164/6934733998229897469 body 271 at 1482251614713274
2021/07/07 20:06:33 response sent : body 145 at 1482251625107943
2021/07/07 20:06:33 request received : POST /audioMode body 64 at 1482251651437105
2021/07/07 20:06:33 map[audioMode:default]
2021/07/07 20:06:33 response sent : body 0 at 1482251657656907
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM gibberish
2021/07/07 20:06:33 Audio Stream init error: could not open ALSA device gibberish
noelhibbard commented 3 years ago

I did a git reset --hard (because I did a lot of dicking around) and then rebuilt and now I am getting errors:

2021/07/07 15:10:10 Device Pi: bebf7835-08cc-43d6-bc12-bd1af42abd21, guid: 4078901e-103f-4123-9548-7b41aba8878a, Psi: 3e20f0da-c9de-484b-aafa-3410b19e8af0
2021/07/07 15:10:21 conn opened
2021/07/07 15:10:21 request received : GET /info body 70 at 10579095608
2021/07/07 15:10:21 response sent : body 415 at 10579342067
2021/07/07 15:10:21 request received : POST /pair-setup body 6 at 10594878241
2021/07/07 15:10:21 response sent : body 409 at 10607979608
2021/07/07 15:10:21 request received : POST /pair-setup body 457 at 10689348925
2021/07/07 15:10:21 response sent : body 69 at 10701876825
2021/07/07 15:10:21 request received : POST /pair-setup body 159 at 10716363992
2021/07/07 15:10:21 response sent : body 143 at 10717740767
2021/07/07 15:10:21 request received : POST /pair-verify body 37 at 10807084562
2021/07/07 15:10:21 response sent : body 140 at 10807602704
2021/07/07 15:10:21 request received : POST /pair-verify body 125 at 10816730575
2021/07/07 15:10:21 response sent : body 3 at 10817329029
2021/07/07 15:10:21 request received : POST /fp-setup body 16 at 10821924150
2021/07/07 15:10:21 response sent : body 142 at 10821961393
2021/07/07 15:10:21 request received : POST /fp-setup body 164 at 10827285868
2021/07/07 15:10:21 response sent : body 32 at 10827322998
2021/07/07 15:10:21 request received : SETUP rtsp://10.1.0.94/6148076841563931421 body 893 at 10832567870
2021/07/07 15:10:21 response sent : body 76 at 10837702333
2021/07/07 15:10:21 request received : GET /info body 0 at 10952307016
2021/07/07 15:10:21 response sent : body 415 at 10952459930
2021/07/07 15:10:21 request received : GET_PARAMETER rtsp://10.1.0.94/6148076841563931421 body 8 at 10958829234
2021/07/07 15:10:21 response sent : body 14 at 10958873814
2021/07/07 15:10:21 request received : RECORD rtsp://10.1.0.94/6148076841563931421 body 0 at 10964105659
2021/07/07 15:10:21 response sent : body 0 at 10964142384
2021/07/07 15:10:21 request received : SETPEERS rtsp://10.1.0.94/6148076841563931421 body 84 at 10968565823
2021/07/07 15:10:21 response sent : body 0 at 10968603149
2021/07/07 15:10:21 request received : POST /command body 7074 at 10972830802
2021/07/07 15:10:21 response sent : body 0 at 10973258053
2021/07/07 15:10:21 request received : SET_PARAMETER rtsp://10.1.0.94/6148076841563931421 body 20 at 318247303394551
2021/07/07 15:10:21 response sent : body 0 at 318247303438439
2021/07/07 15:10:23 request received : POST /feedback body 0 at 318249326262274
2021/07/07 15:10:23 response sent : body 0 at 318249326300201
2021/07/07 15:10:23 request received : SETUP rtsp://10.1.0.94/6148076841563931421 body 271 at 318249451292454
2021/07/07 15:10:23 response sent : body 145 at 318249451494689
2021/07/07 15:10:23 request received : POST /audioMode body 64 at 318249467149047
2021/07/07 15:10:23 map[audioMode:default]
2021/07/07 15:10:23 response sent : body 0 at 318249467242942
2021/07/07 15:10:23 Audio Stream init error: could not get periods: Invalid argument
noelhibbard commented 3 years ago

It also terminates after the "could not get periods" error.

noelhibbard commented 3 years ago

BTW, I am not using an RPi.. this is a full sized Intel powered machine I had laying around.

AlbanSeurat commented 3 years ago

I need to look at what "could not get periods" error means from alsa perspective. I have merge some change anyway, you can pass "-alsa pcm.default" to change the alsa port (README.MD is updated)

noelhibbard commented 3 years ago

Nice, thanks for that cmd line arg! As for the periods error. When I searched the code I see that message is hardcoded in the goalsa package. It's not an error coming directly from ALSA so searching on that error isn't getting me very far.

https://github.com/AlbanSeurat/goalsa/blob/master/alsa.go#L142

noelhibbard commented 3 years ago

I found this documentation: https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___h_w___params.html#ga7242d7045ae23a9ae736c191030c25e8

It says it returns a negative value if the configuration space does not contain a single value. So I think something is just messed up with this default alsa.conf that Debian 10 created. If I run goplay with --alsa pcm.front I get audio although it's breaking up I've made progress. I wouldn't spend anymore time on this. I will test tonight on my server at the house with a working alsa config.

AlbanSeurat commented 3 years ago

From my research it seems indeed that this is a missing configuration. However, I am pretty sure goplay2 does not need this parameters anyway. I am just building goplay on a debian VM to check the issues...

noelhibbard commented 3 years ago

Part of my confusion was that this project only supports BUFFERED and not REALTIME. I was initially testing with Spotify which is why it wasn't giving me any audio but also not returning any errors in stdout.

Thanks for your help and sorry to waste your time.

AlbanSeurat commented 3 years ago

Realtime will have some issue on RTP/UDP part. This is not supported for now. I use apple music on my side. I might try to implement REALTIME one day but for now I focus on Buffered + Apple Music.

AlbanSeurat commented 3 years ago

I have reproduced the issue on debian 10 and if I simply remove the retrieval of periods, I have a nice sound :) I will provide a patch

noelhibbard commented 3 years ago

I can confirm it's working now! Thanks again!