player_control: bundle "get" functions in pc_get_status()
The new player_status struct replaces a bunch of playerGetX() functions. When we add proper locking to the player_control struct, we will only need to lock once for the "status" command.
This commit is contained in:
parent
128a5fa4a5
commit
76953a9748
@ -453,11 +453,14 @@ handle_status(struct client *client,
|
||||
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
||||
{
|
||||
const char *state = NULL;
|
||||
struct player_status player_status;
|
||||
int updateJobId;
|
||||
char *error;
|
||||
int song;
|
||||
|
||||
switch (getPlayerState()) {
|
||||
pc_get_status(&player_status);
|
||||
|
||||
switch (player_status.state) {
|
||||
case PLAYER_STATE_STOP:
|
||||
state = "stop";
|
||||
break;
|
||||
@ -497,17 +500,19 @@ handle_status(struct client *client,
|
||||
song, playlist_get_song_id(&g_playlist, song));
|
||||
}
|
||||
|
||||
if (getPlayerState() != PLAYER_STATE_STOP) {
|
||||
const struct audio_format *af = player_get_audio_format();
|
||||
if (player_status.state != PLAYER_STATE_STOP) {
|
||||
client_printf(client,
|
||||
COMMAND_STATUS_TIME ": %i:%i\n"
|
||||
"elapsed: %1.3f\n"
|
||||
COMMAND_STATUS_BITRATE ": %li\n"
|
||||
COMMAND_STATUS_BITRATE ": %u\n"
|
||||
COMMAND_STATUS_AUDIO ": %u:%u:%u\n",
|
||||
getPlayerElapsedTime(), getPlayerTotalTime(),
|
||||
pc.elapsed_time,
|
||||
getPlayerBitRate(),
|
||||
af->sample_rate, af->bits, af->channels);
|
||||
(int)(player_status.elapsed_time + 0.5),
|
||||
(int)(player_status.total_time + 0.5),
|
||||
player_status.elapsed_time,
|
||||
player_status.bit_rate,
|
||||
player_status.audio_format.sample_rate,
|
||||
player_status.audio_format.bits,
|
||||
player_status.audio_format.channels);
|
||||
}
|
||||
|
||||
if ((updateJobId = isUpdatingDB())) {
|
||||
|
@ -129,19 +129,17 @@ void playerSetPause(int pause_flag)
|
||||
}
|
||||
}
|
||||
|
||||
int getPlayerElapsedTime(void)
|
||||
void
|
||||
pc_get_status(struct player_status *status)
|
||||
{
|
||||
return (int)(pc.elapsed_time + 0.5);
|
||||
}
|
||||
status->state = pc.state;
|
||||
|
||||
unsigned long getPlayerBitRate(void)
|
||||
{
|
||||
return pc.bit_rate;
|
||||
}
|
||||
|
||||
int getPlayerTotalTime(void)
|
||||
{
|
||||
return (int)(pc.total_time + 0.5);
|
||||
if (pc.state != PLAYER_STATE_STOP) {
|
||||
status->bit_rate = pc.bit_rate;
|
||||
status->audio_format = pc.audio_format;
|
||||
status->total_time = pc.total_time;
|
||||
status->elapsed_time = pc.elapsed_time;
|
||||
}
|
||||
}
|
||||
|
||||
enum player_state getPlayerState(void)
|
||||
|
@ -60,6 +60,14 @@ enum player_error {
|
||||
PLAYER_ERROR_FILENOTFOUND,
|
||||
};
|
||||
|
||||
struct player_status {
|
||||
enum player_state state;
|
||||
uint16_t bit_rate;
|
||||
struct audio_format audio_format;
|
||||
float total_time;
|
||||
float elapsed_time;
|
||||
};
|
||||
|
||||
struct player_control {
|
||||
unsigned buffer_chunks;
|
||||
|
||||
@ -112,11 +120,8 @@ void playerPause(void);
|
||||
|
||||
void playerKill(void);
|
||||
|
||||
int getPlayerTotalTime(void);
|
||||
|
||||
int getPlayerElapsedTime(void);
|
||||
|
||||
unsigned long getPlayerBitRate(void);
|
||||
void
|
||||
pc_get_status(struct player_status *status);
|
||||
|
||||
enum player_state getPlayerState(void);
|
||||
|
||||
@ -151,12 +156,6 @@ float getPlayerCrossFade(void);
|
||||
|
||||
double getPlayerTotalPlayTime(void);
|
||||
|
||||
static inline const struct audio_format *
|
||||
player_get_audio_format(void)
|
||||
{
|
||||
return &pc.audio_format;
|
||||
}
|
||||
|
||||
void playerInit(void);
|
||||
|
||||
#endif
|
||||
|
@ -51,10 +51,14 @@
|
||||
void
|
||||
playlist_state_save(FILE *fp, const struct playlist *playlist)
|
||||
{
|
||||
struct player_status player_status;
|
||||
|
||||
pc_get_status(&player_status);
|
||||
|
||||
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
|
||||
|
||||
if (playlist->playing) {
|
||||
switch (getPlayerState()) {
|
||||
switch (player_status.state) {
|
||||
case PLAYER_STATE_PAUSE:
|
||||
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_PAUSE);
|
||||
break;
|
||||
@ -65,7 +69,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist)
|
||||
queue_order_to_position(&playlist->queue,
|
||||
playlist->current));
|
||||
fprintf(fp, "%s%i\n", PLAYLIST_STATE_FILE_TIME,
|
||||
getPlayerElapsedTime());
|
||||
(int)player_status.elapsed_time);
|
||||
} else {
|
||||
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_STOP);
|
||||
|
||||
@ -204,14 +208,20 @@ playlist_state_restore(const char *line, FILE *fp, struct playlist *playlist)
|
||||
unsigned
|
||||
playlist_state_get_hash(const struct playlist *playlist)
|
||||
{
|
||||
struct player_status player_status;
|
||||
|
||||
pc_get_status(&player_status);
|
||||
|
||||
return playlist->queue.version ^
|
||||
(getPlayerElapsedTime() << 8) ^
|
||||
(player_status.state != PLAYER_STATE_STOP
|
||||
? ((int)player_status.elapsed_time << 8)
|
||||
: 0) ^
|
||||
(playlist->current >= 0
|
||||
? (queue_order_to_position(&playlist->queue,
|
||||
playlist->current) << 16)
|
||||
: 0) ^
|
||||
((int)getPlayerCrossFade() << 20) ^
|
||||
(getPlayerState() << 24) ^
|
||||
(player_status.state << 24) ^
|
||||
(playlist->queue.random << 27) ^
|
||||
(playlist->queue.repeat << 28) ^
|
||||
(playlist->queue.single << 29) ^
|
||||
|
Loading…
Reference in New Issue
Block a user