mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.2k stars 571 forks source link

Shairport-Sync only shows metadata for first song when streaming Amazon Music from Mac #1350

Closed derekatkins closed 2 years ago

derekatkins commented 2 years ago

I'm driving Shairport-Sync from a Mac; the audio source is Amazon Music running in a Chrome browser, and I Airplay via the audio icon on the top of the screen.

When I initiate the Airplay, I see the metadata for the currently playing song; it happily sends along all the song info, including artwork. However, once that song ends and it goes to the next song, I don't see the new song metadata. Even more, if I look at the "play timer" I see that it's now playing at, like "6:03/4:05".

Is this a Shairport-Sync issue or is it a Mac/Chrome/Amazon Music issue? One would think that, since it knows how to get the metadata at the beginning, it would continue along. But maybe there is an integration issue at that level?

Just one piece of added information: if I stream from the Amazon Music app on my wife's iPhone then I do get updated metadata when new songs start, so it could be the integration on the Mac.

mikebrady commented 2 years ago

Thanks for this. It looks as if Shairport Sync is working properly alright, but that metadata is not being forwarded by Amazon Music on Chrome. Can you clarify, please, where the "6:03/4:05" is being shown? On Chrome?

derekatkins commented 2 years ago

Sorry for being incomplete. My system is: Mac/Chrome (Amazon Music Website) -> Shairport-Sync | OwnTone -> Shairport-Sync (Speaker) The "6:03/4:05" is being shown on OwnTone. The "4:05" is the length of the first song running when I initialize the Mac -> Shairport Airplay connection.

mikebrady commented 2 years ago

Thanks. Using a fully up to date MacBook Pro M1/Chrome Amazon Music → Shairport Sync (Speaker), the metadata is coming in for each track. I'm just trying their "Christmas Party" mix -- don't judge me, okay?

derekatkins commented 2 years ago

I've been using several channels. Maybe I'm configuring Airplay incorrectly, then? I go to the speaker icon in the top menu (next to the clock) and click on that to pull down the airplay list to send to Shairport. Is there a way to do it from chrome or the amazon music website more directly?

FWIW I'm on an Macbook Air, MacOS 10.15.7 (Catalina), Chrome 96.0.4664.55.

mikebrady commented 2 years ago

I did it just as you described, and I don't know of another way. It suggests to me that the metadata might be getting to OT, but maybe not coming out. You can check yourself to see if metadata is getting through the first Shairport Sync.

derekatkins commented 2 years ago

I did test that -- I ran the AmazonMusic App on my wife's iPhone and it came through correctly all the way to OT.

mikebrady commented 2 years ago

My version of Chrome is Version 96.0.4664.55 (Official Build) (arm64), so it looks the same albeit on different architectures.

So is it worth trying from the Mac/Chrome source as distinct from the iOS/App source to the first Shairport Sync? (On Track 11 here and everything is peachy.)

derekatkins commented 2 years ago

So is it worth trying from the Mac/Chrome source as distinct from the iOS/App source to the first Shairport Sync? (On Track 11 here and everything is peachy.)

I'm not sure what you mean here.

mikebrady commented 2 years ago

As I see it, you have this situation:

macOS/Chrome/Amazon Music → Shairport Sync ("SPS") → OT → Multiple (SPS → Speaker) and it doesn't deliver metadata properly. But:

iOS/Amazon Music App → SPS → OP → Multiple (SPS → Speaker) does deliver metadata properly.

I have found that: macOS/Chrome/Amazon Music → SPS Speaker does deliver metadata properly.

So my suggestion to to check whether macOS/Chrome/Amazon Music → SPS Speaker delivers metadata properly in your situation.

If it does, then is suggests it's getting lost in the rest of the chain (OT, etc.). If it doesn't, then it suggests something weird in macOS/Chrome/Amazon Music, since it works for me here (though I am on the latest SPS).

derekatkins commented 2 years ago

I've only been checking the metadata at OT. The final (Multiple SPS -> Speaker) step(s) don't have metadata ouptut. Although there are two more things for me to try... Hold on..

