[player] Completely stop devices on playback_stop()

Previously we just flushed, and local audio devices would never get closed.
Also a little fixup to the printing of session debug.
This commit is contained in:
ejurgensen 2019-02-22 08:37:50 +01:00
parent 19694ee1dd
commit 5c35e1a9db

View File

@ -126,6 +126,8 @@
// (value is in milliseconds) // (value is in milliseconds)
#define PLAYER_WRITE_BEHIND_MAX 1500 #define PLAYER_WRITE_BEHIND_MAX 1500
//#define DEBUG_PLAYER 1
struct volume_param { struct volume_param {
int volume; int volume;
uint64_t spk_id; uint64_t spk_id;
@ -243,9 +245,6 @@ struct player_session
struct player_source *playing_now; struct player_source *playing_now;
}; };
static int debug_counter = -1;
static struct player_session pb_session; static struct player_session pb_session;
struct event_base *evbase_player; struct event_base *evbase_player;
@ -716,6 +715,9 @@ source_start(void)
// is all they do, they should not do anything else. If you are looking for a // is all they do, they should not do anything else. If you are looking for a
// place to add some non session actions, look further down at the events. // place to add some non session actions, look further down at the events.
#ifdef DEBUG_PLAYER
static int debug_dump_counter = -1;
static int static int
source_print(char *line, size_t linesize, struct player_source *ps, const char *name) source_print(char *line, size_t linesize, struct player_source *ps, const char *name)
{ {
@ -740,11 +742,18 @@ source_print(char *line, size_t linesize, struct player_source *ps, const char *
} }
static void static void
session_dump(void) session_dump(bool use_counter)
{ {
char line[4096]; char line[4096];
int pos = 0; int pos = 0;
if (use_counter)
{
debug_dump_counter++;
if (debug_dump_counter % 100 != 0)
return;
}
pos += snprintf(line + pos, sizeof(line) - pos, "pos=%d; ", pb_session.pos); pos += snprintf(line + pos, sizeof(line) - pos, "pos=%d; ", pb_session.pos);
pos += source_print(line + pos, sizeof(line) - pos, pb_session.reading_now, "reading_now"); pos += source_print(line + pos, sizeof(line) - pos, pb_session.reading_now, "reading_now");
@ -768,6 +777,7 @@ session_dump(void)
DPRINTF(E_DBG, L_PLAYER, "%s\n", line); DPRINTF(E_DBG, L_PLAYER, "%s\n", line);
} }
#endif
static void static void
session_update_play_eof(void) session_update_play_eof(void)
@ -1131,9 +1141,9 @@ playback_cb(int fd, short what, void *arg)
pb_write_recovery = false; pb_write_recovery = false;
} }
debug_counter++; #ifdef DEBUG_PLAYER
if (debug_counter % 100 == 0) session_dump(true);
session_dump(); #endif
// If there was an overrun, we will try to read/write a corresponding number // If there was an overrun, we will try to read/write a corresponding number
// of times so we catch up. The read from the input is non-blocking, so it // of times so we catch up. The read from the input is non-blocking, so it
@ -1754,20 +1764,10 @@ playback_stop(void *arg, int *retval)
if (pb_session.playing_now && pb_session.playing_now->pos_ms > 0) if (pb_session.playing_now && pb_session.playing_now->pos_ms > 0)
history_add(pb_session.playing_now->id, pb_session.playing_now->item_id); history_add(pb_session.playing_now->id, pb_session.playing_now->item_id);
// We may be restarting very soon, so we don't bring the devices to a full playback_abort();
// stop just yet; this saves time when restarting, which is nicer for the user
*retval = outputs_flush(device_command_cb);
playback_session_stop();
status_update(PLAY_STOPPED); status_update(PLAY_STOPPED);
outputs_metadata_purge();
// We're async if we need to flush devices
if (*retval > 0)
return COMMAND_PENDING;
return COMMAND_END; return COMMAND_END;
} }