read_mixer.c 3.44 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 "mixer_control.h"
#include "mixer_list.h"
23 24
#include "filter_registry.h"
#include "pcm_volume.h"
25
#include "event_pipe.h"
26 27 28 29 30 31 32

#include <glib.h>

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

33 34 35
#ifdef HAVE_PULSE
#include "output/pulse_output_plugin.h"

36 37 38 39 40 41 42 43 44 45
void
pulse_output_lock(G_GNUC_UNUSED struct pulse_output *po)
{
}

void
pulse_output_unlock(G_GNUC_UNUSED struct pulse_output *po)
{
}

46
void
47 48
pulse_output_set_mixer(G_GNUC_UNUSED struct pulse_output *po,
		       G_GNUC_UNUSED struct pulse_mixer *pm)
49 50 51
{
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65
void
pulse_output_clear_mixer(G_GNUC_UNUSED struct pulse_output *po,
			 G_GNUC_UNUSED struct pulse_mixer *pm)
{
}

bool
pulse_output_set_volume(G_GNUC_UNUSED struct pulse_output *po,
			G_GNUC_UNUSED const struct pa_cvolume *volume,
			G_GNUC_UNUSED GError **error_r)
{
	return false;
}

66 67
#endif

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#ifdef HAVE_ROAR
#include "output/roar_output_plugin.h"

int
roar_output_get_volume(G_GNUC_UNUSED struct roar *roar)
{
	return -1;
}

bool
roar_output_set_volume(G_GNUC_UNUSED struct roar *roar,
		       G_GNUC_UNUSED unsigned volume)
{
	return true;
}

#endif

86 87 88 89 90
#ifdef ENABLE_RAOP_OUTPUT
#include "output/raop_output_plugin.h"

bool
raop_set_volume(G_GNUC_UNUSED struct raop_data *rd,
91 92
		G_GNUC_UNUSED unsigned volume,
		G_GNUC_UNUSED GError **error_r)
93 94 95 96 97 98 99 100 101 102 103 104
{
	return false;
}

int
raop_get_volume(G_GNUC_UNUSED struct raop_data *rd)
{
	return -1;
}

#endif

105 106 107 108 109
void
event_pipe_emit(G_GNUC_UNUSED enum pipe_event event)
{
}

110 111 112 113 114 115 116 117
const struct filter_plugin *
filter_plugin_by_name(G_GNUC_UNUSED const char *name)
{
	assert(false);
	return NULL;
}

bool
118
pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length,
119
	   G_GNUC_UNUSED enum sample_format format,
120 121 122 123 124 125
	   G_GNUC_UNUSED int volume)
{
	assert(false);
	return false;
}

126 127
int main(int argc, G_GNUC_UNUSED char **argv)
{
128
	GError *error = NULL;
129 130 131 132 133 134 135 136 137 138 139
	struct mixer *mixer;
	bool success;
	int volume;

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

	g_thread_init(NULL);

140
	mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error);
141
	if (mixer == NULL) {
142 143
		g_printerr("mixer_new() failed: %s\n", error->message);
		g_error_free(error);
144 145 146
		return 2;
	}

147
	success = mixer_open(mixer, &error);
148 149
	if (!success) {
		mixer_free(mixer);
150 151
		g_printerr("failed to open the mixer: %s\n", error->message);
		g_error_free(error);
152 153 154
		return 2;
	}

155
	volume = mixer_get_volume(mixer, &error);
156 157 158 159 160 161
	mixer_close(mixer);
	mixer_free(mixer);

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

	if (volume < 0) {
162 163 164 165 166 167
		if (error != NULL) {
			g_printerr("failed to read volume: %s\n",
				   error->message);
			g_error_free(error);
		} else
			g_printerr("failed to read volume\n");
168 169 170 171 172 173
		return 2;
	}

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