mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-15 00:35:03 -05:00
[player] Simplify parameter passing to player commands
This commit is contained in:
parent
d36e6ac5ab
commit
94fd370df2
115
src/player.c
115
src/player.c
@ -155,16 +155,7 @@ struct speaker_auth_param
|
|||||||
|
|
||||||
union player_arg
|
union player_arg
|
||||||
{
|
{
|
||||||
struct volume_param vol_param;
|
|
||||||
void *noarg;
|
|
||||||
struct spk_enum *spk_enum;
|
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
struct player_status *status;
|
|
||||||
struct player_source *ps;
|
|
||||||
struct metadata_param metadata_param;
|
|
||||||
uint32_t *id_ptr;
|
|
||||||
struct speaker_set_param speaker_set_param;
|
|
||||||
enum repeat_mode mode;
|
|
||||||
struct speaker_auth_param auth;
|
struct speaker_auth_param auth;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
int intval;
|
int intval;
|
||||||
@ -1375,13 +1366,12 @@ device_auth_kickoff(void *arg, int *retval)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
device_metadata_send(void *arg, int *retval)
|
device_metadata_send(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg;
|
struct metadata_param *metadata_param = arg;
|
||||||
struct input_metadata *imd;
|
struct input_metadata *imd;
|
||||||
struct output_metadata *omd;
|
struct output_metadata *omd;
|
||||||
|
|
||||||
cmdarg = arg;
|
imd = metadata_param->input;
|
||||||
imd = cmdarg->metadata_param.input;
|
omd = metadata_param->output;
|
||||||
omd = cmdarg->metadata_param.output;
|
|
||||||
|
|
||||||
outputs_metadata_send(omd, imd->rtptime, imd->offset, imd->startup);
|
outputs_metadata_send(omd, imd->rtptime, imd->offset, imd->startup);
|
||||||
|
|
||||||
@ -1777,15 +1767,12 @@ playback_suspend(void)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
get_status(void *arg, int *retval)
|
get_status(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
struct player_status *status = arg;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
struct player_status *status;
|
|
||||||
uint64_t pos;
|
uint64_t pos;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
status = cmdarg->status;
|
|
||||||
|
|
||||||
memset(status, 0, sizeof(struct player_status));
|
memset(status, 0, sizeof(struct player_status));
|
||||||
|
|
||||||
status->shuffle = shuffle;
|
status->shuffle = shuffle;
|
||||||
@ -1865,12 +1852,9 @@ get_status(void *arg, int *retval)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
now_playing(void *arg, int *retval)
|
now_playing(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
uint32_t *id = arg;
|
||||||
uint32_t *id;
|
|
||||||
struct player_source *ps_playing;
|
struct player_source *ps_playing;
|
||||||
|
|
||||||
id = cmdarg->id_ptr;
|
|
||||||
|
|
||||||
ps_playing = source_now_playing();
|
ps_playing = source_now_playing();
|
||||||
|
|
||||||
if (ps_playing)
|
if (ps_playing)
|
||||||
@ -2398,13 +2382,10 @@ player_speaker_status_trigger(void)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
speaker_enumerate(void *arg, int *retval)
|
speaker_enumerate(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
struct spk_enum *spk_enum = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
struct spk_enum *spk_enum;
|
|
||||||
struct spk_flags flags;
|
struct spk_flags flags;
|
||||||
|
|
||||||
spk_enum = cmdarg->spk_enum;
|
|
||||||
|
|
||||||
#ifdef DEBUG_RELVOL
|
#ifdef DEBUG_RELVOL
|
||||||
DPRINTF(E_DBG, L_PLAYER, "*** master: %d\n", master_volume);
|
DPRINTF(E_DBG, L_PLAYER, "*** master: %d\n", master_volume);
|
||||||
#endif
|
#endif
|
||||||
@ -2501,7 +2482,7 @@ speaker_deactivate(struct output_device *device)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
speaker_set(void *arg, int *retval)
|
speaker_set(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
struct speaker_set_param *speaker_set_param = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
uint64_t *ids;
|
uint64_t *ids;
|
||||||
int nspk;
|
int nspk;
|
||||||
@ -2509,7 +2490,7 @@ speaker_set(void *arg, int *retval)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
ids = cmdarg->speaker_set_param.device_ids;
|
ids = speaker_set_param->device_ids;
|
||||||
|
|
||||||
if (ids)
|
if (ids)
|
||||||
nspk = ids[0];
|
nspk = ids[0];
|
||||||
@ -2536,8 +2517,8 @@ speaker_set(void *arg, int *retval)
|
|||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
(*retval)++;
|
(*retval)++;
|
||||||
else if (ret < 0 && cmdarg->speaker_set_param.intval != -2)
|
else if (ret < 0 && speaker_set_param->intval != -2)
|
||||||
cmdarg->speaker_set_param.intval = ret;
|
speaker_set_param->intval = ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2551,7 +2532,7 @@ speaker_set(void *arg, int *retval)
|
|||||||
if (*retval > 0)
|
if (*retval > 0)
|
||||||
return COMMAND_PENDING; // async
|
return COMMAND_PENDING; // async
|
||||||
|
|
||||||
*retval = cmdarg->speaker_set_param.intval;
|
*retval = speaker_set_param->intval;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2596,14 +2577,14 @@ volume_set(void *arg, int *retval)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
volume_setrel_speaker(void *arg, int *retval)
|
volume_setrel_speaker(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
struct volume_param *vol_param = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
int relvol;
|
int relvol;
|
||||||
|
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
id = cmdarg->vol_param.spk_id;
|
id = vol_param->spk_id;
|
||||||
relvol = cmdarg->vol_param.volume;
|
relvol = vol_param->volume;
|
||||||
|
|
||||||
for (device = dev_list; device; device = device->next)
|
for (device = dev_list; device; device = device->next)
|
||||||
{
|
{
|
||||||
@ -2640,14 +2621,14 @@ volume_setrel_speaker(void *arg, int *retval)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
volume_setabs_speaker(void *arg, int *retval)
|
volume_setabs_speaker(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
struct volume_param *vol_param = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
int volume;
|
int volume;
|
||||||
|
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
id = cmdarg->vol_param.spk_id;
|
id = vol_param->spk_id;
|
||||||
volume = cmdarg->vol_param.volume;
|
volume = vol_param->volume;
|
||||||
|
|
||||||
master_volume = volume;
|
master_volume = volume;
|
||||||
|
|
||||||
@ -2690,24 +2671,24 @@ volume_setabs_speaker(void *arg, int *retval)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
repeat_set(void *arg, int *retval)
|
repeat_set(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
union player_arg *cmdarg = arg;
|
enum repeat_mode *mode = arg;
|
||||||
|
|
||||||
if (cmdarg->mode == repeat)
|
if (*mode == repeat)
|
||||||
{
|
{
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cmdarg->mode)
|
switch (*mode)
|
||||||
{
|
{
|
||||||
case REPEAT_OFF:
|
case REPEAT_OFF:
|
||||||
case REPEAT_SONG:
|
case REPEAT_SONG:
|
||||||
case REPEAT_ALL:
|
case REPEAT_ALL:
|
||||||
repeat = cmdarg->mode;
|
repeat = *mode;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", cmdarg->mode);
|
DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", *mode);
|
||||||
*retval = -1;
|
*retval = -1;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
@ -2837,12 +2818,9 @@ player_get_current_pos(uint64_t *pos, struct timespec *ts, int commit)
|
|||||||
int
|
int
|
||||||
player_get_status(struct player_status *status)
|
player_get_status(struct player_status *status)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cmdarg.status = status;
|
ret = commands_exec_sync(cmdbase, get_status, NULL, status);
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, get_status, NULL, &cmdarg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2858,12 +2836,9 @@ player_get_status(struct player_status *status)
|
|||||||
int
|
int
|
||||||
player_now_playing(uint32_t *id)
|
player_now_playing(uint32_t *id)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cmdarg.id_ptr = id;
|
ret = commands_exec_sync(cmdbase, now_playing, NULL, id);
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, now_playing, NULL, &cmdarg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2968,27 +2943,24 @@ player_playback_prev(void)
|
|||||||
void
|
void
|
||||||
player_speaker_enumerate(spk_enum_cb cb, void *arg)
|
player_speaker_enumerate(spk_enum_cb cb, void *arg)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
|
||||||
struct spk_enum spk_enum;
|
struct spk_enum spk_enum;
|
||||||
|
|
||||||
spk_enum.cb = cb;
|
spk_enum.cb = cb;
|
||||||
spk_enum.arg = arg;
|
spk_enum.arg = arg;
|
||||||
|
|
||||||
cmdarg.spk_enum = &spk_enum;
|
commands_exec_sync(cmdbase, speaker_enumerate, NULL, &spk_enum);
|
||||||
|
|
||||||
commands_exec_sync(cmdbase, speaker_enumerate, NULL, &cmdarg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
player_speaker_set(uint64_t *ids)
|
player_speaker_set(uint64_t *ids)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
struct speaker_set_param speaker_set_param;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cmdarg.speaker_set_param.device_ids = ids;
|
speaker_set_param.device_ids = ids;
|
||||||
cmdarg.speaker_set_param.intval = 0;
|
speaker_set_param.intval = 0;
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, speaker_set, NULL, &cmdarg);
|
ret = commands_exec_sync(cmdbase, speaker_set, NULL, &speaker_set_param);
|
||||||
|
|
||||||
listener_notify(LISTENER_SPEAKER);
|
listener_notify(LISTENER_SPEAKER);
|
||||||
|
|
||||||
@ -3016,7 +2988,7 @@ player_volume_set(int vol)
|
|||||||
int
|
int
|
||||||
player_volume_setrel_speaker(uint64_t id, int relvol)
|
player_volume_setrel_speaker(uint64_t id, int relvol)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
struct volume_param vol_param;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (relvol < 0 || relvol > 100)
|
if (relvol < 0 || relvol > 100)
|
||||||
@ -3025,17 +2997,17 @@ player_volume_setrel_speaker(uint64_t id, int relvol)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdarg.vol_param.spk_id = id;
|
vol_param.spk_id = id;
|
||||||
cmdarg.vol_param.volume = relvol;
|
vol_param.volume = relvol;
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, volume_setrel_speaker, NULL, &cmdarg);
|
ret = commands_exec_sync(cmdbase, volume_setrel_speaker, NULL, &vol_param);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
player_volume_setabs_speaker(uint64_t id, int vol)
|
player_volume_setabs_speaker(uint64_t id, int vol)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
struct volume_param vol_param;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (vol < 0 || vol > 100)
|
if (vol < 0 || vol > 100)
|
||||||
@ -3044,22 +3016,19 @@ player_volume_setabs_speaker(uint64_t id, int vol)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdarg.vol_param.spk_id = id;
|
vol_param.spk_id = id;
|
||||||
cmdarg.vol_param.volume = vol;
|
vol_param.volume = vol;
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, volume_setabs_speaker, NULL, &cmdarg);
|
ret = commands_exec_sync(cmdbase, volume_setabs_speaker, NULL, &vol_param);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
player_repeat_set(enum repeat_mode mode)
|
player_repeat_set(enum repeat_mode mode)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cmdarg.mode = mode;
|
ret = commands_exec_sync(cmdbase, repeat_set, NULL, &mode);
|
||||||
|
|
||||||
ret = commands_exec_sync(cmdbase, repeat_set, NULL, &cmdarg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3183,12 +3152,12 @@ player_raop_verification_kickoff(char **arglist)
|
|||||||
void
|
void
|
||||||
player_metadata_send(void *imd, void *omd)
|
player_metadata_send(void *imd, void *omd)
|
||||||
{
|
{
|
||||||
union player_arg cmdarg;
|
struct metadata_param metadata_param;
|
||||||
|
|
||||||
cmdarg.metadata_param.input = imd;
|
metadata_param.input = imd;
|
||||||
cmdarg.metadata_param.output = omd;
|
metadata_param.output = omd;
|
||||||
|
|
||||||
commands_exec_sync(cmdbase, device_metadata_send, NULL, &cmdarg);
|
commands_exec_sync(cmdbase, device_metadata_send, NULL, &metadata_param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user