derekatkins commented 2 years ago

I decided to try with Safari on my MBA, and also try Edge on my wife's Mac -- both of them behave the same as Chrome -- I only get metadata for the first song. So I wonder what's different about your Mac/Chrome/AmazonMusic vs mine/ours?

mikebrady commented 2 years ago

Yes, that's a good question, and I don't have an answer, I'm afraid. My machine is an Apple Silicon Mac, it's on Monterey.

derekatkins commented 2 years ago

Well, other than that I am two releases behind you on my MBA... and she's on Big Sur on her Mac. So... maybe it's something that's been fixed in Monterey? Short of updating, I'm not sure how to test that theory.

mikebrady commented 2 years ago

Indeed. Just trying on a trashcan MacPro running Monterey -- this time with Safari. It is providing some metadata for each track. Artwork is not being supplied, but some other stuff is -- I don't know what it is, but it's short. I won't be able to try Chrome until tomorrow, I'm afraid. So there is some difference between the ASi Macs and the Intel Macs, it seems.

derekatkins commented 2 years ago

Hmm...

mikebrady commented 2 years ago

Okay, I did manage to get Chrome onto my Mac Pro, build Version 96.0.4664.55 (Official Build) (x86_64). It is sending full metadata (including artwork). I'll have to check Safari again tomorrow.

derekatkins commented 2 years ago

So I wonder if it's a Monterey vs Big Sur / Catalina issue?

mikebrady commented 2 years ago

Okay, I've done a bit more work on this. The difference between our experiences is down to you using AirPlay 1 and me using AirPlay 2 (I shoulda thought of that -- sorry).

This table gives an overview of what I found:

amm

There was no great difference between Apple Silicon and Intel Macs.

derekatkins commented 2 years ago

Thanks for that testing. I'll just add that Chrome+AirPlay-1 does show Artwork at Start. For THIS platform it might make sense for me to pull from dev and build with AP-2 (it's an RPM-based system). Let me try that..

derekatkins commented 2 years ago

As a side note, what is it about AP2 that prevents multiple instances from running on the same device? Unfortunately that will be an issue for me.

charlesomer commented 2 years ago

Feel free to correct me on this Mike but I believe it’s down to NQPTP only being able to run on two specific ports and we aren’t sure if it’s possible in principle for one NQPTP instance to handle/manage multiple Shairport Sync instances or how this would be achieved.

mikebrady commented 2 years ago

As a side note, what is it about AP2 that prevents multiple instances from running on the same device? Unfortunately that will be an issue for me.

@charlesomer has it right.

AP2 requires PTP clock functionality. At present, the program that monitors PTP signals -- nqptp -- can deal with one set of timing peers, i.e., clocks belonging to one playing session. The ports used for PTP are fixed -- 319 and 320 -- so we can not simply have multiple instances of nqptp running on separate sets of ports.

We also don't know whether AirPlay 2 implementations would function with multiple Shairport Sync instances at the same addresses.

Our efforts are focused on getting a good understanding of AirPlay 2. As we get more experience, it might become possible to experiment with multiple timing peer groups interfacing to multiple instances of Shairport Sync on the same system. But right now, as you'll appreciate, we need to keep things simple as possible.

derekatkins commented 2 years ago

Interesting. The docs for nqptp claim it can monitor 32 other instances. But I have looked at this for a total of 30 minutes so far, so I'm certainly nowhere near an expert! I completely understand and appreciate the need to keep things simple. Could you bind it down to a single interface and then have different instances running on different interfaces on one host?

Here's a side question: Can I have a single shairport-sync executable configured for both AP1 and AP2, and then via the config file turn off AP2 on all but one instance? That would at least let me play with AP2 for my main OT instance, but still support my other requirements on the single host.

mikebrady commented 2 years ago

Interesting. The docs for nqptp claim it can monitor 32 other instances.

That’s not what is meant. It — nqptp — can monitor up to 32 PTP clocks, belonging to other AP2 devices that are playing the same material.

