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 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>
41 #include <pulsecore/core-util.h>
45 static pa_context
*context
= NULL
;
46 static pa_mainloop_api
*mainloop_api
= NULL
;
48 static char *device
= NULL
, *sample_name
= NULL
, *sink_name
= NULL
, *source_name
= NULL
, *module_name
= NULL
, *module_args
= NULL
;
49 static uint32_t sink_input_idx
= PA_INVALID_INDEX
, source_output_idx
= PA_INVALID_INDEX
;
50 static uint32_t module_index
;
53 static SNDFILE
*sndfile
= NULL
;
54 static pa_stream
*sample_stream
= NULL
;
55 static pa_sample_spec sample_spec
;
56 static size_t sample_length
= 0;
58 static int actions
= 1;
78 static void quit(int ret
) {
80 mainloop_api
->quit(mainloop_api
, ret
);
84 static void context_drain_complete(pa_context
*c
, void *userdata
) {
85 pa_context_disconnect(c
);
88 static void drain(void) {
90 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
91 pa_context_disconnect(context
);
93 pa_operation_unref(o
);
97 static void complete_action(void) {
104 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
107 fprintf(stderr
, _("Failed to get statistics: %s\n"), pa_strerror(pa_context_errno(c
)));
112 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
113 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
115 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
116 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
118 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
119 printf(_("Sample cache size: %s\n"), s
);
124 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
125 char s
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
128 fprintf(stderr
, _("Failed to get server information: %s\n"), pa_strerror(pa_context_errno(c
)));
133 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
);
135 printf(_("User name: %s\n"
138 "Server Version: %s\n"
139 "Default Sample Specification: %s\n"
141 "Default Source: %s\n"
148 i
->default_sink_name
,
149 i
->default_source_name
,
155 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
157 static const char *state_table
[] = {
158 [1+PA_SINK_INVALID_STATE
] = "n/a",
159 [1+PA_SINK_RUNNING
] = "RUNNING",
160 [1+PA_SINK_IDLE
] = "IDLE",
161 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
165 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
166 cv
[PA_CVOLUME_SNPRINT_MAX
],
167 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
168 v
[PA_VOLUME_SNPRINT_MAX
],
169 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
170 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
174 fprintf(stderr
, _("Failed to get sink information: %s\n"), pa_strerror(pa_context_errno(c
)));
190 printf(_("Sink #%u\n"
193 "\tDescription: %s\n"
195 "\tSample Specification: %s\n"
196 "\tChannel Map: %s\n"
197 "\tOwner Module: %u\n"
201 "\tBase Volume: %s%s%s\n"
202 "\tMonitor Source: %s\n"
203 "\tLatency: %0.0f usec, configured %0.0f usec\n"
204 "\tFlags: %s%s%s%s%s%s\n"
205 "\tProperties:\n\t\t%s\n"),
207 state_table
[1+i
->state
],
209 pa_strnull(i
->description
),
210 pa_strnull(i
->driver
),
211 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
212 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
215 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
216 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
217 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
218 pa_cvolume_get_balance(&i
->channel_map
, &i
->volume
),
219 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
220 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
221 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
222 pa_strnull(i
->monitor_source_name
),
223 (double) i
->latency
, (double) i
->configured_latency
,
224 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
225 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
226 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
227 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
228 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
229 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
230 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
235 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
237 static const char *state_table
[] = {
238 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
239 [1+PA_SOURCE_RUNNING
] = "RUNNING",
240 [1+PA_SOURCE_IDLE
] = "IDLE",
241 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
245 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
246 cv
[PA_CVOLUME_SNPRINT_MAX
],
247 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
248 v
[PA_VOLUME_SNPRINT_MAX
],
249 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
250 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
254 fprintf(stderr
, _("Failed to get source information: %s\n"), pa_strerror(pa_context_errno(c
)));
270 printf(_("Source #%u\n"
273 "\tDescription: %s\n"
275 "\tSample Specification: %s\n"
276 "\tChannel Map: %s\n"
277 "\tOwner Module: %u\n"
281 "\tBase Volume: %s%s%s\n"
282 "\tMonitor of Sink: %s\n"
283 "\tLatency: %0.0f usec, configured %0.0f usec\n"
284 "\tFlags: %s%s%s%s%s%s\n"
285 "\tProperties:\n\t\t%s\n"),
287 state_table
[1+i
->state
],
289 pa_strnull(i
->description
),
290 pa_strnull(i
->driver
),
291 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
292 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
295 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
296 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
297 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
298 pa_cvolume_get_balance(&i
->channel_map
, &i
->volume
),
299 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
300 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
301 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
302 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
303 (double) i
->latency
, (double) i
->configured_latency
,
304 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
305 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
306 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
307 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
308 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
309 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
310 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
315 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
320 fprintf(stderr
, _("Failed to get module information: %s\n"), pa_strerror(pa_context_errno(c
)));
336 snprintf(t
, sizeof(t
), "%u", i
->n_used
);
338 printf(_("Module #%u\n"
341 "\tUsage counter: %s\n"
342 "\tProperties:\n\t\t%s\n"),
345 i
->argument
? i
->argument
: "",
346 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
347 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
352 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
357 fprintf(stderr
, _("Failed to get client information: %s\n"), pa_strerror(pa_context_errno(c
)));
373 snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
375 printf(_("Client #%u\n"
377 "\tOwner Module: %s\n"
378 "\tProperties:\n\t\t%s\n"),
380 pa_strnull(i
->driver
),
381 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
382 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
387 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
388 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
];
392 fprintf(stderr
, _("Failed to get sink input information: %s\n"), pa_strerror(pa_context_errno(c
)));
408 snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
409 snprintf(k
, sizeof(k
), "%u", i
->client
);
411 printf(_("Sink Input #%u\n"
413 "\tOwner Module: %s\n"
416 "\tSample Specification: %s\n"
417 "\tChannel Map: %s\n"
422 "\tBuffer Latency: %0.0f usec\n"
423 "\tSink Latency: %0.0f usec\n"
424 "\tResample method: %s\n"
425 "\tProperties:\n\t\t%s\n"),
427 pa_strnull(i
->driver
),
428 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
429 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
431 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
432 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
434 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
435 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
436 pa_cvolume_get_balance(&i
->channel_map
, &i
->volume
),
437 (double) i
->buffer_usec
,
438 (double) i
->sink_usec
,
439 i
->resample_method
? i
->resample_method
: _("n/a"),
440 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
445 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
446 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
450 fprintf(stderr
, _("Failed to get source output information: %s\n"), pa_strerror(pa_context_errno(c
)));
467 snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
468 snprintf(k
, sizeof(k
), "%u", i
->client
);
470 printf(_("Source Output #%u\n"
472 "\tOwner Module: %s\n"
475 "\tSample Specification: %s\n"
476 "\tChannel Map: %s\n"
477 "\tBuffer Latency: %0.0f usec\n"
478 "\tSource Latency: %0.0f usec\n"
479 "\tResample method: %s\n"
480 "\tProperties:\n\t\t%s\n"),
482 pa_strnull(i
->driver
),
483 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
484 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
486 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
487 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
488 (double) i
->buffer_usec
,
489 (double) i
->source_usec
,
490 i
->resample_method
? i
->resample_method
: _("n/a"),
491 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
496 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
497 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
];
501 fprintf(stderr
, _("Failed to get sample information: %s\n"), pa_strerror(pa_context_errno(c
)));
517 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
519 printf(_("Sample #%u\n"
521 "\tSample Specification: %s\n"
522 "\tChannel Map: %s\n"
526 "\tDuration: %0.1fs\n"
530 "\tProperties:\n\t\t%s\n"),
533 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
534 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
535 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
536 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
537 pa_cvolume_get_balance(&i
->channel_map
, &i
->volume
),
538 (double) i
->duration
/1000000.0,
541 i
->filename
? i
->filename
: _("n/a"),
542 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
547 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
549 fprintf(stderr
, _("Failure: %s\n"), pa_strerror(pa_context_errno(c
)));
557 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
558 if (idx
== PA_INVALID_INDEX
) {
559 fprintf(stderr
, _("Failure: %s\n"), pa_strerror(pa_context_errno(c
)));
569 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
572 switch (pa_stream_get_state(s
)) {
573 case PA_STREAM_CREATING
:
574 case PA_STREAM_READY
:
577 case PA_STREAM_TERMINATED
:
581 case PA_STREAM_FAILED
:
583 fprintf(stderr
, _("Failed to upload sample: %s\n"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
588 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
591 assert(s
&& length
&& sndfile
);
593 d
= pa_xmalloc(length
);
595 assert(sample_length
>= length
);
596 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
598 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
600 fprintf(stderr
, _("Premature end of file\n"));
604 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
606 sample_length
-= length
;
608 if (sample_length
<= 0) {
609 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
610 pa_stream_finish_upload(sample_stream
);
614 static void context_state_callback(pa_context
*c
, void *userdata
) {
616 switch (pa_context_get_state(c
)) {
617 case PA_CONTEXT_CONNECTING
:
618 case PA_CONTEXT_AUTHORIZING
:
619 case PA_CONTEXT_SETTING_NAME
:
622 case PA_CONTEXT_READY
:
626 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
627 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
631 pa_operation_unref(pa_context_play_sample(c
, sample_name
, device
, PA_VOLUME_NORM
, simple_callback
, NULL
));
635 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
639 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
640 assert(sample_stream
);
642 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
643 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
644 pa_stream_connect_upload(sample_stream
, sample_length
);
648 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
653 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
654 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
655 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
656 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
657 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
658 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
659 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
662 case MOVE_SINK_INPUT
:
663 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
666 case MOVE_SOURCE_OUTPUT
:
667 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
671 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
675 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
680 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
682 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
687 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
689 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
697 case PA_CONTEXT_TERMINATED
:
701 case PA_CONTEXT_FAILED
:
703 fprintf(stderr
, _("Connection failure: %s\n"), pa_strerror(pa_context_errno(c
)));
708 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
709 fprintf(stderr
, _("Got SIGINT, exiting.\n"));
713 static void help(const char *argv0
) {
715 printf(_("%s [options] stat\n"
716 "%s [options] list\n"
717 "%s [options] exit\n"
718 "%s [options] upload-sample FILENAME [NAME]\n"
719 "%s [options] play-sample NAME [SINK]\n"
720 "%s [options] remove-sample NAME\n"
721 "%s [options] move-sink-input ID SINK\n"
722 "%s [options] move-source-output ID SOURCE\n"
723 "%s [options] load-module NAME [ARGS ...]\n"
724 "%s [options] unload-module ID\n"
725 "%s [options] suspend-sink [SINK] 1|0\n"
726 "%s [options] suspend-source [SOURCE] 1|0\n\n"
727 " -h, --help Show this help\n"
728 " --version Show version\n\n"
729 " -s, --server=SERVER The name of the server to connect to\n"
730 " -n, --client-name=NAME How to call this client on the server\n"),
731 argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
);
734 enum { ARG_VERSION
= 256 };
736 int main(int argc
, char *argv
[]) {
737 pa_mainloop
* m
= NULL
;
740 char *server
= NULL
, *client_name
= NULL
, *bn
;
742 static const struct option long_options
[] = {
743 {"server", 1, NULL
, 's'},
744 {"client-name", 1, NULL
, 'n'},
745 {"version", 0, NULL
, ARG_VERSION
},
746 {"help", 0, NULL
, 'h'},
750 setlocale(LC_ALL
, "");
751 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
753 if (!(bn
= strrchr(argv
[0], '/')))
758 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
766 printf(_("pactl %s\n"
767 "Compiled with libpulse %s\n"
768 "Linked with libpulse %s\n"),
770 pa_get_headers_version(),
771 pa_get_library_version());
777 server
= pa_xstrdup(optarg
);
781 pa_xfree(client_name
);
782 client_name
= pa_xstrdup(optarg
);
791 client_name
= pa_xstrdup(bn
);
794 if (!strcmp(argv
[optind
], "stat"))
796 else if (!strcmp(argv
[optind
], "exit"))
798 else if (!strcmp(argv
[optind
], "list"))
800 else if (!strcmp(argv
[optind
], "upload-sample")) {
801 struct SF_INFO sfinfo
;
802 action
= UPLOAD_SAMPLE
;
804 if (optind
+1 >= argc
) {
805 fprintf(stderr
, _("Please specify a sample file to load\n"));
810 sample_name
= pa_xstrdup(argv
[optind
+2]);
812 char *f
= strrchr(argv
[optind
+1], '/');
822 sample_name
= pa_xstrdup(tmp
);
825 memset(&sfinfo
, 0, sizeof(sfinfo
));
826 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfinfo
))) {
827 fprintf(stderr
, _("Failed to open sound file.\n"));
831 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
832 sample_spec
.rate
= (uint32_t) sfinfo
.samplerate
;
833 sample_spec
.channels
= (uint8_t) sfinfo
.channels
;
835 sample_length
= (size_t)sfinfo
.frames
*pa_frame_size(&sample_spec
);
836 } else if (!strcmp(argv
[optind
], "play-sample")) {
837 action
= PLAY_SAMPLE
;
838 if (argc
!= optind
+2 && argc
!= optind
+3) {
839 fprintf(stderr
, _("You have to specify a sample name to play\n"));
843 sample_name
= pa_xstrdup(argv
[optind
+1]);
846 device
= pa_xstrdup(argv
[optind
+2]);
848 } else if (!strcmp(argv
[optind
], "remove-sample")) {
849 action
= REMOVE_SAMPLE
;
850 if (argc
!= optind
+2) {
851 fprintf(stderr
, _("You have to specify a sample name to remove\n"));
855 sample_name
= pa_xstrdup(argv
[optind
+1]);
856 } else if (!strcmp(argv
[optind
], "move-sink-input")) {
857 action
= MOVE_SINK_INPUT
;
858 if (argc
!= optind
+3) {
859 fprintf(stderr
, _("You have to specify a sink input index and a sink\n"));
863 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
864 sink_name
= pa_xstrdup(argv
[optind
+2]);
865 } else if (!strcmp(argv
[optind
], "move-source-output")) {
866 action
= MOVE_SOURCE_OUTPUT
;
867 if (argc
!= optind
+3) {
868 fprintf(stderr
, _("You have to specify a source output index and a source\n"));
872 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
873 source_name
= pa_xstrdup(argv
[optind
+2]);
874 } else if (!strcmp(argv
[optind
], "load-module")) {
879 action
= LOAD_MODULE
;
881 if (argc
<= optind
+1) {
882 fprintf(stderr
, _("You have to specify a module name and arguments.\n"));
886 module_name
= argv
[optind
+1];
888 for (i
= optind
+2; i
< argc
; i
++)
889 n
+= strlen(argv
[i
])+1;
892 p
= module_args
= pa_xmalloc(n
);
894 for (i
= optind
+2; i
< argc
; i
++)
895 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
898 } else if (!strcmp(argv
[optind
], "unload-module")) {
899 action
= UNLOAD_MODULE
;
901 if (argc
!= optind
+2) {
902 fprintf(stderr
, _("You have to specify a module index\n"));
906 module_index
= (uint32_t) atoi(argv
[optind
+1]);
908 } else if (!strcmp(argv
[optind
], "suspend-sink")) {
909 action
= SUSPEND_SINK
;
911 if (argc
> optind
+3 || optind
+1 >= argc
) {
912 fprintf(stderr
, _("You may not specify more than one sink. You have to specify at least one boolean value.\n"));
916 suspend
= pa_parse_boolean(argv
[argc
-1]);
919 sink_name
= pa_xstrdup(argv
[optind
+1]);
921 } else if (!strcmp(argv
[optind
], "suspend-source")) {
922 action
= SUSPEND_SOURCE
;
924 if (argc
> optind
+3 || optind
+1 >= argc
) {
925 fprintf(stderr
, _("You may not specify more than one source. You have to specify at least one boolean value.\n"));
929 suspend
= pa_parse_boolean(argv
[argc
-1]);
932 source_name
= pa_xstrdup(argv
[optind
+1]);
933 } else if (!strcmp(argv
[optind
], "help")) {
940 if (action
== NONE
) {
941 fprintf(stderr
, _("No valid command specified.\n"));
945 if (!(m
= pa_mainloop_new())) {
946 fprintf(stderr
, _("pa_mainloop_new() failed.\n"));
950 mainloop_api
= pa_mainloop_get_api(m
);
952 r
= pa_signal_init(mainloop_api
);
954 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
956 signal(SIGPIPE
, SIG_IGN
);
959 if (!(context
= pa_context_new(mainloop_api
, client_name
))) {
960 fprintf(stderr
, _("pa_context_new() failed.\n"));
964 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
965 pa_context_connect(context
, server
, 0, NULL
);
967 if (pa_mainloop_run(m
, &ret
) < 0) {
968 fprintf(stderr
, _("pa_mainloop_run() failed.\n"));
974 pa_stream_unref(sample_stream
);
977 pa_context_unref(context
);
989 pa_xfree(sample_name
);
991 pa_xfree(source_name
);
992 pa_xfree(module_args
);
993 pa_xfree(client_name
);