From db7b9c689bf988f5bc64f23ac67e4651f76326c8 Mon Sep 17 00:00:00 2001 From: chme Date: Mon, 21 Jan 2019 09:34:37 +0100 Subject: [PATCH] [player] Add command to get a single speaker info by its id --- src/player.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------- src/player.h | 7 +++-- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/player.c b/src/player.c index 74316f29..b6029ea8 100644 --- a/src/player.c +++ b/src/player.c @@ -146,6 +146,12 @@ struct speaker_set_param int intval; }; +struct speaker_get_param +{ + uint64_t spk_id; + struct spk_info *spk_info; +}; + struct metadata_param { struct input_metadata *input; @@ -2407,6 +2413,25 @@ player_speaker_status_trigger(void) listener_notify(LISTENER_SPEAKER); } +static void +device_to_speaker_info(struct spk_info *spk, struct output_device *device) +{ + memset(spk, 0, sizeof(struct spk_info)); + spk->id = device->id; + strncpy(spk->name, device->name, sizeof(spk->name)); + spk->name[sizeof(spk->name) - 1] = '\0'; + strncpy(spk->output_type, device->type_name, sizeof(spk->output_type)); + spk->output_type[sizeof(spk->output_type) - 1] = '\0'; + spk->relvol = device->relvol; + spk->absvol = device->volume; + + spk->selected = device->selected; + spk->has_password = device->has_password; + spk->has_video = device->has_video; + spk->requires_auth = device->requires_auth; + spk->needs_auth_key = (device->requires_auth && device->auth_key == NULL); +} + static enum command_state speaker_enumerate(void *arg, int *retval) { @@ -2418,18 +2443,7 @@ speaker_enumerate(void *arg, int *retval) { if (device->advertised || device->selected) { - spk.id = device->id; - spk.name = device->name; - spk.output_type = device->type_name; - spk.relvol = device->relvol; - spk.absvol = device->volume; - - spk.selected = device->selected; - spk.has_password = device->has_password; - spk.has_video = device->has_video; - spk.requires_auth = device->requires_auth; - spk.needs_auth_key = (device->requires_auth && device->auth_key == NULL); - + device_to_speaker_info(&spk, device); spk_enum->cb(&spk, spk_enum->arg); } } @@ -2438,6 +2452,28 @@ speaker_enumerate(void *arg, int *retval) return COMMAND_END; } +static enum command_state +speaker_get_byid(void *arg, int *retval) +{ + struct speaker_get_param *spk_param = arg; + struct output_device *device; + + for (device = dev_list; device; device = device->next) + { + if ((device->advertised || device->selected) + && device->id == spk_param->spk_id) + { + device_to_speaker_info(spk_param->spk_info, device); + *retval = 0; + return COMMAND_END; + } + } + + // No output device found with matching id + *retval = -1; + return COMMAND_END; +} + static int speaker_activate(struct output_device *device) { @@ -3123,6 +3159,18 @@ player_speaker_set(uint64_t *ids) return ret; } +int +player_speaker_get_byid(uint64_t id, struct spk_info *spk) +{ + struct speaker_get_param param; + int ret; + + param.spk_id = id; + + ret = commands_exec_sync(cmdbase, speaker_get_byid, NULL, ¶m); + return ret; +} + int player_speaker_enable(uint64_t id) { diff --git a/src/player.h b/src/player.h index 4771e41f..082ac1f0 100644 --- a/src/player.h +++ b/src/player.h @@ -31,8 +31,8 @@ enum repeat_mode { struct spk_info { uint64_t id; - const char *name; - const char *output_type; + char name[255]; + char output_type[50]; int relvol; int absvol; @@ -95,6 +95,9 @@ player_speaker_enumerate(spk_enum_cb cb, void *arg); int player_speaker_set(uint64_t *ids); +int +player_speaker_get_byid(uint64_t id, struct spk_info *spk); + int player_speaker_enable(uint64_t id);