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/pulseaudio.h>
40 #include <pulse/ext-device-restore.h>
42 #include <pulsecore/i18n.h>
43 #include <pulsecore/macro.h>
44 #include <pulsecore/core-util.h>
45 #include <pulsecore/log.h>
46 #include <pulsecore/sndfile-util.h>
48 static pa_context
*context
= NULL
;
49 static pa_mainloop_api
*mainloop_api
= NULL
;
64 sink_input_idx
= PA_INVALID_INDEX
,
65 source_output_idx
= PA_INVALID_INDEX
,
66 sink_idx
= PA_INVALID_INDEX
;
68 static pa_bool_t short_list_format
= FALSE
;
69 static uint32_t module_index
;
70 static int32_t latency_offset
;
71 static pa_bool_t suspend
;
72 static pa_volume_t volume
;
73 static enum volume_flags
{
78 VOL_ABSOLUTE
= 0 << 4,
79 VOL_RELATIVE
= 1 << 4,
82 static enum mute_flags
{
87 } mute
= INVALID_MUTE
;
89 static pa_proplist
*proplist
= NULL
;
91 static SNDFILE
*sndfile
= NULL
;
92 static pa_stream
*sample_stream
= NULL
;
93 static pa_sample_spec sample_spec
;
94 static pa_channel_map channel_map
;
95 static size_t sample_length
= 0;
96 static int actions
= 1;
98 static pa_bool_t nl
= FALSE
;
122 SET_SINK_INPUT_VOLUME
,
123 SET_SOURCE_OUTPUT_VOLUME
,
127 SET_SOURCE_OUTPUT_MUTE
,
129 SET_PORT_LATENCY_OFFSET
,
133 static void quit(int ret
) {
134 pa_assert(mainloop_api
);
135 mainloop_api
->quit(mainloop_api
, ret
);
138 static void context_drain_complete(pa_context
*c
, void *userdata
) {
139 pa_context_disconnect(c
);
142 static void drain(void) {
145 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
146 pa_context_disconnect(context
);
148 pa_operation_unref(o
);
151 static void complete_action(void) {
152 pa_assert(actions
> 0);
158 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
159 char s
[PA_BYTES_SNPRINT_MAX
];
161 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
166 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
167 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
169 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
170 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
172 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
173 printf(_("Sample cache size: %s\n"), s
);
178 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
179 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
182 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
187 printf(_("Server String: %s\n"
188 "Library Protocol Version: %u\n"
189 "Server Protocol Version: %u\n"
193 pa_context_get_server(c
),
194 pa_context_get_protocol_version(c
),
195 pa_context_get_server_protocol_version(c
),
196 pa_yes_no(pa_context_is_local(c
)),
197 pa_context_get_index(c
),
198 pa_context_get_tile_size(c
, NULL
));
200 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
201 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
203 printf(_("User Name: %s\n"
206 "Server Version: %s\n"
207 "Default Sample Specification: %s\n"
208 "Default Channel Map: %s\n"
210 "Default Source: %s\n"
211 "Cookie: %04x:%04x\n"),
218 i
->default_sink_name
,
219 i
->default_source_name
,
221 i
->cookie
& 0xFFFFU
);
226 static const char* get_available_str_ynonly(int available
) {
228 case PA_PORT_AVAILABLE_YES
: return ", available";
229 case PA_PORT_AVAILABLE_NO
: return ", not available";
234 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
236 static const char *state_table
[] = {
237 [1+PA_SINK_INVALID_STATE
] = "n/a",
238 [1+PA_SINK_RUNNING
] = "RUNNING",
239 [1+PA_SINK_IDLE
] = "IDLE",
240 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
244 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
245 cv
[PA_CVOLUME_SNPRINT_MAX
],
246 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
247 v
[PA_VOLUME_SNPRINT_MAX
],
248 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
249 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
250 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
254 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
266 if (nl
&& !short_list_format
)
270 if (short_list_format
) {
271 printf("%u\t%s\t%s\t%s\t%s\n",
274 pa_strnull(i
->driver
),
275 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
276 state_table
[1+i
->state
]);
280 printf(_("Sink #%u\n"
283 "\tDescription: %s\n"
285 "\tSample Specification: %s\n"
286 "\tChannel Map: %s\n"
287 "\tOwner Module: %u\n"
291 "\tBase Volume: %s%s%s\n"
292 "\tMonitor Source: %s\n"
293 "\tLatency: %0.0f usec, configured %0.0f usec\n"
294 "\tFlags: %s%s%s%s%s%s%s\n"
295 "\tProperties:\n\t\t%s\n"),
297 state_table
[1+i
->state
],
299 pa_strnull(i
->description
),
300 pa_strnull(i
->driver
),
301 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
302 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
305 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
306 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
307 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
308 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
309 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
310 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
311 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
312 pa_strnull(i
->monitor_source_name
),
313 (double) i
->latency
, (double) i
->configured_latency
,
314 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
315 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
316 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
317 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
318 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
319 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
320 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
321 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
326 pa_sink_port_info
**p
;
328 printf(_("\tPorts:\n"));
329 for (p
= i
->ports
; *p
; p
++)
330 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
331 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
335 printf(_("\tActive Port: %s\n"),
336 i
->active_port
->name
);
341 printf(_("\tFormats:\n"));
342 for (j
= 0; j
< i
->n_formats
; j
++)
343 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
347 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
349 static const char *state_table
[] = {
350 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
351 [1+PA_SOURCE_RUNNING
] = "RUNNING",
352 [1+PA_SOURCE_IDLE
] = "IDLE",
353 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
357 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
358 cv
[PA_CVOLUME_SNPRINT_MAX
],
359 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
360 v
[PA_VOLUME_SNPRINT_MAX
],
361 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
362 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
363 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
367 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
379 if (nl
&& !short_list_format
)
383 if (short_list_format
) {
384 printf("%u\t%s\t%s\t%s\t%s\n",
387 pa_strnull(i
->driver
),
388 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
389 state_table
[1+i
->state
]);
393 printf(_("Source #%u\n"
396 "\tDescription: %s\n"
398 "\tSample Specification: %s\n"
399 "\tChannel Map: %s\n"
400 "\tOwner Module: %u\n"
404 "\tBase Volume: %s%s%s\n"
405 "\tMonitor of Sink: %s\n"
406 "\tLatency: %0.0f usec, configured %0.0f usec\n"
407 "\tFlags: %s%s%s%s%s%s\n"
408 "\tProperties:\n\t\t%s\n"),
410 state_table
[1+i
->state
],
412 pa_strnull(i
->description
),
413 pa_strnull(i
->driver
),
414 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
415 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
418 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
419 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
420 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
421 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
422 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
423 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
424 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
425 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
426 (double) i
->latency
, (double) i
->configured_latency
,
427 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
428 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
429 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
430 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
431 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
432 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
433 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
438 pa_source_port_info
**p
;
440 printf(_("\tPorts:\n"));
441 for (p
= i
->ports
; *p
; p
++)
442 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
443 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
447 printf(_("\tActive Port: %s\n"),
448 i
->active_port
->name
);
453 printf(_("\tFormats:\n"));
454 for (j
= 0; j
< i
->n_formats
; j
++)
455 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
459 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
464 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
476 if (nl
&& !short_list_format
)
480 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
482 if (short_list_format
) {
483 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
487 printf(_("Module #%u\n"
490 "\tUsage counter: %s\n"
491 "\tProperties:\n\t\t%s\n"),
494 i
->argument
? i
->argument
: "",
495 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
496 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
501 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
506 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
518 if (nl
&& !short_list_format
)
522 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
524 if (short_list_format
) {
525 printf("%u\t%s\t%s\n",
527 pa_strnull(i
->driver
),
528 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
532 printf(_("Client #%u\n"
534 "\tOwner Module: %s\n"
535 "\tProperties:\n\t\t%s\n"),
537 pa_strnull(i
->driver
),
538 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
539 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
544 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
549 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
561 if (nl
&& !short_list_format
)
565 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
567 if (short_list_format
) {
568 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
572 printf(_("Card #%u\n"
575 "\tOwner Module: %s\n"
576 "\tProperties:\n\t\t%s\n"),
579 pa_strnull(i
->driver
),
580 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
581 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
586 pa_card_profile_info
*p
;
588 printf(_("\tProfiles:\n"));
589 for (p
= i
->profiles
; p
->name
; p
++)
590 printf("\t\t%s: %s (sinks: %u, sources: %u, priority: %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
593 if (i
->active_profile
)
594 printf(_("\tActive Profile: %s\n"),
595 i
->active_profile
->name
);
598 pa_card_port_info
**p
;
600 printf(_("\tPorts:\n"));
601 for (p
= i
->ports
; *p
; p
++) {
602 pa_card_profile_info
**pr
= (*p
)->profiles
;
603 printf("\t\t%s: %s (priority: %u, latency offset: %" PRId64
" usec%s)\n", (*p
)->name
,
604 (*p
)->description
, (*p
)->priority
, (*p
)->latency_offset
,
605 get_available_str_ynonly((*p
)->available
));
607 if (!pa_proplist_isempty((*p
)->proplist
)) {
608 printf(_("\t\t\tProperties:\n\t\t\t\t%s\n"), pl
= pa_proplist_to_string_sep((*p
)->proplist
, "\n\t\t\t\t"));
613 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr
)->name
));
616 printf(", %s", pa_strnull((*pr
)->name
));
625 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
626 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
], f
[PA_FORMAT_INFO_SNPRINT_MAX
];
630 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
642 if (nl
&& !short_list_format
)
646 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
647 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
649 if (short_list_format
) {
650 printf("%u\t%u\t%s\t%s\t%s\n",
653 i
->client
!= PA_INVALID_INDEX
? k
: "-",
654 pa_strnull(i
->driver
),
655 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
659 printf(_("Sink Input #%u\n"
661 "\tOwner Module: %s\n"
664 "\tSample Specification: %s\n"
665 "\tChannel Map: %s\n"
672 "\tBuffer Latency: %0.0f usec\n"
673 "\tSink Latency: %0.0f usec\n"
674 "\tResample method: %s\n"
675 "\tProperties:\n\t\t%s\n"),
677 pa_strnull(i
->driver
),
678 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
679 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
681 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
682 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
683 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
684 pa_yes_no(i
->corked
),
686 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
687 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
688 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
689 (double) i
->buffer_usec
,
690 (double) i
->sink_usec
,
691 i
->resample_method
? i
->resample_method
: _("n/a"),
692 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
697 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
698 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
], f
[PA_FORMAT_INFO_SNPRINT_MAX
];
702 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
714 if (nl
&& !short_list_format
)
719 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
720 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
722 if (short_list_format
) {
723 printf("%u\t%u\t%s\t%s\t%s\n",
726 i
->client
!= PA_INVALID_INDEX
? k
: "-",
727 pa_strnull(i
->driver
),
728 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
732 printf(_("Source Output #%u\n"
734 "\tOwner Module: %s\n"
737 "\tSample Specification: %s\n"
738 "\tChannel Map: %s\n"
745 "\tBuffer Latency: %0.0f usec\n"
746 "\tSource Latency: %0.0f usec\n"
747 "\tResample method: %s\n"
748 "\tProperties:\n\t\t%s\n"),
750 pa_strnull(i
->driver
),
751 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
752 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
754 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
755 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
756 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
757 pa_yes_no(i
->corked
),
759 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
760 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
761 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
762 (double) i
->buffer_usec
,
763 (double) i
->source_usec
,
764 i
->resample_method
? i
->resample_method
: _("n/a"),
765 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
770 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
771 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
];
775 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
787 if (nl
&& !short_list_format
)
791 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
793 if (short_list_format
) {
794 printf("%u\t%s\t%s\t%0.3f\n",
797 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
798 (double) i
->duration
/1000000.0);
802 printf(_("Sample #%u\n"
804 "\tSample Specification: %s\n"
805 "\tChannel Map: %s\n"
809 "\tDuration: %0.1fs\n"
813 "\tProperties:\n\t\t%s\n"),
816 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
817 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
818 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
819 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
820 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
821 (double) i
->duration
/1000000.0,
824 i
->filename
? i
->filename
: _("n/a"),
825 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
830 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
832 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
840 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
841 if (idx
== PA_INVALID_INDEX
) {
842 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
852 static void volume_relative_adjust(pa_cvolume
*cv
) {
853 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
855 /* Relative volume change is additive in case of UINT or PERCENT
856 * and multiplicative for LINEAR or DECIBEL */
857 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
858 pa_volume_t v
= pa_cvolume_avg(cv
);
859 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
860 pa_cvolume_set(cv
, 1, v
);
862 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
863 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
867 static void unload_module_by_name_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
868 static pa_bool_t unloaded
= FALSE
;
871 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
877 if (unloaded
== FALSE
)
878 pa_log(_("Failed to unload module: Module %s not loaded"), module_name
);
885 if (pa_streq(module_name
, i
->name
)) {
888 pa_operation_unref(pa_context_unload_module(c
, i
->index
, simple_callback
, NULL
));
892 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
896 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
907 volume_relative_adjust(&cv
);
908 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
911 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
915 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
926 volume_relative_adjust(&cv
);
927 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
930 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
934 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
945 volume_relative_adjust(&cv
);
946 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
949 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
953 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
964 volume_relative_adjust(&cv
);
965 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
968 static void sink_toggle_mute_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
970 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
980 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, i
->name
, !i
->mute
, simple_callback
, NULL
));
983 static void source_toggle_mute_callback(pa_context
*c
, const pa_source_info
*o
, int is_last
, void *userdata
) {
985 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
995 pa_operation_unref(pa_context_set_source_mute_by_name(c
, o
->name
, !o
->mute
, simple_callback
, NULL
));
998 static void sink_input_toggle_mute_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
1000 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
1010 pa_operation_unref(pa_context_set_sink_input_mute(c
, i
->index
, !i
->mute
, simple_callback
, NULL
));
1013 static void source_output_toggle_mute_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
1015 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
1025 pa_operation_unref(pa_context_set_source_output_mute(c
, o
->index
, !o
->mute
, simple_callback
, NULL
));
1028 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
1029 #define MAX_FORMATS 256
1031 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
1032 pa_format_info
*f_arr
[MAX_FORMATS
];
1033 char *format
= NULL
;
1034 const char *state
= NULL
;
1037 while ((format
= pa_split(str
, ";", &state
))) {
1038 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
1041 pa_log(_("Failed to set format: invalid format string %s"), format
);
1049 pa_operation_unref(pa_ext_device_restore_save_formats(c
, PA_DEVICE_TYPE_SINK
, sink
, i
, f_arr
, simple_callback
, NULL
));
1055 pa_format_info_free(f_arr
[i
]);
1061 pa_format_info_free(f_arr
[i
]);
1066 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
1069 switch (pa_stream_get_state(s
)) {
1070 case PA_STREAM_CREATING
:
1071 case PA_STREAM_READY
:
1074 case PA_STREAM_TERMINATED
:
1078 case PA_STREAM_FAILED
:
1080 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
1085 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
1088 pa_assert(s
&& length
&& sndfile
);
1090 d
= pa_xmalloc(length
);
1092 pa_assert(sample_length
>= length
);
1093 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
1095 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
1097 pa_log(_("Premature end of file"));
1102 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
1104 sample_length
-= length
;
1106 if (sample_length
<= 0) {
1107 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
1108 pa_stream_finish_upload(sample_stream
);
1112 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
1114 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
1116 case PA_SUBSCRIPTION_EVENT_NEW
:
1119 case PA_SUBSCRIPTION_EVENT_CHANGE
:
1122 case PA_SUBSCRIPTION_EVENT_REMOVE
:
1126 return _("unknown");
1129 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
1131 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1133 case PA_SUBSCRIPTION_EVENT_SINK
:
1136 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1139 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1140 return _("sink-input");
1142 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1143 return _("source-output");
1145 case PA_SUBSCRIPTION_EVENT_MODULE
:
1148 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1151 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1152 return _("sample-cache");
1154 case PA_SUBSCRIPTION_EVENT_SERVER
:
1157 case PA_SUBSCRIPTION_EVENT_CARD
:
1161 return _("unknown");
1164 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1167 printf(_("Event '%s' on %s #%u\n"),
1168 subscription_event_type_to_string(t
),
1169 subscription_event_facility_to_string(t
),
1174 static void context_state_callback(pa_context
*c
, void *userdata
) {
1176 switch (pa_context_get_state(c
)) {
1177 case PA_CONTEXT_CONNECTING
:
1178 case PA_CONTEXT_AUTHORIZING
:
1179 case PA_CONTEXT_SETTING_NAME
:
1182 case PA_CONTEXT_READY
:
1185 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1186 if (short_list_format
)
1191 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1195 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1199 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1203 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1204 pa_assert(sample_stream
);
1206 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1207 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1208 pa_stream_connect_upload(sample_stream
, sample_length
);
1212 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1217 if (pa_streq(list_type
, "modules"))
1218 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1219 else if (pa_streq(list_type
, "sinks"))
1220 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1221 else if (pa_streq(list_type
, "sources"))
1222 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1223 else if (pa_streq(list_type
, "sink-inputs"))
1224 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1225 else if (pa_streq(list_type
, "source-outputs"))
1226 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1227 else if (pa_streq(list_type
, "clients"))
1228 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1229 else if (pa_streq(list_type
, "samples"))
1230 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1231 else if (pa_streq(list_type
, "cards"))
1232 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1234 pa_assert_not_reached();
1237 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1238 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1239 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1240 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1241 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1242 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1243 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1244 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1248 case MOVE_SINK_INPUT
:
1249 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1252 case MOVE_SOURCE_OUTPUT
:
1253 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1257 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1262 pa_operation_unref(pa_context_get_module_info_list(c
, unload_module_by_name_callback
, NULL
));
1264 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1269 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1271 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1274 case SUSPEND_SOURCE
:
1276 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1278 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1281 case SET_CARD_PROFILE
:
1282 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1286 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1289 case SET_DEFAULT_SINK
:
1290 pa_operation_unref(pa_context_set_default_sink(c
, sink_name
, simple_callback
, NULL
));
1293 case SET_SOURCE_PORT
:
1294 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1297 case SET_DEFAULT_SOURCE
:
1298 pa_operation_unref(pa_context_set_default_source(c
, source_name
, simple_callback
, NULL
));
1302 if (mute
== TOGGLE_MUTE
)
1303 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, sink_toggle_mute_callback
, NULL
));
1305 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1308 case SET_SOURCE_MUTE
:
1309 if (mute
== TOGGLE_MUTE
)
1310 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, source_toggle_mute_callback
, NULL
));
1312 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1315 case SET_SINK_INPUT_MUTE
:
1316 if (mute
== TOGGLE_MUTE
)
1317 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, sink_input_toggle_mute_callback
, NULL
));
1319 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1322 case SET_SOURCE_OUTPUT_MUTE
:
1323 if (mute
== TOGGLE_MUTE
)
1324 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, source_output_toggle_mute_callback
, NULL
));
1326 pa_operation_unref(pa_context_set_source_output_mute(c
, source_output_idx
, mute
, simple_callback
, NULL
));
1329 case SET_SINK_VOLUME
:
1330 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1331 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1334 pa_cvolume_set(&v
, 1, volume
);
1335 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1339 case SET_SOURCE_VOLUME
:
1340 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1341 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1344 pa_cvolume_set(&v
, 1, volume
);
1345 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1349 case SET_SINK_INPUT_VOLUME
:
1350 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1351 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1354 pa_cvolume_set(&v
, 1, volume
);
1355 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1359 case SET_SOURCE_OUTPUT_VOLUME
:
1360 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1361 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1364 pa_cvolume_set(&v
, 1, volume
);
1365 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1369 case SET_SINK_FORMATS
:
1370 set_sink_formats(c
, sink_idx
, formats
);
1373 case SET_PORT_LATENCY_OFFSET
:
1374 pa_operation_unref(pa_context_set_port_latency_offset(c
, card_name
, port_name
, latency_offset
, simple_callback
, NULL
));
1378 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1380 pa_operation_unref(pa_context_subscribe(
1382 PA_SUBSCRIPTION_MASK_SINK
|
1383 PA_SUBSCRIPTION_MASK_SOURCE
|
1384 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1385 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1386 PA_SUBSCRIPTION_MASK_MODULE
|
1387 PA_SUBSCRIPTION_MASK_CLIENT
|
1388 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1389 PA_SUBSCRIPTION_MASK_SERVER
|
1390 PA_SUBSCRIPTION_MASK_CARD
,
1396 pa_assert_not_reached();
1400 case PA_CONTEXT_TERMINATED
:
1404 case PA_CONTEXT_FAILED
:
1406 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1411 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1412 pa_log(_("Got SIGINT, exiting."));
1416 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1420 pa_assert(vol_spec
);
1422 pa_assert(vol_flags
);
1424 vs
= pa_xstrdup(vol_spec
);
1426 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1427 if (strchr(vs
, '.'))
1428 *vol_flags
|= VOL_LINEAR
;
1429 if (pa_endswith(vs
, "%")) {
1430 *vol_flags
|= VOL_PERCENT
;
1431 vs
[strlen(vs
)-1] = 0;
1433 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1434 *vol_flags
|= VOL_DECIBEL
;
1435 vs
[strlen(vs
)-2] = 0;
1438 if (pa_atod(vs
, &v
) < 0) {
1439 pa_log(_("Invalid volume specification"));
1446 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1447 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1448 v
+= (double) PA_VOLUME_NORM
;
1449 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1451 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1454 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1455 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1456 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1457 v
= pa_sw_volume_from_linear(v
);
1458 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1459 v
= pa_sw_volume_from_dB(v
);
1461 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1462 pa_log(_("Volume outside permissible range.\n"));
1466 *vol
= (pa_volume_t
) v
;
1471 static enum mute_flags
parse_mute(const char *mute_text
) {
1474 pa_assert(mute_text
);
1476 if (pa_streq("toggle", mute_text
))
1479 b
= pa_parse_boolean(mute_text
);
1486 return INVALID_MUTE
;
1490 static void help(const char *argv0
) {
1492 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1493 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1494 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1495 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1496 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1497 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1498 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1499 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1500 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("NAME|#N"));
1501 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1502 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1503 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1504 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-default-(sink|source)", _("NAME"));
1505 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1506 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1507 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1508 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0|toggle"));
1509 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0|toggle"));
1510 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1511 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
1512 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1513 printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
1514 "can be used to specify the default sink, source and monitor.\n"));
1517 " -h, --help Show this help\n"
1518 " --version Show version\n\n"
1519 " -s, --server=SERVER The name of the server to connect to\n"
1520 " -n, --client-name=NAME How to call this client on the server\n"));
1527 int main(int argc
, char *argv
[]) {
1528 pa_mainloop
*m
= NULL
;
1530 char *server
= NULL
, *bn
;
1532 static const struct option long_options
[] = {
1533 {"server", 1, NULL
, 's'},
1534 {"client-name", 1, NULL
, 'n'},
1535 {"version", 0, NULL
, ARG_VERSION
},
1536 {"help", 0, NULL
, 'h'},
1540 setlocale(LC_ALL
, "");
1542 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1545 bn
= pa_path_get_filename(argv
[0]);
1547 proplist
= pa_proplist_new();
1549 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1557 printf(_("pactl %s\n"
1558 "Compiled with libpulse %s\n"
1559 "Linked with libpulse %s\n"),
1561 pa_get_headers_version(),
1562 pa_get_library_version());
1568 server
= pa_xstrdup(optarg
);
1574 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1575 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1577 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1591 if (optind
< argc
) {
1592 if (pa_streq(argv
[optind
], "stat")) {
1594 short_list_format
= FALSE
;
1595 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1596 short_list_format
= TRUE
;
1598 } else if (pa_streq(argv
[optind
], "info"))
1601 else if (pa_streq(argv
[optind
], "exit"))
1604 else if (pa_streq(argv
[optind
], "list")) {
1607 for (int i
= optind
+1; i
< argc
; i
++) {
1608 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1609 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1610 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1611 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1612 list_type
= pa_xstrdup(argv
[i
]);
1613 } else if (pa_streq(argv
[i
], "short")) {
1614 short_list_format
= TRUE
;
1616 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1621 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1623 action
= UPLOAD_SAMPLE
;
1625 if (optind
+1 >= argc
) {
1626 pa_log(_("Please specify a sample file to load"));
1630 if (optind
+2 < argc
)
1631 sample_name
= pa_xstrdup(argv
[optind
+2]);
1633 char *f
= pa_path_get_filename(argv
[optind
+1]);
1634 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1638 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1639 pa_log(_("Failed to open sound file."));
1643 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1644 pa_log(_("Failed to determine sample specification from file."));
1647 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1649 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1650 if (sample_spec
.channels
> 2)
1651 pa_log(_("Warning: Failed to determine sample specification from file."));
1652 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1655 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1656 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1658 } else if (pa_streq(argv
[optind
], "play-sample")) {
1659 action
= PLAY_SAMPLE
;
1660 if (argc
!= optind
+2 && argc
!= optind
+3) {
1661 pa_log(_("You have to specify a sample name to play"));
1665 sample_name
= pa_xstrdup(argv
[optind
+1]);
1667 if (optind
+2 < argc
)
1668 sink_name
= pa_xstrdup(argv
[optind
+2]);
1670 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1671 action
= REMOVE_SAMPLE
;
1672 if (argc
!= optind
+2) {
1673 pa_log(_("You have to specify a sample name to remove"));
1677 sample_name
= pa_xstrdup(argv
[optind
+1]);
1679 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1680 action
= MOVE_SINK_INPUT
;
1681 if (argc
!= optind
+3) {
1682 pa_log(_("You have to specify a sink input index and a sink"));
1686 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1687 sink_name
= pa_xstrdup(argv
[optind
+2]);
1689 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1690 action
= MOVE_SOURCE_OUTPUT
;
1691 if (argc
!= optind
+3) {
1692 pa_log(_("You have to specify a source output index and a source"));
1696 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1697 source_name
= pa_xstrdup(argv
[optind
+2]);
1699 } else if (pa_streq(argv
[optind
], "load-module")) {
1704 action
= LOAD_MODULE
;
1706 if (argc
<= optind
+1) {
1707 pa_log(_("You have to specify a module name and arguments."));
1711 module_name
= argv
[optind
+1];
1713 for (i
= optind
+2; i
< argc
; i
++)
1714 n
+= strlen(argv
[i
])+1;
1717 p
= module_args
= pa_xmalloc(n
);
1719 for (i
= optind
+2; i
< argc
; i
++)
1720 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1723 } else if (pa_streq(argv
[optind
], "unload-module")) {
1724 action
= UNLOAD_MODULE
;
1726 if (argc
!= optind
+2) {
1727 pa_log(_("You have to specify a module index or name"));
1731 if (pa_atou(argv
[optind
+ 1], &module_index
) < 0)
1732 module_name
= argv
[optind
+ 1];
1734 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1737 action
= SUSPEND_SINK
;
1739 if (argc
> optind
+3 || optind
+1 >= argc
) {
1740 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1744 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1745 pa_log(_("Invalid suspend specification."));
1751 if (argc
> optind
+2)
1752 sink_name
= pa_xstrdup(argv
[optind
+1]);
1754 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1757 action
= SUSPEND_SOURCE
;
1759 if (argc
> optind
+3 || optind
+1 >= argc
) {
1760 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1764 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1765 pa_log(_("Invalid suspend specification."));
1771 if (argc
> optind
+2)
1772 source_name
= pa_xstrdup(argv
[optind
+1]);
1773 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1774 action
= SET_CARD_PROFILE
;
1776 if (argc
!= optind
+3) {
1777 pa_log(_("You have to specify a card name/index and a profile name"));
1781 card_name
= pa_xstrdup(argv
[optind
+1]);
1782 profile_name
= pa_xstrdup(argv
[optind
+2]);
1784 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1785 action
= SET_SINK_PORT
;
1787 if (argc
!= optind
+3) {
1788 pa_log(_("You have to specify a sink name/index and a port name"));
1792 sink_name
= pa_xstrdup(argv
[optind
+1]);
1793 port_name
= pa_xstrdup(argv
[optind
+2]);
1795 } else if (pa_streq(argv
[optind
], "set-default-sink")) {
1796 action
= SET_DEFAULT_SINK
;
1798 if (argc
!= optind
+2) {
1799 pa_log(_("You have to specify a sink name"));
1803 sink_name
= pa_xstrdup(argv
[optind
+1]);
1805 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1806 action
= SET_SOURCE_PORT
;
1808 if (argc
!= optind
+3) {
1809 pa_log(_("You have to specify a source name/index and a port name"));
1813 source_name
= pa_xstrdup(argv
[optind
+1]);
1814 port_name
= pa_xstrdup(argv
[optind
+2]);
1816 } else if (pa_streq(argv
[optind
], "set-default-source")) {
1817 action
= SET_DEFAULT_SOURCE
;
1819 if (argc
!= optind
+2) {
1820 pa_log(_("You have to specify a source name"));
1824 source_name
= pa_xstrdup(argv
[optind
+1]);
1826 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1827 action
= SET_SINK_VOLUME
;
1829 if (argc
!= optind
+3) {
1830 pa_log(_("You have to specify a sink name/index and a volume"));
1834 sink_name
= pa_xstrdup(argv
[optind
+1]);
1836 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1839 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1840 action
= SET_SOURCE_VOLUME
;
1842 if (argc
!= optind
+3) {
1843 pa_log(_("You have to specify a source name/index and a volume"));
1847 source_name
= pa_xstrdup(argv
[optind
+1]);
1849 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1852 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1853 action
= SET_SINK_INPUT_VOLUME
;
1855 if (argc
!= optind
+3) {
1856 pa_log(_("You have to specify a sink input index and a volume"));
1860 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1861 pa_log(_("Invalid sink input index"));
1865 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1868 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1869 action
= SET_SOURCE_OUTPUT_VOLUME
;
1871 if (argc
!= optind
+3) {
1872 pa_log(_("You have to specify a source output index and a volume"));
1876 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1877 pa_log(_("Invalid source output index"));
1881 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1884 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1885 action
= SET_SINK_MUTE
;
1887 if (argc
!= optind
+3) {
1888 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1892 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1893 pa_log(_("Invalid mute specification"));
1897 sink_name
= pa_xstrdup(argv
[optind
+1]);
1899 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1900 action
= SET_SOURCE_MUTE
;
1902 if (argc
!= optind
+3) {
1903 pa_log(_("You have to specify a source name/index and a mute boolean"));
1907 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1908 pa_log(_("Invalid mute specification"));
1912 source_name
= pa_xstrdup(argv
[optind
+1]);
1914 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1915 action
= SET_SINK_INPUT_MUTE
;
1917 if (argc
!= optind
+3) {
1918 pa_log(_("You have to specify a sink input index and a mute boolean"));
1922 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1923 pa_log(_("Invalid sink input index specification"));
1927 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1928 pa_log(_("Invalid mute specification"));
1932 } else if (pa_streq(argv
[optind
], "set-source-output-mute")) {
1933 action
= SET_SOURCE_OUTPUT_MUTE
;
1935 if (argc
!= optind
+3) {
1936 pa_log(_("You have to specify a source output index and a mute boolean"));
1940 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1941 pa_log(_("Invalid source output index specification"));
1945 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1946 pa_log(_("Invalid mute specification"));
1950 } else if (pa_streq(argv
[optind
], "subscribe"))
1954 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1957 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1958 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1963 action
= SET_SINK_FORMATS
;
1964 formats
= pa_xstrdup(argv
[optind
+2]);
1966 } else if (pa_streq(argv
[optind
], "set-port-latency-offset")) {
1967 action
= SET_PORT_LATENCY_OFFSET
;
1969 if (argc
!= optind
+4) {
1970 pa_log(_("You have to specify a card name/index, a port name and a latency offset"));
1974 card_name
= pa_xstrdup(argv
[optind
+1]);
1975 port_name
= pa_xstrdup(argv
[optind
+2]);
1976 if (pa_atoi(argv
[optind
+ 3], &latency_offset
) < 0) {
1977 pa_log(_("Could not parse latency offset"));
1981 } else if (pa_streq(argv
[optind
], "help")) {
1988 if (action
== NONE
) {
1989 pa_log(_("No valid command specified."));
1993 if (!(m
= pa_mainloop_new())) {
1994 pa_log(_("pa_mainloop_new() failed."));
1998 mainloop_api
= pa_mainloop_get_api(m
);
2000 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
2001 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
2002 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
2003 pa_disable_sigpipe();
2005 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
2006 pa_log(_("pa_context_new() failed."));
2010 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
2011 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
2012 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
2016 if (pa_mainloop_run(m
, &ret
) < 0) {
2017 pa_log(_("pa_mainloop_run() failed."));
2023 pa_stream_unref(sample_stream
);
2026 pa_context_unref(context
);
2030 pa_mainloop_free(m
);
2034 pa_xfree(list_type
);
2035 pa_xfree(sample_name
);
2036 pa_xfree(sink_name
);
2037 pa_xfree(source_name
);
2038 pa_xfree(module_args
);
2039 pa_xfree(card_name
);
2040 pa_xfree(profile_name
);
2041 pa_xfree(port_name
);
2048 pa_proplist_free(proplist
);