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 bool short_list_format
= false;
69 static uint32_t module_index
;
70 static int32_t latency_offset
;
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 bool 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_VERBOSE_MAX
],
246 v
[PA_VOLUME_SNPRINT_VERBOSE_MAX
],
247 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
248 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
252 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
264 if (nl
&& !short_list_format
)
268 if (short_list_format
) {
269 printf("%u\t%s\t%s\t%s\t%s\n",
272 pa_strnull(i
->driver
),
273 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
274 state_table
[1+i
->state
]);
278 printf(_("Sink #%u\n"
281 "\tDescription: %s\n"
283 "\tSample Specification: %s\n"
284 "\tChannel Map: %s\n"
285 "\tOwner Module: %u\n"
289 "\tBase Volume: %s\n"
290 "\tMonitor Source: %s\n"
291 "\tLatency: %0.0f usec, configured %0.0f usec\n"
292 "\tFlags: %s%s%s%s%s%s%s\n"
293 "\tProperties:\n\t\t%s\n"),
295 state_table
[1+i
->state
],
297 pa_strnull(i
->description
),
298 pa_strnull(i
->driver
),
299 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
300 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
303 pa_cvolume_snprint_verbose(cv
, sizeof(cv
), &i
->volume
, &i
->channel_map
, i
->flags
& PA_SINK_DECIBEL_VOLUME
),
304 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
305 pa_volume_snprint_verbose(v
, sizeof(v
), i
->base_volume
, i
->flags
& PA_SINK_DECIBEL_VOLUME
),
306 pa_strnull(i
->monitor_source_name
),
307 (double) i
->latency
, (double) i
->configured_latency
,
308 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
309 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
310 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
311 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
312 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
313 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
314 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
315 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
320 pa_sink_port_info
**p
;
322 printf(_("\tPorts:\n"));
323 for (p
= i
->ports
; *p
; p
++)
324 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
325 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
329 printf(_("\tActive Port: %s\n"),
330 i
->active_port
->name
);
335 printf(_("\tFormats:\n"));
336 for (j
= 0; j
< i
->n_formats
; j
++)
337 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
341 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
343 static const char *state_table
[] = {
344 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
345 [1+PA_SOURCE_RUNNING
] = "RUNNING",
346 [1+PA_SOURCE_IDLE
] = "IDLE",
347 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
351 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
352 cv
[PA_CVOLUME_SNPRINT_VERBOSE_MAX
],
353 v
[PA_VOLUME_SNPRINT_VERBOSE_MAX
],
354 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
355 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
359 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
371 if (nl
&& !short_list_format
)
375 if (short_list_format
) {
376 printf("%u\t%s\t%s\t%s\t%s\n",
379 pa_strnull(i
->driver
),
380 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
381 state_table
[1+i
->state
]);
385 printf(_("Source #%u\n"
388 "\tDescription: %s\n"
390 "\tSample Specification: %s\n"
391 "\tChannel Map: %s\n"
392 "\tOwner Module: %u\n"
396 "\tBase Volume: %s\n"
397 "\tMonitor of Sink: %s\n"
398 "\tLatency: %0.0f usec, configured %0.0f usec\n"
399 "\tFlags: %s%s%s%s%s%s\n"
400 "\tProperties:\n\t\t%s\n"),
402 state_table
[1+i
->state
],
404 pa_strnull(i
->description
),
405 pa_strnull(i
->driver
),
406 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
407 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
410 pa_cvolume_snprint_verbose(cv
, sizeof(cv
), &i
->volume
, &i
->channel_map
, i
->flags
& PA_SOURCE_DECIBEL_VOLUME
),
411 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
412 pa_volume_snprint_verbose(v
, sizeof(v
), i
->base_volume
, i
->flags
& PA_SOURCE_DECIBEL_VOLUME
),
413 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
414 (double) i
->latency
, (double) i
->configured_latency
,
415 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
416 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
417 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
418 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
419 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
420 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
421 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
426 pa_source_port_info
**p
;
428 printf(_("\tPorts:\n"));
429 for (p
= i
->ports
; *p
; p
++)
430 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
431 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
435 printf(_("\tActive Port: %s\n"),
436 i
->active_port
->name
);
441 printf(_("\tFormats:\n"));
442 for (j
= 0; j
< i
->n_formats
; j
++)
443 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
447 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
452 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
464 if (nl
&& !short_list_format
)
468 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
470 if (short_list_format
) {
471 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
475 printf(_("Module #%u\n"
478 "\tUsage counter: %s\n"
479 "\tProperties:\n\t\t%s\n"),
482 i
->argument
? i
->argument
: "",
483 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
484 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
489 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
494 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
506 if (nl
&& !short_list_format
)
510 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
512 if (short_list_format
) {
513 printf("%u\t%s\t%s\n",
515 pa_strnull(i
->driver
),
516 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
520 printf(_("Client #%u\n"
522 "\tOwner Module: %s\n"
523 "\tProperties:\n\t\t%s\n"),
525 pa_strnull(i
->driver
),
526 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
527 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
532 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
537 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
549 if (nl
&& !short_list_format
)
553 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
555 if (short_list_format
) {
556 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
560 printf(_("Card #%u\n"
563 "\tOwner Module: %s\n"
564 "\tProperties:\n\t\t%s\n"),
567 pa_strnull(i
->driver
),
568 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
569 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
574 pa_card_profile_info
*p
;
576 printf(_("\tProfiles:\n"));
577 for (p
= i
->profiles
; p
->name
; p
++)
578 printf("\t\t%s: %s (sinks: %u, sources: %u, priority: %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
581 if (i
->active_profile
)
582 printf(_("\tActive Profile: %s\n"),
583 i
->active_profile
->name
);
586 pa_card_port_info
**p
;
588 printf(_("\tPorts:\n"));
589 for (p
= i
->ports
; *p
; p
++) {
590 pa_card_profile_info
**pr
= (*p
)->profiles
;
591 printf("\t\t%s: %s (priority: %u, latency offset: %" PRId64
" usec%s)\n", (*p
)->name
,
592 (*p
)->description
, (*p
)->priority
, (*p
)->latency_offset
,
593 get_available_str_ynonly((*p
)->available
));
595 if (!pa_proplist_isempty((*p
)->proplist
)) {
596 printf(_("\t\t\tProperties:\n\t\t\t\t%s\n"), pl
= pa_proplist_to_string_sep((*p
)->proplist
, "\n\t\t\t\t"));
601 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr
)->name
));
604 printf(", %s", pa_strnull((*pr
)->name
));
613 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
614 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_VERBOSE_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], f
[PA_FORMAT_INFO_SNPRINT_MAX
];
618 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
630 if (nl
&& !short_list_format
)
634 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
635 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
637 if (short_list_format
) {
638 printf("%u\t%u\t%s\t%s\t%s\n",
641 i
->client
!= PA_INVALID_INDEX
? k
: "-",
642 pa_strnull(i
->driver
),
643 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
647 printf(_("Sink Input #%u\n"
649 "\tOwner Module: %s\n"
652 "\tSample Specification: %s\n"
653 "\tChannel Map: %s\n"
659 "\tBuffer Latency: %0.0f usec\n"
660 "\tSink Latency: %0.0f usec\n"
661 "\tResample method: %s\n"
662 "\tProperties:\n\t\t%s\n"),
664 pa_strnull(i
->driver
),
665 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
666 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
668 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
669 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
670 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
671 pa_yes_no(i
->corked
),
673 pa_cvolume_snprint_verbose(cv
, sizeof(cv
), &i
->volume
, &i
->channel_map
, true),
674 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
675 (double) i
->buffer_usec
,
676 (double) i
->sink_usec
,
677 i
->resample_method
? i
->resample_method
: _("n/a"),
678 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
683 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
684 char t
[32], k
[32], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_VERBOSE_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], f
[PA_FORMAT_INFO_SNPRINT_MAX
];
688 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
700 if (nl
&& !short_list_format
)
704 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
705 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
707 if (short_list_format
) {
708 printf("%u\t%u\t%s\t%s\t%s\n",
711 i
->client
!= PA_INVALID_INDEX
? k
: "-",
712 pa_strnull(i
->driver
),
713 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
717 printf(_("Source Output #%u\n"
719 "\tOwner Module: %s\n"
722 "\tSample Specification: %s\n"
723 "\tChannel Map: %s\n"
729 "\tBuffer Latency: %0.0f usec\n"
730 "\tSource Latency: %0.0f usec\n"
731 "\tResample method: %s\n"
732 "\tProperties:\n\t\t%s\n"),
734 pa_strnull(i
->driver
),
735 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
736 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
738 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
739 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
740 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
741 pa_yes_no(i
->corked
),
743 pa_cvolume_snprint_verbose(cv
, sizeof(cv
), &i
->volume
, &i
->channel_map
, true),
744 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
745 (double) i
->buffer_usec
,
746 (double) i
->source_usec
,
747 i
->resample_method
? i
->resample_method
: _("n/a"),
748 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
753 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
754 char t
[PA_BYTES_SNPRINT_MAX
], s
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_VERBOSE_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
758 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
770 if (nl
&& !short_list_format
)
774 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
776 if (short_list_format
) {
777 printf("%u\t%s\t%s\t%0.3f\n",
780 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
781 (double) i
->duration
/1000000.0);
785 printf(_("Sample #%u\n"
787 "\tSample Specification: %s\n"
788 "\tChannel Map: %s\n"
791 "\tDuration: %0.1fs\n"
795 "\tProperties:\n\t\t%s\n"),
798 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
799 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
800 pa_cvolume_snprint_verbose(cv
, sizeof(cv
), &i
->volume
, &i
->channel_map
, true),
801 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
802 (double) i
->duration
/1000000.0,
805 i
->filename
? i
->filename
: _("n/a"),
806 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
811 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
813 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
821 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
822 if (idx
== PA_INVALID_INDEX
) {
823 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
833 static void volume_relative_adjust(pa_cvolume
*cv
) {
834 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
836 /* Relative volume change is additive in case of UINT or PERCENT
837 * and multiplicative for LINEAR or DECIBEL */
838 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
839 pa_volume_t v
= pa_cvolume_avg(cv
);
840 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
841 pa_cvolume_set(cv
, 1, v
);
843 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
844 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
848 static void unload_module_by_name_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
849 static bool unloaded
= false;
852 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
858 if (unloaded
== false)
859 pa_log(_("Failed to unload module: Module %s not loaded"), module_name
);
866 if (pa_streq(module_name
, i
->name
)) {
869 pa_operation_unref(pa_context_unload_module(c
, i
->index
, simple_callback
, NULL
));
873 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
877 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
888 volume_relative_adjust(&cv
);
889 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
892 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
896 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
907 volume_relative_adjust(&cv
);
908 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
911 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
915 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
926 volume_relative_adjust(&cv
);
927 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
930 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
934 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
945 volume_relative_adjust(&cv
);
946 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
949 static void sink_toggle_mute_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
951 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
961 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, i
->name
, !i
->mute
, simple_callback
, NULL
));
964 static void source_toggle_mute_callback(pa_context
*c
, const pa_source_info
*o
, int is_last
, void *userdata
) {
966 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
976 pa_operation_unref(pa_context_set_source_mute_by_name(c
, o
->name
, !o
->mute
, simple_callback
, NULL
));
979 static void sink_input_toggle_mute_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
981 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
991 pa_operation_unref(pa_context_set_sink_input_mute(c
, i
->index
, !i
->mute
, simple_callback
, NULL
));
994 static void source_output_toggle_mute_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
996 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
1006 pa_operation_unref(pa_context_set_source_output_mute(c
, o
->index
, !o
->mute
, simple_callback
, NULL
));
1009 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
1010 #define MAX_FORMATS 256
1012 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
1013 pa_format_info
*f_arr
[MAX_FORMATS
];
1014 char *format
= NULL
;
1015 const char *state
= NULL
;
1018 while ((format
= pa_split(str
, ";", &state
))) {
1019 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
1022 pa_log(_("Failed to set format: invalid format string %s"), format
);
1030 pa_operation_unref(pa_ext_device_restore_save_formats(c
, PA_DEVICE_TYPE_SINK
, sink
, i
, f_arr
, simple_callback
, NULL
));
1036 pa_format_info_free(f_arr
[i
]);
1042 pa_format_info_free(f_arr
[i
]);
1047 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
1050 switch (pa_stream_get_state(s
)) {
1051 case PA_STREAM_CREATING
:
1052 case PA_STREAM_READY
:
1055 case PA_STREAM_TERMINATED
:
1059 case PA_STREAM_FAILED
:
1061 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
1066 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
1069 pa_assert(s
&& length
&& sndfile
);
1071 d
= pa_xmalloc(length
);
1073 pa_assert(sample_length
>= length
);
1074 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
1076 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
1078 pa_log(_("Premature end of file"));
1083 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
1085 sample_length
-= length
;
1087 if (sample_length
<= 0) {
1088 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
1089 pa_stream_finish_upload(sample_stream
);
1093 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
1095 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
1097 case PA_SUBSCRIPTION_EVENT_NEW
:
1100 case PA_SUBSCRIPTION_EVENT_CHANGE
:
1103 case PA_SUBSCRIPTION_EVENT_REMOVE
:
1107 return _("unknown");
1110 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
1112 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1114 case PA_SUBSCRIPTION_EVENT_SINK
:
1117 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1120 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1121 return _("sink-input");
1123 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1124 return _("source-output");
1126 case PA_SUBSCRIPTION_EVENT_MODULE
:
1129 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1132 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1133 return _("sample-cache");
1135 case PA_SUBSCRIPTION_EVENT_SERVER
:
1138 case PA_SUBSCRIPTION_EVENT_CARD
:
1142 return _("unknown");
1145 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1148 printf(_("Event '%s' on %s #%u\n"),
1149 subscription_event_type_to_string(t
),
1150 subscription_event_facility_to_string(t
),
1155 static void context_state_callback(pa_context
*c
, void *userdata
) {
1157 switch (pa_context_get_state(c
)) {
1158 case PA_CONTEXT_CONNECTING
:
1159 case PA_CONTEXT_AUTHORIZING
:
1160 case PA_CONTEXT_SETTING_NAME
:
1163 case PA_CONTEXT_READY
:
1166 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1167 if (short_list_format
)
1172 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1176 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1180 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1184 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1185 pa_assert(sample_stream
);
1187 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1188 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1189 pa_stream_connect_upload(sample_stream
, sample_length
);
1193 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1198 if (pa_streq(list_type
, "modules"))
1199 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1200 else if (pa_streq(list_type
, "sinks"))
1201 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1202 else if (pa_streq(list_type
, "sources"))
1203 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1204 else if (pa_streq(list_type
, "sink-inputs"))
1205 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1206 else if (pa_streq(list_type
, "source-outputs"))
1207 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1208 else if (pa_streq(list_type
, "clients"))
1209 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1210 else if (pa_streq(list_type
, "samples"))
1211 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1212 else if (pa_streq(list_type
, "cards"))
1213 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1215 pa_assert_not_reached();
1218 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1219 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1220 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1221 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1222 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1223 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1224 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1225 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1229 case MOVE_SINK_INPUT
:
1230 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1233 case MOVE_SOURCE_OUTPUT
:
1234 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1238 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1243 pa_operation_unref(pa_context_get_module_info_list(c
, unload_module_by_name_callback
, NULL
));
1245 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1250 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1252 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1255 case SUSPEND_SOURCE
:
1257 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1259 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1262 case SET_CARD_PROFILE
:
1263 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1267 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1270 case SET_DEFAULT_SINK
:
1271 pa_operation_unref(pa_context_set_default_sink(c
, sink_name
, simple_callback
, NULL
));
1274 case SET_SOURCE_PORT
:
1275 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1278 case SET_DEFAULT_SOURCE
:
1279 pa_operation_unref(pa_context_set_default_source(c
, source_name
, simple_callback
, NULL
));
1283 if (mute
== TOGGLE_MUTE
)
1284 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, sink_toggle_mute_callback
, NULL
));
1286 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1289 case SET_SOURCE_MUTE
:
1290 if (mute
== TOGGLE_MUTE
)
1291 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, source_toggle_mute_callback
, NULL
));
1293 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1296 case SET_SINK_INPUT_MUTE
:
1297 if (mute
== TOGGLE_MUTE
)
1298 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, sink_input_toggle_mute_callback
, NULL
));
1300 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1303 case SET_SOURCE_OUTPUT_MUTE
:
1304 if (mute
== TOGGLE_MUTE
)
1305 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, source_output_toggle_mute_callback
, NULL
));
1307 pa_operation_unref(pa_context_set_source_output_mute(c
, source_output_idx
, mute
, simple_callback
, NULL
));
1310 case SET_SINK_VOLUME
:
1311 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1312 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1315 pa_cvolume_set(&v
, 1, volume
);
1316 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1320 case SET_SOURCE_VOLUME
:
1321 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1322 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1325 pa_cvolume_set(&v
, 1, volume
);
1326 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1330 case SET_SINK_INPUT_VOLUME
:
1331 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1332 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1335 pa_cvolume_set(&v
, 1, volume
);
1336 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1340 case SET_SOURCE_OUTPUT_VOLUME
:
1341 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1342 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1345 pa_cvolume_set(&v
, 1, volume
);
1346 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1350 case SET_SINK_FORMATS
:
1351 set_sink_formats(c
, sink_idx
, formats
);
1354 case SET_PORT_LATENCY_OFFSET
:
1355 pa_operation_unref(pa_context_set_port_latency_offset(c
, card_name
, port_name
, latency_offset
, simple_callback
, NULL
));
1359 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1361 pa_operation_unref(pa_context_subscribe(
1363 PA_SUBSCRIPTION_MASK_SINK
|
1364 PA_SUBSCRIPTION_MASK_SOURCE
|
1365 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1366 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1367 PA_SUBSCRIPTION_MASK_MODULE
|
1368 PA_SUBSCRIPTION_MASK_CLIENT
|
1369 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1370 PA_SUBSCRIPTION_MASK_SERVER
|
1371 PA_SUBSCRIPTION_MASK_CARD
,
1377 pa_assert_not_reached();
1381 case PA_CONTEXT_TERMINATED
:
1385 case PA_CONTEXT_FAILED
:
1387 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1392 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1393 pa_log(_("Got SIGINT, exiting."));
1397 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1401 pa_assert(vol_spec
);
1403 pa_assert(vol_flags
);
1405 vs
= pa_xstrdup(vol_spec
);
1407 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1408 if (strchr(vs
, '.'))
1409 *vol_flags
|= VOL_LINEAR
;
1410 if (pa_endswith(vs
, "%")) {
1411 *vol_flags
|= VOL_PERCENT
;
1412 vs
[strlen(vs
)-1] = 0;
1414 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1415 *vol_flags
|= VOL_DECIBEL
;
1416 vs
[strlen(vs
)-2] = 0;
1419 if (pa_atod(vs
, &v
) < 0) {
1420 pa_log(_("Invalid volume specification"));
1427 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1428 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1429 v
+= (double) PA_VOLUME_NORM
;
1430 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1432 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1435 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1436 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1437 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1438 v
= pa_sw_volume_from_linear(v
);
1439 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1440 v
= pa_sw_volume_from_dB(v
);
1442 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1443 pa_log(_("Volume outside permissible range.\n"));
1447 *vol
= (pa_volume_t
) v
;
1452 static enum mute_flags
parse_mute(const char *mute_text
) {
1455 pa_assert(mute_text
);
1457 if (pa_streq("toggle", mute_text
))
1460 b
= pa_parse_boolean(mute_text
);
1467 return INVALID_MUTE
;
1471 static void help(const char *argv0
) {
1473 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1474 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1475 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1476 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1477 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1478 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1479 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1480 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1481 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("NAME|#N"));
1482 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1483 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1484 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1485 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-default-(sink|source)", _("NAME"));
1486 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1487 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1488 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1489 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0|toggle"));
1490 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0|toggle"));
1491 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1492 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
1493 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1494 printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
1495 "can be used to specify the default sink, source and monitor.\n"));
1498 " -h, --help Show this help\n"
1499 " --version Show version\n\n"
1500 " -s, --server=SERVER The name of the server to connect to\n"
1501 " -n, --client-name=NAME How to call this client on the server\n"));
1508 int main(int argc
, char *argv
[]) {
1509 pa_mainloop
*m
= NULL
;
1511 char *server
= NULL
, *bn
;
1513 static const struct option long_options
[] = {
1514 {"server", 1, NULL
, 's'},
1515 {"client-name", 1, NULL
, 'n'},
1516 {"version", 0, NULL
, ARG_VERSION
},
1517 {"help", 0, NULL
, 'h'},
1521 setlocale(LC_ALL
, "");
1523 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1526 bn
= pa_path_get_filename(argv
[0]);
1528 proplist
= pa_proplist_new();
1530 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1538 printf(_("pactl %s\n"
1539 "Compiled with libpulse %s\n"
1540 "Linked with libpulse %s\n"),
1542 pa_get_headers_version(),
1543 pa_get_library_version());
1549 server
= pa_xstrdup(optarg
);
1555 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1556 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1558 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1572 if (optind
< argc
) {
1573 if (pa_streq(argv
[optind
], "stat")) {
1575 short_list_format
= false;
1576 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1577 short_list_format
= true;
1579 } else if (pa_streq(argv
[optind
], "info"))
1582 else if (pa_streq(argv
[optind
], "exit"))
1585 else if (pa_streq(argv
[optind
], "list")) {
1588 for (int i
= optind
+1; i
< argc
; i
++) {
1589 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1590 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1591 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1592 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1593 list_type
= pa_xstrdup(argv
[i
]);
1594 } else if (pa_streq(argv
[i
], "short")) {
1595 short_list_format
= true;
1597 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1602 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1604 action
= UPLOAD_SAMPLE
;
1606 if (optind
+1 >= argc
) {
1607 pa_log(_("Please specify a sample file to load"));
1611 if (optind
+2 < argc
)
1612 sample_name
= pa_xstrdup(argv
[optind
+2]);
1614 char *f
= pa_path_get_filename(argv
[optind
+1]);
1615 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1619 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1620 pa_log(_("Failed to open sound file."));
1624 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1625 pa_log(_("Failed to determine sample specification from file."));
1628 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1630 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1631 if (sample_spec
.channels
> 2)
1632 pa_log(_("Warning: Failed to determine sample specification from file."));
1633 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1636 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1637 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1639 } else if (pa_streq(argv
[optind
], "play-sample")) {
1640 action
= PLAY_SAMPLE
;
1641 if (argc
!= optind
+2 && argc
!= optind
+3) {
1642 pa_log(_("You have to specify a sample name to play"));
1646 sample_name
= pa_xstrdup(argv
[optind
+1]);
1648 if (optind
+2 < argc
)
1649 sink_name
= pa_xstrdup(argv
[optind
+2]);
1651 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1652 action
= REMOVE_SAMPLE
;
1653 if (argc
!= optind
+2) {
1654 pa_log(_("You have to specify a sample name to remove"));
1658 sample_name
= pa_xstrdup(argv
[optind
+1]);
1660 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1661 action
= MOVE_SINK_INPUT
;
1662 if (argc
!= optind
+3) {
1663 pa_log(_("You have to specify a sink input index and a sink"));
1667 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1668 sink_name
= pa_xstrdup(argv
[optind
+2]);
1670 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1671 action
= MOVE_SOURCE_OUTPUT
;
1672 if (argc
!= optind
+3) {
1673 pa_log(_("You have to specify a source output index and a source"));
1677 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1678 source_name
= pa_xstrdup(argv
[optind
+2]);
1680 } else if (pa_streq(argv
[optind
], "load-module")) {
1685 action
= LOAD_MODULE
;
1687 if (argc
<= optind
+1) {
1688 pa_log(_("You have to specify a module name and arguments."));
1692 module_name
= argv
[optind
+1];
1694 for (i
= optind
+2; i
< argc
; i
++)
1695 n
+= strlen(argv
[i
])+1;
1698 p
= module_args
= pa_xmalloc(n
);
1700 for (i
= optind
+2; i
< argc
; i
++)
1701 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1704 } else if (pa_streq(argv
[optind
], "unload-module")) {
1705 action
= UNLOAD_MODULE
;
1707 if (argc
!= optind
+2) {
1708 pa_log(_("You have to specify a module index or name"));
1712 if (pa_atou(argv
[optind
+ 1], &module_index
) < 0)
1713 module_name
= argv
[optind
+ 1];
1715 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1718 action
= SUSPEND_SINK
;
1720 if (argc
> optind
+3 || optind
+1 >= argc
) {
1721 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1725 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1726 pa_log(_("Invalid suspend specification."));
1732 if (argc
> optind
+2)
1733 sink_name
= pa_xstrdup(argv
[optind
+1]);
1735 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1738 action
= SUSPEND_SOURCE
;
1740 if (argc
> optind
+3 || optind
+1 >= argc
) {
1741 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1745 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1746 pa_log(_("Invalid suspend specification."));
1752 if (argc
> optind
+2)
1753 source_name
= pa_xstrdup(argv
[optind
+1]);
1754 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1755 action
= SET_CARD_PROFILE
;
1757 if (argc
!= optind
+3) {
1758 pa_log(_("You have to specify a card name/index and a profile name"));
1762 card_name
= pa_xstrdup(argv
[optind
+1]);
1763 profile_name
= pa_xstrdup(argv
[optind
+2]);
1765 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1766 action
= SET_SINK_PORT
;
1768 if (argc
!= optind
+3) {
1769 pa_log(_("You have to specify a sink name/index and a port name"));
1773 sink_name
= pa_xstrdup(argv
[optind
+1]);
1774 port_name
= pa_xstrdup(argv
[optind
+2]);
1776 } else if (pa_streq(argv
[optind
], "set-default-sink")) {
1777 action
= SET_DEFAULT_SINK
;
1779 if (argc
!= optind
+2) {
1780 pa_log(_("You have to specify a sink name"));
1784 sink_name
= pa_xstrdup(argv
[optind
+1]);
1786 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1787 action
= SET_SOURCE_PORT
;
1789 if (argc
!= optind
+3) {
1790 pa_log(_("You have to specify a source name/index and a port name"));
1794 source_name
= pa_xstrdup(argv
[optind
+1]);
1795 port_name
= pa_xstrdup(argv
[optind
+2]);
1797 } else if (pa_streq(argv
[optind
], "set-default-source")) {
1798 action
= SET_DEFAULT_SOURCE
;
1800 if (argc
!= optind
+2) {
1801 pa_log(_("You have to specify a source name"));
1805 source_name
= pa_xstrdup(argv
[optind
+1]);
1807 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1808 action
= SET_SINK_VOLUME
;
1810 if (argc
!= optind
+3) {
1811 pa_log(_("You have to specify a sink name/index and a volume"));
1815 sink_name
= pa_xstrdup(argv
[optind
+1]);
1817 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1820 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1821 action
= SET_SOURCE_VOLUME
;
1823 if (argc
!= optind
+3) {
1824 pa_log(_("You have to specify a source name/index and a volume"));
1828 source_name
= pa_xstrdup(argv
[optind
+1]);
1830 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1833 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1834 action
= SET_SINK_INPUT_VOLUME
;
1836 if (argc
!= optind
+3) {
1837 pa_log(_("You have to specify a sink input index and a volume"));
1841 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1842 pa_log(_("Invalid sink input index"));
1846 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1849 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1850 action
= SET_SOURCE_OUTPUT_VOLUME
;
1852 if (argc
!= optind
+3) {
1853 pa_log(_("You have to specify a source output index and a volume"));
1857 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1858 pa_log(_("Invalid source output index"));
1862 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1865 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1866 action
= SET_SINK_MUTE
;
1868 if (argc
!= optind
+3) {
1869 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1873 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1874 pa_log(_("Invalid mute specification"));
1878 sink_name
= pa_xstrdup(argv
[optind
+1]);
1880 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1881 action
= SET_SOURCE_MUTE
;
1883 if (argc
!= optind
+3) {
1884 pa_log(_("You have to specify a source name/index and a mute boolean"));
1888 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1889 pa_log(_("Invalid mute specification"));
1893 source_name
= pa_xstrdup(argv
[optind
+1]);
1895 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1896 action
= SET_SINK_INPUT_MUTE
;
1898 if (argc
!= optind
+3) {
1899 pa_log(_("You have to specify a sink input index and a mute boolean"));
1903 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1904 pa_log(_("Invalid sink input index specification"));
1908 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1909 pa_log(_("Invalid mute specification"));
1913 } else if (pa_streq(argv
[optind
], "set-source-output-mute")) {
1914 action
= SET_SOURCE_OUTPUT_MUTE
;
1916 if (argc
!= optind
+3) {
1917 pa_log(_("You have to specify a source output index and a mute boolean"));
1921 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1922 pa_log(_("Invalid source output index specification"));
1926 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1927 pa_log(_("Invalid mute specification"));
1931 } else if (pa_streq(argv
[optind
], "subscribe"))
1935 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1938 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1939 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1944 action
= SET_SINK_FORMATS
;
1945 formats
= pa_xstrdup(argv
[optind
+2]);
1947 } else if (pa_streq(argv
[optind
], "set-port-latency-offset")) {
1948 action
= SET_PORT_LATENCY_OFFSET
;
1950 if (argc
!= optind
+4) {
1951 pa_log(_("You have to specify a card name/index, a port name and a latency offset"));
1955 card_name
= pa_xstrdup(argv
[optind
+1]);
1956 port_name
= pa_xstrdup(argv
[optind
+2]);
1957 if (pa_atoi(argv
[optind
+ 3], &latency_offset
) < 0) {
1958 pa_log(_("Could not parse latency offset"));
1962 } else if (pa_streq(argv
[optind
], "help")) {
1969 if (action
== NONE
) {
1970 pa_log(_("No valid command specified."));
1974 if (!(m
= pa_mainloop_new())) {
1975 pa_log(_("pa_mainloop_new() failed."));
1979 mainloop_api
= pa_mainloop_get_api(m
);
1981 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1982 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1983 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1984 pa_disable_sigpipe();
1986 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1987 pa_log(_("pa_context_new() failed."));
1991 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1992 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1993 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1997 if (pa_mainloop_run(m
, &ret
) < 0) {
1998 pa_log(_("pa_mainloop_run() failed."));
2004 pa_stream_unref(sample_stream
);
2007 pa_context_unref(context
);
2011 pa_mainloop_free(m
);
2015 pa_xfree(list_type
);
2016 pa_xfree(sample_name
);
2017 pa_xfree(sink_name
);
2018 pa_xfree(source_name
);
2019 pa_xfree(module_args
);
2020 pa_xfree(card_name
);
2021 pa_xfree(profile_name
);
2022 pa_xfree(port_name
);
2029 pa_proplist_free(proplist
);