From 18e75c244558e23b6c12d7193f0c3eb4614d18e2 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 26 May 2020 22:45:38 +0200 Subject: [PATCH] [player] Add player_speaker_authorize() A more straightforward function for device verification, using the new outputs_device_authorize() function. --- src/player.c | 36 +++++++++++++++++++++++++++++++++++- src/player.h | 3 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/player.c b/src/player.c index e80b8e5f..77e55468 100644 --- a/src/player.c +++ b/src/player.c @@ -147,6 +147,8 @@ struct speaker_attr_param bool prevent_playback; bool busy; + + const char *pin; }; struct speaker_get_param @@ -1552,7 +1554,7 @@ device_activate_cb(struct output_device *device, enum output_device_state status retval = commands_exec_returnvalue(cmdbase); if (!device) { - DPRINTF(E_WARN, L_PLAYER, "Output device disappeared during startup!\n"); + DPRINTF(E_WARN, L_PLAYER, "Output device disappeared during activation!\n"); if (retval != -2) retval = -1; @@ -2752,6 +2754,24 @@ speaker_resurrect_bh(void *arg, int *retval) return COMMAND_END; } +static enum command_state +speaker_authorize(void *arg, int *retval) +{ + struct speaker_attr_param *param = arg; + struct output_device *device; + + device = outputs_device_get(param->spk_id); + if (!device) + return COMMAND_END; + + *retval = outputs_device_authorize(device, param->pin, device_activate_cb); + + if (*retval > 0) + return COMMAND_PENDING; // async + + return COMMAND_END; +} + static enum command_state volume_set(void *arg, int *retval) { @@ -3227,6 +3247,20 @@ player_speaker_resurrect(void *arg) commands_exec_sync(cmdbase, speaker_resurrect, speaker_resurrect_bh, ¶m); } +int +player_speaker_authorize(uint64_t id, const char *pin) +{ + struct speaker_attr_param param; + int ret; + + param.spk_id = id; + param.pin = pin; + + ret = commands_exec_sync(cmdbase, speaker_authorize, speaker_generic_bh, ¶m); + + return ret; +} + int player_volume_set(int vol) { diff --git a/src/player.h b/src/player.h index 45cf104c..d913c78b 100644 --- a/src/player.h +++ b/src/player.h @@ -114,6 +114,9 @@ player_speaker_busy_set(uint64_t id, bool busy); void player_speaker_resurrect(void *arg); +int +player_speaker_authorize(uint64_t id, const char *pin); + int player_playback_start(void);