mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-05 10:48:09 -05:00
Use a union for command argument in struct player_command
This commit is contained in:
parent
7f79ca5709
commit
bff494ac5d
95
src/player.c
95
src/player.c
@ -87,7 +87,19 @@ struct player_command
|
|||||||
|
|
||||||
cmd_func func;
|
cmd_func func;
|
||||||
cmd_func func_bh;
|
cmd_func func_bh;
|
||||||
void *arg;
|
|
||||||
|
union {
|
||||||
|
void *noarg;
|
||||||
|
struct player_status *status;
|
||||||
|
struct player_source *ps;
|
||||||
|
player_status_handler status_handler;
|
||||||
|
uint32_t *id_ptr;
|
||||||
|
uint64_t *raop_ids;
|
||||||
|
enum repeat_mode mode;
|
||||||
|
uint32_t id;
|
||||||
|
int intval;
|
||||||
|
} arg;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
int raop_pending;
|
int raop_pending;
|
||||||
@ -1498,7 +1510,7 @@ get_status(struct player_command *cmd)
|
|||||||
uint64_t pos;
|
uint64_t pos;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
status = (struct player_status *)cmd->arg;
|
status = cmd->arg.status;
|
||||||
|
|
||||||
status->shuffle = shuffle;
|
status->shuffle = shuffle;
|
||||||
status->repeat = repeat;
|
status->repeat = repeat;
|
||||||
@ -1574,7 +1586,7 @@ now_playing(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
uint32_t *id;
|
uint32_t *id;
|
||||||
|
|
||||||
id = (uint32_t *)cmd->arg;
|
id = cmd->arg.id_ptr;
|
||||||
|
|
||||||
if (cur_playing)
|
if (cur_playing)
|
||||||
*id = cur_playing->id;
|
*id = cur_playing->id;
|
||||||
@ -1745,7 +1757,7 @@ playback_start(struct player_command *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx_id = (uint32_t *)cmd->arg;
|
idx_id = cmd->arg.id_ptr;
|
||||||
|
|
||||||
if (player_state == PLAY_PLAYING)
|
if (player_state == PLAY_PLAYING)
|
||||||
{
|
{
|
||||||
@ -1945,7 +1957,7 @@ playback_seek_bh(struct player_command *cmd)
|
|||||||
int ms;
|
int ms;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ms = *(int *)cmd->arg;
|
ms = cmd->arg.intval;
|
||||||
|
|
||||||
if (cur_playing)
|
if (cur_playing)
|
||||||
ps = cur_playing;
|
ps = cur_playing;
|
||||||
@ -2193,7 +2205,7 @@ speaker_set(struct player_command *cmd)
|
|||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ids = (uint64_t *)cmd->arg;
|
ids = cmd->arg.raop_ids;
|
||||||
|
|
||||||
if (ids)
|
if (ids)
|
||||||
nspk = ids[0];
|
nspk = ids[0];
|
||||||
@ -2325,12 +2337,9 @@ speaker_set(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
volume_set(struct player_command *cmd)
|
volume_set(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int vol;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
vol = *(int *)cmd->arg;
|
volume = cmd->arg.intval;
|
||||||
|
|
||||||
volume = vol;
|
|
||||||
|
|
||||||
cmd->raop_pending = raop_set_volume(volume, device_command_cb);
|
cmd->raop_pending = raop_set_volume(volume, device_command_cb);
|
||||||
laudio_set_volume(volume);
|
laudio_set_volume(volume);
|
||||||
@ -2348,20 +2357,16 @@ volume_set(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
repeat_set(struct player_command *cmd)
|
repeat_set(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
enum repeat_mode *mode;
|
switch (cmd->arg.mode)
|
||||||
|
|
||||||
mode = (enum repeat_mode *)cmd->arg;
|
|
||||||
|
|
||||||
switch (*mode)
|
|
||||||
{
|
{
|
||||||
case REPEAT_OFF:
|
case REPEAT_OFF:
|
||||||
case REPEAT_SONG:
|
case REPEAT_SONG:
|
||||||
case REPEAT_ALL:
|
case REPEAT_ALL:
|
||||||
repeat = *mode;
|
repeat = cmd->arg.mode;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", *mode);
|
DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", cmd->arg.mode);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2371,22 +2376,18 @@ repeat_set(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
shuffle_set(struct player_command *cmd)
|
shuffle_set(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int *enable;
|
switch (cmd->arg.intval)
|
||||||
|
|
||||||
enable = (int *)cmd->arg;
|
|
||||||
|
|
||||||
switch (*enable)
|
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
if (!shuffle)
|
if (!shuffle)
|
||||||
source_reshuffle();
|
source_reshuffle();
|
||||||
/* FALLTHROUGH*/
|
/* FALLTHROUGH*/
|
||||||
case 0:
|
case 0:
|
||||||
shuffle = *enable;
|
shuffle = cmd->arg.intval;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Invalid shuffle mode: %d\n", *enable);
|
DPRINTF(E_LOG, L_PLAYER, "Invalid shuffle mode: %d\n", cmd->arg.intval);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2401,7 +2402,7 @@ queue_add(struct player_command *cmd)
|
|||||||
struct player_source *source_tail;
|
struct player_source *source_tail;
|
||||||
struct player_source *ps_tail;
|
struct player_source *ps_tail;
|
||||||
|
|
||||||
ps = (struct player_source *)cmd->arg;
|
ps = cmd->arg.ps;
|
||||||
|
|
||||||
ps_shuffle = source_shuffle(ps);
|
ps_shuffle = source_shuffle(ps);
|
||||||
if (!ps_shuffle)
|
if (!ps_shuffle)
|
||||||
@ -2467,14 +2468,10 @@ queue_clear(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
queue_plid(struct player_command *cmd)
|
queue_plid(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
uint32_t *plid;
|
|
||||||
|
|
||||||
if (!source_head)
|
if (!source_head)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
plid = (uint32_t *)cmd->arg;
|
cur_plid = cmd->arg.id;
|
||||||
|
|
||||||
cur_plid = *plid;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2482,11 +2479,7 @@ queue_plid(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
set_update_handler(struct player_command *cmd)
|
set_update_handler(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
player_status_handler handler;
|
update_handler = cmd->arg.status_handler;
|
||||||
|
|
||||||
handler = (player_status_handler)cmd->arg;
|
|
||||||
|
|
||||||
update_handler = handler;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2581,7 +2574,7 @@ player_get_status(struct player_status *status)
|
|||||||
|
|
||||||
cmd.func = get_status;
|
cmd.func = get_status;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = status;
|
cmd.arg.status = status;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2600,7 +2593,7 @@ player_now_playing(uint32_t *id)
|
|||||||
|
|
||||||
cmd.func = now_playing;
|
cmd.func = now_playing;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = id;
|
cmd.arg.id_ptr = id;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2619,7 +2612,7 @@ player_playback_start(uint32_t *idx_id)
|
|||||||
|
|
||||||
cmd.func = playback_start;
|
cmd.func = playback_start;
|
||||||
cmd.func_bh = playback_start_bh;
|
cmd.func_bh = playback_start_bh;
|
||||||
cmd.arg = idx_id;
|
cmd.arg.id_ptr = idx_id;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2637,7 +2630,7 @@ player_playback_stop(void)
|
|||||||
command_init(&cmd);
|
command_init(&cmd);
|
||||||
|
|
||||||
cmd.func = playback_stop;
|
cmd.func = playback_stop;
|
||||||
cmd.arg = NULL;
|
cmd.arg.noarg = NULL;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2656,7 +2649,7 @@ player_playback_pause(void)
|
|||||||
|
|
||||||
cmd.func = playback_pause;
|
cmd.func = playback_pause;
|
||||||
cmd.func_bh = playback_pause_bh;
|
cmd.func_bh = playback_pause_bh;
|
||||||
cmd.arg = NULL;
|
cmd.arg.noarg = NULL;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2675,7 +2668,7 @@ player_playback_seek(int ms)
|
|||||||
|
|
||||||
cmd.func = playback_pause;
|
cmd.func = playback_pause;
|
||||||
cmd.func_bh = playback_seek_bh;
|
cmd.func_bh = playback_seek_bh;
|
||||||
cmd.arg = &ms;
|
cmd.arg.intval = ms;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2692,7 +2685,7 @@ player_playback_next(void)
|
|||||||
|
|
||||||
cmd.func = playback_pause;
|
cmd.func = playback_pause;
|
||||||
cmd.func_bh = playback_next_bh;
|
cmd.func_bh = playback_next_bh;
|
||||||
cmd.arg = NULL;
|
cmd.arg.noarg = NULL;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2711,7 +2704,7 @@ player_playback_prev(void)
|
|||||||
|
|
||||||
cmd.func = playback_pause;
|
cmd.func = playback_pause;
|
||||||
cmd.func_bh = playback_prev_bh;
|
cmd.func_bh = playback_prev_bh;
|
||||||
cmd.arg = NULL;
|
cmd.arg.noarg = NULL;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2755,7 +2748,7 @@ player_speaker_set(uint64_t *ids)
|
|||||||
|
|
||||||
cmd.func = speaker_set;
|
cmd.func = speaker_set;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = ids;
|
cmd.arg.raop_ids = ids;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2774,7 +2767,7 @@ player_volume_set(int vol)
|
|||||||
|
|
||||||
cmd.func = volume_set;
|
cmd.func = volume_set;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = &vol;
|
cmd.arg.intval = vol;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2793,7 +2786,7 @@ player_repeat_set(enum repeat_mode mode)
|
|||||||
|
|
||||||
cmd.func = repeat_set;
|
cmd.func = repeat_set;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = &mode;
|
cmd.arg.mode = mode;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2812,7 +2805,7 @@ player_shuffle_set(int enable)
|
|||||||
|
|
||||||
cmd.func = shuffle_set;
|
cmd.func = shuffle_set;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = &enable;
|
cmd.arg.intval = enable;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2831,7 +2824,7 @@ player_queue_add(struct player_source *ps)
|
|||||||
|
|
||||||
cmd.func = queue_add;
|
cmd.func = queue_add;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = ps;
|
cmd.arg.ps = ps;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -2849,7 +2842,7 @@ player_queue_clear(void)
|
|||||||
|
|
||||||
cmd.func = queue_clear;
|
cmd.func = queue_clear;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = NULL;
|
cmd.arg.noarg = NULL;
|
||||||
|
|
||||||
sync_command(&cmd);
|
sync_command(&cmd);
|
||||||
|
|
||||||
@ -2865,7 +2858,7 @@ player_queue_plid(uint32_t plid)
|
|||||||
|
|
||||||
cmd.func = queue_plid;
|
cmd.func = queue_plid;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = &plid;
|
cmd.arg.id = plid;
|
||||||
|
|
||||||
sync_command(&cmd);
|
sync_command(&cmd);
|
||||||
|
|
||||||
@ -2881,7 +2874,7 @@ player_set_update_handler(player_status_handler handler)
|
|||||||
|
|
||||||
cmd.func = set_update_handler;
|
cmd.func = set_update_handler;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg = handler;
|
cmd.arg.status_handler = handler;
|
||||||
|
|
||||||
sync_command(&cmd);
|
sync_command(&cmd);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user