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[])
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
||||||
{
|
{
|
||||||
const char *state = NULL;
|
const char *state = NULL;
|
||||||
|
struct player_status player_status;
|
||||||
int updateJobId;
|
int updateJobId;
|
||||||
char *error;
|
char *error;
|
||||||
int song;
|
int song;
|
||||||
|
|
||||||
switch (getPlayerState()) {
|
pc_get_status(&player_status);
|
||||||
|
|
||||||
|
switch (player_status.state) {
|
||||||
case PLAYER_STATE_STOP:
|
case PLAYER_STATE_STOP:
|
||||||
state = "stop";
|
state = "stop";
|
||||||
break;
|
break;
|
||||||
@ -497,17 +500,19 @@ handle_status(struct client *client,
|
|||||||
song, playlist_get_song_id(&g_playlist, song));
|
song, playlist_get_song_id(&g_playlist, song));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPlayerState() != PLAYER_STATE_STOP) {
|
if (player_status.state != PLAYER_STATE_STOP) {
|
||||||
const struct audio_format *af = player_get_audio_format();
|
|
||||||
client_printf(client,
|
client_printf(client,
|
||||||
COMMAND_STATUS_TIME ": %i:%i\n"
|
COMMAND_STATUS_TIME ": %i:%i\n"
|
||||||
"elapsed: %1.3f\n"
|
"elapsed: %1.3f\n"
|
||||||
COMMAND_STATUS_BITRATE ": %li\n"
|
COMMAND_STATUS_BITRATE ": %u\n"
|
||||||
COMMAND_STATUS_AUDIO ": %u:%u:%u\n",
|
COMMAND_STATUS_AUDIO ": %u:%u:%u\n",
|
||||||
getPlayerElapsedTime(), getPlayerTotalTime(),
|
(int)(player_status.elapsed_time + 0.5),
|
||||||
pc.elapsed_time,
|
(int)(player_status.total_time + 0.5),
|
||||||
getPlayerBitRate(),
|
player_status.elapsed_time,
|
||||||
af->sample_rate, af->bits, af->channels);
|
player_status.bit_rate,
|
||||||
|
player_status.audio_format.sample_rate,
|
||||||
|
player_status.audio_format.bits,
|
||||||
|
player_status.audio_format.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((updateJobId = isUpdatingDB())) {
|
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)
|
if (pc.state != PLAYER_STATE_STOP) {
|
||||||
{
|
status->bit_rate = pc.bit_rate;
|
||||||
return pc.bit_rate;
|
status->audio_format = pc.audio_format;
|
||||||
}
|
status->total_time = pc.total_time;
|
||||||
|
status->elapsed_time = pc.elapsed_time;
|
||||||
int getPlayerTotalTime(void)
|
}
|
||||||
{
|
|
||||||
return (int)(pc.total_time + 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum player_state getPlayerState(void)
|
enum player_state getPlayerState(void)
|
||||||
|
@ -60,6 +60,14 @@ enum player_error {
|
|||||||
PLAYER_ERROR_FILENOTFOUND,
|
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 {
|
struct player_control {
|
||||||
unsigned buffer_chunks;
|
unsigned buffer_chunks;
|
||||||
|
|
||||||
@ -112,11 +120,8 @@ void playerPause(void);
|
|||||||
|
|
||||||
void playerKill(void);
|
void playerKill(void);
|
||||||
|
|
||||||
int getPlayerTotalTime(void);
|
void
|
||||||
|
pc_get_status(struct player_status *status);
|
||||||
int getPlayerElapsedTime(void);
|
|
||||||
|
|
||||||
unsigned long getPlayerBitRate(void);
|
|
||||||
|
|
||||||
enum player_state getPlayerState(void);
|
enum player_state getPlayerState(void);
|
||||||
|
|
||||||
@ -151,12 +156,6 @@ float getPlayerCrossFade(void);
|
|||||||
|
|
||||||
double getPlayerTotalPlayTime(void);
|
double getPlayerTotalPlayTime(void);
|
||||||
|
|
||||||
static inline const struct audio_format *
|
|
||||||
player_get_audio_format(void)
|
|
||||||
{
|
|
||||||
return &pc.audio_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
void playerInit(void);
|
void playerInit(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,10 +51,14 @@
|
|||||||
void
|
void
|
||||||
playlist_state_save(FILE *fp, const struct playlist *playlist)
|
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);
|
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
|
||||||
|
|
||||||
if (playlist->playing) {
|
if (playlist->playing) {
|
||||||
switch (getPlayerState()) {
|
switch (player_status.state) {
|
||||||
case PLAYER_STATE_PAUSE:
|
case PLAYER_STATE_PAUSE:
|
||||||
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_PAUSE);
|
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_PAUSE);
|
||||||
break;
|
break;
|
||||||
@ -65,7 +69,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist)
|
|||||||
queue_order_to_position(&playlist->queue,
|
queue_order_to_position(&playlist->queue,
|
||||||
playlist->current));
|
playlist->current));
|
||||||
fprintf(fp, "%s%i\n", PLAYLIST_STATE_FILE_TIME,
|
fprintf(fp, "%s%i\n", PLAYLIST_STATE_FILE_TIME,
|
||||||
getPlayerElapsedTime());
|
(int)player_status.elapsed_time);
|
||||||
} else {
|
} else {
|
||||||
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_STOP);
|
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
|
unsigned
|
||||||
playlist_state_get_hash(const struct playlist *playlist)
|
playlist_state_get_hash(const struct playlist *playlist)
|
||||||
{
|
{
|
||||||
|
struct player_status player_status;
|
||||||
|
|
||||||
|
pc_get_status(&player_status);
|
||||||
|
|
||||||
return playlist->queue.version ^
|
return playlist->queue.version ^
|
||||||
(getPlayerElapsedTime() << 8) ^
|
(player_status.state != PLAYER_STATE_STOP
|
||||||
|
? ((int)player_status.elapsed_time << 8)
|
||||||
|
: 0) ^
|
||||||
(playlist->current >= 0
|
(playlist->current >= 0
|
||||||
? (queue_order_to_position(&playlist->queue,
|
? (queue_order_to_position(&playlist->queue,
|
||||||
playlist->current) << 16)
|
playlist->current) << 16)
|
||||||
: 0) ^
|
: 0) ^
|
||||||
((int)getPlayerCrossFade() << 20) ^
|
((int)getPlayerCrossFade() << 20) ^
|
||||||
(getPlayerState() << 24) ^
|
(player_status.state << 24) ^
|
||||||
(playlist->queue.random << 27) ^
|
(playlist->queue.random << 27) ^
|
||||||
(playlist->queue.repeat << 28) ^
|
(playlist->queue.repeat << 28) ^
|
||||||
(playlist->queue.single << 29) ^
|
(playlist->queue.single << 29) ^
|
||||||
|
Loading…
Reference in New Issue
Block a user