OutputCommand.cxx 2.37 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19 20 21 22 23 24 25 26
 */

/*
 * Glue functions for controlling the audio outputs over the MPD
 * protocol.  These functions perform extra validation on all
 * parameters, because they might be from an untrusted source.
 *
 */

27
#include "config.h"
28
#include "OutputCommand.hxx"
29
#include "MultipleOutputs.hxx"
30
#include "Internal.hxx"
31
#include "PlayerControl.hxx"
Max Kellermann's avatar
Max Kellermann committed
32
#include "mixer/MixerControl.hxx"
Max Kellermann's avatar
Max Kellermann committed
33
#include "Idle.hxx"
34

35 36
extern unsigned audio_output_state_version;

37
bool
38
audio_output_enable_index(MultipleOutputs &outputs, unsigned idx)
39
{
40
	if (idx >= outputs.Size())
41 42
		return false;

43
	AudioOutput &ao = outputs.Get(idx);
44
	if (ao.enabled)
45
		return true;
46

47
	ao.enabled = true;
48 49
	idle_add(IDLE_OUTPUT);

50
	ao.player_control->UpdateAudio();
51

52 53
	++audio_output_state_version;

54 55 56 57
	return true;
}

bool
58
audio_output_disable_index(MultipleOutputs &outputs, unsigned idx)
59
{
60
	if (idx >= outputs.Size())
61 62
		return false;

63
	AudioOutput &ao = outputs.Get(idx);
64
	if (!ao.enabled)
65
		return true;
66

67
	ao.enabled = false;
68 69
	idle_add(IDLE_OUTPUT);

70
	Mixer *mixer = ao.mixer;
71
	if (mixer != nullptr) {
72 73 74 75
		mixer_close(mixer);
		idle_add(IDLE_MIXER);
	}

76
	ao.player_control->UpdateAudio();
77

78 79
	++audio_output_state_version;

80 81
	return true;
}
82 83

bool
84
audio_output_toggle_index(MultipleOutputs &outputs, unsigned idx)
85
{
86
	if (idx >= outputs.Size())
87 88
		return false;

89
	AudioOutput &ao = outputs.Get(idx);
90
	const bool enabled = ao.enabled = !ao.enabled;
91 92 93
	idle_add(IDLE_OUTPUT);

	if (!enabled) {
94
		Mixer *mixer = ao.mixer;
95 96 97 98 99 100
		if (mixer != nullptr) {
			mixer_close(mixer);
			idle_add(IDLE_MIXER);
		}
	}

101
	ao.player_control->UpdateAudio();
102 103 104 105 106

	++audio_output_state_version;

	return true;
}