read_mixer.cxx 3.17 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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.
 *
 * 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.
 */

20
#include "config.h"
21 22
#include "MixerControl.hxx"
#include "MixerList.hxx"
Max Kellermann's avatar
Max Kellermann committed
23
#include "FilterRegistry.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "pcm/PcmVolume.hxx"
25
#include "GlobalEvents.hxx"
26 27
#include "Main.hxx"
#include "event/Loop.hxx"
28
#include "ConfigData.hxx"
29
#include "util/Error.hxx"
30 31 32 33 34 35 36

#include <glib.h>

#include <assert.h>
#include <string.h>
#include <unistd.h>

37 38
EventLoop *main_loop;

39
#ifdef HAVE_PULSE
40
#include "output/PulseOutputPlugin.hxx"
41

42
void
43
pulse_output_lock(gcc_unused PulseOutput *po)
44 45 46 47
{
}

void
48
pulse_output_unlock(gcc_unused PulseOutput *po)
49 50 51
{
}

52
void
53 54
pulse_output_set_mixer(gcc_unused PulseOutput *po,
		       gcc_unused PulseMixer *pm)
55 56 57
{
}

58
void
59 60
pulse_output_clear_mixer(gcc_unused PulseOutput *po,
			 gcc_unused PulseMixer *pm)
61 62 63 64
{
}

bool
65 66
pulse_output_set_volume(gcc_unused PulseOutput *po,
			gcc_unused const struct pa_cvolume *volume,
67
			gcc_unused Error &error)
68 69 70 71
{
	return false;
}

72 73
#endif

74
#ifdef HAVE_ROAR
75
#include "output/RoarOutputPlugin.hxx"
76 77

int
78
roar_output_get_volume(gcc_unused RoarOutput *roar)
79 80 81 82 83
{
	return -1;
}

bool
84
roar_output_set_volume(gcc_unused RoarOutput *roar,
85
		       gcc_unused unsigned volume)
86 87 88 89 90 91
{
	return true;
}

#endif

92
void
93
GlobalEvents::Emit(gcc_unused Event event)
94 95 96
{
}

97
const struct filter_plugin *
98
filter_plugin_by_name(gcc_unused const char *name)
99 100 101 102 103 104
{
	assert(false);
	return NULL;
}

bool
105 106 107
pcm_volume(gcc_unused void *buffer, gcc_unused size_t length,
	   gcc_unused SampleFormat format,
	   gcc_unused int volume)
108 109 110 111 112
{
	assert(false);
	return false;
}

113
int main(int argc, gcc_unused char **argv)
114 115 116 117 118 119 120 121
{
	int volume;

	if (argc != 2) {
		g_printerr("Usage: read_mixer PLUGIN\n");
		return 1;
	}

122
#if !GLIB_CHECK_VERSION(2,32,0)
123
	g_thread_init(NULL);
124
#endif
125

126 127
	main_loop = new EventLoop(EventLoop::Default());

128
	Error error;
129
	Mixer *mixer = mixer_new(&alsa_mixer_plugin, nullptr,
130
				 config_param(), error);
131
	if (mixer == NULL) {
132
		g_printerr("mixer_new() failed: %s\n", error.GetMessage());
133 134 135
		return 2;
	}

136
	if (!mixer_open(mixer, error)) {
137
		mixer_free(mixer);
138
		g_printerr("failed to open the mixer: %s\n", error.GetMessage());
139 140 141
		return 2;
	}

142
	volume = mixer_get_volume(mixer, error);
143 144 145
	mixer_close(mixer);
	mixer_free(mixer);

146 147
	delete main_loop;

148 149 150
	assert(volume >= -1 && volume <= 100);

	if (volume < 0) {
151
		if (error.IsDefined()) {
152
			g_printerr("failed to read volume: %s\n",
153
				   error.GetMessage());
154 155
		} else
			g_printerr("failed to read volume\n");
156 157 158 159 160 161
		return 2;
	}

	g_print("%d\n", volume);
	return 0;
}