[mpd] Add new command 'outputvolume' to set volume for a specific output

This commit is contained in:
chme 2016-10-15 10:52:46 +02:00
parent bdb2c74934
commit 60f9c779b6
1 changed files with 84 additions and 0 deletions

View File

@ -3560,6 +3560,82 @@ mpd_command_outputs(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
return 0; return 0;
} }
static int
mpd_command_outputvolume(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{
uint32_t shortid;
int volume;
struct outputs outputs;
struct output *output;
int ret;
if (argc < 3)
{
ret = asprintf(errmsg, "Missing argument for command 'outputvolume'");
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
}
ret = safe_atou32(argv[1], &shortid);
if (ret < 0)
{
ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[1]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
}
ret = safe_atoi32(argv[2], &volume);
if (ret < 0)
{
ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[2]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
}
outputs.count = 0;
outputs.active = 0;
outputs.outputs = NULL;
player_speaker_enumerate(outputs_enum_cb, &outputs);
output = outputs.outputs;
while (output)
{
if (output->shortid == shortid)
{
break;
}
output = output->next;
}
if (!output)
{
free_outputs(outputs.outputs);
ret = asprintf(errmsg, "No speaker found for short id: %d", shortid);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_UNKNOWN;
}
ret = player_volume_setabs_speaker(output->id, volume);
if (ret < 0)
{
free_outputs(outputs.outputs);
ret = asprintf(errmsg, "Setting volume to %d for speaker with short-id %d failed", volume, shortid);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_UNKNOWN;
}
free_outputs(outputs.outputs);
return 0;
}
/* /*
* Dummy function to handle commands that are not supported by forked-daapd and should * Dummy function to handle commands that are not supported by forked-daapd and should
* not raise an error. * not raise an error.
@ -4102,6 +4178,14 @@ static struct mpd_command mpd_handlers[] =
.handler = mpd_command_ignore .handler = mpd_command_ignore
}, },
/*
* Forked-daapd commands (not supported by mpd)
*/
{
.mpdcommand = "outputvolume",
.handler = mpd_command_outputvolume
},
/* /*
* NULL command to terminate loop * NULL command to terminate loop
*/ */