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
;
120 SET_SINK_INPUT_VOLUME
,
121 SET_SOURCE_OUTPUT_VOLUME
,
125 SET_SOURCE_OUTPUT_MUTE
,
127 SET_PORT_LATENCY_OFFSET
,
131 static void quit(int ret
) {
132 pa_assert(mainloop_api
);
133 mainloop_api
->quit(mainloop_api
, ret
);
136 static void context_drain_complete(pa_context
*c
, void *userdata
) {
137 pa_context_disconnect(c
);
140 static void drain(void) {
143 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
144 pa_context_disconnect(context
);
146 pa_operation_unref(o
);
149 static void complete_action(void) {
150 pa_assert(actions
> 0);
156 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
157 char s
[PA_BYTES_SNPRINT_MAX
];
159 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
164 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
165 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
167 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
168 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
170 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
171 printf(_("Sample cache size: %s\n"), s
);
176 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
177 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
180 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
185 printf(_("Server String: %s\n"
186 "Library Protocol Version: %u\n"
187 "Server Protocol Version: %u\n"
191 pa_context_get_server(c
),
192 pa_context_get_protocol_version(c
),
193 pa_context_get_server_protocol_version(c
),
194 pa_yes_no(pa_context_is_local(c
)),
195 pa_context_get_index(c
),
196 pa_context_get_tile_size(c
, NULL
));
198 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
199 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
201 printf(_("User Name: %s\n"
204 "Server Version: %s\n"
205 "Default Sample Specification: %s\n"
206 "Default Channel Map: %s\n"
208 "Default Source: %s\n"
209 "Cookie: %04x:%04x\n"),
216 i
->default_sink_name
,
217 i
->default_source_name
,
219 i
->cookie
& 0xFFFFU
);
224 static const char* get_available_str_ynonly(int available
)
227 case PA_PORT_AVAILABLE_YES
: return ", available";
228 case PA_PORT_AVAILABLE_NO
: return ", not available";
233 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
235 static const char *state_table
[] = {
236 [1+PA_SINK_INVALID_STATE
] = "n/a",
237 [1+PA_SINK_RUNNING
] = "RUNNING",
238 [1+PA_SINK_IDLE
] = "IDLE",
239 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
243 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
244 cv
[PA_CVOLUME_SNPRINT_MAX
],
245 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
246 v
[PA_VOLUME_SNPRINT_MAX
],
247 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
248 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
249 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
253 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
265 if (nl
&& !short_list_format
)
269 if (short_list_format
) {
270 printf("%u\t%s\t%s\t%s\t%s\n",
273 pa_strnull(i
->driver
),
274 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
275 state_table
[1+i
->state
]);
279 printf(_("Sink #%u\n"
282 "\tDescription: %s\n"
284 "\tSample Specification: %s\n"
285 "\tChannel Map: %s\n"
286 "\tOwner Module: %u\n"
290 "\tBase Volume: %s%s%s\n"
291 "\tMonitor Source: %s\n"
292 "\tLatency: %0.0f usec, configured %0.0f usec\n"
293 "\tFlags: %s%s%s%s%s%s%s\n"
294 "\tProperties:\n\t\t%s\n"),
296 state_table
[1+i
->state
],
298 pa_strnull(i
->description
),
299 pa_strnull(i
->driver
),
300 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
301 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
304 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
305 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
306 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
307 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
308 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
309 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
310 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
311 pa_strnull(i
->monitor_source_name
),
312 (double) i
->latency
, (double) i
->configured_latency
,
313 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
314 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
315 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
316 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
317 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
318 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
319 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
320 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
325 pa_sink_port_info
**p
;
327 printf(_("\tPorts:\n"));
328 for (p
= i
->ports
; *p
; p
++)
329 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
330 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
334 printf(_("\tActive Port: %s\n"),
335 i
->active_port
->name
);
340 printf(_("\tFormats:\n"));
341 for (j
= 0; j
< i
->n_formats
; j
++)
342 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
346 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
348 static const char *state_table
[] = {
349 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
350 [1+PA_SOURCE_RUNNING
] = "RUNNING",
351 [1+PA_SOURCE_IDLE
] = "IDLE",
352 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
356 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
357 cv
[PA_CVOLUME_SNPRINT_MAX
],
358 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
359 v
[PA_VOLUME_SNPRINT_MAX
],
360 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
361 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
362 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
366 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
378 if (nl
&& !short_list_format
)
382 if (short_list_format
) {
383 printf("%u\t%s\t%s\t%s\t%s\n",
386 pa_strnull(i
->driver
),
387 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
388 state_table
[1+i
->state
]);
392 printf(_("Source #%u\n"
395 "\tDescription: %s\n"
397 "\tSample Specification: %s\n"
398 "\tChannel Map: %s\n"
399 "\tOwner Module: %u\n"
403 "\tBase Volume: %s%s%s\n"
404 "\tMonitor of Sink: %s\n"
405 "\tLatency: %0.0f usec, configured %0.0f usec\n"
406 "\tFlags: %s%s%s%s%s%s\n"
407 "\tProperties:\n\t\t%s\n"),
409 state_table
[1+i
->state
],
411 pa_strnull(i
->description
),
412 pa_strnull(i
->driver
),
413 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
414 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
417 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
418 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
419 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
420 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
421 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
422 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
423 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
424 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
425 (double) i
->latency
, (double) i
->configured_latency
,
426 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
427 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
428 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
429 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
430 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
431 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
432 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
437 pa_source_port_info
**p
;
439 printf(_("\tPorts:\n"));
440 for (p
= i
->ports
; *p
; p
++)
441 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
,
442 (*p
)->priority
, get_available_str_ynonly((*p
)->available
));
446 printf(_("\tActive Port: %s\n"),
447 i
->active_port
->name
);
452 printf(_("\tFormats:\n"));
453 for (j
= 0; j
< i
->n_formats
; j
++)
454 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
458 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
463 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
475 if (nl
&& !short_list_format
)
479 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
481 if (short_list_format
) {
482 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
486 printf(_("Module #%u\n"
489 "\tUsage counter: %s\n"
490 "\tProperties:\n\t\t%s\n"),
493 i
->argument
? i
->argument
: "",
494 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
495 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
500 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
505 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
517 if (nl
&& !short_list_format
)
521 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
523 if (short_list_format
) {
524 printf("%u\t%s\t%s\n",
526 pa_strnull(i
->driver
),
527 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
531 printf(_("Client #%u\n"
533 "\tOwner Module: %s\n"
534 "\tProperties:\n\t\t%s\n"),
536 pa_strnull(i
->driver
),
537 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
538 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
543 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
548 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
560 if (nl
&& !short_list_format
)
564 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
566 if (short_list_format
) {
567 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
571 printf(_("Card #%u\n"
574 "\tOwner Module: %s\n"
575 "\tProperties:\n\t\t%s\n"),
578 pa_strnull(i
->driver
),
579 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
580 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
585 pa_card_profile_info
*p
;
587 printf(_("\tProfiles:\n"));
588 for (p
= i
->profiles
; p
->name
; p
++)
589 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
592 if (i
->active_profile
)
593 printf(_("\tActive Profile: %s\n"),
594 i
->active_profile
->name
);
597 pa_card_port_info
**p
;
599 printf(_("\tPorts:\n"));
600 for (p
= i
->ports
; *p
; p
++) {
601 pa_card_profile_info
**pr
= (*p
)->profiles
;
602 printf("\t\t%s: %s (priority: %u, latency offset: %" PRId64
" usec%s)\n", (*p
)->name
,
603 (*p
)->description
, (*p
)->priority
, (*p
)->latency_offset
,
604 get_available_str_ynonly((*p
)->available
));
606 if (!pa_proplist_isempty((*p
)->proplist
)) {
607 printf(_("\t\t\tProperties:\n\t\t\t\t%s\n"), pl
= pa_proplist_to_string_sep((*p
)->proplist
, "\n\t\t\t\t"));
612 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr
)->name
));
615 printf(", %s", pa_strnull((*pr
)->name
));
624 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
625 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
];
629 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
641 if (nl
&& !short_list_format
)
645 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
646 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
648 if (short_list_format
) {
649 printf("%u\t%u\t%s\t%s\t%s\n",
652 i
->client
!= PA_INVALID_INDEX
? k
: "-",
653 pa_strnull(i
->driver
),
654 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
658 printf(_("Sink Input #%u\n"
660 "\tOwner Module: %s\n"
663 "\tSample Specification: %s\n"
664 "\tChannel Map: %s\n"
671 "\tBuffer Latency: %0.0f usec\n"
672 "\tSink Latency: %0.0f usec\n"
673 "\tResample method: %s\n"
674 "\tProperties:\n\t\t%s\n"),
676 pa_strnull(i
->driver
),
677 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
678 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
680 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
681 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
682 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
683 pa_yes_no(i
->corked
),
685 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
686 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
687 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
688 (double) i
->buffer_usec
,
689 (double) i
->sink_usec
,
690 i
->resample_method
? i
->resample_method
: _("n/a"),
691 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
696 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
697 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
];
701 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
713 if (nl
&& !short_list_format
)
718 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
719 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
721 if (short_list_format
) {
722 printf("%u\t%u\t%s\t%s\t%s\n",
725 i
->client
!= PA_INVALID_INDEX
? k
: "-",
726 pa_strnull(i
->driver
),
727 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
731 printf(_("Source Output #%u\n"
733 "\tOwner Module: %s\n"
736 "\tSample Specification: %s\n"
737 "\tChannel Map: %s\n"
744 "\tBuffer Latency: %0.0f usec\n"
745 "\tSource Latency: %0.0f usec\n"
746 "\tResample method: %s\n"
747 "\tProperties:\n\t\t%s\n"),
749 pa_strnull(i
->driver
),
750 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
751 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
753 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
754 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
755 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
756 pa_yes_no(i
->corked
),
758 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
759 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
760 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
761 (double) i
->buffer_usec
,
762 (double) i
->source_usec
,
763 i
->resample_method
? i
->resample_method
: _("n/a"),
764 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
769 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
770 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
];
774 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
786 if (nl
&& !short_list_format
)
790 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
792 if (short_list_format
) {
793 printf("%u\t%s\t%s\t%0.3f\n",
796 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
797 (double) i
->duration
/1000000.0);
801 printf(_("Sample #%u\n"
803 "\tSample Specification: %s\n"
804 "\tChannel Map: %s\n"
808 "\tDuration: %0.1fs\n"
812 "\tProperties:\n\t\t%s\n"),
815 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
816 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
817 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
818 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
819 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
820 (double) i
->duration
/1000000.0,
823 i
->filename
? i
->filename
: _("n/a"),
824 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
829 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
831 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
839 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
840 if (idx
== PA_INVALID_INDEX
) {
841 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
851 static void volume_relative_adjust(pa_cvolume
*cv
) {
852 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
854 /* Relative volume change is additive in case of UINT or PERCENT
855 * and multiplicative for LINEAR or DECIBEL */
856 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
857 pa_volume_t v
= pa_cvolume_avg(cv
);
858 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
859 pa_cvolume_set(cv
, 1, v
);
861 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
862 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
866 static void unload_module_by_name_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
867 static pa_bool_t unloaded
= FALSE
;
870 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
876 if (unloaded
== FALSE
)
877 pa_log(_("Failed to unload module: Module %s not loaded"), module_name
);
884 if (pa_streq(module_name
, i
->name
)) {
887 pa_operation_unref(pa_context_unload_module(c
, i
->index
, simple_callback
, NULL
));
891 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
895 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
906 volume_relative_adjust(&cv
);
907 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
910 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
914 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
925 volume_relative_adjust(&cv
);
926 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
929 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
933 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
944 volume_relative_adjust(&cv
);
945 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
948 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
952 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
963 volume_relative_adjust(&cv
);
964 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
967 static void sink_toggle_mute_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
969 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
979 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, i
->name
, !i
->mute
, simple_callback
, NULL
));
982 static void source_toggle_mute_callback(pa_context
*c
, const pa_source_info
*o
, int is_last
, void *userdata
) {
984 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
994 pa_operation_unref(pa_context_set_source_mute_by_name(c
, o
->name
, !o
->mute
, simple_callback
, NULL
));
997 static void sink_input_toggle_mute_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
999 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
1009 pa_operation_unref(pa_context_set_sink_input_mute(c
, i
->index
, !i
->mute
, simple_callback
, NULL
));
1012 static void source_output_toggle_mute_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
1014 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
1024 pa_operation_unref(pa_context_set_source_output_mute(c
, o
->index
, !o
->mute
, simple_callback
, NULL
));
1027 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
1028 #define MAX_FORMATS 256
1030 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
1031 pa_format_info
*f_arr
[MAX_FORMATS
];
1032 char *format
= NULL
;
1033 const char *state
= NULL
;
1036 while ((format
= pa_split(str
, ";", &state
))) {
1037 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
1040 pa_log(_("Failed to set format: invalid format string %s"), format
);
1048 pa_operation_unref(pa_ext_device_restore_save_formats(c
, PA_DEVICE_TYPE_SINK
, sink
, i
, f_arr
, simple_callback
, NULL
));
1054 pa_format_info_free(f_arr
[i
]);
1060 pa_format_info_free(f_arr
[i
]);
1065 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
1068 switch (pa_stream_get_state(s
)) {
1069 case PA_STREAM_CREATING
:
1070 case PA_STREAM_READY
:
1073 case PA_STREAM_TERMINATED
:
1077 case PA_STREAM_FAILED
:
1079 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
1084 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
1087 pa_assert(s
&& length
&& sndfile
);
1089 d
= pa_xmalloc(length
);
1091 pa_assert(sample_length
>= length
);
1092 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
1094 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
1096 pa_log(_("Premature end of file"));
1101 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
1103 sample_length
-= length
;
1105 if (sample_length
<= 0) {
1106 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
1107 pa_stream_finish_upload(sample_stream
);
1111 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
1113 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
1115 case PA_SUBSCRIPTION_EVENT_NEW
:
1118 case PA_SUBSCRIPTION_EVENT_CHANGE
:
1121 case PA_SUBSCRIPTION_EVENT_REMOVE
:
1125 return _("unknown");
1128 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
1130 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1132 case PA_SUBSCRIPTION_EVENT_SINK
:
1135 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1138 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1139 return _("sink-input");
1141 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1142 return _("source-output");
1144 case PA_SUBSCRIPTION_EVENT_MODULE
:
1147 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1150 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1151 return _("sample-cache");
1153 case PA_SUBSCRIPTION_EVENT_SERVER
:
1156 case PA_SUBSCRIPTION_EVENT_CARD
:
1160 return _("unknown");
1163 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1166 printf(_("Event '%s' on %s #%u\n"),
1167 subscription_event_type_to_string(t
),
1168 subscription_event_facility_to_string(t
),
1172 static void context_state_callback(pa_context
*c
, void *userdata
) {
1174 switch (pa_context_get_state(c
)) {
1175 case PA_CONTEXT_CONNECTING
:
1176 case PA_CONTEXT_AUTHORIZING
:
1177 case PA_CONTEXT_SETTING_NAME
:
1180 case PA_CONTEXT_READY
:
1183 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1184 if (short_list_format
)
1189 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1193 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1197 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1201 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1202 pa_assert(sample_stream
);
1204 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1205 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1206 pa_stream_connect_upload(sample_stream
, sample_length
);
1210 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1215 if (pa_streq(list_type
, "modules"))
1216 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1217 else if (pa_streq(list_type
, "sinks"))
1218 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1219 else if (pa_streq(list_type
, "sources"))
1220 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1221 else if (pa_streq(list_type
, "sink-inputs"))
1222 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1223 else if (pa_streq(list_type
, "source-outputs"))
1224 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1225 else if (pa_streq(list_type
, "clients"))
1226 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1227 else if (pa_streq(list_type
, "samples"))
1228 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1229 else if (pa_streq(list_type
, "cards"))
1230 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1232 pa_assert_not_reached();
1235 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1236 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1237 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1238 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1239 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1240 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1241 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1242 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1246 case MOVE_SINK_INPUT
:
1247 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1250 case MOVE_SOURCE_OUTPUT
:
1251 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1255 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1260 pa_operation_unref(pa_context_get_module_info_list(c
, unload_module_by_name_callback
, NULL
));
1262 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1267 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1269 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1272 case SUSPEND_SOURCE
:
1274 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1276 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1279 case SET_CARD_PROFILE
:
1280 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1284 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1287 case SET_SOURCE_PORT
:
1288 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1292 if (mute
== TOGGLE_MUTE
)
1293 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, sink_toggle_mute_callback
, NULL
));
1295 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1298 case SET_SOURCE_MUTE
:
1299 if (mute
== TOGGLE_MUTE
)
1300 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, source_toggle_mute_callback
, NULL
));
1302 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1305 case SET_SINK_INPUT_MUTE
:
1306 if (mute
== TOGGLE_MUTE
)
1307 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, sink_input_toggle_mute_callback
, NULL
));
1309 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1312 case SET_SOURCE_OUTPUT_MUTE
:
1313 if (mute
== TOGGLE_MUTE
)
1314 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, source_output_toggle_mute_callback
, NULL
));
1316 pa_operation_unref(pa_context_set_source_output_mute(c
, source_output_idx
, mute
, simple_callback
, NULL
));
1319 case SET_SINK_VOLUME
:
1320 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1321 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1324 pa_cvolume_set(&v
, 1, volume
);
1325 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1329 case SET_SOURCE_VOLUME
:
1330 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1331 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1334 pa_cvolume_set(&v
, 1, volume
);
1335 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1339 case SET_SINK_INPUT_VOLUME
:
1340 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1341 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1344 pa_cvolume_set(&v
, 1, volume
);
1345 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1349 case SET_SOURCE_OUTPUT_VOLUME
:
1350 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1351 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1354 pa_cvolume_set(&v
, 1, volume
);
1355 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1359 case SET_SINK_FORMATS
:
1360 set_sink_formats(c
, sink_idx
, formats
);
1363 case SET_PORT_LATENCY_OFFSET
:
1364 pa_operation_unref(pa_context_set_port_latency_offset(c
, card_name
, port_name
, latency_offset
, simple_callback
, NULL
));
1368 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1370 pa_operation_unref(pa_context_subscribe(
1372 PA_SUBSCRIPTION_MASK_SINK
|
1373 PA_SUBSCRIPTION_MASK_SOURCE
|
1374 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1375 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1376 PA_SUBSCRIPTION_MASK_MODULE
|
1377 PA_SUBSCRIPTION_MASK_CLIENT
|
1378 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1379 PA_SUBSCRIPTION_MASK_SERVER
|
1380 PA_SUBSCRIPTION_MASK_CARD
,
1386 pa_assert_not_reached();
1390 case PA_CONTEXT_TERMINATED
:
1394 case PA_CONTEXT_FAILED
:
1396 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1401 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1402 pa_log(_("Got SIGINT, exiting."));
1406 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1410 pa_assert(vol_spec
);
1412 pa_assert(vol_flags
);
1414 vs
= pa_xstrdup(vol_spec
);
1416 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1417 if (strchr(vs
, '.'))
1418 *vol_flags
|= VOL_LINEAR
;
1419 if (pa_endswith(vs
, "%")) {
1420 *vol_flags
|= VOL_PERCENT
;
1421 vs
[strlen(vs
)-1] = 0;
1423 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1424 *vol_flags
|= VOL_DECIBEL
;
1425 vs
[strlen(vs
)-2] = 0;
1428 if (pa_atod(vs
, &v
) < 0) {
1429 pa_log(_("Invalid volume specification"));
1436 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1437 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1438 v
+= (double) PA_VOLUME_NORM
;
1439 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1441 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1444 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1445 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1446 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1447 v
= pa_sw_volume_from_linear(v
);
1448 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1449 v
= pa_sw_volume_from_dB(v
);
1451 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1452 pa_log(_("Volume outside permissible range.\n"));
1456 *vol
= (pa_volume_t
) v
;
1461 static enum mute_flags
parse_mute(const char *mute_text
) {
1464 pa_assert(mute_text
);
1466 if (pa_streq("toggle", mute_text
))
1469 b
= pa_parse_boolean(mute_text
);
1476 return INVALID_MUTE
;
1480 static void help(const char *argv0
) {
1482 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1483 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1484 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1485 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1486 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1487 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1488 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1489 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1490 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("NAME|#N"));
1491 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1492 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1493 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1494 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1495 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1496 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1497 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0|toggle"));
1498 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0|toggle"));
1499 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1500 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
1501 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1504 " -h, --help Show this help\n"
1505 " --version Show version\n\n"
1506 " -s, --server=SERVER The name of the server to connect to\n"
1507 " -n, --client-name=NAME How to call this client on the server\n"));
1514 int main(int argc
, char *argv
[]) {
1515 pa_mainloop
*m
= NULL
;
1517 char *server
= NULL
, *bn
;
1519 static const struct option long_options
[] = {
1520 {"server", 1, NULL
, 's'},
1521 {"client-name", 1, NULL
, 'n'},
1522 {"version", 0, NULL
, ARG_VERSION
},
1523 {"help", 0, NULL
, 'h'},
1527 setlocale(LC_ALL
, "");
1529 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1532 bn
= pa_path_get_filename(argv
[0]);
1534 proplist
= pa_proplist_new();
1536 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1544 printf(_("pactl %s\n"
1545 "Compiled with libpulse %s\n"
1546 "Linked with libpulse %s\n"),
1548 pa_get_headers_version(),
1549 pa_get_library_version());
1555 server
= pa_xstrdup(optarg
);
1561 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1562 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1564 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1578 if (optind
< argc
) {
1579 if (pa_streq(argv
[optind
], "stat")) {
1581 short_list_format
= FALSE
;
1582 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1583 short_list_format
= TRUE
;
1585 } else if (pa_streq(argv
[optind
], "info"))
1588 else if (pa_streq(argv
[optind
], "exit"))
1591 else if (pa_streq(argv
[optind
], "list")) {
1594 for (int i
= optind
+1; i
< argc
; i
++){
1595 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1596 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1597 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1598 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1599 list_type
= pa_xstrdup(argv
[i
]);
1600 } else if (pa_streq(argv
[i
], "short")) {
1601 short_list_format
= TRUE
;
1603 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1608 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1610 action
= UPLOAD_SAMPLE
;
1612 if (optind
+1 >= argc
) {
1613 pa_log(_("Please specify a sample file to load"));
1617 if (optind
+2 < argc
)
1618 sample_name
= pa_xstrdup(argv
[optind
+2]);
1620 char *f
= pa_path_get_filename(argv
[optind
+1]);
1621 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1625 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1626 pa_log(_("Failed to open sound file."));
1630 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1631 pa_log(_("Failed to determine sample specification from file."));
1634 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1636 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1637 if (sample_spec
.channels
> 2)
1638 pa_log(_("Warning: Failed to determine sample specification from file."));
1639 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1642 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1643 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1645 } else if (pa_streq(argv
[optind
], "play-sample")) {
1646 action
= PLAY_SAMPLE
;
1647 if (argc
!= optind
+2 && argc
!= optind
+3) {
1648 pa_log(_("You have to specify a sample name to play"));
1652 sample_name
= pa_xstrdup(argv
[optind
+1]);
1654 if (optind
+2 < argc
)
1655 sink_name
= pa_xstrdup(argv
[optind
+2]);
1657 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1658 action
= REMOVE_SAMPLE
;
1659 if (argc
!= optind
+2) {
1660 pa_log(_("You have to specify a sample name to remove"));
1664 sample_name
= pa_xstrdup(argv
[optind
+1]);
1666 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1667 action
= MOVE_SINK_INPUT
;
1668 if (argc
!= optind
+3) {
1669 pa_log(_("You have to specify a sink input index and a sink"));
1673 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1674 sink_name
= pa_xstrdup(argv
[optind
+2]);
1676 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1677 action
= MOVE_SOURCE_OUTPUT
;
1678 if (argc
!= optind
+3) {
1679 pa_log(_("You have to specify a source output index and a source"));
1683 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1684 source_name
= pa_xstrdup(argv
[optind
+2]);
1686 } else if (pa_streq(argv
[optind
], "load-module")) {
1691 action
= LOAD_MODULE
;
1693 if (argc
<= optind
+1) {
1694 pa_log(_("You have to specify a module name and arguments."));
1698 module_name
= argv
[optind
+1];
1700 for (i
= optind
+2; i
< argc
; i
++)
1701 n
+= strlen(argv
[i
])+1;
1704 p
= module_args
= pa_xmalloc(n
);
1706 for (i
= optind
+2; i
< argc
; i
++)
1707 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1710 } else if (pa_streq(argv
[optind
], "unload-module")) {
1711 action
= UNLOAD_MODULE
;
1713 if (argc
!= optind
+2) {
1714 pa_log(_("You have to specify a module index or name"));
1718 if (pa_atou(argv
[optind
+ 1], &module_index
) < 0)
1719 module_name
= argv
[optind
+ 1];
1721 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1724 action
= SUSPEND_SINK
;
1726 if (argc
> optind
+3 || optind
+1 >= argc
) {
1727 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1731 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1732 pa_log(_("Invalid suspend specification."));
1738 if (argc
> optind
+2)
1739 sink_name
= pa_xstrdup(argv
[optind
+1]);
1741 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1744 action
= SUSPEND_SOURCE
;
1746 if (argc
> optind
+3 || optind
+1 >= argc
) {
1747 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1751 if ((b
= pa_parse_boolean(argv
[argc
-1])) < 0) {
1752 pa_log(_("Invalid suspend specification."));
1758 if (argc
> optind
+2)
1759 source_name
= pa_xstrdup(argv
[optind
+1]);
1760 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1761 action
= SET_CARD_PROFILE
;
1763 if (argc
!= optind
+3) {
1764 pa_log(_("You have to specify a card name/index and a profile name"));
1768 card_name
= pa_xstrdup(argv
[optind
+1]);
1769 profile_name
= pa_xstrdup(argv
[optind
+2]);
1771 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1772 action
= SET_SINK_PORT
;
1774 if (argc
!= optind
+3) {
1775 pa_log(_("You have to specify a sink name/index and a port name"));
1779 sink_name
= pa_xstrdup(argv
[optind
+1]);
1780 port_name
= pa_xstrdup(argv
[optind
+2]);
1782 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1783 action
= SET_SOURCE_PORT
;
1785 if (argc
!= optind
+3) {
1786 pa_log(_("You have to specify a source name/index and a port name"));
1790 source_name
= pa_xstrdup(argv
[optind
+1]);
1791 port_name
= pa_xstrdup(argv
[optind
+2]);
1793 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1794 action
= SET_SINK_VOLUME
;
1796 if (argc
!= optind
+3) {
1797 pa_log(_("You have to specify a sink name/index and a volume"));
1801 sink_name
= pa_xstrdup(argv
[optind
+1]);
1803 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1806 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1807 action
= SET_SOURCE_VOLUME
;
1809 if (argc
!= optind
+3) {
1810 pa_log(_("You have to specify a source name/index and a volume"));
1814 source_name
= pa_xstrdup(argv
[optind
+1]);
1816 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1819 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1820 action
= SET_SINK_INPUT_VOLUME
;
1822 if (argc
!= optind
+3) {
1823 pa_log(_("You have to specify a sink input index and a volume"));
1827 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1828 pa_log(_("Invalid sink input index"));
1832 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1835 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1836 action
= SET_SOURCE_OUTPUT_VOLUME
;
1838 if (argc
!= optind
+3) {
1839 pa_log(_("You have to specify a source output index and a volume"));
1843 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1844 pa_log(_("Invalid source output index"));
1848 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1851 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1852 action
= SET_SINK_MUTE
;
1854 if (argc
!= optind
+3) {
1855 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1859 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1860 pa_log(_("Invalid mute specification"));
1864 sink_name
= pa_xstrdup(argv
[optind
+1]);
1866 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1867 action
= SET_SOURCE_MUTE
;
1869 if (argc
!= optind
+3) {
1870 pa_log(_("You have to specify a source name/index and a mute boolean"));
1874 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1875 pa_log(_("Invalid mute specification"));
1879 source_name
= pa_xstrdup(argv
[optind
+1]);
1881 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1882 action
= SET_SINK_INPUT_MUTE
;
1884 if (argc
!= optind
+3) {
1885 pa_log(_("You have to specify a sink input index and a mute boolean"));
1889 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1890 pa_log(_("Invalid sink input index specification"));
1894 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1895 pa_log(_("Invalid mute specification"));
1899 } else if (pa_streq(argv
[optind
], "set-source-output-mute")) {
1900 action
= SET_SOURCE_OUTPUT_MUTE
;
1902 if (argc
!= optind
+3) {
1903 pa_log(_("You have to specify a source output index and a mute boolean"));
1907 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1908 pa_log(_("Invalid source output index specification"));
1912 if ((mute
= parse_mute(argv
[optind
+2])) == INVALID_MUTE
) {
1913 pa_log(_("Invalid mute specification"));
1917 } else if (pa_streq(argv
[optind
], "subscribe"))
1921 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1924 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1925 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1930 action
= SET_SINK_FORMATS
;
1931 formats
= pa_xstrdup(argv
[optind
+2]);
1933 } else if (pa_streq(argv
[optind
], "set-port-latency-offset")) {
1934 action
= SET_PORT_LATENCY_OFFSET
;
1936 if (argc
!= optind
+4) {
1937 pa_log(_("You have to specify a card name/index, a port name and a latency offset"));
1941 card_name
= pa_xstrdup(argv
[optind
+1]);
1942 port_name
= pa_xstrdup(argv
[optind
+2]);
1943 if (pa_atoi(argv
[optind
+ 3], &latency_offset
) < 0) {
1944 pa_log(_("Could not parse latency offset"));
1948 } else if (pa_streq(argv
[optind
], "help")) {
1955 if (action
== NONE
) {
1956 pa_log(_("No valid command specified."));
1960 if (!(m
= pa_mainloop_new())) {
1961 pa_log(_("pa_mainloop_new() failed."));
1965 mainloop_api
= pa_mainloop_get_api(m
);
1967 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1968 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1969 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1970 pa_disable_sigpipe();
1972 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1973 pa_log(_("pa_context_new() failed."));
1977 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1978 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1979 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1983 if (pa_mainloop_run(m
, &ret
) < 0) {
1984 pa_log(_("pa_mainloop_run() failed."));
1990 pa_stream_unref(sample_stream
);
1993 pa_context_unref(context
);
1997 pa_mainloop_free(m
);
2001 pa_xfree(list_type
);
2002 pa_xfree(sample_name
);
2003 pa_xfree(sink_name
);
2004 pa_xfree(source_name
);
2005 pa_xfree(module_args
);
2006 pa_xfree(card_name
);
2007 pa_xfree(profile_name
);
2008 pa_xfree(port_name
);
2015 pa_proplist_free(proplist
);