Could you bind it down to a single interface and then have different instances running on different interfaces on one host?

One could imagine doing that, but it complicates things unnecessarily when we’re still trying to figure things out. The idea is to avoid adding features and settings that don’t contribute to understanding the protocols.

Here's a side question: Can I have a single shairport-sync executable configured for both AP1 and AP2, and then via the config file turn off AP2 on all but one instance? That would at least let me play with AP2 for my main OT instance, but still support my other requirements on the single host.

Same reason as before — it doesn’t really help us to move forward. Adding your suggested feature would simply complicate things for no gain right now.

To solve this problem, why not have two separate builds of Shairport Sync on the system, one of each build type?

derekatkins commented 2 years ago

@mikebrady Just FYI, (let me know if you want me to open another ticket for this) -- I cannot build the development branch on F35 with AP2 because the header in question is in /usr/include/ffmpeg/libavcodec/avcodec.h:

gcc -DHAVE_CONFIG_H -I.    -fno-common -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread -DSYSCONFDIR=\"/etc\"  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -c -o rtp.o rtp.c
rtp.c:49:10: fatal error: libavcodec/avcodec.h: No such file or directory
   49 | #include <libavcodec/avcodec.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Looking at configure.ac, it doesn't use pkg-config, because if it did it would have known to add the proper include:

$ pkg-config --cflags libavcodec
-I/usr/include/ffmpeg 
mikebrady commented 2 years ago

Thanks. I'll take a look at it.

mikebrady commented 2 years ago

Meantime, could you try this -- comment out the AC_CHECK_LIB and insert a PKG_CHECK_MODULES instead in configure.ac?

  PKG_CHECK_MODULES([libavcodec], [libavcodec],[CFLAGS="${libavcodec_CFLAGS} ${CFLAGS}" LIBS="${libavcodec_LIBS} ${LIBS}"],[
      AC_MSG_ERROR(AirPlay 2 support requires libavcodec -- libavcodec-dev suggested)])
#  AC_CHECK_LIB([avcodec],[avcodec_find_encoder], [], [AC_MSG_ERROR([AirPlay 2 support requires libavcodec -- libavcodec-dev suggested])])

You'll need to do an autoreconf -fi and the ./configure... step again...

derekatkins commented 2 years ago

@mikebrady That fixed it; it builds now. Thanks.

mikebrady commented 2 years ago

Thanks for that testing. I'll just add that Chrome+AirPlay-1 does show Artwork at Start.

Yeah, just checked again, getting pictures of size 0 bytes with macOS/Chrome/AirPlay 1.

mikebrady commented 2 years ago

@mikebrady That fixed it; it builds now. Thanks.

Cool -- it's in the upcoming development update...

derekatkins commented 2 years ago

Yeah, just checked again, getting pictures of size 0 bytes with macOS/Chrome/AirPlay 1.

That's odd, because I thought I was seeing artwork on OT's WebUI from the first song being played. Anyways, I'm almost ready to start testing AP2

derekatkins commented 2 years ago

So I got the development version up and running, but while I am getting audio out via my pipe to OT, I'm not getting ANY metadata out (song title/artist or artwork) -- or if there is, OT can't read it. I'm using the exact same config I had been using from v3.3.8. Yes, I compiled with:

           --with-avahi --with-alsa --with-ssl=openssl --with-soxr \
       --with-pipe --with-dummy --with-stdout --with-pa --with-metadata \
       --with-airplay-2
mikebrady commented 2 years ago

Thanks for the update. Could we see the configuration string please? From:

$ shairport-sync -V
mikebrady commented 2 years ago

And could we see the configuration file, please?

derekatkins commented 2 years ago

Sure. shairport-sync -V reports:

4.1-dev-25-ga05db621-dirty-AirPlay2-OpenSSL-Avahi-ALSA-pa-dummy-stdout-pipe-soxr-metadata-sysconfdir:/etc

and the config file (I removed all commented-out and blank lines):

