diff options
author | Max Kellermann <max@duempel.org> | 2009-10-30 16:28:15 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-10-30 16:28:15 +0100 |
commit | 73cff374fd94a1c16e0201fcda020396c0f41962 (patch) | |
tree | 20fd66a68625db58cbad46ecf674dbfeda29c36d | |
parent | cec019efffe4ebb87ec2c630003e6bce5083bb5e (diff) | |
download | mpd-73cff374fd94a1c16e0201fcda020396c0f41962.tar.gz mpd-73cff374fd94a1c16e0201fcda020396c0f41962.tar.xz mpd-73cff374fd94a1c16e0201fcda020396c0f41962.zip |
{player,output}_thread: fixed elapsed_time quirks
Right after seeking and song change, the elapsed_time shows old
information, because the output thread didn't finish a full chunk
yet. This patch re-adds a second elapsed_time variable, and keeps
track of a fallback value, in case the output thread can't provide a
reliable value.
-rw-r--r-- | src/output_all.c | 7 | ||||
-rw-r--r-- | src/output_all.h | 3 | ||||
-rw-r--r-- | src/player_thread.c | 16 |
3 files changed, 23 insertions, 3 deletions
diff --git a/src/output_all.c b/src/output_all.c index 05cd1d350..08f4ee0dc 100644 --- a/src/output_all.c +++ b/src/output_all.c @@ -55,7 +55,7 @@ static struct music_pipe *g_mp; /** * The "elapsed_time" stamp of the most recently finished chunk. */ -static float audio_output_all_elapsed_time; +static float audio_output_all_elapsed_time = -1.0; unsigned int audio_output_count(void) { @@ -482,6 +482,8 @@ audio_output_all_cancel(void) if (g_mp != NULL) music_pipe_clear(g_mp, g_music_buffer); + + audio_output_all_elapsed_time = -1.0; } void @@ -498,12 +500,13 @@ audio_output_all_close(void) music_pipe_clear(g_mp, g_music_buffer); music_pipe_free(g_mp); g_mp = NULL; - audio_output_all_elapsed_time = 0.0; } g_music_buffer = NULL; audio_format_clear(&input_audio_format); + + audio_output_all_elapsed_time = -1.0; } float diff --git a/src/output_all.h b/src/output_all.h index 2f5101f1b..91b6f3f5d 100644 --- a/src/output_all.h +++ b/src/output_all.h @@ -137,7 +137,8 @@ audio_output_all_cancel(void); /** * Returns the "elapsed_time" stamp of the most recently finished - * chunk. + * chunk. A negative value is returned when no chunk has been + * finished yet. */ float audio_output_all_get_elapsed_time(void); diff --git a/src/player_thread.c b/src/player_thread.c index 9d13e44f9..dbafa168f 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -93,6 +93,15 @@ struct player { * The current audio format for the audio outputs. */ struct audio_format play_audio_format; + + /** + * The time stamp of the chunk most recently sent to the + * output thread. This attribute is only used if + * audio_output_all_get_elapsed_time() didn't return a usable + * value; the output thread can estimate the elapsed time more + * precisly. + */ + float elapsed_time; }; static struct music_buffer *player_buffer; @@ -152,6 +161,7 @@ player_wait_for_decoder(struct player *player) player->song = pc.next_song; pc.next_song = NULL; player->queued = false; + player->elapsed_time = 0.0; /* set the "starting" flag, which will be cleared by player_check_decoder_startup() */ @@ -329,6 +339,8 @@ static bool player_seek_decoder(struct player *player) return false; } + player->elapsed_time = where; + player_command_finished(); player->xfade = XFADE_UNKNOWN; @@ -419,6 +431,9 @@ static void player_process_command(struct player *player) audio_output_all_check(); pc.elapsed_time = audio_output_all_get_elapsed_time(); + if (pc.elapsed_time < 0.0) + pc.elapsed_time = player->elapsed_time; + player_command_finished(); break; } @@ -625,6 +640,7 @@ static void do_play(void) .xfade = XFADE_UNKNOWN, .cross_fading = false, .cross_fade_chunks = 0, + .elapsed_time = 0.0, }; player.pipe = music_pipe_new(); |