[mpd] Add support to change output volume through sendmessage command

Output volume can be set by sending a message to the channel
'outputvolume' by passing a message with the output id and the volume
separated by a colon.
This commit is contained in:
chme 2017-03-19 12:01:41 +01:00
parent d8b5951e40
commit eeef65f951

View File

@ -3703,7 +3703,7 @@ mpd_command_outputvolume(struct evbuffer *evbuf, int argc, char **argv, char **e
{
ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[1]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
}
@ -3721,6 +3721,47 @@ mpd_command_outputvolume(struct evbuffer *evbuf, int argc, char **argv, char **e
return ret;
}
static void
channel_outputvolume(const char *message)
{
uint32_t shortid;
int volume;
char *tmp;
char *ptr;
char *errmsg = NULL;
int ret;
tmp = strdup(message);
ptr = strrchr(tmp, ':');
if (!ptr)
{
DPRINTF(E_LOG, L_MPD, "Failed to parse output id and volume from message '%s' (expected format: \"output-id:volume\"\n", message);
return;
}
*ptr = '\0';
ret = safe_atou32(tmp, &shortid);
if (ret < 0)
{
free(tmp);
DPRINTF(E_LOG, L_MPD, "Failed to parse output id from message: '%s'\n", message);
return;
}
ret = safe_atoi32((ptr + 1), &volume);
if (ret < 0)
{
free(tmp);
DPRINTF(E_LOG, L_MPD, "Failed to parse volume from message: '%s'\n", message);
return;
}
outputvolume_set(shortid, volume, &errmsg);
if (errmsg)
DPRINTF(E_LOG, L_MPD, "Failed to set output volume from message: '%s' (error='%s')\n", message, errmsg);
}
static void
channel_pairing(const char *message)
{
@ -3742,6 +3783,10 @@ struct mpd_channel
static struct mpd_channel mpd_channels[] =
{
{
.channel = "outputvolume",
.handler = channel_outputvolume
},
{
.channel = "pairing",
.handler = channel_pairing