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 static pa_context
*context
= NULL
;
48 static pa_mainloop_api
*mainloop_api
= NULL
;
61 sink_input_idx
= PA_INVALID_INDEX
,
62 source_output_idx
= PA_INVALID_INDEX
;
64 static uint32_t module_index
;
65 static pa_bool_t suspend
;
66 static pa_bool_t mute
;
67 static pa_volume_t volume
;
69 static pa_proplist
*proplist
= NULL
;
71 static SNDFILE
*sndfile
= NULL
;
72 static pa_stream
*sample_stream
= NULL
;
73 static pa_sample_spec sample_spec
;
74 static pa_channel_map channel_map
;
75 static size_t sample_length
= 0;
76 static int actions
= 1;
78 static pa_bool_t nl
= FALSE
;
99 SET_SINK_INPUT_VOLUME
,
105 static void quit(int ret
) {
106 pa_assert(mainloop_api
);
107 mainloop_api
->quit(mainloop_api
, ret
);
110 static void context_drain_complete(pa_context
*c
, void *userdata
) {
111 pa_context_disconnect(c
);
114 static void drain(void) {
117 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
118 pa_context_disconnect(context
);
120 pa_operation_unref(o
);
123 static void complete_action(void) {
124 pa_assert(actions
> 0);
130 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
131 char s
[PA_BYTES_SNPRINT_MAX
];
133 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
138 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
139 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
141 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
142 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
144 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
145 printf(_("Sample cache size: %s\n"), s
);
150 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
151 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
154 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
159 printf(_("Server String: %s\n"
160 "Library Protocol Version: %u\n"
161 "Server Protocol Version: %u\n"
165 pa_context_get_server(c
),
166 pa_context_get_protocol_version(c
),
167 pa_context_get_server_protocol_version(c
),
168 pa_yes_no(pa_context_is_local(c
)),
169 pa_context_get_index(c
),
170 pa_context_get_tile_size(c
, NULL
));
172 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
173 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
175 printf(_("User Name: %s\n"
178 "Server Version: %s\n"
179 "Default Sample Specification: %s\n"
180 "Default Channel Map: %s\n"
182 "Default Source: %s\n"
183 "Cookie: %04x:%04x\n"),
190 i
->default_sink_name
,
191 i
->default_source_name
,
193 i
->cookie
& 0xFFFFU
);
198 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
200 static const char *state_table
[] = {
201 [1+PA_SINK_INVALID_STATE
] = "n/a",
202 [1+PA_SINK_RUNNING
] = "RUNNING",
203 [1+PA_SINK_IDLE
] = "IDLE",
204 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
208 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
209 cv
[PA_CVOLUME_SNPRINT_MAX
],
210 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
211 v
[PA_VOLUME_SNPRINT_MAX
],
212 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
213 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
217 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
233 printf(_("Sink #%u\n"
236 "\tDescription: %s\n"
238 "\tSample Specification: %s\n"
239 "\tChannel Map: %s\n"
240 "\tOwner Module: %u\n"
244 "\tBase Volume: %s%s%s\n"
245 "\tMonitor Source: %s\n"
246 "\tLatency: %0.0f usec, configured %0.0f usec\n"
247 "\tFlags: %s%s%s%s%s%s\n"
248 "\tProperties:\n\t\t%s\n"),
250 state_table
[1+i
->state
],
252 pa_strnull(i
->description
),
253 pa_strnull(i
->driver
),
254 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
255 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
258 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
259 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
260 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
261 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
262 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
263 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
264 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
265 pa_strnull(i
->monitor_source_name
),
266 (double) i
->latency
, (double) i
->configured_latency
,
267 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
268 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
269 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
270 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
271 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
272 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
273 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
278 pa_sink_port_info
**p
;
280 printf(_("\tPorts:\n"));
281 for (p
= i
->ports
; *p
; p
++)
282 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
286 printf(_("\tActive Port: %s\n"),
287 i
->active_port
->name
);
290 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
292 static const char *state_table
[] = {
293 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
294 [1+PA_SOURCE_RUNNING
] = "RUNNING",
295 [1+PA_SOURCE_IDLE
] = "IDLE",
296 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
300 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
301 cv
[PA_CVOLUME_SNPRINT_MAX
],
302 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
303 v
[PA_VOLUME_SNPRINT_MAX
],
304 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
305 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
309 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
325 printf(_("Source #%u\n"
328 "\tDescription: %s\n"
330 "\tSample Specification: %s\n"
331 "\tChannel Map: %s\n"
332 "\tOwner Module: %u\n"
336 "\tBase Volume: %s%s%s\n"
337 "\tMonitor of Sink: %s\n"
338 "\tLatency: %0.0f usec, configured %0.0f usec\n"
339 "\tFlags: %s%s%s%s%s%s\n"
340 "\tProperties:\n\t\t%s\n"),
342 state_table
[1+i
->state
],
344 pa_strnull(i
->description
),
345 pa_strnull(i
->driver
),
346 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
347 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
350 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
351 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
352 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
353 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
354 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
355 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
356 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
357 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
358 (double) i
->latency
, (double) i
->configured_latency
,
359 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
360 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
361 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
362 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
363 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
364 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
365 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
370 pa_source_port_info
**p
;
372 printf(_("\tPorts:\n"));
373 for (p
= i
->ports
; *p
; p
++)
374 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
378 printf(_("\tActive Port: %s\n"),
379 i
->active_port
->name
);
382 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
387 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
403 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
405 printf(_("Module #%u\n"
408 "\tUsage counter: %s\n"
409 "\tProperties:\n\t\t%s\n"),
412 i
->argument
? i
->argument
: "",
413 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
414 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
419 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
424 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
440 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
442 printf(_("Client #%u\n"
444 "\tOwner Module: %s\n"
445 "\tProperties:\n\t\t%s\n"),
447 pa_strnull(i
->driver
),
448 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
449 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
454 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
459 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
475 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
477 printf(_("Card #%u\n"
480 "\tOwner Module: %s\n"
481 "\tProperties:\n\t\t%s\n"),
484 pa_strnull(i
->driver
),
485 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
486 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
489 pa_card_profile_info
*p
;
491 printf(_("\tProfiles:\n"));
492 for (p
= i
->profiles
; p
->name
; p
++)
493 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
496 if (i
->active_profile
)
497 printf(_("\tActive Profile: %s\n"),
498 i
->active_profile
->name
);
503 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
504 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
];
508 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
524 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
525 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
527 printf(_("Sink Input #%u\n"
529 "\tOwner Module: %s\n"
532 "\tSample Specification: %s\n"
533 "\tChannel Map: %s\n"
538 "\tBuffer Latency: %0.0f usec\n"
539 "\tSink Latency: %0.0f usec\n"
540 "\tResample method: %s\n"
541 "\tProperties:\n\t\t%s\n"),
543 pa_strnull(i
->driver
),
544 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
545 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
547 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
548 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
550 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
551 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
552 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
553 (double) i
->buffer_usec
,
554 (double) i
->sink_usec
,
555 i
->resample_method
? i
->resample_method
: _("n/a"),
556 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
561 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
562 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
566 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
583 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
584 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
586 printf(_("Source Output #%u\n"
588 "\tOwner Module: %s\n"
591 "\tSample Specification: %s\n"
592 "\tChannel Map: %s\n"
593 "\tBuffer Latency: %0.0f usec\n"
594 "\tSource Latency: %0.0f usec\n"
595 "\tResample method: %s\n"
596 "\tProperties:\n\t\t%s\n"),
598 pa_strnull(i
->driver
),
599 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
600 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
602 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
603 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
604 (double) i
->buffer_usec
,
605 (double) i
->source_usec
,
606 i
->resample_method
? i
->resample_method
: _("n/a"),
607 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
612 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
613 char t
[PA_BYTES_SNPRINT_MAX
], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
617 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
633 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
635 printf(_("Sample #%u\n"
637 "\tSample Specification: %s\n"
638 "\tChannel Map: %s\n"
642 "\tDuration: %0.1fs\n"
646 "\tProperties:\n\t\t%s\n"),
649 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
650 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
651 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
652 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
653 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
654 (double) i
->duration
/1000000.0,
657 i
->filename
? i
->filename
: _("n/a"),
658 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
663 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
665 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
673 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
674 if (idx
== PA_INVALID_INDEX
) {
675 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
685 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
688 switch (pa_stream_get_state(s
)) {
689 case PA_STREAM_CREATING
:
690 case PA_STREAM_READY
:
693 case PA_STREAM_TERMINATED
:
697 case PA_STREAM_FAILED
:
699 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
704 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
707 pa_assert(s
&& length
&& sndfile
);
709 d
= pa_xmalloc(length
);
711 pa_assert(sample_length
>= length
);
712 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
714 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
716 pa_log(_("Premature end of file"));
721 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
723 sample_length
-= length
;
725 if (sample_length
<= 0) {
726 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
727 pa_stream_finish_upload(sample_stream
);
731 static void context_state_callback(pa_context
*c
, void *userdata
) {
733 switch (pa_context_get_state(c
)) {
734 case PA_CONTEXT_CONNECTING
:
735 case PA_CONTEXT_AUTHORIZING
:
736 case PA_CONTEXT_SETTING_NAME
:
739 case PA_CONTEXT_READY
:
743 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
744 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
748 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
752 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
756 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
757 pa_assert(sample_stream
);
759 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
760 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
761 pa_stream_connect_upload(sample_stream
, sample_length
);
765 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
770 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
771 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
772 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
773 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
774 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
775 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
776 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
777 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
780 case MOVE_SINK_INPUT
:
781 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
784 case MOVE_SOURCE_OUTPUT
:
785 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
789 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
793 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
798 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
800 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
805 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
807 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
810 case SET_CARD_PROFILE
:
811 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
815 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
818 case SET_SOURCE_PORT
:
819 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
823 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
826 case SET_SOURCE_MUTE
:
827 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
830 case SET_SINK_INPUT_MUTE
:
831 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
834 case SET_SINK_VOLUME
: {
837 pa_cvolume_set(&v
, 1, volume
);
838 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
842 case SET_SOURCE_VOLUME
: {
845 pa_cvolume_set(&v
, 1, volume
);
846 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
850 case SET_SINK_INPUT_VOLUME
: {
853 pa_cvolume_set(&v
, 1, volume
);
854 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
859 pa_assert_not_reached();
863 case PA_CONTEXT_TERMINATED
:
867 case PA_CONTEXT_FAILED
:
869 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
874 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
875 pa_log(_("Got SIGINT, exiting."));
879 static void help(const char *argv0
) {
881 printf(_("%s [options] stat\n"
882 "%s [options] list\n"
883 "%s [options] exit\n"
884 "%s [options] upload-sample FILENAME [NAME]\n"
885 "%s [options] play-sample NAME [SINK]\n"
886 "%s [options] remove-sample NAME\n"
887 "%s [options] move-sink-input SINKINPUT SINK\n"
888 "%s [options] move-source-output SOURCEOUTPUT SOURCE\n"
889 "%s [options] load-module NAME [ARGS ...]\n"
890 "%s [options] unload-module MODULE\n"
891 "%s [options] suspend-sink SINK 1|0\n"
892 "%s [options] suspend-source SOURCE 1|0\n"
893 "%s [options] set-card-profile CARD PROFILE\n"
894 "%s [options] set-sink-port SINK PORT\n"
895 "%s [options] set-source-port SOURCE PORT\n"
896 "%s [options] set-sink-volume SINK VOLUME\n"
897 "%s [options] set-source-volume SOURCE VOLUME\n"
898 "%s [options] set-sink-input-volume SINKINPUT VOLUME\n"
899 "%s [options] set-sink-mute SINK 1|0\n"
900 "%s [options] set-source-mute SOURCE 1|0\n"
901 "%s [options] set-sink-input-mute SINKINPUT 1|0\n\n"
902 " -h, --help Show this help\n"
903 " --version Show version\n\n"
904 " -s, --server=SERVER The name of the server to connect to\n"
905 " -n, --client-name=NAME How to call this client on the server\n"),
906 argv0
, argv0
, argv0
, argv0
, argv0
,
907 argv0
, argv0
, argv0
, argv0
, argv0
,
908 argv0
, argv0
, argv0
, argv0
, argv0
,
909 argv0
, argv0
, argv0
, argv0
, argv0
,
917 int main(int argc
, char *argv
[]) {
918 pa_mainloop
* m
= NULL
;
920 char *server
= NULL
, *bn
;
922 static const struct option long_options
[] = {
923 {"server", 1, NULL
, 's'},
924 {"client-name", 1, NULL
, 'n'},
925 {"version", 0, NULL
, ARG_VERSION
},
926 {"help", 0, NULL
, 'h'},
930 setlocale(LC_ALL
, "");
931 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
933 bn
= pa_path_get_filename(argv
[0]);
935 proplist
= pa_proplist_new();
937 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
945 printf(_("pactl %s\n"
946 "Compiled with libpulse %s\n"
947 "Linked with libpulse %s\n"),
949 pa_get_headers_version(),
950 pa_get_library_version());
956 server
= pa_xstrdup(optarg
);
962 if (!(t
= pa_locale_to_utf8(optarg
)) ||
963 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
965 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
980 if (pa_streq(argv
[optind
], "stat"))
982 else if (pa_streq(argv
[optind
], "exit"))
984 else if (pa_streq(argv
[optind
], "list"))
986 else if (pa_streq(argv
[optind
], "upload-sample")) {
988 action
= UPLOAD_SAMPLE
;
990 if (optind
+1 >= argc
) {
991 pa_log(_("Please specify a sample file to load"));
996 sample_name
= pa_xstrdup(argv
[optind
+2]);
998 char *f
= pa_path_get_filename(argv
[optind
+1]);
999 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1003 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1004 pa_log(_("Failed to open sound file."));
1008 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1009 pa_log(_("Failed to determine sample specification from file."));
1012 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1014 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1015 if (sample_spec
.channels
> 2)
1016 pa_log(_("Warning: Failed to determine sample specification from file."));
1017 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1020 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1021 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1023 } else if (pa_streq(argv
[optind
], "play-sample")) {
1024 action
= PLAY_SAMPLE
;
1025 if (argc
!= optind
+2 && argc
!= optind
+3) {
1026 pa_log(_("You have to specify a sample name to play"));
1030 sample_name
= pa_xstrdup(argv
[optind
+1]);
1032 if (optind
+2 < argc
)
1033 sink_name
= pa_xstrdup(argv
[optind
+2]);
1035 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1036 action
= REMOVE_SAMPLE
;
1037 if (argc
!= optind
+2) {
1038 pa_log(_("You have to specify a sample name to remove"));
1042 sample_name
= pa_xstrdup(argv
[optind
+1]);
1044 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1045 action
= MOVE_SINK_INPUT
;
1046 if (argc
!= optind
+3) {
1047 pa_log(_("You have to specify a sink input index and a sink"));
1051 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1052 sink_name
= pa_xstrdup(argv
[optind
+2]);
1054 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1055 action
= MOVE_SOURCE_OUTPUT
;
1056 if (argc
!= optind
+3) {
1057 pa_log(_("You have to specify a source output index and a source"));
1061 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1062 source_name
= pa_xstrdup(argv
[optind
+2]);
1064 } else if (pa_streq(argv
[optind
], "load-module")) {
1069 action
= LOAD_MODULE
;
1071 if (argc
<= optind
+1) {
1072 pa_log(_("You have to specify a module name and arguments."));
1076 module_name
= argv
[optind
+1];
1078 for (i
= optind
+2; i
< argc
; i
++)
1079 n
+= strlen(argv
[i
])+1;
1082 p
= module_args
= pa_xmalloc(n
);
1084 for (i
= optind
+2; i
< argc
; i
++)
1085 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1088 } else if (pa_streq(argv
[optind
], "unload-module")) {
1089 action
= UNLOAD_MODULE
;
1091 if (argc
!= optind
+2) {
1092 pa_log(_("You have to specify a module index"));
1096 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1098 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1099 action
= SUSPEND_SINK
;
1101 if (argc
> optind
+3 || optind
+1 >= argc
) {
1102 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1106 suspend
= pa_parse_boolean(argv
[argc
-1]);
1108 if (argc
> optind
+2)
1109 sink_name
= pa_xstrdup(argv
[optind
+1]);
1111 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1112 action
= SUSPEND_SOURCE
;
1114 if (argc
> optind
+3 || optind
+1 >= argc
) {
1115 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1119 suspend
= pa_parse_boolean(argv
[argc
-1]);
1121 if (argc
> optind
+2)
1122 source_name
= pa_xstrdup(argv
[optind
+1]);
1123 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1124 action
= SET_CARD_PROFILE
;
1126 if (argc
!= optind
+3) {
1127 pa_log(_("You have to specify a card name/index and a profile name"));
1131 card_name
= pa_xstrdup(argv
[optind
+1]);
1132 profile_name
= pa_xstrdup(argv
[optind
+2]);
1134 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1135 action
= SET_SINK_PORT
;
1137 if (argc
!= optind
+3) {
1138 pa_log(_("You have to specify a sink name/index and a port name"));
1142 sink_name
= pa_xstrdup(argv
[optind
+1]);
1143 port_name
= pa_xstrdup(argv
[optind
+2]);
1145 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1146 action
= SET_SOURCE_PORT
;
1148 if (argc
!= optind
+3) {
1149 pa_log(_("You have to specify a source name/index and a port name"));
1153 source_name
= pa_xstrdup(argv
[optind
+1]);
1154 port_name
= pa_xstrdup(argv
[optind
+2]);
1156 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1158 action
= SET_SINK_VOLUME
;
1160 if (argc
!= optind
+3) {
1161 pa_log(_("You have to specify a sink name/index and a volume"));
1165 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1166 pa_log(_("Invalid volume specification"));
1170 sink_name
= pa_xstrdup(argv
[optind
+1]);
1171 volume
= (pa_volume_t
) v
;
1173 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1175 action
= SET_SOURCE_VOLUME
;
1177 if (argc
!= optind
+3) {
1178 pa_log(_("You have to specify a source name/index and a volume"));
1182 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1183 pa_log(_("Invalid volume specification"));
1187 source_name
= pa_xstrdup(argv
[optind
+1]);
1188 volume
= (pa_volume_t
) v
;
1190 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1192 action
= SET_SINK_INPUT_VOLUME
;
1194 if (argc
!= optind
+3) {
1195 pa_log(_("You have to specify a sink input index and a volume"));
1199 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1200 pa_log(_("Invalid sink input index"));
1204 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1205 pa_log(_("Invalid volume specification"));
1209 volume
= (pa_volume_t
) v
;
1211 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1213 action
= SET_SINK_MUTE
;
1215 if (argc
!= optind
+3) {
1216 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1220 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1221 pa_log(_("Invalid volume specification"));
1225 sink_name
= pa_xstrdup(argv
[optind
+1]);
1228 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1230 action
= SET_SOURCE_MUTE
;
1232 if (argc
!= optind
+3) {
1233 pa_log(_("You have to specify a source name/index and a mute boolean"));
1237 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1238 pa_log(_("Invalid volume specification"));
1242 source_name
= pa_xstrdup(argv
[optind
+1]);
1245 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1247 action
= SET_SINK_INPUT_MUTE
;
1249 if (argc
!= optind
+3) {
1250 pa_log(_("You have to specify a sink input index and a mute boolean"));
1254 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1255 pa_log(_("Invalid sink input index specification"));
1259 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1260 pa_log(_("Invalid volume specification"));
1266 } else if (pa_streq(argv
[optind
], "help")) {
1273 if (action
== NONE
) {
1274 pa_log(_("No valid command specified."));
1278 if (!(m
= pa_mainloop_new())) {
1279 pa_log(_("pa_mainloop_new() failed."));
1283 mainloop_api
= pa_mainloop_get_api(m
);
1285 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1286 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1287 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1288 pa_disable_sigpipe();
1290 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1291 pa_log(_("pa_context_new() failed."));
1295 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1296 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1297 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1301 if (pa_mainloop_run(m
, &ret
) < 0) {
1302 pa_log(_("pa_mainloop_run() failed."));
1308 pa_stream_unref(sample_stream
);
1311 pa_context_unref(context
);
1315 pa_mainloop_free(m
);
1319 pa_xfree(sample_name
);
1320 pa_xfree(sink_name
);
1321 pa_xfree(source_name
);
1322 pa_xfree(module_args
);
1323 pa_xfree(card_name
);
1324 pa_xfree(profile_name
);
1330 pa_proplist_free(proplist
);