diff options
author | Max Kellermann <max@duempel.org> | 2014-08-27 18:50:16 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-27 19:07:16 +0200 |
commit | 0f2a7226fb36b3b04b1fa408882a8f0920081850 (patch) | |
tree | 009050341ed7e6335c7810a1027c00d462bae38c /src | |
parent | f8d0ebe92f9ceb4be761078395ef51a15fb0ae47 (diff) | |
download | mpd-0f2a7226fb36b3b04b1fa408882a8f0920081850.tar.gz mpd-0f2a7226fb36b3b04b1fa408882a8f0920081850.tar.xz mpd-0f2a7226fb36b3b04b1fa408882a8f0920081850.zip |
PlayerControl: use std::chrono::duration for Seek()
Diffstat (limited to 'src')
-rw-r--r-- | src/PlayerControl.cxx | 4 | ||||
-rw-r--r-- | src/PlayerControl.hxx | 5 | ||||
-rw-r--r-- | src/PlayerThread.cxx | 19 | ||||
-rw-r--r-- | src/queue/PlaylistControl.cxx | 3 |
4 files changed, 17 insertions, 14 deletions
diff --git a/src/PlayerControl.cxx b/src/PlayerControl.cxx index 244b64f5c..4f1c3d2ac 100644 --- a/src/PlayerControl.cxx +++ b/src/PlayerControl.cxx @@ -221,7 +221,7 @@ PlayerControl::EnqueueSong(DetachedSong *song) } bool -PlayerControl::Seek(DetachedSong *song, float seek_time) +PlayerControl::Seek(DetachedSong *song, SongTime t) { assert(song != nullptr); @@ -229,7 +229,7 @@ PlayerControl::Seek(DetachedSong *song, float seek_time) delete next_song; next_song = song; - seek_where = seek_time; + seek_time = t; SynchronousCommand(PlayerCommand::SEEK); Unlock(); diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index b60227d23..ac5e6602d 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -26,6 +26,7 @@ #include "thread/Thread.hxx" #include "util/Error.hxx" #include "CrossFade.hxx" +#include "Chrono.hxx" #include <stdint.h> @@ -161,7 +162,7 @@ struct PlayerControl { */ DetachedSong *next_song; - double seek_where; + SongTime seek_time; CrossFadeSettings cross_fade; @@ -434,7 +435,7 @@ public: * @return true on success, false on failure (e.g. if MPD isn't * playing currently) */ - bool Seek(DetachedSong *song, float seek_time); + bool Seek(DetachedSong *song, SongTime t); void SetCrossFade(float cross_fade_seconds); diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index 00f8007a1..0aa8d105d 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -293,7 +293,7 @@ Player::StartDecoder(MusicPipe &_pipe) unsigned start_ms = pc.next_song->GetStartMS(); if (pc.command == PlayerCommand::SEEK) - start_ms += (unsigned)(pc.seek_where * 1000); + start_ms += pc.seek_time.ToMS(); dc.Start(new DetachedSong(*pc.next_song), start_ms, pc.next_song->GetEndMS(), @@ -561,19 +561,20 @@ Player::SeekDecoder() /* send the SEEK command */ - double where = pc.seek_where; - if (pc.total_time > 0 && where > pc.total_time) - where = pc.total_time - 0.1; - if (where < 0.0) - where = 0.0; + SongTime where = pc.seek_time; + if (pc.total_time > 0) { + const SongTime total_time = SongTime::FromS(pc.total_time); + if (where > total_time) + where = total_time; + } - if (!dc.Seek(SongTime::FromS(where) + SongTime::FromMS(start_ms))) { + if (!dc.Seek(where + SongTime::FromMS(start_ms))) { /* decoder failure */ player_command_finished(pc); return false; } - elapsed_time = where; + elapsed_time = where.ToDoubleS(); player_command_finished(pc); @@ -923,7 +924,7 @@ Player::Run() pc.state = PlayerState::PLAY; if (pc.command == PlayerCommand::SEEK) - elapsed_time = pc.seek_where; + elapsed_time = pc.seek_time.ToDoubleS(); pc.CommandFinished(); diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx index db0b8a25d..5d4a910b0 100644 --- a/src/queue/PlaylistControl.cxx +++ b/src/queue/PlaylistControl.cxx @@ -215,7 +215,8 @@ playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time) queued_song = nullptr; } - if (!pc.Seek(new DetachedSong(queue.GetOrder(i)), seek_time)) { + if (!pc.Seek(new DetachedSong(queue.GetOrder(i)), + SongTime::FromS(seek_time))) { UpdateQueuedSong(pc, queued_song); return PlaylistResult::NOT_PLAYING; |