From 75a89c59838ff764b55ba3ce359d59d031446b3d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2014 13:07:38 +0200 Subject: PlayerThread: use SongTime for elapsed_time --- src/PlayerControl.hxx | 4 ++-- src/PlayerThread.cxx | 16 ++++++++-------- src/command/PlayerCommands.cxx | 4 ++-- src/queue/PlaylistControl.cxx | 2 +- src/queue/PlaylistState.cxx | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index abd8e6af5..61c345416 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -90,7 +90,7 @@ struct player_status { uint16_t bit_rate; AudioFormat audio_format; SignedSongTime total_time; - float elapsed_time; + SongTime elapsed_time; }; struct PlayerControl { @@ -152,7 +152,7 @@ struct PlayerControl { uint16_t bit_rate; AudioFormat audio_format; SignedSongTime total_time; - float elapsed_time; + SongTime elapsed_time; /** * The next queued song. diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index 15593ceb0..e4fc84da1 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -129,7 +129,7 @@ class Player { * value; the output thread can estimate the elapsed time more * precisely. */ - float elapsed_time; + SongTime elapsed_time; public: Player(PlayerControl &_pc, DecoderControl &_dc, @@ -146,7 +146,7 @@ public: cross_fading(false), cross_fade_chunks(0), cross_fade_tag(nullptr), - elapsed_time(0.0) {} + elapsed_time(SongTime::zero()) {} private: void ClearAndDeletePipe() { @@ -342,7 +342,7 @@ Player::WaitForDecoder() delete song; song = pc.next_song; - elapsed_time = 0.0; + elapsed_time = SongTime::zero(); /* set the "starting" flag, which will be cleared by player_check_decoder_startup() */ @@ -574,7 +574,7 @@ Player::SeekDecoder() return false; } - elapsed_time = where.ToDoubleS(); + elapsed_time = where; player_command_finished(pc); @@ -674,9 +674,9 @@ Player::ProcessCommand() pc.Lock(); } - pc.elapsed_time = pc.outputs.GetElapsedTime(); - if (pc.elapsed_time < 0.0) - pc.elapsed_time = elapsed_time; + pc.elapsed_time = pc.outputs.GetElapsedTime() >= 0 + ? SongTime::FromS(pc.outputs.GetElapsedTime()) + : elapsed_time; pc.CommandFinished(); break; @@ -924,7 +924,7 @@ Player::Run() pc.state = PlayerState::PLAY; if (pc.command == PlayerCommand::SEEK) - elapsed_time = pc.seek_time.ToDoubleS(); + elapsed_time = pc.seek_time; pc.CommandFinished(); diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index f4b4674a0..cd7f42289 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -175,11 +175,11 @@ handle_status(Client &client, COMMAND_STATUS_TIME ": %i:%i\n" "elapsed: %1.3f\n" COMMAND_STATUS_BITRATE ": %u\n", - (int)(player_status.elapsed_time + 0.5), + player_status.elapsed_time.RoundS(), player_status.total_time.IsNegative() ? 0u : unsigned(player_status.total_time.RoundS()), - player_status.elapsed_time, + player_status.elapsed_time.ToDoubleS(), player_status.bit_rate); if (player_status.audio_format.IsDefined()) { diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx index e33386e41..df6b6ed0f 100644 --- a/src/queue/PlaylistControl.cxx +++ b/src/queue/PlaylistControl.cxx @@ -252,7 +252,7 @@ playlist::SeekCurrent(PlayerControl &pc, status.state != PlayerState::PAUSE) return PlaylistResult::NOT_PLAYING; - seek_time += SignedSongTime::FromS(status.elapsed_time); + seek_time += status.elapsed_time; if (seek_time.IsNegative()) seek_time = SignedSongTime::zero(); } diff --git a/src/queue/PlaylistState.cxx b/src/queue/PlaylistState.cxx index 316a0767f..6ea86166e 100644 --- a/src/queue/PlaylistState.cxx +++ b/src/queue/PlaylistState.cxx @@ -77,8 +77,8 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist, } os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n", playlist.queue.OrderToPosition(playlist.current)); - os.Format(PLAYLIST_STATE_FILE_TIME "%i\n", - (int)player_status.elapsed_time); + os.Format(PLAYLIST_STATE_FILE_TIME "%f\n", + player_status.elapsed_time.ToDoubleS()); } else { os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n"); @@ -150,7 +150,7 @@ playlist_state_restore(const char *line, TextFile &file, while ((line = file.ReadLine()) != nullptr) { if (StringStartsWith(line, PLAYLIST_STATE_FILE_TIME)) { - unsigned seconds = atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)])); + double seconds = atof(line + strlen(PLAYLIST_STATE_FILE_TIME)); seek_time = SongTime::FromS(seconds); } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) { playlist.SetRepeat(pc, @@ -229,7 +229,7 @@ playlist_state_get_hash(const playlist &playlist, return playlist.queue.version ^ (player_status.state != PlayerState::STOP - ? ((int)player_status.elapsed_time << 8) + ? (player_status.elapsed_time.ToS() << 8) : 0) ^ (playlist.current >= 0 ? (playlist.queue.OrderToPosition(playlist.current) << 16) -- cgit v1.2.3