2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
39 #include <pulse/pulseaudio.h>
40 #include <pulse/ext-device-restore.h>
41 #include <pulse/ext-node-manager.h>
42 #include <pulse/ext-volume-api.h>
44 #include <pulsecore/i18n.h>
45 #include <pulsecore/macro.h>
46 #include <pulsecore/core-util.h>
47 #include <pulsecore/log.h>
48 #include <pulsecore/sndfile-util.h>
50 static pa_context *context = NULL;
51 static pa_mainloop_api *mainloop_api = NULL;
64 *volume_control_name = NULL,
65 *mute_control_name = NULL;
68 sink_input_idx = PA_INVALID_INDEX,
69 source_output_idx = PA_INVALID_INDEX,
70 sink_idx = PA_INVALID_INDEX;
72 static bool short_list_format = false;
73 static uint32_t module_index;
74 static int32_t latency_offset;
76 static pa_volume_t volume;
77 static enum volume_flags {
82 VOL_ABSOLUTE = 0 << 4,
83 VOL_RELATIVE = 1 << 4,
86 static enum mute_flags {
91 } mute = INVALID_MUTE;
93 static pa_proplist *proplist = NULL;
95 static SNDFILE *sndfile = NULL;
96 static pa_stream *sample_stream = NULL;
97 static pa_sample_spec sample_spec;
98 static pa_channel_map channel_map;
99 static size_t sample_length = 0;
100 static int actions = 0;
102 static bool nl = false;
104 static uint32_t src_node_id;
105 static uint32_t dst_node_id;
106 static uint32_t conn_id;
107 bool volume_api_connected = false;
108 pa_ext_volume_api_bvolume bvolume;
109 bool volume_valid = false;
110 bool balance_valid = false;
111 uint32_t main_output_volume_control = PA_INVALID_INDEX;
112 uint32_t main_input_volume_control = PA_INVALID_INDEX;
113 uint32_t main_output_mute_control = PA_INVALID_INDEX;
114 uint32_t main_input_mute_control = PA_INVALID_INDEX;
138 SET_SINK_INPUT_VOLUME,
139 SET_SOURCE_OUTPUT_VOLUME,
143 SET_SOURCE_OUTPUT_MUTE,
145 SET_PORT_LATENCY_OFFSET,
146 SET_VOLUME_CONTROL_VOLUME,
147 SET_MUTE_CONTROL_MUTE,
153 static void quit(int ret) {
154 pa_assert(mainloop_api);
155 mainloop_api->quit(mainloop_api, ret);
158 static void context_drain_complete(pa_context *c, void *userdata) {
159 pa_context_disconnect(c);
162 static void drain(void) {
165 if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
166 pa_context_disconnect(context);
168 pa_operation_unref(o);
171 static void complete_action(void) {
172 pa_assert(actions > 0);
178 static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata) {
179 char s[PA_BYTES_SNPRINT_MAX];
181 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c)));
186 pa_bytes_snprint(s, sizeof(s), i->memblock_total_size);
187 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i->memblock_total, s);
189 pa_bytes_snprint(s, sizeof(s), i->memblock_allocated_size);
190 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i->memblock_allocated, s);
192 pa_bytes_snprint(s, sizeof(s), i->scache_size);
193 printf(_("Sample cache size: %s\n"), s);
198 static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
199 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
202 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c)));
207 printf(_("Server String: %s\n"
208 "Library Protocol Version: %u\n"
209 "Server Protocol Version: %u\n"
213 pa_context_get_server(c),
214 pa_context_get_protocol_version(c),
215 pa_context_get_server_protocol_version(c),
216 pa_yes_no(pa_context_is_local(c)),
217 pa_context_get_index(c),
218 pa_context_get_tile_size(c, NULL));
220 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
221 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map);
223 printf(_("User Name: %s\n"
226 "Server Version: %s\n"
227 "Default Sample Specification: %s\n"
228 "Default Channel Map: %s\n"
230 "Default Source: %s\n"
231 "Cookie: %04x:%04x\n"),
238 i->default_sink_name,
239 i->default_source_name,
241 i->cookie & 0xFFFFU);
246 static const char* get_available_str_ynonly(int available) {
248 case PA_PORT_AVAILABLE_YES: return ", available";
249 case PA_PORT_AVAILABLE_NO: return ", not available";
254 static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
256 static const char *state_table[] = {
257 [1+PA_SINK_INVALID_STATE] = "n/a",
258 [1+PA_SINK_RUNNING] = "RUNNING",
259 [1+PA_SINK_IDLE] = "IDLE",
260 [1+PA_SINK_SUSPENDED] = "SUSPENDED"
264 s[PA_SAMPLE_SPEC_SNPRINT_MAX],
265 cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
266 v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
267 cm[PA_CHANNEL_MAP_SNPRINT_MAX],
268 f[PA_FORMAT_INFO_SNPRINT_MAX];
272 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c)));
284 if (nl && !short_list_format)
288 if (short_list_format) {
289 printf("%u\t%s\t%s\t%s\t%s\n",
292 pa_strnull(i->driver),
293 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
294 state_table[1+i->state]);
298 printf(_("Sink #%u\n"
301 "\tDescription: %s\n"
303 "\tSample Specification: %s\n"
304 "\tChannel Map: %s\n"
305 "\tOwner Module: %u\n"
309 "\tBase Volume: %s\n"
310 "\tMonitor Source: %s\n"
311 "\tLatency: %0.0f usec, configured %0.0f usec\n"
312 "\tFlags: %s%s%s%s%s%s%s\n"
313 "\tProperties:\n\t\t%s\n"),
315 state_table[1+i->state],
317 pa_strnull(i->description),
318 pa_strnull(i->driver),
319 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
320 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
323 pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, i->flags & PA_SINK_DECIBEL_VOLUME),
324 pa_cvolume_get_balance(&i->volume, &i->channel_map),
325 pa_volume_snprint_verbose(v, sizeof(v), i->base_volume, i->flags & PA_SINK_DECIBEL_VOLUME),
326 pa_strnull(i->monitor_source_name),
327 (double) i->latency, (double) i->configured_latency,
328 i->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
329 i->flags & PA_SINK_NETWORK ? "NETWORK " : "",
330 i->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
331 i->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
332 i->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
333 i->flags & PA_SINK_LATENCY ? "LATENCY " : "",
334 i->flags & PA_SINK_SET_FORMATS ? "SET_FORMATS " : "",
335 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
340 pa_sink_port_info **p;
342 printf(_("\tPorts:\n"));
343 for (p = i->ports; *p; p++)
344 printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description,
345 (*p)->priority, get_available_str_ynonly((*p)->available));
349 printf(_("\tActive Port: %s\n"),
350 i->active_port->name);
355 printf(_("\tFormats:\n"));
356 for (j = 0; j < i->n_formats; j++)
357 printf("\t\t%s\n", pa_format_info_snprint(f, sizeof(f), i->formats[j]));
361 static void get_source_info_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
363 static const char *state_table[] = {
364 [1+PA_SOURCE_INVALID_STATE] = "n/a",
365 [1+PA_SOURCE_RUNNING] = "RUNNING",
366 [1+PA_SOURCE_IDLE] = "IDLE",
367 [1+PA_SOURCE_SUSPENDED] = "SUSPENDED"
371 s[PA_SAMPLE_SPEC_SNPRINT_MAX],
372 cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
373 v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
374 cm[PA_CHANNEL_MAP_SNPRINT_MAX],
375 f[PA_FORMAT_INFO_SNPRINT_MAX];
379 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c)));
391 if (nl && !short_list_format)
395 if (short_list_format) {
396 printf("%u\t%s\t%s\t%s\t%s\n",
399 pa_strnull(i->driver),
400 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
401 state_table[1+i->state]);
405 printf(_("Source #%u\n"
408 "\tDescription: %s\n"
410 "\tSample Specification: %s\n"
411 "\tChannel Map: %s\n"
412 "\tOwner Module: %u\n"
416 "\tBase Volume: %s\n"
417 "\tMonitor of Sink: %s\n"
418 "\tLatency: %0.0f usec, configured %0.0f usec\n"
419 "\tFlags: %s%s%s%s%s%s\n"
420 "\tProperties:\n\t\t%s\n"),
422 state_table[1+i->state],
424 pa_strnull(i->description),
425 pa_strnull(i->driver),
426 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
427 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
430 pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, i->flags & PA_SOURCE_DECIBEL_VOLUME),
431 pa_cvolume_get_balance(&i->volume, &i->channel_map),
432 pa_volume_snprint_verbose(v, sizeof(v), i->base_volume, i->flags & PA_SOURCE_DECIBEL_VOLUME),
433 i->monitor_of_sink_name ? i->monitor_of_sink_name : _("n/a"),
434 (double) i->latency, (double) i->configured_latency,
435 i->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
436 i->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
437 i->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
438 i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
439 i->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
440 i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
441 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
446 pa_source_port_info **p;
448 printf(_("\tPorts:\n"));
449 for (p = i->ports; *p; p++)
450 printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description,
451 (*p)->priority, get_available_str_ynonly((*p)->available));
455 printf(_("\tActive Port: %s\n"),
456 i->active_port->name);
461 printf(_("\tFormats:\n"));
462 for (j = 0; j < i->n_formats; j++)
463 printf("\t\t%s\n", pa_format_info_snprint(f, sizeof(f), i->formats[j]));
467 static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
472 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c)));
484 if (nl && !short_list_format)
488 pa_snprintf(t, sizeof(t), "%u", i->n_used);
490 if (short_list_format) {
491 printf("%u\t%s\t%s\t\n", i->index, i->name, i->argument ? i->argument : "");
495 printf(_("Module #%u\n"
498 "\tUsage counter: %s\n"
499 "\tProperties:\n\t\t%s\n"),
502 i->argument ? i->argument : "",
503 i->n_used != PA_INVALID_INDEX ? t : _("n/a"),
504 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
509 static void get_client_info_callback(pa_context *c, const pa_client_info *i, int is_last, void *userdata) {
514 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c)));
526 if (nl && !short_list_format)
530 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
532 if (short_list_format) {
533 printf("%u\t%s\t%s\n",
535 pa_strnull(i->driver),
536 pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_APPLICATION_PROCESS_BINARY)));
540 printf(_("Client #%u\n"
542 "\tOwner Module: %s\n"
543 "\tProperties:\n\t\t%s\n"),
545 pa_strnull(i->driver),
546 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
547 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
552 static void get_card_info_callback(pa_context *c, const pa_card_info *i, int is_last, void *userdata) {
557 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c)));
569 if (nl && !short_list_format)
573 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
575 if (short_list_format) {
576 printf("%u\t%s\t%s\n", i->index, i->name, pa_strnull(i->driver));
580 printf(_("Card #%u\n"
583 "\tOwner Module: %s\n"
584 "\tProperties:\n\t\t%s\n"),
587 pa_strnull(i->driver),
588 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
589 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
593 if (i->n_profiles > 0) {
594 pa_card_profile_info2 **p;
596 printf(_("\tProfiles:\n"));
597 for (p = i->profiles2; *p; p++)
598 printf("\t\t%s: %s (sinks: %u, sources: %u, priority: %u, available: %s)\n", (*p)->name,
599 (*p)->description, (*p)->n_sinks, (*p)->n_sources, (*p)->priority, pa_yes_no((*p)->available));
602 if (i->active_profile)
603 printf(_("\tActive Profile: %s\n"),
604 i->active_profile->name);
607 pa_card_port_info **p;
609 printf(_("\tPorts:\n"));
610 for (p = i->ports; *p; p++) {
611 pa_card_profile_info **pr = (*p)->profiles;
612 printf("\t\t%s: %s (priority: %u, latency offset: %" PRId64 " usec%s)\n", (*p)->name,
613 (*p)->description, (*p)->priority, (*p)->latency_offset,
614 get_available_str_ynonly((*p)->available));
616 if (!pa_proplist_isempty((*p)->proplist)) {
617 printf(_("\t\t\tProperties:\n\t\t\t\t%s\n"), pl = pa_proplist_to_string_sep((*p)->proplist, "\n\t\t\t\t"));
622 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr)->name));
625 printf(", %s", pa_strnull((*pr)->name));
634 static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
635 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
639 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c)));
651 if (nl && !short_list_format)
655 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
656 pa_snprintf(k, sizeof(k), "%u", i->client);
658 if (short_list_format) {
659 printf("%u\t%u\t%s\t%s\t%s\n",
662 i->client != PA_INVALID_INDEX ? k : "-",
663 pa_strnull(i->driver),
664 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec));
668 printf(_("Sink Input #%u\n"
670 "\tOwner Module: %s\n"
673 "\tSample Specification: %s\n"
674 "\tChannel Map: %s\n"
680 "\tBuffer Latency: %0.0f usec\n"
681 "\tSink Latency: %0.0f usec\n"
682 "\tResample method: %s\n"
683 "\tProperties:\n\t\t%s\n"),
685 pa_strnull(i->driver),
686 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
687 i->client != PA_INVALID_INDEX ? k : _("n/a"),
689 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
690 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
691 pa_format_info_snprint(f, sizeof(f), i->format),
692 pa_yes_no(i->corked),
694 pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
695 pa_cvolume_get_balance(&i->volume, &i->channel_map),
696 (double) i->buffer_usec,
697 (double) i->sink_usec,
698 i->resample_method ? i->resample_method : _("n/a"),
699 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
704 static void get_source_output_info_callback(pa_context *c, const pa_source_output_info *i, int is_last, void *userdata) {
705 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
709 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c)));
721 if (nl && !short_list_format)
725 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
726 pa_snprintf(k, sizeof(k), "%u", i->client);
728 if (short_list_format) {
729 printf("%u\t%u\t%s\t%s\t%s\n",
732 i->client != PA_INVALID_INDEX ? k : "-",
733 pa_strnull(i->driver),
734 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec));
738 printf(_("Source Output #%u\n"
740 "\tOwner Module: %s\n"
743 "\tSample Specification: %s\n"
744 "\tChannel Map: %s\n"
750 "\tBuffer Latency: %0.0f usec\n"
751 "\tSource Latency: %0.0f usec\n"
752 "\tResample method: %s\n"
753 "\tProperties:\n\t\t%s\n"),
755 pa_strnull(i->driver),
756 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
757 i->client != PA_INVALID_INDEX ? k : _("n/a"),
759 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
760 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
761 pa_format_info_snprint(f, sizeof(f), i->format),
762 pa_yes_no(i->corked),
764 pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
765 pa_cvolume_get_balance(&i->volume, &i->channel_map),
766 (double) i->buffer_usec,
767 (double) i->source_usec,
768 i->resample_method ? i->resample_method : _("n/a"),
769 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
774 static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) {
775 char t[PA_BYTES_SNPRINT_MAX], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
779 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c)));
791 if (nl && !short_list_format)
795 pa_bytes_snprint(t, sizeof(t), i->bytes);
797 if (short_list_format) {
798 printf("%u\t%s\t%s\t%0.3f\n",
801 pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : "-",
802 (double) i->duration/1000000.0);
806 printf(_("Sample #%u\n"
808 "\tSample Specification: %s\n"
809 "\tChannel Map: %s\n"
812 "\tDuration: %0.1fs\n"
816 "\tProperties:\n\t\t%s\n"),
819 pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : _("n/a"),
820 pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : _("n/a"),
821 pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
822 pa_cvolume_get_balance(&i->volume, &i->channel_map),
823 (double) i->duration/1000000.0,
826 i->filename ? i->filename : _("n/a"),
827 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
832 static void simple_callback(pa_context *c, int success, void *userdata) {
834 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c)));
842 static void index_callback(pa_context *c, uint32_t idx, void *userdata) {
843 if (idx == PA_INVALID_INDEX) {
844 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c)));
854 static void volume_relative_adjust(pa_cvolume *cv, pa_volume_t adjustment) {
855 pa_assert((volume_flags & VOL_RELATIVE) == VOL_RELATIVE);
857 /* Relative volume change is additive in case of UINT or PERCENT
858 * and multiplicative for LINEAR or DECIBEL */
859 if ((volume_flags & 0x0F) == VOL_UINT || (volume_flags & 0x0F) == VOL_PERCENT) {
860 pa_volume_t v = pa_cvolume_avg(cv);
861 v = v + adjustment < PA_VOLUME_NORM ? PA_VOLUME_MUTED : v + adjustment - PA_VOLUME_NORM;
862 pa_cvolume_set(cv, 1, v);
864 if ((volume_flags & 0x0F) == VOL_LINEAR || (volume_flags & 0x0F) == VOL_DECIBEL) {
865 pa_sw_cvolume_multiply_scalar(cv, cv, adjustment);
869 static void unload_module_by_name_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
870 static bool unloaded = false;
873 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c)));
879 if (unloaded == false)
880 pa_log(_("Failed to unload module: Module %s not loaded"), module_name);
887 if (pa_streq(module_name, i->name)) {
890 pa_operation_unref(pa_context_unload_module(c, i->index, simple_callback, NULL));
894 static void get_sink_volume_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
898 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c)));
909 volume_relative_adjust(&cv, volume);
910 pa_operation_unref(pa_context_set_sink_volume_by_name(c, sink_name, &cv, simple_callback, NULL));
913 static void get_source_volume_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
917 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c)));
928 volume_relative_adjust(&cv, volume);
929 pa_operation_unref(pa_context_set_source_volume_by_name(c, source_name, &cv, simple_callback, NULL));
932 static void get_sink_input_volume_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
936 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c)));
947 volume_relative_adjust(&cv, volume);
948 pa_operation_unref(pa_context_set_sink_input_volume(c, sink_input_idx, &cv, simple_callback, NULL));
951 static void get_source_output_volume_callback(pa_context *c, const pa_source_output_info *o, int is_last, void *userdata) {
955 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c)));
966 volume_relative_adjust(&cv, volume);
967 pa_operation_unref(pa_context_set_source_output_volume(c, source_output_idx, &cv, simple_callback, NULL));
970 static void sink_toggle_mute_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
972 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c)));
982 pa_operation_unref(pa_context_set_sink_mute_by_name(c, i->name, !i->mute, simple_callback, NULL));
985 static void source_toggle_mute_callback(pa_context *c, const pa_source_info *o, int is_last, void *userdata) {
987 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c)));
997 pa_operation_unref(pa_context_set_source_mute_by_name(c, o->name, !o->mute, simple_callback, NULL));
1000 static void sink_input_toggle_mute_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
1002 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c)));
1012 pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, !i->mute, simple_callback, NULL));
1015 static void source_output_toggle_mute_callback(pa_context *c, const pa_source_output_info *o, int is_last, void *userdata) {
1017 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c)));
1027 pa_operation_unref(pa_context_set_source_output_mute(c, o->index, !o->mute, simple_callback, NULL));
1030 static void node_list_callback(pa_context *c,
1031 const pa_ext_node_manager_info *info,
1036 const char *node_id = pa_proplist_gets(info->props, "index");
1037 if (node_id != NULL) {
1038 printf("Node #%s (%s)\n", node_id, info->name);
1039 printf("%s\n", pa_proplist_to_string(info->props));
1045 static void node_connect_callback(pa_context *c,
1049 printf("New connection id: %d\n", conne_id);
1054 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
1055 #define MAX_FORMATS 256
1057 static void set_sink_formats(pa_context *c, uint32_t sink, const char *str) {
1058 pa_format_info *f_arr[MAX_FORMATS];
1059 char *format = NULL;
1060 const char *state = NULL;
1062 pa_operation *o = NULL;
1064 while ((format = pa_split(str, ";", &state))) {
1065 pa_format_info *f = pa_format_info_from_string(pa_strip(format));
1068 pa_log(_("Failed to set format: invalid format string %s"), format);
1076 o = pa_ext_device_restore_save_formats(c, PA_DEVICE_TYPE_SINK, sink, i, f_arr, simple_callback, NULL);
1078 pa_operation_unref(o);
1086 pa_format_info_free(f_arr[i]);
1092 pa_format_info_free(f_arr[i]);
1097 static void stream_state_callback(pa_stream *s, void *userdata) {
1100 switch (pa_stream_get_state(s)) {
1101 case PA_STREAM_CREATING:
1102 case PA_STREAM_READY:
1105 case PA_STREAM_TERMINATED:
1109 case PA_STREAM_FAILED:
1111 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s))));
1116 static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
1119 pa_assert(s && length && sndfile);
1121 d = pa_xmalloc(length);
1123 pa_assert(sample_length >= length);
1124 l = (sf_count_t) (length/pa_frame_size(&sample_spec));
1126 if ((sf_readf_float(sndfile, d, l)) != l) {
1128 pa_log(_("Premature end of file"));
1133 pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
1135 sample_length -= length;
1137 if (sample_length <= 0) {
1138 pa_stream_set_write_callback(sample_stream, NULL, NULL);
1139 pa_stream_finish_upload(sample_stream);
1143 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t) {
1145 switch (t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
1147 case PA_SUBSCRIPTION_EVENT_NEW:
1150 case PA_SUBSCRIPTION_EVENT_CHANGE:
1153 case PA_SUBSCRIPTION_EVENT_REMOVE:
1157 return _("unknown");
1160 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t) {
1162 switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
1164 case PA_SUBSCRIPTION_EVENT_SINK:
1167 case PA_SUBSCRIPTION_EVENT_SOURCE:
1170 case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
1171 return _("sink-input");
1173 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
1174 return _("source-output");
1176 case PA_SUBSCRIPTION_EVENT_MODULE:
1179 case PA_SUBSCRIPTION_EVENT_CLIENT:
1182 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE:
1183 return _("sample-cache");
1185 case PA_SUBSCRIPTION_EVENT_SERVER:
1188 case PA_SUBSCRIPTION_EVENT_CARD:
1192 return _("unknown");
1195 static void context_subscribe_callback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
1198 printf(_("Event '%s' on %s #%u\n"),
1199 subscription_event_type_to_string(t),
1200 subscription_event_facility_to_string(t),
1205 static void get_volume_control_info_callback(pa_context *c, const pa_ext_volume_api_volume_control_info *info,
1206 int is_last, void *userdata) {
1207 char volume_str[PA_VOLUME_SNPRINT_VERBOSE_MAX];
1208 char balance_str[PA_EXT_VOLUME_API_BVOLUME_SNPRINT_BALANCE_MAX];
1214 pa_log(_("Failed to get volume control information: %s"), pa_strerror(pa_context_errno(c)));
1226 if (action == INFO) {
1227 if (info->index == main_output_volume_control)
1228 printf(_("Main output volume control: %s\n"), info->name);
1230 if (info->index == main_input_volume_control)
1231 printf(_("Main input volume control: %s\n"), info->name);
1236 if (action == SET_VOLUME_CONTROL_VOLUME) {
1237 pa_ext_volume_api_bvolume bv;
1239 if (balance_valid && bvolume.channel_map.channels != info->volume.channel_map.channels) {
1240 pa_log(_("Incompatible number of channels, expected %u channels."), info->volume.channel_map.channels);
1247 if (volume_flags & VOL_RELATIVE) {
1250 pa_cvolume_set(&cv, 1, info->volume.volume);
1251 volume_relative_adjust(&cv, bvolume.volume);
1252 bv.volume = cv.values[0];
1254 bv.volume = bvolume.volume;
1258 memcpy(bv.balance, bvolume.balance, sizeof(bv.balance));
1260 pa_operation_unref(pa_ext_volume_api_set_volume_control_volume_by_name(c, volume_control_name, &bv,
1261 volume_valid, balance_valid,
1262 simple_callback, NULL));
1268 pa_assert(action == LIST);
1270 if (nl && !short_list_format)
1274 if (short_list_format) {
1275 printf("%u\t%s\t%u\n", info->index, info->name, info->volume.volume);
1279 pa_volume_snprint_verbose(volume_str, sizeof(volume_str), info->volume.volume, info->convertible_to_dB);
1280 pa_ext_volume_api_bvolume_snprint_balance(balance_str, sizeof(balance_str), &info->volume);
1281 proplist_str = pa_proplist_to_string_sep(info->proplist, "\n\t\t");
1283 printf(_("Volume Control #%u\n"
1285 "\tDescription: %s\n"
1288 "\tProperties: %s%s\n"),
1294 *proplist_str ? "\n\t\t" : _("(none)"),
1297 pa_xfree(proplist_str);
1300 static void get_mute_control_info_callback(pa_context *c, const pa_ext_volume_api_mute_control_info *info, int is_last,
1307 pa_log(_("Failed to get mute control information: %s"), pa_strerror(pa_context_errno(c)));
1319 if (action == INFO) {
1320 if (info->index == main_output_mute_control)
1321 printf(_("Main output mute control: %s\n"), info->name);
1323 if (info->index == main_input_mute_control)
1324 printf(_("Main input mute control: %s\n"), info->name);
1329 if (action == SET_MUTE_CONTROL_MUTE) {
1330 pa_operation_unref(pa_ext_volume_api_set_mute_control_mute_by_index(c, info->index, info->mute ? false : true,
1331 simple_callback, NULL));
1336 pa_assert(action == LIST);
1338 if (nl && !short_list_format)
1342 if (short_list_format) {
1343 printf("%u\t%s\t%s\n", info->index, info->name, pa_yes_no(info->mute));
1347 proplist_str = pa_proplist_to_string_sep(info->proplist, "\n\t\t");
1349 printf(_("Mute Control #%u\n"
1351 "\tDescription: %s\n"
1353 "\tProperties: %s%s\n"),
1357 pa_yes_no(info->mute),
1358 *proplist_str ? "\n\t\t" : _("(none)"),
1361 pa_xfree(proplist_str);
1364 static void volume_api_get_server_info_callback(pa_context *c, const pa_ext_volume_api_server_info *info, void *userdata) {
1368 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c)));
1373 main_output_volume_control = info->main_output_volume_control;
1374 main_input_volume_control = info->main_input_volume_control;
1375 main_output_mute_control = info->main_output_mute_control;
1376 main_input_mute_control = info->main_input_mute_control;
1378 if (main_output_volume_control == PA_INVALID_INDEX)
1379 printf(_("Main output volume control: (unset)\n"));
1381 if (main_input_volume_control == PA_INVALID_INDEX)
1382 printf(_("Main input volume control: (unset)\n"));
1384 if (main_output_mute_control == PA_INVALID_INDEX)
1385 printf(_("Main output mute control: (unset)\n"));
1387 if (main_input_mute_control == PA_INVALID_INDEX)
1388 printf(_("Main input mute control: (unset)\n"));
1390 if (main_output_volume_control != PA_INVALID_INDEX || main_input_volume_control != PA_INVALID_INDEX) {
1391 pa_operation_unref(pa_ext_volume_api_get_volume_control_info_list(c, get_volume_control_info_callback, NULL));
1395 if (main_output_mute_control != PA_INVALID_INDEX || main_input_mute_control != PA_INVALID_INDEX) {
1396 pa_operation_unref(pa_ext_volume_api_get_mute_control_info_list(c, get_mute_control_info_callback, NULL));
1403 static void get_device_info_callback(pa_context *c, const pa_ext_volume_api_device_info *info, int is_last,
1405 char *device_types_str = NULL;
1406 char *volume_control_str;
1407 char *mute_control_str;
1413 pa_log(_("Failed to get device information: %s"), pa_strerror(pa_context_errno(c)));
1425 if (nl && !short_list_format)
1429 if (info->n_device_types > 0)
1430 device_types_str = pa_join(info->device_types, info->n_device_types, ", ");
1432 device_types_str = pa_xstrdup(_("(none)"));
1434 if (info->volume_control != PA_INVALID_INDEX)
1435 volume_control_str = pa_sprintf_malloc("%u", info->volume_control);
1437 volume_control_str = pa_xstrdup(_("(unset)"));
1439 if (info->mute_control != PA_INVALID_INDEX)
1440 mute_control_str = pa_sprintf_malloc("%u", info->mute_control);
1442 mute_control_str = pa_xstrdup(_("(unset)"));
1444 if (short_list_format) {
1445 printf("%u\t%s\t%s\t%s\t%s\t%s\n", info->index, info->name, pa_direction_to_string(info->direction), device_types_str,
1446 volume_control_str, mute_control_str);
1447 pa_xfree(mute_control_str);
1448 pa_xfree(volume_control_str);
1449 pa_xfree(device_types_str);
1453 proplist_str = pa_proplist_to_string_sep(info->proplist, "\n\t\t");
1455 printf(_("Device #%u\n"
1457 "\tDescription: %s\n"
1459 "\tDevice Types: %s\n"
1460 "\tVolume Control: %s\n"
1461 "\tMute Control: %s\n"
1462 "\tProperties: %s%s\n"),
1466 pa_direction_to_string(info->direction),
1470 *proplist_str ? "\n\t\t" : _("(none)"),
1473 pa_xfree(proplist_str);
1474 pa_xfree(mute_control_str);
1475 pa_xfree(volume_control_str);
1476 pa_xfree(device_types_str);
1479 static void get_stream_info_callback(pa_context *c, const pa_ext_volume_api_stream_info *info, int is_last,
1481 char *volume_control_str;
1482 char *mute_control_str;
1488 pa_log(_("Failed to get stream information: %s"), pa_strerror(pa_context_errno(c)));
1500 if (nl && !short_list_format)
1504 if (info->volume_control != PA_INVALID_INDEX)
1505 volume_control_str = pa_sprintf_malloc("%u", info->volume_control);
1507 volume_control_str = pa_xstrdup(_("(unset)"));
1509 if (info->mute_control != PA_INVALID_INDEX)
1510 mute_control_str = pa_sprintf_malloc("%u", info->mute_control);
1512 mute_control_str = pa_xstrdup(_("(unset)"));
1514 if (short_list_format) {
1515 printf("%u\t%s\t%s\t%s\t%s\n", info->index, info->name, pa_direction_to_string(info->direction), volume_control_str,
1517 pa_xfree(mute_control_str);
1518 pa_xfree(volume_control_str);
1522 proplist_str = pa_proplist_to_string_sep(info->proplist, "\n\t\t");
1524 printf(_("Stream #%u\n"
1526 "\tDescription: %s\n"
1528 "\tVolume Control: %s\n"
1529 "\tMute Control: %s\n"
1530 "\tProperties: %s%s\n"),
1534 pa_direction_to_string(info->direction),
1537 *proplist_str ? "\n\t\t" : _("(none)"),
1540 pa_xfree(proplist_str);
1541 pa_xfree(mute_control_str);
1542 pa_xfree(volume_control_str);
1545 static void get_audio_group_info_callback(pa_context *c, const pa_ext_volume_api_audio_group_info *info, int is_last,
1547 char *volume_control_str;
1548 char *mute_control_str;
1554 pa_log(_("Failed to get audio group information: %s"), pa_strerror(pa_context_errno(c)));
1566 if (nl && !short_list_format)
1570 if (info->volume_control != PA_INVALID_INDEX)
1571 volume_control_str = pa_sprintf_malloc("%u", info->volume_control);
1573 volume_control_str = pa_xstrdup(_("(unset)"));
1575 if (info->mute_control != PA_INVALID_INDEX)
1576 mute_control_str = pa_sprintf_malloc("%u", info->mute_control);
1578 mute_control_str = pa_xstrdup(_("(unset)"));
1580 if (short_list_format) {
1581 printf("%u\t%s\t%s\t%s\n", info->index, info->name, volume_control_str, mute_control_str);
1582 pa_xfree(mute_control_str);
1583 pa_xfree(volume_control_str);
1587 proplist_str = pa_proplist_to_string_sep(info->proplist, "\n\t\t");
1589 printf(_("Audio Group #%u\n"
1591 "\tDescription: %s\n"
1592 "\tVolume Control: %s\n"
1593 "\tMute Control: %s\n"
1594 "\tProperties: %s%s\n"),
1600 *proplist_str ? "\n\t\t" : _("(none)"),
1603 pa_xfree(proplist_str);
1604 pa_xfree(mute_control_str);
1605 pa_xfree(volume_control_str);
1608 static const char *volume_api_subscription_event_facility_to_string(pa_ext_volume_api_subscription_event_type_t type) {
1610 switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
1611 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_SERVER:
1612 return _("server (volume API)");
1614 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_VOLUME_CONTROL:
1615 return _("volume-control");
1617 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_MUTE_CONTROL:
1618 return _("mute-control");
1620 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_DEVICE:
1623 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_STREAM:
1626 case PA_EXT_VOLUME_API_SUBSCRIPTION_EVENT_AUDIO_GROUP:
1627 return _("audio-group");
1630 return _("unknown");
1633 static void volume_api_subscribe_cb(pa_context *c, pa_ext_volume_api_subscription_event_type_t event_type, uint32_t idx,
1637 printf(_("Event '%s' on %s #%u\n"),
1638 subscription_event_type_to_string(event_type),
1639 volume_api_subscription_event_facility_to_string(event_type),
1644 static void volume_api_state_cb(pa_context *c, void *userdata) {
1645 pa_ext_volume_api_state_t state;
1649 state = pa_ext_volume_api_get_state(c);
1652 case PA_EXT_VOLUME_API_STATE_READY: {
1653 pa_operation *o = NULL;
1655 volume_api_connected = true;
1659 o = pa_ext_volume_api_get_server_info(c, volume_api_get_server_info_callback, NULL);
1665 o = pa_ext_volume_api_get_volume_control_info_list(c, get_volume_control_info_callback, NULL);
1666 pa_operation_unref(o);
1667 o = pa_ext_volume_api_get_mute_control_info_list(c, get_mute_control_info_callback, NULL);
1668 pa_operation_unref(o);
1669 o = pa_ext_volume_api_get_device_info_list(c, get_device_info_callback, NULL);
1670 pa_operation_unref(o);
1671 o = pa_ext_volume_api_get_stream_info_list(c, get_stream_info_callback, NULL);
1672 pa_operation_unref(o);
1673 o = pa_ext_volume_api_get_audio_group_info_list(c, get_audio_group_info_callback, NULL);
1674 pa_operation_unref(o);
1677 } else if (pa_streq(list_type, "volume-controls")) {
1678 o = pa_ext_volume_api_get_volume_control_info_list(c, get_volume_control_info_callback, NULL);
1680 } else if (pa_streq(list_type, "mute-controls")) {
1681 o = pa_ext_volume_api_get_mute_control_info_list(c, get_mute_control_info_callback, NULL);
1683 } else if (pa_streq(list_type, "devices")) {
1684 o = pa_ext_volume_api_get_device_info_list(c, get_device_info_callback, NULL);
1686 } else if (pa_streq(list_type, "streams")) {
1687 o = pa_ext_volume_api_get_stream_info_list(c, get_stream_info_callback, NULL);
1689 } else if (pa_streq(list_type, "audio-groups")) {
1690 o = pa_ext_volume_api_get_audio_group_info_list(c, get_audio_group_info_callback, NULL);
1695 case SET_VOLUME_CONTROL_VOLUME:
1696 if (!balance_valid && !(volume_flags & VOL_RELATIVE)) {
1697 pa_assert(volume_valid);
1698 o = pa_ext_volume_api_set_volume_control_volume_by_name(c, volume_control_name, &bvolume, true,
1699 false, simple_callback, NULL);
1701 o = pa_ext_volume_api_get_volume_control_info_by_name(c, volume_control_name,
1702 get_volume_control_info_callback, NULL);
1707 case SET_MUTE_CONTROL_MUTE:
1708 if (mute == TOGGLE_MUTE)
1709 o = pa_ext_volume_api_get_mute_control_info_by_name(c, mute_control_name,
1710 get_mute_control_info_callback, NULL);
1712 o = pa_ext_volume_api_set_mute_control_mute_by_name(c, mute_control_name, mute, simple_callback,
1719 pa_ext_volume_api_set_subscribe_callback(c, volume_api_subscribe_cb, NULL);
1720 o = pa_ext_volume_api_subscribe(c, PA_EXT_VOLUME_API_SUBSCRIPTION_MASK_ALL, NULL, NULL);
1728 pa_operation_unref(o);
1734 case PA_EXT_VOLUME_API_STATE_FAILED:
1735 pa_log("Volume API context failed: %s", pa_strerror(pa_context_errno(c)));
1737 /* If the main context failed too, let's not do anything, because
1738 * calling complete_action() would reset the context error code to
1739 * PA_ERR_BADSTATE, meaning that the original error code would be
1741 if (pa_context_get_state(c) == PA_CONTEXT_FAILED)
1744 if (action == INFO || (action == LIST && !list_type) || action == SUBSCRIBE) {
1745 /* In these cases we shouldn't exit with an error if the volume
1746 * API happens to be or become unavailable. If we haven't yet
1747 * connected to the volume API, then we need to complete the
1748 * "connect to volume API" action. */
1750 if (!volume_api_connected)
1762 static void connect_to_volume_api(void) {
1767 pa_ext_volume_api_set_state_callback(context, volume_api_state_cb, NULL);
1769 r = pa_ext_volume_api_connect(context);
1774 static void context_state_callback(pa_context *c, void *userdata) {
1775 pa_operation *o = NULL;
1779 switch (pa_context_get_state(c)) {
1780 case PA_CONTEXT_CONNECTING:
1781 case PA_CONTEXT_AUTHORIZING:
1782 case PA_CONTEXT_SETTING_NAME:
1785 case PA_CONTEXT_READY:
1788 o = pa_context_stat(c, stat_callback, NULL);
1789 if (short_list_format)
1793 pa_operation_unref(o);
1799 o = pa_context_get_server_info(c, get_server_info_callback, NULL);
1800 connect_to_volume_api();
1804 o = pa_context_play_sample(c, sample_name, sink_name, PA_VOLUME_NORM, simple_callback, NULL);
1808 o = pa_context_remove_sample(c, sample_name, simple_callback, NULL);
1812 sample_stream = pa_stream_new(c, sample_name, &sample_spec, NULL);
1813 pa_assert(sample_stream);
1815 pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
1816 pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
1817 pa_stream_connect_upload(sample_stream, sample_length);
1822 o = pa_context_exit_daemon(c, simple_callback, NULL);
1827 if (pa_streq(list_type, "modules"))
1828 o = pa_context_get_module_info_list(c, get_module_info_callback, NULL);
1829 else if (pa_streq(list_type, "sinks"))
1830 o = pa_context_get_sink_info_list(c, get_sink_info_callback, NULL);
1831 else if (pa_streq(list_type, "sources"))
1832 o = pa_context_get_source_info_list(c, get_source_info_callback, NULL);
1833 else if (pa_streq(list_type, "sink-inputs"))
1834 o = pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL);
1835 else if (pa_streq(list_type, "source-outputs"))
1836 o = pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL);
1837 else if (pa_streq(list_type, "clients"))
1838 o = pa_context_get_client_info_list(c, get_client_info_callback, NULL);
1839 else if (pa_streq(list_type, "samples"))
1840 o = pa_context_get_sample_info_list(c, get_sample_info_callback, NULL);
1841 else if (pa_streq(list_type, "cards"))
1842 o = pa_context_get_card_info_list(c, get_card_info_callback, NULL);
1843 else if (pa_streq(list_type, "nodes"))
1844 o = pa_ext_node_manager_read_nodes(c, node_list_callback, NULL);
1845 else if (pa_streq(list_type, "volume-controls")
1846 || pa_streq(list_type, "mute-controls")
1847 || pa_streq(list_type, "devices")
1848 || pa_streq(list_type, "streams")
1849 || pa_streq(list_type, "audio-groups")) {
1850 connect_to_volume_api();
1853 pa_assert_not_reached();
1855 o = pa_context_get_module_info_list(c, get_module_info_callback, NULL);
1857 pa_operation_unref(o);
1861 o = pa_context_get_sink_info_list(c, get_sink_info_callback, NULL);
1863 pa_operation_unref(o);
1867 o = pa_context_get_source_info_list(c, get_source_info_callback, NULL);
1869 pa_operation_unref(o);
1872 o = pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL);
1874 pa_operation_unref(o);
1878 o = pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL);
1880 pa_operation_unref(o);
1884 o = pa_context_get_client_info_list(c, get_client_info_callback, NULL);
1886 pa_operation_unref(o);
1890 o = pa_context_get_sample_info_list(c, get_sample_info_callback, NULL);
1892 pa_operation_unref(o);
1896 o = pa_context_get_card_info_list(c, get_card_info_callback, NULL);
1898 pa_operation_unref(o);
1902 connect_to_volume_api();
1907 case MOVE_SINK_INPUT:
1908 o = pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, NULL);
1911 case MOVE_SOURCE_OUTPUT:
1912 o = pa_context_move_source_output_by_name(c, source_output_idx, source_name, simple_callback, NULL);
1916 o = pa_context_load_module(c, module_name, module_args, index_callback, NULL);
1921 o = pa_context_get_module_info_list(c, unload_module_by_name_callback, NULL);
1923 o = pa_context_unload_module(c, module_index, simple_callback, NULL);
1928 o = pa_context_suspend_sink_by_name(c, sink_name, suspend, simple_callback, NULL);
1930 o = pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL);
1933 case SUSPEND_SOURCE:
1935 o = pa_context_suspend_source_by_name(c, source_name, suspend, simple_callback, NULL);
1937 o = pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL);
1940 case SET_CARD_PROFILE:
1941 o = pa_context_set_card_profile_by_name(c, card_name, profile_name, simple_callback, NULL);
1945 o = pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL);
1948 case SET_DEFAULT_SINK:
1949 o = pa_context_set_default_sink(c, sink_name, simple_callback, NULL);
1952 case SET_SOURCE_PORT:
1953 o = pa_context_set_source_port_by_name(c, source_name, port_name, simple_callback, NULL);
1956 case SET_DEFAULT_SOURCE:
1957 o = pa_context_set_default_source(c, source_name, simple_callback, NULL);
1961 if (mute == TOGGLE_MUTE)
1962 o = pa_context_get_sink_info_by_name(c, sink_name, sink_toggle_mute_callback, NULL);
1964 o = pa_context_set_sink_mute_by_name(c, sink_name, mute, simple_callback, NULL);
1967 case SET_SOURCE_MUTE:
1968 if (mute == TOGGLE_MUTE)
1969 o = pa_context_get_source_info_by_name(c, source_name, source_toggle_mute_callback, NULL);
1971 o = pa_context_set_source_mute_by_name(c, source_name, mute, simple_callback, NULL);
1974 case SET_SINK_INPUT_MUTE:
1975 if (mute == TOGGLE_MUTE)
1976 o = pa_context_get_sink_input_info(c, sink_input_idx, sink_input_toggle_mute_callback, NULL);
1978 o = pa_context_set_sink_input_mute(c, sink_input_idx, mute, simple_callback, NULL);
1981 case SET_SOURCE_OUTPUT_MUTE:
1982 if (mute == TOGGLE_MUTE)
1983 o = pa_context_get_source_output_info(c, source_output_idx, source_output_toggle_mute_callback, NULL);
1985 o = pa_context_set_source_output_mute(c, source_output_idx, mute, simple_callback, NULL);
1988 case SET_SINK_VOLUME:
1989 if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
1990 o = pa_context_get_sink_info_by_name(c, sink_name, get_sink_volume_callback, NULL);
1993 pa_cvolume_set(&v, 1, volume);
1994 o = pa_context_set_sink_volume_by_name(c, sink_name, &v, simple_callback, NULL);
1998 case SET_SOURCE_VOLUME:
1999 if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
2000 o = pa_context_get_source_info_by_name(c, source_name, get_source_volume_callback, NULL);
2003 pa_cvolume_set(&v, 1, volume);
2004 o = pa_context_set_source_volume_by_name(c, source_name, &v, simple_callback, NULL);
2008 case SET_SINK_INPUT_VOLUME:
2009 if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
2010 o = pa_context_get_sink_input_info(c, sink_input_idx, get_sink_input_volume_callback, NULL);
2013 pa_cvolume_set(&v, 1, volume);
2014 o = pa_context_set_sink_input_volume(c, sink_input_idx, &v, simple_callback, NULL);
2018 case SET_SOURCE_OUTPUT_VOLUME:
2019 if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
2020 o = pa_context_get_source_output_info(c, source_output_idx, get_source_output_volume_callback, NULL);
2023 pa_cvolume_set(&v, 1, volume);
2024 o = pa_context_set_source_output_volume(c, source_output_idx, &v, simple_callback, NULL);
2028 case SET_SINK_FORMATS:
2029 set_sink_formats(c, sink_idx, formats);
2032 case SET_PORT_LATENCY_OFFSET:
2033 o = pa_context_set_port_latency_offset(c, card_name, port_name, latency_offset, simple_callback, NULL);
2036 case SET_VOLUME_CONTROL_VOLUME:
2037 case SET_MUTE_CONTROL_MUTE:
2038 connect_to_volume_api();
2042 pa_context_set_subscribe_callback(c, context_subscribe_callback, NULL);
2044 o = pa_context_subscribe(c,
2045 PA_SUBSCRIPTION_MASK_SINK|
2046 PA_SUBSCRIPTION_MASK_SOURCE|
2047 PA_SUBSCRIPTION_MASK_SINK_INPUT|
2048 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
2049 PA_SUBSCRIPTION_MASK_MODULE|
2050 PA_SUBSCRIPTION_MASK_CLIENT|
2051 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE|
2052 PA_SUBSCRIPTION_MASK_SERVER|
2053 PA_SUBSCRIPTION_MASK_CARD,
2058 pa_operation_unref(o);
2063 connect_to_volume_api();
2067 pa_operation_unref(pa_ext_node_manager_connect_nodes(c,
2070 node_connect_callback,
2074 case NODE_DISCONNECT:
2075 pa_operation_unref(pa_ext_node_manager_disconnect_nodes(c, conn_id,
2081 pa_assert_not_reached();
2085 pa_operation_unref(o);
2090 pa_log("Operation failed: %s", pa_strerror(pa_context_errno(c)));
2096 case PA_CONTEXT_TERMINATED:
2100 case PA_CONTEXT_FAILED:
2102 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c)));
2107 static void exit_signal_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
2108 pa_log(_("Got SIGINT, exiting."));
2112 static int parse_volume(const char *vol_spec, pa_volume_t *vol, enum volume_flags *vol_flags) {
2116 pa_assert(vol_spec);
2118 pa_assert(vol_flags);
2120 vs = pa_xstrdup(vol_spec);
2122 *vol_flags = (pa_startswith(vs, "+") || pa_startswith(vs, "-")) ? VOL_RELATIVE : VOL_ABSOLUTE;
2123 if (strchr(vs, '.'))
2124 *vol_flags |= VOL_LINEAR;
2125 if (pa_endswith(vs, "%")) {
2126 *vol_flags |= VOL_PERCENT;
2127 vs[strlen(vs)-1] = 0;
2129 if (pa_endswith(vs, "db") || pa_endswith(vs, "dB")) {
2130 *vol_flags |= VOL_DECIBEL;
2131 vs[strlen(vs)-2] = 0;
2134 if (pa_atod(vs, &v) < 0) {
2135 pa_log(_("Invalid volume specification"));
2142 if ((*vol_flags & VOL_RELATIVE) == VOL_RELATIVE) {
2143 if ((*vol_flags & 0x0F) == VOL_UINT)
2144 v += (double) PA_VOLUME_NORM;
2145 if ((*vol_flags & 0x0F) == VOL_PERCENT)
2147 if ((*vol_flags & 0x0F) == VOL_LINEAR)
2150 if ((*vol_flags & 0x0F) == VOL_PERCENT)
2151 v = v * (double) PA_VOLUME_NORM / 100;
2152 if ((*vol_flags & 0x0F) == VOL_LINEAR)
2153 v = pa_sw_volume_from_linear(v);
2154 if ((*vol_flags & 0x0F) == VOL_DECIBEL)
2155 v = pa_sw_volume_from_dB(v);
2157 if (!PA_VOLUME_IS_VALID((pa_volume_t) v)) {
2158 pa_log(_("Volume outside permissible range.\n"));
2162 *vol = (pa_volume_t) v;
2167 static enum mute_flags parse_mute(const char *mute_text) {
2170 pa_assert(mute_text);
2172 if (pa_streq("toggle", mute_text))
2175 b = pa_parse_boolean(mute_text);
2182 return INVALID_MUTE;
2186 static void help(const char *argv0) {
2188 printf("%s %s %s\n", argv0, _("[options]"), "stat [short]");
2189 printf("%s %s %s\n", argv0, _("[options]"), "info");
2190 printf("%s %s %s %s\n", argv0, _("[options]"), "list [short]", _("[TYPE]"));
2191 printf("%s %s %s\n", argv0, _("[options]"), "exit");
2192 printf("%s %s %s %s\n", argv0, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
2193 printf("%s %s %s %s\n", argv0, _("[options]"), "play-sample ", _("NAME [SINK]"));
2194 printf("%s %s %s %s\n", argv0, _("[options]"), "remove-sample ", _("NAME"));
2195 printf("%s %s %s %s\n", argv0, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
2196 printf("%s %s %s %s\n", argv0, _("[options]"), "unload-module ", _("NAME|#N"));
2197 printf("%s %s %s %s\n", argv0, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
2198 printf("%s %s %s %s\n", argv0, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
2199 printf("%s %s %s %s\n", argv0, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
2200 printf("%s %s %s %s\n", argv0, _("[options]"), "set-default-(sink|source)", _("NAME"));
2201 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
2202 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
2203 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
2204 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0|toggle"));
2205 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0|toggle"));
2206 printf("%s %s %s %s\n", argv0, _("[options]"), "set-sink-formats", _("#N FORMATS"));
2207 printf("%s %s %s %s\n", argv0, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
2208 printf("%s %s %s %s\n", argv0, _("[options]"), "set-volume-control-volume", _("NAME|#N VOLUME [BALANCE ...]"));
2209 printf("%s %s %s %s\n", argv0, _("[options]"), "set-volume-control-balance", _("NAME|#N BALANCE ..."));
2210 printf("%s %s %s %s\n", argv0, _("[options]"), "set-mute-control-mute", _("NAME|#N 1|0|toggle"));
2211 printf("%s %s %s\n", argv0, _("[options]"), "subscribe");
2212 printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
2213 "can be used to specify the default sink, source and monitor.\n"));
2214 printf("%s %s %s\n", argv0, _("[options]"), "node-list ");
2215 printf("%s %s %s %s %s\n", argv0, _("[options]"), "node-connect ", _("#N"), _("#N"));
2216 printf("%s %s %s %s\n", argv0, _("[options]"), "node-disconnect ", _("#N"));
2219 " -h, --help Show this help\n"
2220 " --version Show version\n\n"
2221 " -s, --server=SERVER The name of the server to connect to\n"
2222 " -n, --client-name=NAME How to call this client on the server\n"));
2225 static int parse_balance(char *argv[], unsigned first_arg, unsigned n_channels, pa_ext_volume_api_bvolume *bv) {
2226 pa_ext_volume_api_bvolume bv_local;
2229 pa_assert(n_channels > 0);
2232 if (n_channels > PA_CHANNELS_MAX) {
2233 pa_log("Too many channels, the maximum is %u.", PA_CHANNELS_MAX);
2239 for (i = 0; i < n_channels; i++) {
2240 const char *balance_str;
2243 balance_str = argv[first_arg + i];
2245 if (pa_atod(balance_str, &balance) < 0 || !pa_ext_volume_api_balance_valid(balance)) {
2246 pa_log(_("Invalid balance value: %s"), balance_str);
2250 bv_local.balance[i] = balance;
2253 bv_local.channel_map.channels = n_channels;
2263 int main(int argc, char *argv[]) {
2264 pa_mainloop *m = NULL;
2266 char *server = NULL, *bn;
2268 static const struct option long_options[] = {
2269 {"server", 1, NULL, 's'},
2270 {"client-name", 1, NULL, 'n'},
2271 {"version", 0, NULL, ARG_VERSION},
2272 {"help", 0, NULL, 'h'},
2276 setlocale(LC_ALL, "");
2278 bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
2281 bn = pa_path_get_filename(argv[0]);
2283 proplist = pa_proplist_new();
2285 while ((c = getopt_long(argc, argv, "s:n:h", long_options, NULL)) != -1) {
2293 printf(_("pactl %s\n"
2294 "Compiled with libpulse %s\n"
2295 "Linked with libpulse %s\n"),
2297 pa_get_headers_version(),
2298 pa_get_library_version());
2304 server = pa_xstrdup(optarg);
2310 if (!(t = pa_locale_to_utf8(optarg)) ||
2311 pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, t) < 0) {
2313 pa_log(_("Invalid client name '%s'"), t ? t : optarg);
2327 if (optind < argc) {
2328 if (pa_streq(argv[optind], "stat")) {
2330 short_list_format = false;
2331 if (optind+1 < argc && pa_streq(argv[optind+1], "short"))
2332 short_list_format = true;
2334 } else if (pa_streq(argv[optind], "info"))
2337 else if (pa_streq(argv[optind], "exit"))
2340 else if (pa_streq(argv[optind], "list")) {
2343 for (int i = optind+1; i < argc; i++) {
2344 if (pa_streq(argv[i], "modules") || pa_streq(argv[i], "clients") ||
2345 pa_streq(argv[i], "sinks") || pa_streq(argv[i], "sink-inputs") ||
2346 pa_streq(argv[i], "sources") || pa_streq(argv[i], "source-outputs") ||
2347 pa_streq(argv[i], "samples") || pa_streq(argv[i], "cards") || pa_streq(argv[i], "nodes") ||
2348 pa_streq(argv[i], "volume-controls") || pa_streq(argv[i], "mute-controls") ||
2349 pa_streq(argv[i], "devices") || pa_streq(argv[i], "streams") ||
2350 pa_streq(argv[i], "audio-groups")) {
2351 list_type = pa_xstrdup(argv[i]);
2352 } else if (pa_streq(argv[i], "short")) {
2353 short_list_format = true;
2355 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, "
2356 "clients, samples, cards, volume-controls, mute-controls, devices, streams, audio-groups");
2361 } else if (pa_streq(argv[optind], "upload-sample")) {
2363 action = UPLOAD_SAMPLE;
2365 if (optind+1 >= argc) {
2366 pa_log(_("Please specify a sample file to load"));
2370 if (optind+2 < argc)
2371 sample_name = pa_xstrdup(argv[optind+2]);
2373 char *f = pa_path_get_filename(argv[optind+1]);
2374 sample_name = pa_xstrndup(f, strcspn(f, "."));
2378 if (!(sndfile = sf_open(argv[optind+1], SFM_READ, &sfi))) {
2379 pa_log(_("Failed to open sound file."));
2383 if (pa_sndfile_read_sample_spec(sndfile, &sample_spec) < 0) {
2384 pa_log(_("Failed to determine sample specification from file."));
2387 sample_spec.format = PA_SAMPLE_FLOAT32;
2389 if (pa_sndfile_read_channel_map(sndfile, &channel_map) < 0) {
2390 if (sample_spec.channels > 2)
2391 pa_log(_("Warning: Failed to determine sample specification from file."));
2392 pa_channel_map_init_extend(&channel_map, sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
2395 pa_assert(pa_channel_map_compatible(&channel_map, &sample_spec));
2396 sample_length = (size_t) sfi.frames*pa_frame_size(&sample_spec);
2398 } else if (pa_streq(argv[optind], "play-sample")) {
2399 action = PLAY_SAMPLE;
2400 if (argc != optind+2 && argc != optind+3) {
2401 pa_log(_("You have to specify a sample name to play"));
2405 sample_name = pa_xstrdup(argv[optind+1]);
2407 if (optind+2 < argc)
2408 sink_name = pa_xstrdup(argv[optind+2]);
2410 } else if (pa_streq(argv[optind], "remove-sample")) {
2411 action = REMOVE_SAMPLE;
2412 if (argc != optind+2) {
2413 pa_log(_("You have to specify a sample name to remove"));
2417 sample_name = pa_xstrdup(argv[optind+1]);
2419 } else if (pa_streq(argv[optind], "move-sink-input")) {
2420 action = MOVE_SINK_INPUT;
2421 if (argc != optind+3) {
2422 pa_log(_("You have to specify a sink input index and a sink"));
2426 sink_input_idx = (uint32_t) atoi(argv[optind+1]);
2427 sink_name = pa_xstrdup(argv[optind+2]);
2429 } else if (pa_streq(argv[optind], "move-source-output")) {
2430 action = MOVE_SOURCE_OUTPUT;
2431 if (argc != optind+3) {
2432 pa_log(_("You have to specify a source output index and a source"));
2436 source_output_idx = (uint32_t) atoi(argv[optind+1]);
2437 source_name = pa_xstrdup(argv[optind+2]);
2439 } else if (pa_streq(argv[optind], "load-module")) {
2444 action = LOAD_MODULE;
2446 if (argc <= optind+1) {
2447 pa_log(_("You have to specify a module name and arguments."));
2451 module_name = argv[optind+1];
2453 for (i = optind+2; i < argc; i++)
2454 n += strlen(argv[i])+1;
2457 p = module_args = pa_xmalloc(n);
2459 for (i = optind+2; i < argc; i++)
2460 p += sprintf(p, "%s%s", p == module_args ? "" : " ", argv[i]);
2463 } else if (pa_streq(argv[optind], "unload-module")) {
2464 action = UNLOAD_MODULE;
2466 if (argc != optind+2) {
2467 pa_log(_("You have to specify a module index or name"));
2471 if (pa_atou(argv[optind + 1], &module_index) < 0)
2472 module_name = argv[optind + 1];
2474 } else if (pa_streq(argv[optind], "suspend-sink")) {
2477 action = SUSPEND_SINK;
2479 if (argc > optind+3 || optind+1 >= argc) {
2480 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
2484 if ((b = pa_parse_boolean(argv[argc-1])) < 0) {
2485 pa_log(_("Invalid suspend specification."));
2491 if (argc > optind+2)
2492 sink_name = pa_xstrdup(argv[optind+1]);
2494 } else if (pa_streq(argv[optind], "suspend-source")) {
2497 action = SUSPEND_SOURCE;
2499 if (argc > optind+3 || optind+1 >= argc) {
2500 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
2504 if ((b = pa_parse_boolean(argv[argc-1])) < 0) {
2505 pa_log(_("Invalid suspend specification."));
2511 if (argc > optind+2)
2512 source_name = pa_xstrdup(argv[optind+1]);
2513 } else if (pa_streq(argv[optind], "set-card-profile")) {
2514 action = SET_CARD_PROFILE;
2516 if (argc != optind+3) {
2517 pa_log(_("You have to specify a card name/index and a profile name"));
2521 card_name = pa_xstrdup(argv[optind+1]);
2522 profile_name = pa_xstrdup(argv[optind+2]);
2524 } else if (pa_streq(argv[optind], "set-sink-port")) {
2525 action = SET_SINK_PORT;
2527 if (argc != optind+3) {
2528 pa_log(_("You have to specify a sink name/index and a port name"));
2532 sink_name = pa_xstrdup(argv[optind+1]);
2533 port_name = pa_xstrdup(argv[optind+2]);
2535 } else if (pa_streq(argv[optind], "set-default-sink")) {
2536 action = SET_DEFAULT_SINK;
2538 if (argc != optind+2) {
2539 pa_log(_("You have to specify a sink name"));
2543 sink_name = pa_xstrdup(argv[optind+1]);
2545 } else if (pa_streq(argv[optind], "set-source-port")) {
2546 action = SET_SOURCE_PORT;
2548 if (argc != optind+3) {
2549 pa_log(_("You have to specify a source name/index and a port name"));
2553 source_name = pa_xstrdup(argv[optind+1]);
2554 port_name = pa_xstrdup(argv[optind+2]);
2556 } else if (pa_streq(argv[optind], "set-default-source")) {
2557 action = SET_DEFAULT_SOURCE;
2559 if (argc != optind+2) {
2560 pa_log(_("You have to specify a source name"));
2564 source_name = pa_xstrdup(argv[optind+1]);
2566 } else if (pa_streq(argv[optind], "set-sink-volume")) {
2567 action = SET_SINK_VOLUME;
2569 if (argc != optind+3) {
2570 pa_log(_("You have to specify a sink name/index and a volume"));
2574 sink_name = pa_xstrdup(argv[optind+1]);
2576 if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
2579 } else if (pa_streq(argv[optind], "set-source-volume")) {
2580 action = SET_SOURCE_VOLUME;
2582 if (argc != optind+3) {
2583 pa_log(_("You have to specify a source name/index and a volume"));
2587 source_name = pa_xstrdup(argv[optind+1]);
2589 if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
2592 } else if (pa_streq(argv[optind], "set-sink-input-volume")) {
2593 action = SET_SINK_INPUT_VOLUME;
2595 if (argc != optind+3) {
2596 pa_log(_("You have to specify a sink input index and a volume"));
2600 if (pa_atou(argv[optind+1], &sink_input_idx) < 0) {
2601 pa_log(_("Invalid sink input index"));
2605 if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
2608 } else if (pa_streq(argv[optind], "set-source-output-volume")) {
2609 action = SET_SOURCE_OUTPUT_VOLUME;
2611 if (argc != optind+3) {
2612 pa_log(_("You have to specify a source output index and a volume"));
2616 if (pa_atou(argv[optind+1], &source_output_idx) < 0) {
2617 pa_log(_("Invalid source output index"));
2621 if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
2624 } else if (pa_streq(argv[optind], "set-sink-mute")) {
2625 action = SET_SINK_MUTE;
2627 if (argc != optind+3) {
2628 pa_log(_("You have to specify a sink name/index and a mute boolean"));
2632 if ((mute = parse_mute(argv[optind+2])) == INVALID_MUTE) {
2633 pa_log(_("Invalid mute specification"));
2637 sink_name = pa_xstrdup(argv[optind+1]);
2639 } else if (pa_streq(argv[optind], "set-source-mute")) {
2640 action = SET_SOURCE_MUTE;
2642 if (argc != optind+3) {
2643 pa_log(_("You have to specify a source name/index and a mute boolean"));
2647 if ((mute = parse_mute(argv[optind+2])) == INVALID_MUTE) {
2648 pa_log(_("Invalid mute specification"));
2652 source_name = pa_xstrdup(argv[optind+1]);
2654 } else if (pa_streq(argv[optind], "set-sink-input-mute")) {
2655 action = SET_SINK_INPUT_MUTE;
2657 if (argc != optind+3) {
2658 pa_log(_("You have to specify a sink input index and a mute boolean"));
2662 if (pa_atou(argv[optind+1], &sink_input_idx) < 0) {
2663 pa_log(_("Invalid sink input index specification"));
2667 if ((mute = parse_mute(argv[optind+2])) == INVALID_MUTE) {
2668 pa_log(_("Invalid mute specification"));
2672 } else if (pa_streq(argv[optind], "set-source-output-mute")) {
2673 action = SET_SOURCE_OUTPUT_MUTE;
2675 if (argc != optind+3) {
2676 pa_log(_("You have to specify a source output index and a mute boolean"));
2680 if (pa_atou(argv[optind+1], &source_output_idx) < 0) {
2681 pa_log(_("Invalid source output index specification"));
2685 if ((mute = parse_mute(argv[optind+2])) == INVALID_MUTE) {
2686 pa_log(_("Invalid mute specification"));
2690 } else if (pa_streq(argv[optind], "subscribe"))
2694 else if (pa_streq(argv[optind], "set-sink-formats")) {
2697 if (argc != optind+3 || pa_atoi(argv[optind+1], &tmp) < 0) {
2698 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
2703 action = SET_SINK_FORMATS;
2704 formats = pa_xstrdup(argv[optind+2]);
2706 } else if (pa_streq(argv[optind], "set-port-latency-offset")) {
2707 action = SET_PORT_LATENCY_OFFSET;
2709 if (argc != optind+4) {
2710 pa_log(_("You have to specify a card name/index, a port name and a latency offset"));
2714 card_name = pa_xstrdup(argv[optind+1]);
2715 port_name = pa_xstrdup(argv[optind+2]);
2716 if (pa_atoi(argv[optind + 3], &latency_offset) < 0) {
2717 pa_log(_("Could not parse latency offset"));
2721 } else if (pa_streq(argv[optind], "node-connect")) {
2722 action = NODE_CONNECT;
2724 if (argc != optind+3) {
2725 pa_log(_("You have to specify a source and destination node indexes"));
2729 src_node_id = (uint32_t) atoi(argv[optind+1]);
2730 dst_node_id = (uint32_t) atoi(argv[optind+2]);
2732 } else if (pa_streq(argv[optind], "node-disconnect")) {
2733 action = NODE_DISCONNECT;
2735 if (argc != optind+2) {
2736 pa_log(_("You have to specify a connection id"));
2740 conn_id = (uint32_t) atoi(argv[optind+1]);
2742 } else if (pa_streq(argv[optind], "set-volume-control-volume")) {
2743 action = SET_VOLUME_CONTROL_VOLUME;
2745 if (argc < optind + 3) {
2746 pa_log(_("You have to specify a volume control name/index and a volume, and optionally balance parameters."));
2750 volume_control_name = pa_xstrdup(argv[optind + 1]);
2752 if (parse_volume(argv[optind + 2], &bvolume.volume, &volume_flags) < 0)
2755 volume_valid = true;
2757 if (argc > optind + 3) {
2758 if (parse_balance(argv, optind + 3, argc - (optind + 3), &bvolume) < 0)
2761 balance_valid = true;
2764 } else if (pa_streq(argv[optind], "set-volume-control-balance")) {
2765 action = SET_VOLUME_CONTROL_VOLUME;
2767 if (argc < optind + 3) {
2768 pa_log(_("You have to specify a volume control name/index and balance parameters."));
2772 volume_control_name = pa_xstrdup(argv[optind + 1]);
2774 if (parse_balance(argv, optind + 2, argc - (optind + 2), &bvolume) < 0)
2777 balance_valid = true;
2779 } else if (pa_streq(argv[optind], "set-mute-control-mute")) {
2780 action = SET_MUTE_CONTROL_MUTE;
2782 if (argc != optind + 3) {
2783 pa_log(_("You have to specify a mute control name/index and a mute value."));
2787 mute_control_name = pa_xstrdup(argv[optind + 1]);
2789 if ((mute = parse_mute(argv[optind + 2])) == INVALID_MUTE) {
2790 pa_log(_("Invalid mute specification"));
2794 } else if (pa_streq(argv[optind], "help")) {
2801 if (action == NONE) {
2802 pa_log(_("No valid command specified."));
2806 if (!(m = pa_mainloop_new())) {
2807 pa_log(_("pa_mainloop_new() failed."));
2811 mainloop_api = pa_mainloop_get_api(m);
2813 pa_assert_se(pa_signal_init(mainloop_api) == 0);
2814 pa_signal_new(SIGINT, exit_signal_callback, NULL);
2815 pa_signal_new(SIGTERM, exit_signal_callback, NULL);
2816 pa_disable_sigpipe();
2818 if (!(context = pa_context_new_with_proplist(mainloop_api, NULL, proplist))) {
2819 pa_log(_("pa_context_new() failed."));
2823 pa_context_set_state_callback(context, context_state_callback, NULL);
2824 if (pa_context_connect(context, server, 0, NULL) < 0) {
2825 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context)));
2829 if (pa_mainloop_run(m, &ret) < 0) {
2830 pa_log(_("pa_mainloop_run() failed."));
2836 pa_stream_unref(sample_stream);
2839 pa_context_unref(context);
2843 pa_mainloop_free(m);
2847 pa_xfree(list_type);
2848 pa_xfree(sample_name);
2849 pa_xfree(sink_name);
2850 pa_xfree(source_name);
2851 pa_xfree(module_args);
2852 pa_xfree(card_name);
2853 pa_xfree(profile_name);
2854 pa_xfree(port_name);
2856 pa_xfree(mute_control_name);
2857 pa_xfree(volume_control_name);
2863 pa_proplist_free(proplist);