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
;
64 sink_input_idx
= PA_INVALID_INDEX
,
65 source_output_idx
= PA_INVALID_INDEX
;
67 static uint32_t module_index
;
68 static pa_bool_t suspend
;
70 static pa_proplist
*proplist
= NULL
;
72 static SNDFILE
*sndfile
= NULL
;
73 static pa_stream
*sample_stream
= NULL
;
74 static pa_sample_spec sample_spec
;
75 static pa_channel_map channel_map
;
76 static size_t sample_length
= 0;
78 static int actions
= 1;
80 static pa_bool_t nl
= FALSE
;
101 static void quit(int ret
) {
102 pa_assert(mainloop_api
);
103 mainloop_api
->quit(mainloop_api
, ret
);
106 static void context_drain_complete(pa_context
*c
, void *userdata
) {
107 pa_context_disconnect(c
);
110 static void drain(void) {
112 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
113 pa_context_disconnect(context
);
115 pa_operation_unref(o
);
118 static void complete_action(void) {
119 pa_assert(actions
> 0);
125 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
128 pa_log(_("Failed to get statistics: %s\n"), pa_strerror(pa_context_errno(c
)));
133 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
134 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
136 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
137 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
139 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
140 printf(_("Sample cache size: %s\n"), s
);
145 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
146 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
149 pa_log(_("Failed to get server information: %s\n"), pa_strerror(pa_context_errno(c
)));
154 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
155 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
157 printf(_("User name: %s\n"
160 "Server Version: %s\n"
161 "Default Sample Specification: %s\n"
162 "Default Channel Map: %s\n"
164 "Default Source: %s\n"
172 i
->default_sink_name
,
173 i
->default_source_name
,
179 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
181 static const char *state_table
[] = {
182 [1+PA_SINK_INVALID_STATE
] = "n/a",
183 [1+PA_SINK_RUNNING
] = "RUNNING",
184 [1+PA_SINK_IDLE
] = "IDLE",
185 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
189 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
190 cv
[PA_CVOLUME_SNPRINT_MAX
],
191 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
192 v
[PA_VOLUME_SNPRINT_MAX
],
193 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
194 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
198 pa_log(_("Failed to get sink information: %s\n"), pa_strerror(pa_context_errno(c
)));
214 printf(_("Sink #%u\n"
217 "\tDescription: %s\n"
219 "\tSample Specification: %s\n"
220 "\tChannel Map: %s\n"
221 "\tOwner Module: %u\n"
225 "\tBase Volume: %s%s%s\n"
226 "\tMonitor Source: %s\n"
227 "\tLatency: %0.0f usec, configured %0.0f usec\n"
228 "\tFlags: %s%s%s%s%s%s\n"
229 "\tProperties:\n\t\t%s\n"),
231 state_table
[1+i
->state
],
233 pa_strnull(i
->description
),
234 pa_strnull(i
->driver
),
235 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
236 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
239 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
240 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
241 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
242 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
243 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
244 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
245 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
246 pa_strnull(i
->monitor_source_name
),
247 (double) i
->latency
, (double) i
->configured_latency
,
248 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
249 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
250 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
251 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
252 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
253 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
254 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
259 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
261 static const char *state_table
[] = {
262 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
263 [1+PA_SOURCE_RUNNING
] = "RUNNING",
264 [1+PA_SOURCE_IDLE
] = "IDLE",
265 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
269 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
270 cv
[PA_CVOLUME_SNPRINT_MAX
],
271 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
272 v
[PA_VOLUME_SNPRINT_MAX
],
273 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
274 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
278 pa_log(_("Failed to get source information: %s\n"), pa_strerror(pa_context_errno(c
)));
294 printf(_("Source #%u\n"
297 "\tDescription: %s\n"
299 "\tSample Specification: %s\n"
300 "\tChannel Map: %s\n"
301 "\tOwner Module: %u\n"
305 "\tBase Volume: %s%s%s\n"
306 "\tMonitor of Sink: %s\n"
307 "\tLatency: %0.0f usec, configured %0.0f usec\n"
308 "\tFlags: %s%s%s%s%s%s\n"
309 "\tProperties:\n\t\t%s\n"),
311 state_table
[1+i
->state
],
313 pa_strnull(i
->description
),
314 pa_strnull(i
->driver
),
315 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
316 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
319 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
320 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
321 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
322 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
323 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
324 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
325 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
326 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
327 (double) i
->latency
, (double) i
->configured_latency
,
328 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
329 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
330 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
331 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
332 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
333 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
334 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
339 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
344 pa_log(_("Failed to get module information: %s\n"), pa_strerror(pa_context_errno(c
)));
360 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
362 printf(_("Module #%u\n"
365 "\tUsage counter: %s\n"
366 "\tProperties:\n\t\t%s\n"),
369 i
->argument
? i
->argument
: "",
370 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
371 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
376 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
381 pa_log(_("Failed to get client information: %s\n"), pa_strerror(pa_context_errno(c
)));
397 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
399 printf(_("Client #%u\n"
401 "\tOwner Module: %s\n"
402 "\tProperties:\n\t\t%s\n"),
404 pa_strnull(i
->driver
),
405 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
406 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
411 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
416 pa_log(_("Failed to get card information: %s\n"), pa_strerror(pa_context_errno(c
)));
432 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
434 printf(_("Card #%u\n"
437 "\tOwner Module: %s\n"
438 "\tProperties:\n\t\t%s\n"),
441 pa_strnull(i
->driver
),
442 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
443 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
446 pa_card_profile_info
*p
;
448 printf(_("\tProfiles:\n"));
449 for (p
= i
->profiles
; p
->name
; p
++)
450 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
453 if (i
->active_profile
)
454 printf(_("\tActive Profile: %s\n"),
455 i
->active_profile
->name
);
460 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
461 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
];
465 pa_log(_("Failed to get sink input information: %s\n"), pa_strerror(pa_context_errno(c
)));
481 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
482 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
484 printf(_("Sink Input #%u\n"
486 "\tOwner Module: %s\n"
489 "\tSample Specification: %s\n"
490 "\tChannel Map: %s\n"
495 "\tBuffer Latency: %0.0f usec\n"
496 "\tSink Latency: %0.0f usec\n"
497 "\tResample method: %s\n"
498 "\tProperties:\n\t\t%s\n"),
500 pa_strnull(i
->driver
),
501 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
502 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
504 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
505 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
507 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
508 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
509 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
510 (double) i
->buffer_usec
,
511 (double) i
->sink_usec
,
512 i
->resample_method
? i
->resample_method
: _("n/a"),
513 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
518 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
519 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
523 pa_log(_("Failed to get source output information: %s\n"), pa_strerror(pa_context_errno(c
)));
540 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
541 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
543 printf(_("Source Output #%u\n"
545 "\tOwner Module: %s\n"
548 "\tSample Specification: %s\n"
549 "\tChannel Map: %s\n"
550 "\tBuffer Latency: %0.0f usec\n"
551 "\tSource Latency: %0.0f usec\n"
552 "\tResample method: %s\n"
553 "\tProperties:\n\t\t%s\n"),
555 pa_strnull(i
->driver
),
556 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
557 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
559 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
560 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
561 (double) i
->buffer_usec
,
562 (double) i
->source_usec
,
563 i
->resample_method
? i
->resample_method
: _("n/a"),
564 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
569 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
570 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
];
574 pa_log(_("Failed to get sample information: %s\n"), pa_strerror(pa_context_errno(c
)));
590 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
592 printf(_("Sample #%u\n"
594 "\tSample Specification: %s\n"
595 "\tChannel Map: %s\n"
599 "\tDuration: %0.1fs\n"
603 "\tProperties:\n\t\t%s\n"),
606 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
607 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
608 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
609 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
610 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
611 (double) i
->duration
/1000000.0,
614 i
->filename
? i
->filename
: _("n/a"),
615 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
620 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
622 pa_log(_("Failure: %s\n"), pa_strerror(pa_context_errno(c
)));
630 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
631 if (idx
== PA_INVALID_INDEX
) {
632 pa_log(_("Failure: %s\n"), pa_strerror(pa_context_errno(c
)));
642 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
645 switch (pa_stream_get_state(s
)) {
646 case PA_STREAM_CREATING
:
647 case PA_STREAM_READY
:
650 case PA_STREAM_TERMINATED
:
654 case PA_STREAM_FAILED
:
656 pa_log(_("Failed to upload sample: %s\n"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
661 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
664 pa_assert(s
&& length
&& sndfile
);
666 d
= pa_xmalloc(length
);
668 pa_assert(sample_length
>= length
);
669 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
671 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
673 pa_log(_("Premature end of file\n"));
678 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
680 sample_length
-= length
;
682 if (sample_length
<= 0) {
683 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
684 pa_stream_finish_upload(sample_stream
);
688 static void context_state_callback(pa_context
*c
, void *userdata
) {
690 switch (pa_context_get_state(c
)) {
691 case PA_CONTEXT_CONNECTING
:
692 case PA_CONTEXT_AUTHORIZING
:
693 case PA_CONTEXT_SETTING_NAME
:
696 case PA_CONTEXT_READY
:
700 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
701 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
705 pa_operation_unref(pa_context_play_sample(c
, sample_name
, device
, PA_VOLUME_NORM
, simple_callback
, NULL
));
709 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
713 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
714 pa_assert(sample_stream
);
716 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
717 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
718 pa_stream_connect_upload(sample_stream
, sample_length
);
722 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
727 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
728 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
729 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
730 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
731 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
732 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
733 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
734 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
737 case MOVE_SINK_INPUT
:
738 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
741 case MOVE_SOURCE_OUTPUT
:
742 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
746 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
750 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
755 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
757 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
762 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
764 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
767 case SET_CARD_PROFILE
:
768 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
772 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
775 case SET_SOURCE_PORT
:
776 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
780 pa_assert_not_reached();
784 case PA_CONTEXT_TERMINATED
:
788 case PA_CONTEXT_FAILED
:
790 pa_log(_("Connection failure: %s\n"), pa_strerror(pa_context_errno(c
)));
795 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
796 pa_log(_("Got SIGINT, exiting.\n"));
800 static void help(const char *argv0
) {
802 printf(_("%s [options] stat\n"
803 "%s [options] list\n"
804 "%s [options] exit\n"
805 "%s [options] upload-sample FILENAME [NAME]\n"
806 "%s [options] play-sample NAME [SINK]\n"
807 "%s [options] remove-sample NAME\n"
808 "%s [options] move-sink-input ID SINK\n"
809 "%s [options] move-source-output ID SOURCE\n"
810 "%s [options] load-module NAME [ARGS ...]\n"
811 "%s [options] unload-module ID\n"
812 "%s [options] suspend-sink [SINK] 1|0\n"
813 "%s [options] suspend-source [SOURCE] 1|0\n"
814 "%s [options] set-card-profile [CARD] [PROFILE] \n"
815 "%s [options] set-sink-port [SINK] [PORT] \n"
816 "%s [options] set-source-port [SOURCE] [PORT] \n\n"
817 " -h, --help Show this help\n"
818 " --version Show version\n\n"
819 " -s, --server=SERVER The name of the server to connect to\n"
820 " -n, --client-name=NAME How to call this client on the server\n"),
821 argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
, argv0
);
828 int main(int argc
, char *argv
[]) {
829 pa_mainloop
* m
= NULL
;
831 char *server
= NULL
, *bn
;
833 static const struct option long_options
[] = {
834 {"server", 1, NULL
, 's'},
835 {"client-name", 1, NULL
, 'n'},
836 {"version", 0, NULL
, ARG_VERSION
},
837 {"help", 0, NULL
, 'h'},
841 setlocale(LC_ALL
, "");
842 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
844 bn
= pa_path_get_filename(argv
[0]);
846 proplist
= pa_proplist_new();
848 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
856 printf(_("pactl %s\n"
857 "Compiled with libpulse %s\n"
858 "Linked with libpulse %s\n"),
860 pa_get_headers_version(),
861 pa_get_library_version());
867 server
= pa_xstrdup(optarg
);
873 if (!(t
= pa_locale_to_utf8(optarg
)) ||
874 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
876 pa_log(_("Invalid client name '%s'\n"), t
? t
: optarg
);
891 if (pa_streq(argv
[optind
], "stat"))
893 else if (pa_streq(argv
[optind
], "exit"))
895 else if (pa_streq(argv
[optind
], "list"))
897 else if (pa_streq(argv
[optind
], "upload-sample")) {
899 action
= UPLOAD_SAMPLE
;
901 if (optind
+1 >= argc
) {
902 pa_log(_("Please specify a sample file to load\n"));
907 sample_name
= pa_xstrdup(argv
[optind
+2]);
909 char *f
= pa_path_get_filename(argv
[optind
+1]);
910 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
914 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
915 pa_log(_("Failed to open sound file.\n"));
919 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
920 pa_log(_("Failed to determine sample specification from file.\n"));
923 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
925 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
926 if (sample_spec
.channels
> 2)
927 pa_log(_("Warning: Failed to determine sample specification from file.\n"));
928 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
931 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
932 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
934 } else if (pa_streq(argv
[optind
], "play-sample")) {
935 action
= PLAY_SAMPLE
;
936 if (argc
!= optind
+2 && argc
!= optind
+3) {
937 pa_log(_("You have to specify a sample name to play\n"));
941 sample_name
= pa_xstrdup(argv
[optind
+1]);
944 device
= pa_xstrdup(argv
[optind
+2]);
946 } else if (pa_streq(argv
[optind
], "remove-sample")) {
947 action
= REMOVE_SAMPLE
;
948 if (argc
!= optind
+2) {
949 pa_log(_("You have to specify a sample name to remove\n"));
953 sample_name
= pa_xstrdup(argv
[optind
+1]);
955 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
956 action
= MOVE_SINK_INPUT
;
957 if (argc
!= optind
+3) {
958 pa_log(_("You have to specify a sink input index and a sink\n"));
962 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
963 sink_name
= pa_xstrdup(argv
[optind
+2]);
965 } else if (pa_streq(argv
[optind
], "move-source-output")) {
966 action
= MOVE_SOURCE_OUTPUT
;
967 if (argc
!= optind
+3) {
968 pa_log(_("You have to specify a source output index and a source\n"));
972 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
973 source_name
= pa_xstrdup(argv
[optind
+2]);
975 } else if (pa_streq(argv
[optind
], "load-module")) {
980 action
= LOAD_MODULE
;
982 if (argc
<= optind
+1) {
983 pa_log(_("You have to specify a module name and arguments.\n"));
987 module_name
= argv
[optind
+1];
989 for (i
= optind
+2; i
< argc
; i
++)
990 n
+= strlen(argv
[i
])+1;
993 p
= module_args
= pa_xmalloc(n
);
995 for (i
= optind
+2; i
< argc
; i
++)
996 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
999 } else if (pa_streq(argv
[optind
], "unload-module")) {
1000 action
= UNLOAD_MODULE
;
1002 if (argc
!= optind
+2) {
1003 pa_log(_("You have to specify a module index\n"));
1007 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1009 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1010 action
= SUSPEND_SINK
;
1012 if (argc
> optind
+3 || optind
+1 >= argc
) {
1013 pa_log(_("You may not specify more than one sink. You have to specify a boolean value.\n"));
1017 suspend
= pa_parse_boolean(argv
[argc
-1]);
1019 if (argc
> optind
+2)
1020 sink_name
= pa_xstrdup(argv
[optind
+1]);
1022 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1023 action
= SUSPEND_SOURCE
;
1025 if (argc
> optind
+3 || optind
+1 >= argc
) {
1026 pa_log(_("You may not specify more than one source. You have to specify a boolean value.\n"));
1030 suspend
= pa_parse_boolean(argv
[argc
-1]);
1032 if (argc
> optind
+2)
1033 source_name
= pa_xstrdup(argv
[optind
+1]);
1034 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1035 action
= SET_CARD_PROFILE
;
1037 if (argc
!= optind
+3) {
1038 pa_log(_("You have to specify a card name/index and a profile name\n"));
1042 card_name
= pa_xstrdup(argv
[optind
+1]);
1043 profile_name
= pa_xstrdup(argv
[optind
+2]);
1045 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1046 action
= SET_SINK_PORT
;
1048 if (argc
!= optind
+3) {
1049 pa_log(_("You have to specify a sink name/index and a port name\n"));
1053 sink_name
= pa_xstrdup(argv
[optind
+1]);
1054 port_name
= pa_xstrdup(argv
[optind
+2]);
1056 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1057 action
= SET_SOURCE_PORT
;
1059 if (argc
!= optind
+3) {
1060 pa_log(_("You have to specify a source name/index and a port name\n"));
1064 source_name
= pa_xstrdup(argv
[optind
+1]);
1065 port_name
= pa_xstrdup(argv
[optind
+2]);
1067 } else if (pa_streq(argv
[optind
], "help")) {
1074 if (action
== NONE
) {
1075 pa_log(_("No valid command specified.\n"));
1079 if (!(m
= pa_mainloop_new())) {
1080 pa_log(_("pa_mainloop_new() failed.\n"));
1084 mainloop_api
= pa_mainloop_get_api(m
);
1086 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1087 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1088 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1089 pa_disable_sigpipe();
1091 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1092 pa_log(_("pa_context_new() failed.\n"));
1096 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1097 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1098 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1102 if (pa_mainloop_run(m
, &ret
) < 0) {
1103 pa_log(_("pa_mainloop_run() failed.\n"));
1109 pa_stream_unref(sample_stream
);
1112 pa_context_unref(context
);
1116 pa_mainloop_free(m
);
1121 pa_xfree(sample_name
);
1122 pa_xfree(sink_name
);
1123 pa_xfree(source_name
);
1124 pa_xfree(module_args
);
1125 pa_xfree(card_name
);
1126 pa_xfree(profile_name
);
1132 pa_proplist_free(proplist
);