Commands: new command "toggleoutput"
This commit is contained in:
@@ -159,6 +159,7 @@ static const struct command commands[] = {
|
||||
{ "swap", PERMISSION_CONTROL, 2, 2, handle_swap },
|
||||
{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
|
||||
{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
|
||||
{ "toggleoutput", PERMISSION_ADMIN, 1, 1, handle_toggleoutput },
|
||||
{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
|
||||
{ "update", PERMISSION_CONTROL, 0, 1, handle_update },
|
||||
{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
|
||||
|
@@ -84,3 +84,30 @@ audio_output_disable_index(unsigned idx)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
audio_output_toggle_index(unsigned idx)
|
||||
{
|
||||
struct audio_output *ao;
|
||||
|
||||
if (idx >= audio_output_count())
|
||||
return false;
|
||||
|
||||
ao = audio_output_get(idx);
|
||||
const bool enabled = ao->enabled = !ao->enabled;
|
||||
idle_add(IDLE_OUTPUT);
|
||||
|
||||
if (!enabled) {
|
||||
Mixer *mixer = ao->mixer;
|
||||
if (mixer != nullptr) {
|
||||
mixer_close(mixer);
|
||||
idle_add(IDLE_MIXER);
|
||||
}
|
||||
}
|
||||
|
||||
ao->player_control->UpdateAudio();
|
||||
|
||||
++audio_output_state_version;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -41,4 +41,11 @@ audio_output_enable_index(unsigned idx);
|
||||
bool
|
||||
audio_output_disable_index(unsigned idx);
|
||||
|
||||
/**
|
||||
* Toggles an audio output. Returns false if the specified output
|
||||
* does not exist.
|
||||
*/
|
||||
bool
|
||||
audio_output_toggle_index(unsigned idx);
|
||||
|
||||
#endif
|
||||
|
@@ -64,6 +64,22 @@ handle_disableoutput(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
||||
return COMMAND_RETURN_OK;
|
||||
}
|
||||
|
||||
enum command_return
|
||||
handle_toggleoutput(Client *client, gcc_unused int argc, char *argv[])
|
||||
{
|
||||
unsigned device;
|
||||
if (!check_unsigned(client, &device, argv[1]))
|
||||
return COMMAND_RETURN_ERROR;
|
||||
|
||||
if (!audio_output_toggle_index(device)) {
|
||||
command_error(client, ACK_ERROR_NO_EXIST,
|
||||
"No such audio output");
|
||||
return COMMAND_RETURN_ERROR;
|
||||
}
|
||||
|
||||
return COMMAND_RETURN_OK;
|
||||
}
|
||||
|
||||
enum command_return
|
||||
handle_devices(Client *client,
|
||||
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
||||
|
@@ -30,6 +30,9 @@ handle_enableoutput(Client *client, int argc, char *argv[]);
|
||||
enum command_return
|
||||
handle_disableoutput(Client *client, int argc, char *argv[]);
|
||||
|
||||
enum command_return
|
||||
handle_toggleoutput(Client *client, int argc, char *argv[]);
|
||||
|
||||
enum command_return
|
||||
handle_devices(Client *client, int argc, char *argv[]);
|
||||
|
||||
|
Reference in New Issue
Block a user