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/i18n.h>
40 #include <pulse/pulseaudio.h>
42 #include <pulsecore/macro.h>
43 #include <pulsecore/core-util.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/sndfile-util.h>
47 #define BUFSIZE (16*1024)
49 static pa_context *context = NULL;
50 static pa_mainloop_api *mainloop_api = NULL;
52 static char *device = NULL, *sample_name = NULL, *sink_name = NULL, *source_name = NULL, *module_name = NULL, *module_args = NULL, *card_name = NULL, *profile_name = NULL;
53 static uint32_t sink_input_idx = PA_INVALID_INDEX, source_output_idx = PA_INVALID_INDEX;
54 static uint32_t module_index;
55 static pa_bool_t suspend;
57 static pa_proplist *proplist = NULL;
59 static SNDFILE *sndfile = NULL;
60 static pa_stream *sample_stream = NULL;
61 static pa_sample_spec sample_spec;
62 static pa_channel_map channel_map;
63 static size_t sample_length = 0;
65 static int actions = 1;
67 static pa_bool_t nl = FALSE;
86 static void quit(int ret) {
87 pa_assert(mainloop_api);
88 mainloop_api->quit(mainloop_api, ret);
91 static void context_drain_complete(pa_context *c, void *userdata) {
92 pa_context_disconnect(c);
95 static void drain(void) {
97 if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
98 pa_context_disconnect(context);
100 pa_operation_unref(o);
103 static void complete_action(void) {
104 pa_assert(actions > 0);
110 static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata) {
113 pa_log(_("Failed to get statistics: %s\n"), pa_strerror(pa_context_errno(c)));
118 pa_bytes_snprint(s, sizeof(s), i->memblock_total_size);
119 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i->memblock_total, s);
121 pa_bytes_snprint(s, sizeof(s), i->memblock_allocated_size);
122 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i->memblock_allocated, s);
124 pa_bytes_snprint(s, sizeof(s), i->scache_size);
125 printf(_("Sample cache size: %s\n"), s);
130 static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
131 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
134 pa_log(_("Failed to get server information: %s\n"), pa_strerror(pa_context_errno(c)));
139 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
140 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map);
142 printf(_("User name: %s\n"
145 "Server Version: %s\n"
146 "Default Sample Specification: %s\n"
147 "Default Channel Map: %s\n"
149 "Default Source: %s\n"
157 i->default_sink_name,
158 i->default_source_name,
164 static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
166 static const char *state_table[] = {
167 [1+PA_SINK_INVALID_STATE] = "n/a",
168 [1+PA_SINK_RUNNING] = "RUNNING",
169 [1+PA_SINK_IDLE] = "IDLE",
170 [1+PA_SINK_SUSPENDED] = "SUSPENDED"
174 s[PA_SAMPLE_SPEC_SNPRINT_MAX],
175 cv[PA_CVOLUME_SNPRINT_MAX],
176 cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
177 v[PA_VOLUME_SNPRINT_MAX],
178 vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
179 cm[PA_CHANNEL_MAP_SNPRINT_MAX];
183 pa_log(_("Failed to get sink information: %s\n"), pa_strerror(pa_context_errno(c)));
199 printf(_("Sink #%u\n"
202 "\tDescription: %s\n"
204 "\tSample Specification: %s\n"
205 "\tChannel Map: %s\n"
206 "\tOwner Module: %u\n"
210 "\tBase Volume: %s%s%s\n"
211 "\tMonitor Source: %s\n"
212 "\tLatency: %0.0f usec, configured %0.0f usec\n"
213 "\tFlags: %s%s%s%s%s%s\n"
214 "\tProperties:\n\t\t%s\n"),
216 state_table[1+i->state],
218 pa_strnull(i->description),
219 pa_strnull(i->driver),
220 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
221 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
224 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
225 i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
226 i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
227 pa_cvolume_get_balance(&i->volume, &i->channel_map),
228 pa_volume_snprint(v, sizeof(v), i->base_volume),
229 i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
230 i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
231 pa_strnull(i->monitor_source_name),
232 (double) i->latency, (double) i->configured_latency,
233 i->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
234 i->flags & PA_SINK_NETWORK ? "NETWORK " : "",
235 i->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
236 i->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
237 i->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
238 i->flags & PA_SINK_LATENCY ? "LATENCY " : "",
239 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
244 static void get_source_info_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
246 static const char *state_table[] = {
247 [1+PA_SOURCE_INVALID_STATE] = "n/a",
248 [1+PA_SOURCE_RUNNING] = "RUNNING",
249 [1+PA_SOURCE_IDLE] = "IDLE",
250 [1+PA_SOURCE_SUSPENDED] = "SUSPENDED"
254 s[PA_SAMPLE_SPEC_SNPRINT_MAX],
255 cv[PA_CVOLUME_SNPRINT_MAX],
256 cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
257 v[PA_VOLUME_SNPRINT_MAX],
258 vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
259 cm[PA_CHANNEL_MAP_SNPRINT_MAX];
263 pa_log(_("Failed to get source information: %s\n"), pa_strerror(pa_context_errno(c)));
279 printf(_("Source #%u\n"
282 "\tDescription: %s\n"
284 "\tSample Specification: %s\n"
285 "\tChannel Map: %s\n"
286 "\tOwner Module: %u\n"
290 "\tBase Volume: %s%s%s\n"
291 "\tMonitor of Sink: %s\n"
292 "\tLatency: %0.0f usec, configured %0.0f usec\n"
293 "\tFlags: %s%s%s%s%s%s\n"
294 "\tProperties:\n\t\t%s\n"),
296 state_table[1+i->state],
298 pa_strnull(i->description),
299 pa_strnull(i->driver),
300 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
301 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
304 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
305 i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
306 i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
307 pa_cvolume_get_balance(&i->volume, &i->channel_map),
308 pa_volume_snprint(v, sizeof(v), i->base_volume),
309 i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
310 i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
311 i->monitor_of_sink_name ? i->monitor_of_sink_name : _("n/a"),
312 (double) i->latency, (double) i->configured_latency,
313 i->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
314 i->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
315 i->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
316 i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
317 i->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
318 i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
319 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
324 static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
329 pa_log(_("Failed to get module information: %s\n"), pa_strerror(pa_context_errno(c)));
345 pa_snprintf(t, sizeof(t), "%u", i->n_used);
347 printf(_("Module #%u\n"
350 "\tUsage counter: %s\n"
351 "\tProperties:\n\t\t%s\n"),
354 i->argument ? i->argument : "",
355 i->n_used != PA_INVALID_INDEX ? t : _("n/a"),
356 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
361 static void get_client_info_callback(pa_context *c, const pa_client_info *i, int is_last, void *userdata) {
366 pa_log(_("Failed to get client information: %s\n"), pa_strerror(pa_context_errno(c)));
382 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
384 printf(_("Client #%u\n"
386 "\tOwner Module: %s\n"
387 "\tProperties:\n\t\t%s\n"),
389 pa_strnull(i->driver),
390 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
391 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
396 static void get_card_info_callback(pa_context *c, const pa_card_info *i, int is_last, void *userdata) {
401 pa_log(_("Failed to get card information: %s\n"), pa_strerror(pa_context_errno(c)));
417 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
419 printf(_("Card #%u\n"
422 "\tOwner Module: %s\n"
423 "\tProperties:\n\t\t%s\n"),
426 pa_strnull(i->driver),
427 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
428 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
431 pa_card_profile_info *p;
433 printf(_("\tProfiles:\n"));
434 for (p = i->profiles; p->name; p++)
435 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p->name, p->description, p->n_sinks, p->n_sources, p->priority);
438 if (i->active_profile)
439 printf(_("\tActive Profile: %s\n"),
440 i->active_profile->name);
445 static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
446 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
450 pa_log(_("Failed to get sink input information: %s\n"), pa_strerror(pa_context_errno(c)));
466 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
467 pa_snprintf(k, sizeof(k), "%u", i->client);
469 printf(_("Sink Input #%u\n"
471 "\tOwner Module: %s\n"
474 "\tSample Specification: %s\n"
475 "\tChannel Map: %s\n"
480 "\tBuffer Latency: %0.0f usec\n"
481 "\tSink Latency: %0.0f usec\n"
482 "\tResample method: %s\n"
483 "\tProperties:\n\t\t%s\n"),
485 pa_strnull(i->driver),
486 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
487 i->client != PA_INVALID_INDEX ? k : _("n/a"),
489 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
490 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
492 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
493 pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
494 pa_cvolume_get_balance(&i->volume, &i->channel_map),
495 (double) i->buffer_usec,
496 (double) i->sink_usec,
497 i->resample_method ? i->resample_method : _("n/a"),
498 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
503 static void get_source_output_info_callback(pa_context *c, const pa_source_output_info *i, int is_last, void *userdata) {
504 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
508 pa_log(_("Failed to get source output information: %s\n"), pa_strerror(pa_context_errno(c)));
525 pa_snprintf(t, sizeof(t), "%u", i->owner_module);
526 pa_snprintf(k, sizeof(k), "%u", i->client);
528 printf(_("Source Output #%u\n"
530 "\tOwner Module: %s\n"
533 "\tSample Specification: %s\n"
534 "\tChannel Map: %s\n"
535 "\tBuffer Latency: %0.0f usec\n"
536 "\tSource Latency: %0.0f usec\n"
537 "\tResample method: %s\n"
538 "\tProperties:\n\t\t%s\n"),
540 pa_strnull(i->driver),
541 i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
542 i->client != PA_INVALID_INDEX ? k : _("n/a"),
544 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
545 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
546 (double) i->buffer_usec,
547 (double) i->source_usec,
548 i->resample_method ? i->resample_method : _("n/a"),
549 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
554 static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) {
555 char t[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
559 pa_log(_("Failed to get sample information: %s\n"), pa_strerror(pa_context_errno(c)));
575 pa_bytes_snprint(t, sizeof(t), i->bytes);
577 printf(_("Sample #%u\n"
579 "\tSample Specification: %s\n"
580 "\tChannel Map: %s\n"
584 "\tDuration: %0.1fs\n"
588 "\tProperties:\n\t\t%s\n"),
591 pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : _("n/a"),
592 pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : _("n/a"),
593 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
594 pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
595 pa_cvolume_get_balance(&i->volume, &i->channel_map),
596 (double) i->duration/1000000.0,
599 i->filename ? i->filename : _("n/a"),
600 pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
605 static void simple_callback(pa_context *c, int success, void *userdata) {
607 pa_log(_("Failure: %s\n"), pa_strerror(pa_context_errno(c)));
615 static void index_callback(pa_context *c, uint32_t idx, void *userdata) {
616 if (idx == PA_INVALID_INDEX) {
617 pa_log(_("Failure: %s\n"), pa_strerror(pa_context_errno(c)));
627 static void stream_state_callback(pa_stream *s, void *userdata) {
630 switch (pa_stream_get_state(s)) {
631 case PA_STREAM_CREATING:
632 case PA_STREAM_READY:
635 case PA_STREAM_TERMINATED:
639 case PA_STREAM_FAILED:
641 pa_log(_("Failed to upload sample: %s\n"), pa_strerror(pa_context_errno(pa_stream_get_context(s))));
646 static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
649 pa_assert(s && length && sndfile);
651 d = pa_xmalloc(length);
653 pa_assert(sample_length >= length);
654 l = (sf_count_t) (length/pa_frame_size(&sample_spec));
656 if ((sf_readf_float(sndfile, d, l)) != l) {
658 pa_log(_("Premature end of file\n"));
663 pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
665 sample_length -= length;
667 if (sample_length <= 0) {
668 pa_stream_set_write_callback(sample_stream, NULL, NULL);
669 pa_stream_finish_upload(sample_stream);
673 static void context_state_callback(pa_context *c, void *userdata) {
675 switch (pa_context_get_state(c)) {
676 case PA_CONTEXT_CONNECTING:
677 case PA_CONTEXT_AUTHORIZING:
678 case PA_CONTEXT_SETTING_NAME:
681 case PA_CONTEXT_READY:
685 pa_operation_unref(pa_context_stat(c, stat_callback, NULL));
686 pa_operation_unref(pa_context_get_server_info(c, get_server_info_callback, NULL));
690 pa_operation_unref(pa_context_play_sample(c, sample_name, device, PA_VOLUME_NORM, simple_callback, NULL));
694 pa_operation_unref(pa_context_remove_sample(c, sample_name, simple_callback, NULL));
698 sample_stream = pa_stream_new(c, sample_name, &sample_spec, NULL);
699 pa_assert(sample_stream);
701 pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
702 pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
703 pa_stream_connect_upload(sample_stream, sample_length);
707 pa_operation_unref(pa_context_exit_daemon(c, simple_callback, NULL));
712 pa_operation_unref(pa_context_get_module_info_list(c, get_module_info_callback, NULL));
713 pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
714 pa_operation_unref(pa_context_get_source_info_list(c, get_source_info_callback, NULL));
715 pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
716 pa_operation_unref(pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL));
717 pa_operation_unref(pa_context_get_client_info_list(c, get_client_info_callback, NULL));
718 pa_operation_unref(pa_context_get_sample_info_list(c, get_sample_info_callback, NULL));
719 pa_operation_unref(pa_context_get_card_info_list(c, get_card_info_callback, NULL));
722 case MOVE_SINK_INPUT:
723 pa_operation_unref(pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, NULL));
726 case MOVE_SOURCE_OUTPUT:
727 pa_operation_unref(pa_context_move_source_output_by_name(c, source_output_idx, source_name, simple_callback, NULL));
731 pa_operation_unref(pa_context_load_module(c, module_name, module_args, index_callback, NULL));
735 pa_operation_unref(pa_context_unload_module(c, module_index, simple_callback, NULL));
740 pa_operation_unref(pa_context_suspend_sink_by_name(c, sink_name, suspend, simple_callback, NULL));
742 pa_operation_unref(pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL));
747 pa_operation_unref(pa_context_suspend_source_by_name(c, source_name, suspend, simple_callback, NULL));
749 pa_operation_unref(pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL));
752 case SET_CARD_PROFILE:
753 pa_operation_unref(pa_context_set_card_profile_by_name(c, card_name, profile_name, simple_callback, NULL));
757 pa_assert_not_reached();
761 case PA_CONTEXT_TERMINATED:
765 case PA_CONTEXT_FAILED:
767 pa_log(_("Connection failure: %s\n"), pa_strerror(pa_context_errno(c)));
772 static void exit_signal_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
773 pa_log(_("Got SIGINT, exiting.\n"));
777 static void help(const char *argv0) {
779 printf(_("%s [options] stat\n"
780 "%s [options] list\n"
781 "%s [options] exit\n"
782 "%s [options] upload-sample FILENAME [NAME]\n"
783 "%s [options] play-sample NAME [SINK]\n"
784 "%s [options] remove-sample NAME\n"
785 "%s [options] move-sink-input ID SINK\n"
786 "%s [options] move-source-output ID SOURCE\n"
787 "%s [options] load-module NAME [ARGS ...]\n"
788 "%s [options] unload-module ID\n"
789 "%s [options] suspend-sink [SINK] 1|0\n"
790 "%s [options] suspend-source [SOURCE] 1|0\n"
791 "%s [options] set-card-profile [CARD] [PROFILE] \n\n"
792 " -h, --help Show this help\n"
793 " --version Show version\n\n"
794 " -s, --server=SERVER The name of the server to connect to\n"
795 " -n, --client-name=NAME How to call this client on the server\n"),
796 argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0);
803 int main(int argc, char *argv[]) {
804 pa_mainloop* m = NULL;
806 char *server = NULL, *bn;
808 static const struct option long_options[] = {
809 {"server", 1, NULL, 's'},
810 {"client-name", 1, NULL, 'n'},
811 {"version", 0, NULL, ARG_VERSION},
812 {"help", 0, NULL, 'h'},
816 setlocale(LC_ALL, "");
817 bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
819 bn = pa_path_get_filename(argv[0]);
821 proplist = pa_proplist_new();
823 while ((c = getopt_long(argc, argv, "s:n:h", long_options, NULL)) != -1) {
831 printf(_("pactl %s\n"
832 "Compiled with libpulse %s\n"
833 "Linked with libpulse %s\n"),
835 pa_get_headers_version(),
836 pa_get_library_version());
842 server = pa_xstrdup(optarg);
848 if (!(t = pa_locale_to_utf8(optarg)) ||
849 pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, t) < 0) {
851 pa_log(_("Invalid client name '%s'\n"), t ? t : optarg);
866 if (pa_streq(argv[optind], "stat"))
868 else if (pa_streq(argv[optind], "exit"))
870 else if (pa_streq(argv[optind], "list"))
872 else if (pa_streq(argv[optind], "upload-sample")) {
874 action = UPLOAD_SAMPLE;
876 if (optind+1 >= argc) {
877 pa_log(_("Please specify a sample file to load\n"));
882 sample_name = pa_xstrdup(argv[optind+2]);
884 char *f = pa_path_get_filename(argv[optind+1]);
885 sample_name = pa_xstrndup(f, strcspn(f, "."));
889 if (!(sndfile = sf_open(argv[optind+1], SFM_READ, &sfi))) {
890 pa_log(_("Failed to open sound file.\n"));
894 if (pa_sndfile_read_sample_spec(sndfile, &sample_spec) < 0) {
895 pa_log(_("Failed to determine sample specification from file.\n"));
898 sample_spec.format = PA_SAMPLE_FLOAT32;
900 if (pa_sndfile_read_channel_map(sndfile, &channel_map) < 0) {
901 if (sample_spec.channels > 2)
902 pa_log(_("Warning: Failed to determine sample specification from file.\n"));
903 pa_channel_map_init_extend(&channel_map, sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
906 pa_assert(pa_channel_map_compatible(&channel_map, &sample_spec));
907 sample_length = (size_t) sfi.frames*pa_frame_size(&sample_spec);
909 } else if (pa_streq(argv[optind], "play-sample")) {
910 action = PLAY_SAMPLE;
911 if (argc != optind+2 && argc != optind+3) {
912 pa_log(_("You have to specify a sample name to play\n"));
916 sample_name = pa_xstrdup(argv[optind+1]);
919 device = pa_xstrdup(argv[optind+2]);
921 } else if (pa_streq(argv[optind], "remove-sample")) {
922 action = REMOVE_SAMPLE;
923 if (argc != optind+2) {
924 pa_log(_("You have to specify a sample name to remove\n"));
928 sample_name = pa_xstrdup(argv[optind+1]);
930 } else if (pa_streq(argv[optind], "move-sink-input")) {
931 action = MOVE_SINK_INPUT;
932 if (argc != optind+3) {
933 pa_log(_("You have to specify a sink input index and a sink\n"));
937 sink_input_idx = (uint32_t) atoi(argv[optind+1]);
938 sink_name = pa_xstrdup(argv[optind+2]);
940 } else if (pa_streq(argv[optind], "move-source-output")) {
941 action = MOVE_SOURCE_OUTPUT;
942 if (argc != optind+3) {
943 pa_log(_("You have to specify a source output index and a source\n"));
947 source_output_idx = (uint32_t) atoi(argv[optind+1]);
948 source_name = pa_xstrdup(argv[optind+2]);
950 } else if (pa_streq(argv[optind], "load-module")) {
955 action = LOAD_MODULE;
957 if (argc <= optind+1) {
958 pa_log(_("You have to specify a module name and arguments.\n"));
962 module_name = argv[optind+1];
964 for (i = optind+2; i < argc; i++)
965 n += strlen(argv[i])+1;
968 p = module_args = pa_xmalloc(n);
970 for (i = optind+2; i < argc; i++)
971 p += sprintf(p, "%s%s", p == module_args ? "" : " ", argv[i]);
974 } else if (pa_streq(argv[optind], "unload-module")) {
975 action = UNLOAD_MODULE;
977 if (argc != optind+2) {
978 pa_log(_("You have to specify a module index\n"));
982 module_index = (uint32_t) atoi(argv[optind+1]);
984 } else if (pa_streq(argv[optind], "suspend-sink")) {
985 action = SUSPEND_SINK;
987 if (argc > optind+3 || optind+1 >= argc) {
988 pa_log(_("You may not specify more than one sink. You have to specify a boolean value.\n"));
992 suspend = pa_parse_boolean(argv[argc-1]);
995 sink_name = pa_xstrdup(argv[optind+1]);
997 } else if (pa_streq(argv[optind], "suspend-source")) {
998 action = SUSPEND_SOURCE;
1000 if (argc > optind+3 || optind+1 >= argc) {
1001 pa_log(_("You may not specify more than one source. You have to specify a boolean value.\n"));
1005 suspend = pa_parse_boolean(argv[argc-1]);
1007 if (argc > optind+2)
1008 source_name = pa_xstrdup(argv[optind+1]);
1009 } else if (pa_streq(argv[optind], "set-card-profile")) {
1010 action = SET_CARD_PROFILE;
1012 if (argc != optind+3) {
1013 pa_log(_("You have to specify a card name/index and a profile name\n"));
1017 card_name = pa_xstrdup(argv[optind+1]);
1018 profile_name = pa_xstrdup(argv[optind+2]);
1020 } else if (pa_streq(argv[optind], "help")) {
1027 if (action == NONE) {
1028 pa_log(_("No valid command specified.\n"));
1032 if (!(m = pa_mainloop_new())) {
1033 pa_log(_("pa_mainloop_new() failed.\n"));
1037 mainloop_api = pa_mainloop_get_api(m);
1039 pa_assert_se(pa_signal_init(mainloop_api) == 0);
1040 pa_signal_new(SIGINT, exit_signal_callback, NULL);
1041 pa_signal_new(SIGTERM, exit_signal_callback, NULL);
1042 pa_disable_sigpipe();
1044 if (!(context = pa_context_new_with_proplist(mainloop_api, NULL, proplist))) {
1045 pa_log(_("pa_context_new() failed.\n"));
1049 pa_context_set_state_callback(context, context_state_callback, NULL);
1050 if (pa_context_connect(context, server, 0, NULL) < 0) {
1051 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context)));
1055 if (pa_mainloop_run(m, &ret) < 0) {
1056 pa_log(_("pa_mainloop_run() failed.\n"));
1062 pa_stream_unref(sample_stream);
1065 pa_context_unref(context);
1069 pa_mainloop_free(m);
1074 pa_xfree(sample_name);
1075 pa_xfree(sink_name);
1076 pa_xfree(source_name);
1077 pa_xfree(module_args);
1078 pa_xfree(card_name);
1079 pa_xfree(profile_name);
1085 pa_proplist_free(proplist);