general =
{
    name = "Whole House";
    output_backend = "pipe";
    port = 5000; // Listen for service requests on this port
    udp_port_base = 10000; // start allocating UDP ports from this port number when needed
    udp_port_range = 48; // look for free ports in this number of places, starting at the UDP port base. Allow at least 10, though only three are needed in a steady state.
    ignore_volume_control = "yes"; // set this to "yes" if you want the volume to be at 100% no matter what the source's volume control is set to.
};
sessioncontrol =
{
};
alsa =
{
};
sndio =
{
};
pa =
{
};
jack =
{
};
pipe =
{
    name = "/srv/whole_house/shairport-sync"; // this is the default
};
dsp =
{
};
metadata =
{
    enabled = "yes"; // set this to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe
    pipe_name = "/srv/whole_house/shairport-sync.metadata";
};
mqtt =
{
};
diagnostics =
{
};
mikebrady commented 2 years ago

Thanks. I've just tried that, but in /tmp/whole_house/shairport-sync.metadata. I had to create the directory whole_house and I had to ensure that it was owned by shairport-sync user and group (on a Pi) -- otherwise Shairport Sync would die because it would be unable to create the pipe. (BTW, I didn't create the pipe itself -- Shairport Sync did that.)

root@RaspberryPi3B:/tmp# ls -al
total 44
drwxrwxrwt 11 root           root           4096 Dec  1 21:55 .
drwxr-xr-x 18 root           root           4096 Nov  8 15:07 ..
drwxrwxrwt  2 root           root           4096 Nov 21 09:25 .font-unix
drwxrwxrwt  2 root           root           4096 Nov 21 09:25 .ICE-unix
drwxrwxrwx  3 shairport-sync shairport-sync 4096 Nov 28 21:44 shairport-sync
prw-rw-rw-  1 shairport-sync shairport-sync    0 Dec  1 21:53 shairport-sync-metadata
drwx------  3 root           root           4096 Nov 21 09:28 systemd-private-46b44e60809a4c33995b0c2dd62e37d4-systemd-logind.service-jdEE8f
drwx------  3 root           root           4096 Dec  1 21:53 systemd-private-46b44e60809a4c33995b0c2dd62e37d4-systemd-timesyncd.service-tLI3Qf
drwxrwxrwt  2 root           root           4096 Nov 21 09:25 .Test-unix
drwxr-xr-x  2 shairport-sync shairport-sync 4096 Dec  1 21:58 whole_house
drwxrwxrwt  2 root           root           4096 Nov 21 09:25 .X11-unix
drwxrwxrwt  2 root           root           4096 Nov 21 09:25 .XIM-unix

and

root@RaspberryPi3B:/tmp/whole_house# ls -al
total 8
drwxr-xr-x  2 shairport-sync shairport-sync 4096 Dec  1 21:58 .
drwxrwxrwt 11 root           root           4096 Dec  1 21:55 ..
prw-rw-rw-  1 shairport-sync shairport-sync    0 Dec  1 22:00 shairport-sync.metadata
root@RaspberryPi3B:/tmp/whole_house# 

The pipe file was created by Shairport Sync. I watched it with the sample metadata reader:

