diff options
author | Max Kellermann <max@duempel.org> | 2014-08-29 12:43:47 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-29 13:20:58 +0200 |
commit | 22899686346088a536be11e0c6a68700d4a237a4 (patch) | |
tree | 4e3843a55dd85bd34ac8740561c36506d03cd564 /src | |
parent | ca252804c6bbba163fe00d660f47ca4856e4874e (diff) | |
download | mpd-22899686346088a536be11e0c6a68700d4a237a4.tar.gz mpd-22899686346088a536be11e0c6a68700d4a237a4.tar.xz mpd-22899686346088a536be11e0c6a68700d4a237a4.zip |
PlayerControl: use SignedSongTime for the song duration
Diffstat (limited to '')
-rw-r--r-- | src/PlayerControl.hxx | 4 | ||||
-rw-r--r-- | src/PlayerThread.cxx | 22 | ||||
-rw-r--r-- | src/command/PlayerCommands.cxx | 4 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index ac5e6602d..abd8e6af5 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -89,7 +89,7 @@ struct player_status { PlayerState state; uint16_t bit_rate; AudioFormat audio_format; - float total_time; + SignedSongTime total_time; float elapsed_time; }; @@ -151,7 +151,7 @@ struct PlayerControl { uint16_t bit_rate; AudioFormat audio_format; - float total_time; + SignedSongTime total_time; float elapsed_time; /** diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index b8d0b43da..15593ceb0 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -349,7 +349,7 @@ Player::WaitForDecoder() decoder_starting = true; /* update PlayerControl's song information */ - pc.total_time = pc.next_song->GetDuration().ToDoubleS(); + pc.total_time = pc.next_song->GetDuration(); pc.bit_rate = 0; pc.audio_format.Clear(); @@ -368,21 +368,21 @@ Player::WaitForDecoder() * Returns the real duration of the song, comprising the duration * indicated by the decoder plugin. */ -static double -real_song_duration(const DetachedSong &song, double decoder_duration) +static SignedSongTime +real_song_duration(const DetachedSong &song, SignedSongTime decoder_duration) { - if (decoder_duration <= 0.0) + if (decoder_duration.IsNegative()) /* the decoder plugin didn't provide information; fall back to Song::GetDuration() */ - return song.GetDuration().ToDoubleS(); + return song.GetDuration(); const SongTime start_time = song.GetStartTime(); const SongTime end_time = song.GetEndTime(); - if (end_time.IsPositive() && end_time.ToDoubleS() < decoder_duration) - return (end_time - start_time).ToDoubleS(); + if (end_time.IsPositive() && end_time < SongTime(decoder_duration)) + return SignedSongTime(end_time - start_time); - return decoder_duration - start_time.ToDoubleS(); + return SignedSongTime(SongTime(decoder_duration) - start_time); } bool @@ -450,7 +450,7 @@ Player::CheckDecoderStartup() return true; pc.Lock(); - pc.total_time = real_song_duration(*dc.song, dc.total_time.ToDoubleS()); + pc.total_time = real_song_duration(*dc.song, dc.total_time); pc.audio_format = dc.in_audio_format; pc.Unlock(); @@ -562,8 +562,8 @@ Player::SeekDecoder() /* send the SEEK command */ SongTime where = pc.seek_time; - if (pc.total_time > 0) { - const SongTime total_time = SongTime::FromS(pc.total_time); + if (!pc.total_time.IsNegative()) { + const SongTime total_time(pc.total_time); if (where > total_time) where = total_time; } diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index 7b033368a..f4b4674a0 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -176,7 +176,9 @@ handle_status(Client &client, "elapsed: %1.3f\n" COMMAND_STATUS_BITRATE ": %u\n", (int)(player_status.elapsed_time + 0.5), - (int)(player_status.total_time + 0.5), + player_status.total_time.IsNegative() + ? 0u + : unsigned(player_status.total_time.RoundS()), player_status.elapsed_time, player_status.bit_rate); |