PlayerThread: use SongTime for elapsed_time
This commit is contained in:
parent
2289968634
commit
75a89c5983
@ -90,7 +90,7 @@ struct player_status {
|
|||||||
uint16_t bit_rate;
|
uint16_t bit_rate;
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
SignedSongTime total_time;
|
SignedSongTime total_time;
|
||||||
float elapsed_time;
|
SongTime elapsed_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerControl {
|
struct PlayerControl {
|
||||||
@ -152,7 +152,7 @@ struct PlayerControl {
|
|||||||
uint16_t bit_rate;
|
uint16_t bit_rate;
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
SignedSongTime total_time;
|
SignedSongTime total_time;
|
||||||
float elapsed_time;
|
SongTime elapsed_time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The next queued song.
|
* The next queued song.
|
||||||
|
@ -129,7 +129,7 @@ class Player {
|
|||||||
* value; the output thread can estimate the elapsed time more
|
* value; the output thread can estimate the elapsed time more
|
||||||
* precisely.
|
* precisely.
|
||||||
*/
|
*/
|
||||||
float elapsed_time;
|
SongTime elapsed_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Player(PlayerControl &_pc, DecoderControl &_dc,
|
Player(PlayerControl &_pc, DecoderControl &_dc,
|
||||||
@ -146,7 +146,7 @@ public:
|
|||||||
cross_fading(false),
|
cross_fading(false),
|
||||||
cross_fade_chunks(0),
|
cross_fade_chunks(0),
|
||||||
cross_fade_tag(nullptr),
|
cross_fade_tag(nullptr),
|
||||||
elapsed_time(0.0) {}
|
elapsed_time(SongTime::zero()) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearAndDeletePipe() {
|
void ClearAndDeletePipe() {
|
||||||
@ -342,7 +342,7 @@ Player::WaitForDecoder()
|
|||||||
|
|
||||||
delete song;
|
delete song;
|
||||||
song = pc.next_song;
|
song = pc.next_song;
|
||||||
elapsed_time = 0.0;
|
elapsed_time = SongTime::zero();
|
||||||
|
|
||||||
/* set the "starting" flag, which will be cleared by
|
/* set the "starting" flag, which will be cleared by
|
||||||
player_check_decoder_startup() */
|
player_check_decoder_startup() */
|
||||||
@ -574,7 +574,7 @@ Player::SeekDecoder()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed_time = where.ToDoubleS();
|
elapsed_time = where;
|
||||||
|
|
||||||
player_command_finished(pc);
|
player_command_finished(pc);
|
||||||
|
|
||||||
@ -674,9 +674,9 @@ Player::ProcessCommand()
|
|||||||
pc.Lock();
|
pc.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.elapsed_time = pc.outputs.GetElapsedTime();
|
pc.elapsed_time = pc.outputs.GetElapsedTime() >= 0
|
||||||
if (pc.elapsed_time < 0.0)
|
? SongTime::FromS(pc.outputs.GetElapsedTime())
|
||||||
pc.elapsed_time = elapsed_time;
|
: elapsed_time;
|
||||||
|
|
||||||
pc.CommandFinished();
|
pc.CommandFinished();
|
||||||
break;
|
break;
|
||||||
@ -924,7 +924,7 @@ Player::Run()
|
|||||||
pc.state = PlayerState::PLAY;
|
pc.state = PlayerState::PLAY;
|
||||||
|
|
||||||
if (pc.command == PlayerCommand::SEEK)
|
if (pc.command == PlayerCommand::SEEK)
|
||||||
elapsed_time = pc.seek_time.ToDoubleS();
|
elapsed_time = pc.seek_time;
|
||||||
|
|
||||||
pc.CommandFinished();
|
pc.CommandFinished();
|
||||||
|
|
||||||
|
@ -175,11 +175,11 @@ handle_status(Client &client,
|
|||||||
COMMAND_STATUS_TIME ": %i:%i\n"
|
COMMAND_STATUS_TIME ": %i:%i\n"
|
||||||
"elapsed: %1.3f\n"
|
"elapsed: %1.3f\n"
|
||||||
COMMAND_STATUS_BITRATE ": %u\n",
|
COMMAND_STATUS_BITRATE ": %u\n",
|
||||||
(int)(player_status.elapsed_time + 0.5),
|
player_status.elapsed_time.RoundS(),
|
||||||
player_status.total_time.IsNegative()
|
player_status.total_time.IsNegative()
|
||||||
? 0u
|
? 0u
|
||||||
: unsigned(player_status.total_time.RoundS()),
|
: unsigned(player_status.total_time.RoundS()),
|
||||||
player_status.elapsed_time,
|
player_status.elapsed_time.ToDoubleS(),
|
||||||
player_status.bit_rate);
|
player_status.bit_rate);
|
||||||
|
|
||||||
if (player_status.audio_format.IsDefined()) {
|
if (player_status.audio_format.IsDefined()) {
|
||||||
|
@ -252,7 +252,7 @@ playlist::SeekCurrent(PlayerControl &pc,
|
|||||||
status.state != PlayerState::PAUSE)
|
status.state != PlayerState::PAUSE)
|
||||||
return PlaylistResult::NOT_PLAYING;
|
return PlaylistResult::NOT_PLAYING;
|
||||||
|
|
||||||
seek_time += SignedSongTime::FromS(status.elapsed_time);
|
seek_time += status.elapsed_time;
|
||||||
if (seek_time.IsNegative())
|
if (seek_time.IsNegative())
|
||||||
seek_time = SignedSongTime::zero();
|
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",
|
os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n",
|
||||||
playlist.queue.OrderToPosition(playlist.current));
|
playlist.queue.OrderToPosition(playlist.current));
|
||||||
os.Format(PLAYLIST_STATE_FILE_TIME "%i\n",
|
os.Format(PLAYLIST_STATE_FILE_TIME "%f\n",
|
||||||
(int)player_status.elapsed_time);
|
player_status.elapsed_time.ToDoubleS());
|
||||||
} else {
|
} else {
|
||||||
os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n");
|
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) {
|
while ((line = file.ReadLine()) != nullptr) {
|
||||||
if (StringStartsWith(line, PLAYLIST_STATE_FILE_TIME)) {
|
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);
|
seek_time = SongTime::FromS(seconds);
|
||||||
} else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) {
|
} else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) {
|
||||||
playlist.SetRepeat(pc,
|
playlist.SetRepeat(pc,
|
||||||
@ -229,7 +229,7 @@ playlist_state_get_hash(const playlist &playlist,
|
|||||||
|
|
||||||
return playlist.queue.version ^
|
return playlist.queue.version ^
|
||||||
(player_status.state != PlayerState::STOP
|
(player_status.state != PlayerState::STOP
|
||||||
? ((int)player_status.elapsed_time << 8)
|
? (player_status.elapsed_time.ToS() << 8)
|
||||||
: 0) ^
|
: 0) ^
|
||||||
(playlist.current >= 0
|
(playlist.current >= 0
|
||||||
? (playlist.queue.OrderToPosition(playlist.current) << 16)
|
? (playlist.queue.OrderToPosition(playlist.current) << 16)
|
||||||
|
Loading…
Reference in New Issue
Block a user