pi@RaspberryPi3B:~/shairport-sync-metadata-reader $ cat /tmp/whole_house/shairport-sync.metadata | ./shairport-sync-metadata-reader 
"ssnc" "mdst": "698003119".
Persistent ID: "1970cf6a03c1b6bb".
Album Name: "".
Artist: "Mariah Carey".
Composer: "".
Genre: "".
Title: "All I Want for Christmas Is You".
"ssnc" "mden": "698003119".
"ssnc" "prgr": "697045705/698003119/707698603".
"ssnc" "pcst": "698004879".
Picture received, length 0 bytes.
"ssnc" "pcen": "698004879".
"ssnc" "mdst": "698004879".
Persistent ID: "1970cf6a03c1b6bb".
Album Name: "".
Artist: "Mariah Carey".
Composer: "".
Genre: "".
Title: "All I Want for Christmas Is You".
"ssnc" "mden": "698004879".
"ssnc" "pcst": "698004879".
Picture received, length 40358 bytes.
"ssnc" "pcen": "698004879".
"ssnc" "mdst": "698069295".
Persistent ID: "1970cf6a03c1b6bb".
Album Name: "".
Artist: "Mariah Carey".
Composer: "".
Genre: "".
Title: "All I Want for Christmas Is You".
"ssnc" "mden": "698069295".
"ssnc" "prgr": "697111756/698070703/707764654".
"ssnc" "pcst": "698070703".
Picture received, length 0 bytes.
"ssnc" "pcen": "698070703".
"ssnc" "mdst": "698070703".
Persistent ID: "1970cf6a03c1b6bb".
Album Name: "".
Artist: "Mariah Carey".
Composer: "".
Genre: "".
Title: "All I Want for Christmas Is You".
"ssnc" "mden": "698070703".
"ssnc" "pcst": "698070703".
Picture received, length 40358 bytes.
"ssnc" "pcen": "698070703".

Is there anything there that might raise a suspicion?

derekatkins commented 2 years ago

Hmm.. INTERESTING.. I see that too. So maybe it's an issue with OT. Let be go back and check with 3.3.8 and see what output I get on the fifo...

derekatkins commented 2 years ago

Okay, so watching this with Airplay-1 I only get the first song, but with Airplay-2 I DO get data for each song. I wonder if the XML changed between AP-1 and AP-2 such that OT can't read it?

derekatkins commented 2 years ago

WTF? NOW it's working?!? I copied out some XML and copied it into OT... and that worked.. So then I reconfigured shairport-sync back to the normal file location, and now OT is getting updates. WTAF? Why didn't it work earlier when I tried it hours ago?

mikebrady commented 2 years ago

That’s good news. I think we have noticed that there can be problems when an AP1 device is replaced by an AP2 device at the same address. And vice-versa. Don’t know why though.

mikebrady commented 2 years ago

Just FYI, there are two kinds of audio streams in AP2 -- Realtime and Buffered. The SPS-generated metadata (type ssnc) may be different in each case, and certainly it looks as if some of it is missing for buffered streams (see #1354). Hopefully some of this will be rectified soon.

derekatkins commented 2 years ago

Interesting. I wonder if the Mac caches some information? Yesterday morning I switched from AP1 to AP2 and it didn't work. Then I stopped testing for a while (hours), and when I went back to re-test it, it worked. I'll note that at that point, once it worked, I went back to AP1 and noticed only the single-metadata, and then went back to AP2 and saw the multi-metadata again. SO.... Yeah, it could be a cache thing. Or something else. Color me confused, but happy it's working now (albeit only for one instance of SPS).

mikebrady commented 2 years ago

Yeah, it's a mystery. Anyway it's good that you got there.

The fixes you identified will be in the next update to the development branch. There will also be pretty big changes in the timing infrastructure and to nqptp, hence the delay just to check as much as possible. We normally believe in updating quickly but this is potentially pretty far reaching...

derekatkins commented 2 years ago

Sounds good. I also might have a small update to the spec and service file, if you're interested in a small PR (against development)

derekatkins commented 2 years ago

Oh, and let me know if/when you want me to help test! :)

mikebrady commented 2 years ago

Hi Derek. There's an updated Shairport Sync and a companion updated nqptp out. Comments welcome!

github-actions[bot] commented 2 years ago

This issue has been inactive for 45 days so will be closed 7 days from now. To prevent this, please remove the "stale" label or post a comment.

derekatkins commented 2 years ago

Hi @mikebrady -- sorry for the delay in responding. I haven't had a chance to update yet. Lately I've been using the home-assistant -> owntone playlist feature to play from wall-mounted tablets. But I'll go re-test SPS2.

github-actions[bot] commented 2 years ago

This issue has been inactive for 45 days so will be closed 7 days from now. To prevent this, please remove the "stale" label or post a comment.