Commit 75a89c59 authored by Max Kellermann's avatar Max Kellermann

PlayerThread: use SongTime for elapsed_time

parent 22899686
......@@ -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.
......
......@@ -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();
......
......@@ -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()) {
......
......@@ -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();
}
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment