PromyLOPh / pianobar

Console-based pandora.com player
http://6xq.net/pianobar/
Other
1.73k stars 323 forks source link

Cuts off the end of the song #735

Closed ronilaukkarinen closed 1 year ago

ronilaukkarinen commented 1 year ago

Subject of the issue

In the end of every song about 10 seconds gets cut off before starting the next song in queue.

Your environment

#tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0
user = xxxxxxx@xxxxxxx.com
password = xxxxxxx
event_command = /Users/rolle/.config/pianobar/events.py
proxy = http://127.0.0.1:9090

Steps to reproduce

Play any station.

Expected behaviour

Songs should play through.

Actual behaviour

Songs get cut off about 10 seconds before they are ending.

PromyLOPh commented 1 year ago

I cannot reproduce this behavior, but I also don’t have a Mac. Can you build pianobar with debug info and run PIANOBAR_DEBUG=2 ./pianobar? It’ll spit out alot of debug messages regarding the audio playback. Perhaps there’s anything suspicious in there rigth before the cutoff.

zuphinx commented 1 year ago

This is what I see when the song cuts off:

av_read_frame failed with code -54, sending NULL frame
decoder is done, waiting for ao player
ao player got EOF, exiting
ao player is done
PromyLOPh commented 1 year ago

If I see correctly error code 54 is ECONNRESET on MacOS. Can you confirm that?

zuphinx commented 1 year ago

Confirmed. I used av_err2str() to get more information about the error code.

av_read_frame failed with code -54, sending NULL frame
[DBG] error code -54 gives: Connection reset by peer    <<<<<
decoder is done, waiting for ao player
ao player got EOF, exiting
ao player is done
PromyLOPh commented 1 year ago

Maybe something like this might help already? In theory it should re-open the stream where it stopped.

diff --git a/src/player.c b/src/player.c
index 875f473..ebcbeea 100644
--- a/src/player.c
+++ b/src/player.c
@@ -533,7 +533,8 @@ void *BarPlayerThread (void *data) {
            if (openFilter (player) && openDevice (player)) {
                changeMode (player, PLAYER_PLAYING);
                BarPlayerSetVolume (player);
-               retry = play (player) == AVERROR_INVALIDDATA &&
+               int ret = play (player);
+               retry = (ret == AVERROR_INVALIDDATA || ret == -ECONNRESET) &&
                        !player->interrupted;
            } else {
                /* filter missing or audio device busy */

edit: Should be -ECONNRESET obviously.

zuphinx commented 1 year ago

With the patch, the song completes. There is a slight blip in the audio, but the patch is a definite improvement. On one occasion, I saw the remaining time flip to the song duration and then back to where it was, but this doesn't happen all the time.

PromyLOPh commented 1 year ago

Thanks for testing! The blip and time flipping probably happen for all reconnects, not just this one.

I’m still curious why this happens, because I’ve never seen this issue before. Is your network particularly unstable?

zuphinx commented 1 year ago

No, the network is fine. I have a newer MacBook Pro running Ventura and the problem doesn't happen. The problem happens on an older MacBook Pro running Monterey (with all of the latest OS and homebrew updates). When I was actively using the older laptop a couple/few years ago I didn't run into any pianobar problems. I noticed the problem when I recently started using the laptop again.