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"
190 i
->default_sink_name
,
191 i
->default_source_name
,
197 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
199 static const char *state_table
[] = {
200 [1+PA_SINK_INVALID_STATE
] = "n/a",
201 [1+PA_SINK_RUNNING
] = "RUNNING",
202 [1+PA_SINK_IDLE
] = "IDLE",
203 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
207 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
208 cv
[PA_CVOLUME_SNPRINT_MAX
],
209 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
210 v
[PA_VOLUME_SNPRINT_MAX
],
211 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
212 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
216 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
232 printf(_("Sink #%u\n"
235 "\tDescription: %s\n"
237 "\tSample Specification: %s\n"
238 "\tChannel Map: %s\n"
239 "\tOwner Module: %u\n"
243 "\tBase Volume: %s%s%s\n"
244 "\tMonitor Source: %s\n"
245 "\tLatency: %0.0f usec, configured %0.0f usec\n"
246 "\tFlags: %s%s%s%s%s%s\n"
247 "\tProperties:\n\t\t%s\n"),
249 state_table
[1+i
->state
],
251 pa_strnull(i
->description
),
252 pa_strnull(i
->driver
),
253 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
254 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
257 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
258 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
259 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
260 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
261 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
262 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
263 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
264 pa_strnull(i
->monitor_source_name
),
265 (double) i
->latency
, (double) i
->configured_latency
,
266 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
267 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
268 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
269 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
270 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
271 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
272 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
277 pa_sink_port_info
**p
;
279 printf(_("\tPorts:\n"));
280 for (p
= i
->ports
; *p
; p
++)
281 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
285 printf(_("\tActive Port: %s\n"),
286 i
->active_port
->name
);
289 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
291 static const char *state_table
[] = {
292 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
293 [1+PA_SOURCE_RUNNING
] = "RUNNING",
294 [1+PA_SOURCE_IDLE
] = "IDLE",
295 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
299 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
300 cv
[PA_CVOLUME_SNPRINT_MAX
],
301 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
302 v
[PA_VOLUME_SNPRINT_MAX
],
303 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
304 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
308 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
324 printf(_("Source #%u\n"
327 "\tDescription: %s\n"
329 "\tSample Specification: %s\n"
330 "\tChannel Map: %s\n"
331 "\tOwner Module: %u\n"
335 "\tBase Volume: %s%s%s\n"
336 "\tMonitor of Sink: %s\n"
337 "\tLatency: %0.0f usec, configured %0.0f usec\n"
338 "\tFlags: %s%s%s%s%s%s\n"
339 "\tProperties:\n\t\t%s\n"),
341 state_table
[1+i
->state
],
343 pa_strnull(i
->description
),
344 pa_strnull(i
->driver
),
345 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
346 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
349 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
350 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
351 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
352 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
353 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
354 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
355 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
356 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
357 (double) i
->latency
, (double) i
->configured_latency
,
358 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
359 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
360 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
361 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
362 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
363 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
364 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
369 pa_source_port_info
**p
;
371 printf(_("\tPorts:\n"));
372 for (p
= i
->ports
; *p
; p
++)
373 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
377 printf(_("\tActive Port: %s\n"),
378 i
->active_port
->name
);
381 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
386 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
402 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
404 printf(_("Module #%u\n"
407 "\tUsage counter: %s\n"
408 "\tProperties:\n\t\t%s\n"),
411 i
->argument
? i
->argument
: "",
412 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
413 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
418 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
423 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
439 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
441 printf(_("Client #%u\n"
443 "\tOwner Module: %s\n"
444 "\tProperties:\n\t\t%s\n"),
446 pa_strnull(i
->driver
),
447 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
448 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
453 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
458 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
474 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
476 printf(_("Card #%u\n"
479 "\tOwner Module: %s\n"
480 "\tProperties:\n\t\t%s\n"),
483 pa_strnull(i
->driver
),
484 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
485 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
488 pa_card_profile_info
*p
;
490 printf(_("\tProfiles:\n"));
491 for (p
= i
->profiles
; p
->name
; p
++)
492 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
495 if (i
->active_profile
)
496 printf(_("\tActive Profile: %s\n"),
497 i
->active_profile
->name
);
502 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
503 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
];
507 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
523 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
524 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
526 printf(_("Sink Input #%u\n"
528 "\tOwner Module: %s\n"
531 "\tSample Specification: %s\n"
532 "\tChannel Map: %s\n"
537 "\tBuffer Latency: %0.0f usec\n"
538 "\tSink Latency: %0.0f usec\n"
539 "\tResample method: %s\n"
540 "\tProperties:\n\t\t%s\n"),
542 pa_strnull(i
->driver
),
543 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
544 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
546 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
547 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
549 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
550 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
551 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
552 (double) i
->buffer_usec
,
553 (double) i
->sink_usec
,
554 i
->resample_method
? i
->resample_method
: _("n/a"),
555 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
560 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
561 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
565 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
582 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
583 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
585 printf(_("Source Output #%u\n"
587 "\tOwner Module: %s\n"
590 "\tSample Specification: %s\n"
591 "\tChannel Map: %s\n"
592 "\tBuffer Latency: %0.0f usec\n"
593 "\tSource Latency: %0.0f usec\n"
594 "\tResample method: %s\n"
595 "\tProperties:\n\t\t%s\n"),
597 pa_strnull(i
->driver
),
598 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
599 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
601 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
602 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
603 (double) i
->buffer_usec
,
604 (double) i
->source_usec
,
605 i
->resample_method
? i
->resample_method
: _("n/a"),
606 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
611 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
612 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
];
616 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
632 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
634 printf(_("Sample #%u\n"
636 "\tSample Specification: %s\n"
637 "\tChannel Map: %s\n"
641 "\tDuration: %0.1fs\n"
645 "\tProperties:\n\t\t%s\n"),
648 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
649 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
650 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
651 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
652 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
653 (double) i
->duration
/1000000.0,
656 i
->filename
? i
->filename
: _("n/a"),
657 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
662 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
664 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
672 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
673 if (idx
== PA_INVALID_INDEX
) {
674 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
684 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
687 switch (pa_stream_get_state(s
)) {
688 case PA_STREAM_CREATING
:
689 case PA_STREAM_READY
:
692 case PA_STREAM_TERMINATED
:
696 case PA_STREAM_FAILED
:
698 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
703 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
706 pa_assert(s
&& length
&& sndfile
);
708 d
= pa_xmalloc(length
);
710 pa_assert(sample_length
>= length
);
711 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
713 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
715 pa_log(_("Premature end of file"));
720 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
722 sample_length
-= length
;
724 if (sample_length
<= 0) {
725 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
726 pa_stream_finish_upload(sample_stream
);
730 static void context_state_callback(pa_context
*c
, void *userdata
) {
732 switch (pa_context_get_state(c
)) {
733 case PA_CONTEXT_CONNECTING
:
734 case PA_CONTEXT_AUTHORIZING
:
735 case PA_CONTEXT_SETTING_NAME
:
738 case PA_CONTEXT_READY
:
742 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
743 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
747 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
751 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
755 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
756 pa_assert(sample_stream
);
758 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
759 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
760 pa_stream_connect_upload(sample_stream
, sample_length
);
764 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
769 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
770 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
771 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
772 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
773 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
774 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
775 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
776 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
779 case MOVE_SINK_INPUT
:
780 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
783 case MOVE_SOURCE_OUTPUT
:
784 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
788 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
792 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
797 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
799 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
804 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
806 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
809 case SET_CARD_PROFILE
:
810 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
814 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
817 case SET_SOURCE_PORT
:
818 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
822 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
825 case SET_SOURCE_MUTE
:
826 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
829 case SET_SINK_INPUT_MUTE
:
830 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
833 case SET_SINK_VOLUME
: {
836 pa_cvolume_set(&v
, 1, volume
);
837 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
841 case SET_SOURCE_VOLUME
: {
844 pa_cvolume_set(&v
, 1, volume
);
845 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
849 case SET_SINK_INPUT_VOLUME
: {
852 pa_cvolume_set(&v
, 1, volume
);
853 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
858 pa_assert_not_reached();
862 case PA_CONTEXT_TERMINATED
:
866 case PA_CONTEXT_FAILED
:
868 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
873 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
874 pa_log(_("Got SIGINT, exiting."));
878 static void help(const char *argv0
) {
880 printf(_("%s [options] stat\n"
881 "%s [options] list\n"
882 "%s [options] exit\n"
883 "%s [options] upload-sample FILENAME [NAME]\n"
884 "%s [options] play-sample NAME [SINK]\n"
885 "%s [options] remove-sample NAME\n"
886 "%s [options] move-sink-input SINKINPUT SINK\n"
887 "%s [options] move-source-output SOURCEOUTPUT SOURCE\n"
888 "%s [options] load-module NAME [ARGS ...]\n"
889 "%s [options] unload-module MODULE\n"
890 "%s [options] suspend-sink SINK 1|0\n"
891 "%s [options] suspend-source SOURCE 1|0\n"
892 "%s [options] set-card-profile CARD PROFILE\n"
893 "%s [options] set-sink-port SINK PORT\n"
894 "%s [options] set-source-port SOURCE PORT\n"
895 "%s [options] set-sink-volume SINK VOLUME\n"
896 "%s [options] set-source-volume SOURCE VOLUME\n"
897 "%s [options] set-sink-input-volume SINKINPUT VOLUME\n"
898 "%s [options] set-sink-mute SINK 1|0\n"
899 "%s [options] set-source-mute SOURCE 1|0\n"
900 "%s [options] set-sink-input-mute SINKINPUT 1|0\n\n"
901 " -h, --help Show this help\n"
902 " --version Show version\n\n"
903 " -s, --server=SERVER The name of the server to connect to\n"
904 " -n, --client-name=NAME How to call this client on the server\n"),
905 argv0
, argv0
, argv0
, argv0
, argv0
,
906 argv0
, argv0
, argv0
, argv0
, argv0
,
907 argv0
, argv0
, argv0
, argv0
, argv0
,
908 argv0
, argv0
, argv0
, argv0
, argv0
,
916 int main(int argc
, char *argv
[]) {
917 pa_mainloop
* m
= NULL
;
919 char *server
= NULL
, *bn
;
921 static const struct option long_options
[] = {
922 {"server", 1, NULL
, 's'},
923 {"client-name", 1, NULL
, 'n'},
924 {"version", 0, NULL
, ARG_VERSION
},
925 {"help", 0, NULL
, 'h'},
929 setlocale(LC_ALL
, "");
930 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
932 bn
= pa_path_get_filename(argv
[0]);
934 proplist
= pa_proplist_new();
936 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
944 printf(_("pactl %s\n"
945 "Compiled with libpulse %s\n"
946 "Linked with libpulse %s\n"),
948 pa_get_headers_version(),
949 pa_get_library_version());
955 server
= pa_xstrdup(optarg
);
961 if (!(t
= pa_locale_to_utf8(optarg
)) ||
962 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
964 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
979 if (pa_streq(argv
[optind
], "stat"))
981 else if (pa_streq(argv
[optind
], "exit"))
983 else if (pa_streq(argv
[optind
], "list"))
985 else if (pa_streq(argv
[optind
], "upload-sample")) {
987 action
= UPLOAD_SAMPLE
;
989 if (optind
+1 >= argc
) {
990 pa_log(_("Please specify a sample file to load"));
995 sample_name
= pa_xstrdup(argv
[optind
+2]);
997 char *f
= pa_path_get_filename(argv
[optind
+1]);
998 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1002 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1003 pa_log(_("Failed to open sound file."));
1007 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1008 pa_log(_("Failed to determine sample specification from file."));
1011 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1013 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1014 if (sample_spec
.channels
> 2)
1015 pa_log(_("Warning: Failed to determine sample specification from file."));
1016 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1019 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1020 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1022 } else if (pa_streq(argv
[optind
], "play-sample")) {
1023 action
= PLAY_SAMPLE
;
1024 if (argc
!= optind
+2 && argc
!= optind
+3) {
1025 pa_log(_("You have to specify a sample name to play"));
1029 sample_name
= pa_xstrdup(argv
[optind
+1]);
1031 if (optind
+2 < argc
)
1032 sink_name
= pa_xstrdup(argv
[optind
+2]);
1034 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1035 action
= REMOVE_SAMPLE
;
1036 if (argc
!= optind
+2) {
1037 pa_log(_("You have to specify a sample name to remove"));
1041 sample_name
= pa_xstrdup(argv
[optind
+1]);
1043 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1044 action
= MOVE_SINK_INPUT
;
1045 if (argc
!= optind
+3) {
1046 pa_log(_("You have to specify a sink input index and a sink"));
1050 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1051 sink_name
= pa_xstrdup(argv
[optind
+2]);
1053 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1054 action
= MOVE_SOURCE_OUTPUT
;
1055 if (argc
!= optind
+3) {
1056 pa_log(_("You have to specify a source output index and a source"));
1060 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1061 source_name
= pa_xstrdup(argv
[optind
+2]);
1063 } else if (pa_streq(argv
[optind
], "load-module")) {
1068 action
= LOAD_MODULE
;
1070 if (argc
<= optind
+1) {
1071 pa_log(_("You have to specify a module name and arguments."));
1075 module_name
= argv
[optind
+1];
1077 for (i
= optind
+2; i
< argc
; i
++)
1078 n
+= strlen(argv
[i
])+1;
1081 p
= module_args
= pa_xmalloc(n
);
1083 for (i
= optind
+2; i
< argc
; i
++)
1084 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1087 } else if (pa_streq(argv
[optind
], "unload-module")) {
1088 action
= UNLOAD_MODULE
;
1090 if (argc
!= optind
+2) {
1091 pa_log(_("You have to specify a module index"));
1095 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1097 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1098 action
= SUSPEND_SINK
;
1100 if (argc
> optind
+3 || optind
+1 >= argc
) {
1101 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1105 suspend
= pa_parse_boolean(argv
[argc
-1]);
1107 if (argc
> optind
+2)
1108 sink_name
= pa_xstrdup(argv
[optind
+1]);
1110 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1111 action
= SUSPEND_SOURCE
;
1113 if (argc
> optind
+3 || optind
+1 >= argc
) {
1114 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1118 suspend
= pa_parse_boolean(argv
[argc
-1]);
1120 if (argc
> optind
+2)
1121 source_name
= pa_xstrdup(argv
[optind
+1]);
1122 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1123 action
= SET_CARD_PROFILE
;
1125 if (argc
!= optind
+3) {
1126 pa_log(_("You have to specify a card name/index and a profile name"));
1130 card_name
= pa_xstrdup(argv
[optind
+1]);
1131 profile_name
= pa_xstrdup(argv
[optind
+2]);
1133 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1134 action
= SET_SINK_PORT
;
1136 if (argc
!= optind
+3) {
1137 pa_log(_("You have to specify a sink name/index and a port name"));
1141 sink_name
= pa_xstrdup(argv
[optind
+1]);
1142 port_name
= pa_xstrdup(argv
[optind
+2]);
1144 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1145 action
= SET_SOURCE_PORT
;
1147 if (argc
!= optind
+3) {
1148 pa_log(_("You have to specify a source name/index and a port name"));
1152 source_name
= pa_xstrdup(argv
[optind
+1]);
1153 port_name
= pa_xstrdup(argv
[optind
+2]);
1155 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1157 action
= SET_SINK_VOLUME
;
1159 if (argc
!= optind
+3) {
1160 pa_log(_("You have to specify a sink name/index and a volume"));
1164 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1165 pa_log(_("Invalid volume specification"));
1169 sink_name
= pa_xstrdup(argv
[optind
+1]);
1170 volume
= (pa_volume_t
) v
;
1172 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1174 action
= SET_SOURCE_VOLUME
;
1176 if (argc
!= optind
+3) {
1177 pa_log(_("You have to specify a source name/index and a volume"));
1181 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1182 pa_log(_("Invalid volume specification"));
1186 source_name
= pa_xstrdup(argv
[optind
+1]);
1187 volume
= (pa_volume_t
) v
;
1189 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1191 action
= SET_SINK_INPUT_VOLUME
;
1193 if (argc
!= optind
+3) {
1194 pa_log(_("You have to specify a sink input index and a volume"));
1198 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1199 pa_log(_("Invalid sink input index"));
1203 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1204 pa_log(_("Invalid volume specification"));
1208 volume
= (pa_volume_t
) v
;
1210 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1212 action
= SET_SINK_MUTE
;
1214 if (argc
!= optind
+3) {
1215 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1219 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1220 pa_log(_("Invalid volume specification"));
1224 sink_name
= pa_xstrdup(argv
[optind
+1]);
1227 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1229 action
= SET_SOURCE_MUTE
;
1231 if (argc
!= optind
+3) {
1232 pa_log(_("You have to specify a source name/index and a mute boolean"));
1236 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1237 pa_log(_("Invalid volume specification"));
1241 source_name
= pa_xstrdup(argv
[optind
+1]);
1244 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1246 action
= SET_SINK_INPUT_MUTE
;
1248 if (argc
!= optind
+3) {
1249 pa_log(_("You have to specify a sink input index and a mute boolean"));
1253 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1254 pa_log(_("Invalid sink input index specification"));
1258 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1259 pa_log(_("Invalid volume specification"));
1265 } else if (pa_streq(argv
[optind
], "help")) {
1272 if (action
== NONE
) {
1273 pa_log(_("No valid command specified."));
1277 if (!(m
= pa_mainloop_new())) {
1278 pa_log(_("pa_mainloop_new() failed."));
1282 mainloop_api
= pa_mainloop_get_api(m
);
1284 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1285 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1286 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1287 pa_disable_sigpipe();
1289 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1290 pa_log(_("pa_context_new() failed."));
1294 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1295 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1296 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1300 if (pa_mainloop_run(m
, &ret
) < 0) {
1301 pa_log(_("pa_mainloop_run() failed."));
1307 pa_stream_unref(sample_stream
);
1310 pa_context_unref(context
);
1314 pa_mainloop_free(m
);
1318 pa_xfree(sample_name
);
1319 pa_xfree(sink_name
);
1320 pa_xfree(source_name
);
1321 pa_xfree(module_args
);
1322 pa_xfree(card_name
);
1323 pa_xfree(profile_name
);
1329 pa_proplist_free(proplist
);