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 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
160 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
162 printf(_("User name: %s\n"
165 "Server Version: %s\n"
166 "Default Sample Specification: %s\n"
167 "Default Channel Map: %s\n"
169 "Default Source: %s\n"
177 i
->default_sink_name
,
178 i
->default_source_name
,
184 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
186 static const char *state_table
[] = {
187 [1+PA_SINK_INVALID_STATE
] = "n/a",
188 [1+PA_SINK_RUNNING
] = "RUNNING",
189 [1+PA_SINK_IDLE
] = "IDLE",
190 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
194 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
195 cv
[PA_CVOLUME_SNPRINT_MAX
],
196 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
197 v
[PA_VOLUME_SNPRINT_MAX
],
198 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
199 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
203 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
219 printf(_("Sink #%u\n"
222 "\tDescription: %s\n"
224 "\tSample Specification: %s\n"
225 "\tChannel Map: %s\n"
226 "\tOwner Module: %u\n"
230 "\tBase Volume: %s%s%s\n"
231 "\tMonitor Source: %s\n"
232 "\tLatency: %0.0f usec, configured %0.0f usec\n"
233 "\tFlags: %s%s%s%s%s%s\n"
234 "\tProperties:\n\t\t%s\n"),
236 state_table
[1+i
->state
],
238 pa_strnull(i
->description
),
239 pa_strnull(i
->driver
),
240 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
241 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
244 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
245 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
246 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
247 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
248 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
249 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
250 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
251 pa_strnull(i
->monitor_source_name
),
252 (double) i
->latency
, (double) i
->configured_latency
,
253 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
254 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
255 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
256 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
257 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
258 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
259 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
264 pa_sink_port_info
**p
;
266 printf(_("\tPorts:\n"));
267 for (p
= i
->ports
; *p
; p
++)
268 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
272 printf(_("\tActive Port: %s\n"),
273 i
->active_port
->name
);
276 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
278 static const char *state_table
[] = {
279 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
280 [1+PA_SOURCE_RUNNING
] = "RUNNING",
281 [1+PA_SOURCE_IDLE
] = "IDLE",
282 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
286 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
287 cv
[PA_CVOLUME_SNPRINT_MAX
],
288 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
289 v
[PA_VOLUME_SNPRINT_MAX
],
290 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
291 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
295 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
311 printf(_("Source #%u\n"
314 "\tDescription: %s\n"
316 "\tSample Specification: %s\n"
317 "\tChannel Map: %s\n"
318 "\tOwner Module: %u\n"
322 "\tBase Volume: %s%s%s\n"
323 "\tMonitor of Sink: %s\n"
324 "\tLatency: %0.0f usec, configured %0.0f usec\n"
325 "\tFlags: %s%s%s%s%s%s\n"
326 "\tProperties:\n\t\t%s\n"),
328 state_table
[1+i
->state
],
330 pa_strnull(i
->description
),
331 pa_strnull(i
->driver
),
332 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
333 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
336 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
337 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
338 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
339 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
340 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
341 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
342 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
343 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
344 (double) i
->latency
, (double) i
->configured_latency
,
345 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
346 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
347 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
348 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
349 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
350 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
351 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
356 pa_source_port_info
**p
;
358 printf(_("\tPorts:\n"));
359 for (p
= i
->ports
; *p
; p
++)
360 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
364 printf(_("\tActive Port: %s\n"),
365 i
->active_port
->name
);
368 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
373 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
389 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
391 printf(_("Module #%u\n"
394 "\tUsage counter: %s\n"
395 "\tProperties:\n\t\t%s\n"),
398 i
->argument
? i
->argument
: "",
399 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
400 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
405 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
410 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
426 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
428 printf(_("Client #%u\n"
430 "\tOwner Module: %s\n"
431 "\tProperties:\n\t\t%s\n"),
433 pa_strnull(i
->driver
),
434 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
435 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
440 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
445 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
461 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
463 printf(_("Card #%u\n"
466 "\tOwner Module: %s\n"
467 "\tProperties:\n\t\t%s\n"),
470 pa_strnull(i
->driver
),
471 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
472 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
475 pa_card_profile_info
*p
;
477 printf(_("\tProfiles:\n"));
478 for (p
= i
->profiles
; p
->name
; p
++)
479 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
482 if (i
->active_profile
)
483 printf(_("\tActive Profile: %s\n"),
484 i
->active_profile
->name
);
489 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
490 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
];
494 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
510 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
511 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
513 printf(_("Sink Input #%u\n"
515 "\tOwner Module: %s\n"
518 "\tSample Specification: %s\n"
519 "\tChannel Map: %s\n"
524 "\tBuffer Latency: %0.0f usec\n"
525 "\tSink Latency: %0.0f usec\n"
526 "\tResample method: %s\n"
527 "\tProperties:\n\t\t%s\n"),
529 pa_strnull(i
->driver
),
530 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
531 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
533 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
534 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
536 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
537 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
538 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
539 (double) i
->buffer_usec
,
540 (double) i
->sink_usec
,
541 i
->resample_method
? i
->resample_method
: _("n/a"),
542 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
547 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
548 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
552 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
569 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
570 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
572 printf(_("Source Output #%u\n"
574 "\tOwner Module: %s\n"
577 "\tSample Specification: %s\n"
578 "\tChannel Map: %s\n"
579 "\tBuffer Latency: %0.0f usec\n"
580 "\tSource Latency: %0.0f usec\n"
581 "\tResample method: %s\n"
582 "\tProperties:\n\t\t%s\n"),
584 pa_strnull(i
->driver
),
585 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
586 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
588 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
589 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
590 (double) i
->buffer_usec
,
591 (double) i
->source_usec
,
592 i
->resample_method
? i
->resample_method
: _("n/a"),
593 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
598 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
599 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
];
603 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
619 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
621 printf(_("Sample #%u\n"
623 "\tSample Specification: %s\n"
624 "\tChannel Map: %s\n"
628 "\tDuration: %0.1fs\n"
632 "\tProperties:\n\t\t%s\n"),
635 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
636 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
637 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
638 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
639 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
640 (double) i
->duration
/1000000.0,
643 i
->filename
? i
->filename
: _("n/a"),
644 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
649 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
651 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
659 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
660 if (idx
== PA_INVALID_INDEX
) {
661 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
671 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
674 switch (pa_stream_get_state(s
)) {
675 case PA_STREAM_CREATING
:
676 case PA_STREAM_READY
:
679 case PA_STREAM_TERMINATED
:
683 case PA_STREAM_FAILED
:
685 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
690 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
693 pa_assert(s
&& length
&& sndfile
);
695 d
= pa_xmalloc(length
);
697 pa_assert(sample_length
>= length
);
698 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
700 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
702 pa_log(_("Premature end of file"));
707 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
709 sample_length
-= length
;
711 if (sample_length
<= 0) {
712 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
713 pa_stream_finish_upload(sample_stream
);
717 static void context_state_callback(pa_context
*c
, void *userdata
) {
719 switch (pa_context_get_state(c
)) {
720 case PA_CONTEXT_CONNECTING
:
721 case PA_CONTEXT_AUTHORIZING
:
722 case PA_CONTEXT_SETTING_NAME
:
725 case PA_CONTEXT_READY
:
729 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
730 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
734 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
738 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
742 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
743 pa_assert(sample_stream
);
745 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
746 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
747 pa_stream_connect_upload(sample_stream
, sample_length
);
751 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
756 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
757 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
758 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
759 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
760 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
761 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
762 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
763 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
766 case MOVE_SINK_INPUT
:
767 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
770 case MOVE_SOURCE_OUTPUT
:
771 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
775 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
779 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
784 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
786 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
791 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
793 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
796 case SET_CARD_PROFILE
:
797 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
801 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
804 case SET_SOURCE_PORT
:
805 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
809 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
812 case SET_SOURCE_MUTE
:
813 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
816 case SET_SINK_INPUT_MUTE
:
817 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
820 case SET_SINK_VOLUME
: {
823 pa_cvolume_set(&v
, 1, volume
);
824 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
828 case SET_SOURCE_VOLUME
: {
831 pa_cvolume_set(&v
, 1, volume
);
832 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
836 case SET_SINK_INPUT_VOLUME
: {
839 pa_cvolume_set(&v
, 1, volume
);
840 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
845 pa_assert_not_reached();
849 case PA_CONTEXT_TERMINATED
:
853 case PA_CONTEXT_FAILED
:
855 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
860 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
861 pa_log(_("Got SIGINT, exiting."));
865 static void help(const char *argv0
) {
867 printf(_("%s [options] stat\n"
868 "%s [options] list\n"
869 "%s [options] exit\n"
870 "%s [options] upload-sample FILENAME [NAME]\n"
871 "%s [options] play-sample NAME [SINK]\n"
872 "%s [options] remove-sample NAME\n"
873 "%s [options] move-sink-input SINKINPUT SINK\n"
874 "%s [options] move-source-output SOURCEOUTPUT SOURCE\n"
875 "%s [options] load-module NAME [ARGS ...]\n"
876 "%s [options] unload-module MODULE\n"
877 "%s [options] suspend-sink SINK 1|0\n"
878 "%s [options] suspend-source SOURCE 1|0\n"
879 "%s [options] set-card-profile CARD PROFILE\n"
880 "%s [options] set-sink-port SINK PORT\n"
881 "%s [options] set-source-port SOURCE PORT\n"
882 "%s [options] set-sink-volume SINK VOLUME\n"
883 "%s [options] set-source-volume SOURCE VOLUME\n"
884 "%s [options] set-sink-input-volume SINKINPUT VOLUME\n"
885 "%s [options] set-sink-mute SINK 1|0\n"
886 "%s [options] set-source-mute SOURCE 1|0\n"
887 "%s [options] set-sink-input-mute SINKINPUT 1|0\n\n"
888 " -h, --help Show this help\n"
889 " --version Show version\n\n"
890 " -s, --server=SERVER The name of the server to connect to\n"
891 " -n, --client-name=NAME How to call this client on the server\n"),
892 argv0
, argv0
, argv0
, argv0
, argv0
,
893 argv0
, argv0
, argv0
, argv0
, argv0
,
894 argv0
, argv0
, argv0
, argv0
, argv0
,
895 argv0
, argv0
, argv0
, argv0
, argv0
,
903 int main(int argc
, char *argv
[]) {
904 pa_mainloop
* m
= NULL
;
906 char *server
= NULL
, *bn
;
908 static const struct option long_options
[] = {
909 {"server", 1, NULL
, 's'},
910 {"client-name", 1, NULL
, 'n'},
911 {"version", 0, NULL
, ARG_VERSION
},
912 {"help", 0, NULL
, 'h'},
916 setlocale(LC_ALL
, "");
917 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
919 bn
= pa_path_get_filename(argv
[0]);
921 proplist
= pa_proplist_new();
923 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
931 printf(_("pactl %s\n"
932 "Compiled with libpulse %s\n"
933 "Linked with libpulse %s\n"),
935 pa_get_headers_version(),
936 pa_get_library_version());
942 server
= pa_xstrdup(optarg
);
948 if (!(t
= pa_locale_to_utf8(optarg
)) ||
949 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
951 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
966 if (pa_streq(argv
[optind
], "stat"))
968 else if (pa_streq(argv
[optind
], "exit"))
970 else if (pa_streq(argv
[optind
], "list"))
972 else if (pa_streq(argv
[optind
], "upload-sample")) {
974 action
= UPLOAD_SAMPLE
;
976 if (optind
+1 >= argc
) {
977 pa_log(_("Please specify a sample file to load"));
982 sample_name
= pa_xstrdup(argv
[optind
+2]);
984 char *f
= pa_path_get_filename(argv
[optind
+1]);
985 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
989 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
990 pa_log(_("Failed to open sound file."));
994 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
995 pa_log(_("Failed to determine sample specification from file."));
998 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1000 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1001 if (sample_spec
.channels
> 2)
1002 pa_log(_("Warning: Failed to determine sample specification from file."));
1003 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1006 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1007 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1009 } else if (pa_streq(argv
[optind
], "play-sample")) {
1010 action
= PLAY_SAMPLE
;
1011 if (argc
!= optind
+2 && argc
!= optind
+3) {
1012 pa_log(_("You have to specify a sample name to play"));
1016 sample_name
= pa_xstrdup(argv
[optind
+1]);
1018 if (optind
+2 < argc
)
1019 sink_name
= pa_xstrdup(argv
[optind
+2]);
1021 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1022 action
= REMOVE_SAMPLE
;
1023 if (argc
!= optind
+2) {
1024 pa_log(_("You have to specify a sample name to remove"));
1028 sample_name
= pa_xstrdup(argv
[optind
+1]);
1030 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1031 action
= MOVE_SINK_INPUT
;
1032 if (argc
!= optind
+3) {
1033 pa_log(_("You have to specify a sink input index and a sink"));
1037 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1038 sink_name
= pa_xstrdup(argv
[optind
+2]);
1040 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1041 action
= MOVE_SOURCE_OUTPUT
;
1042 if (argc
!= optind
+3) {
1043 pa_log(_("You have to specify a source output index and a source"));
1047 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1048 source_name
= pa_xstrdup(argv
[optind
+2]);
1050 } else if (pa_streq(argv
[optind
], "load-module")) {
1055 action
= LOAD_MODULE
;
1057 if (argc
<= optind
+1) {
1058 pa_log(_("You have to specify a module name and arguments."));
1062 module_name
= argv
[optind
+1];
1064 for (i
= optind
+2; i
< argc
; i
++)
1065 n
+= strlen(argv
[i
])+1;
1068 p
= module_args
= pa_xmalloc(n
);
1070 for (i
= optind
+2; i
< argc
; i
++)
1071 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1074 } else if (pa_streq(argv
[optind
], "unload-module")) {
1075 action
= UNLOAD_MODULE
;
1077 if (argc
!= optind
+2) {
1078 pa_log(_("You have to specify a module index"));
1082 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1084 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1085 action
= SUSPEND_SINK
;
1087 if (argc
> optind
+3 || optind
+1 >= argc
) {
1088 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1092 suspend
= pa_parse_boolean(argv
[argc
-1]);
1094 if (argc
> optind
+2)
1095 sink_name
= pa_xstrdup(argv
[optind
+1]);
1097 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1098 action
= SUSPEND_SOURCE
;
1100 if (argc
> optind
+3 || optind
+1 >= argc
) {
1101 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1105 suspend
= pa_parse_boolean(argv
[argc
-1]);
1107 if (argc
> optind
+2)
1108 source_name
= pa_xstrdup(argv
[optind
+1]);
1109 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1110 action
= SET_CARD_PROFILE
;
1112 if (argc
!= optind
+3) {
1113 pa_log(_("You have to specify a card name/index and a profile name"));
1117 card_name
= pa_xstrdup(argv
[optind
+1]);
1118 profile_name
= pa_xstrdup(argv
[optind
+2]);
1120 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1121 action
= SET_SINK_PORT
;
1123 if (argc
!= optind
+3) {
1124 pa_log(_("You have to specify a sink name/index and a port name"));
1128 sink_name
= pa_xstrdup(argv
[optind
+1]);
1129 port_name
= pa_xstrdup(argv
[optind
+2]);
1131 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1132 action
= SET_SOURCE_PORT
;
1134 if (argc
!= optind
+3) {
1135 pa_log(_("You have to specify a source name/index and a port name"));
1139 source_name
= pa_xstrdup(argv
[optind
+1]);
1140 port_name
= pa_xstrdup(argv
[optind
+2]);
1142 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1144 action
= SET_SINK_VOLUME
;
1146 if (argc
!= optind
+3) {
1147 pa_log(_("You have to specify a sink name/index and a volume"));
1151 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1152 pa_log(_("Invalid volume specification"));
1156 sink_name
= pa_xstrdup(argv
[optind
+1]);
1157 volume
= (pa_volume_t
) v
;
1159 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1161 action
= SET_SOURCE_VOLUME
;
1163 if (argc
!= optind
+3) {
1164 pa_log(_("You have to specify a source name/index and a volume"));
1168 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1169 pa_log(_("Invalid volume specification"));
1173 source_name
= pa_xstrdup(argv
[optind
+1]);
1174 volume
= (pa_volume_t
) v
;
1176 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1178 action
= SET_SINK_INPUT_VOLUME
;
1180 if (argc
!= optind
+3) {
1181 pa_log(_("You have to specify a sink input index and a volume"));
1185 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1186 pa_log(_("Invalid sink input index"));
1190 if (pa_atou(argv
[optind
+2], &v
) < 0) {
1191 pa_log(_("Invalid volume specification"));
1195 volume
= (pa_volume_t
) v
;
1197 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1199 action
= SET_SINK_MUTE
;
1201 if (argc
!= optind
+3) {
1202 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1206 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1207 pa_log(_("Invalid volume specification"));
1211 sink_name
= pa_xstrdup(argv
[optind
+1]);
1214 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1216 action
= SET_SOURCE_MUTE
;
1218 if (argc
!= optind
+3) {
1219 pa_log(_("You have to specify a source name/index and a mute boolean"));
1223 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1224 pa_log(_("Invalid volume specification"));
1228 source_name
= pa_xstrdup(argv
[optind
+1]);
1231 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1233 action
= SET_SINK_INPUT_MUTE
;
1235 if (argc
!= optind
+3) {
1236 pa_log(_("You have to specify a sink input index and a mute boolean"));
1240 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1241 pa_log(_("Invalid sink input index specification"));
1245 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1246 pa_log(_("Invalid volume specification"));
1252 } else if (pa_streq(argv
[optind
], "help")) {
1259 if (action
== NONE
) {
1260 pa_log(_("No valid command specified."));
1264 if (!(m
= pa_mainloop_new())) {
1265 pa_log(_("pa_mainloop_new() failed."));
1269 mainloop_api
= pa_mainloop_get_api(m
);
1271 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1272 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1273 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1274 pa_disable_sigpipe();
1276 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1277 pa_log(_("pa_context_new() failed."));
1281 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1282 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1283 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1287 if (pa_mainloop_run(m
, &ret
) < 0) {
1288 pa_log(_("pa_mainloop_run() failed."));
1294 pa_stream_unref(sample_stream
);
1297 pa_context_unref(context
);
1301 pa_mainloop_free(m
);
1305 pa_xfree(sample_name
);
1306 pa_xfree(sink_name
);
1307 pa_xfree(source_name
);
1308 pa_xfree(module_args
);
1309 pa_xfree(card_name
);
1310 pa_xfree(profile_name
);
1316 pa_proplist_free(proplist
);