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 pa_bool_t suspend
;
71 static pa_bool_t mute
;
72 static pa_volume_t volume
;
73 static enum volume_flags
{
78 VOL_ABSOLUTE
= 0 << 4,
79 VOL_RELATIVE
= 1 << 4,
82 static pa_proplist
*proplist
= NULL
;
84 static SNDFILE
*sndfile
= NULL
;
85 static pa_stream
*sample_stream
= NULL
;
86 static pa_sample_spec sample_spec
;
87 static pa_channel_map channel_map
;
88 static size_t sample_length
= 0;
89 static int actions
= 1;
91 static pa_bool_t nl
= FALSE
;
113 SET_SINK_INPUT_VOLUME
,
114 SET_SOURCE_OUTPUT_VOLUME
,
118 SET_SOURCE_OUTPUT_MUTE
,
123 static void quit(int ret
) {
124 pa_assert(mainloop_api
);
125 mainloop_api
->quit(mainloop_api
, ret
);
128 static void context_drain_complete(pa_context
*c
, void *userdata
) {
129 pa_context_disconnect(c
);
132 static void drain(void) {
135 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
136 pa_context_disconnect(context
);
138 pa_operation_unref(o
);
141 static void complete_action(void) {
142 pa_assert(actions
> 0);
148 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
149 char s
[PA_BYTES_SNPRINT_MAX
];
151 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
156 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
157 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
159 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
160 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
162 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
163 printf(_("Sample cache size: %s\n"), s
);
168 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
169 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
172 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
177 printf(_("Server String: %s\n"
178 "Library Protocol Version: %u\n"
179 "Server Protocol Version: %u\n"
183 pa_context_get_server(c
),
184 pa_context_get_protocol_version(c
),
185 pa_context_get_server_protocol_version(c
),
186 pa_yes_no(pa_context_is_local(c
)),
187 pa_context_get_index(c
),
188 pa_context_get_tile_size(c
, NULL
));
190 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
191 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
193 printf(_("User Name: %s\n"
196 "Server Version: %s\n"
197 "Default Sample Specification: %s\n"
198 "Default Channel Map: %s\n"
200 "Default Source: %s\n"
201 "Cookie: %04x:%04x\n"),
208 i
->default_sink_name
,
209 i
->default_source_name
,
211 i
->cookie
& 0xFFFFU
);
216 static const char* get_available_str_ynonly(int available
)
219 case PA_PORT_AVAILABLE_YES
: return ", available";
220 case PA_PORT_AVAILABLE_NO
: return ", not available";
225 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
227 static const char *state_table
[] = {
228 [1+PA_SINK_INVALID_STATE
] = "n/a",
229 [1+PA_SINK_RUNNING
] = "RUNNING",
230 [1+PA_SINK_IDLE
] = "IDLE",
231 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
235 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
236 cv
[PA_CVOLUME_SNPRINT_MAX
],
237 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
238 v
[PA_VOLUME_SNPRINT_MAX
],
239 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
240 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
241 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
245 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
257 if (nl
&& !short_list_format
)
261 if (short_list_format
) {
262 printf("%u\t%s\t%s\t%s\t%s\n",
265 pa_strnull(i
->driver
),
266 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
267 state_table
[1+i
->state
]);
271 printf(_("Sink #%u\n"
274 "\tDescription: %s\n"
276 "\tSample Specification: %s\n"
277 "\tChannel Map: %s\n"
278 "\tOwner Module: %u\n"
282 "\tBase Volume: %s%s%s\n"
283 "\tMonitor Source: %s\n"
284 "\tLatency: %0.0f usec, configured %0.0f usec\n"
285 "\tFlags: %s%s%s%s%s%s%s\n"
286 "\tProperties:\n\t\t%s\n"),
288 state_table
[1+i
->state
],
290 pa_strnull(i
->description
),
291 pa_strnull(i
->driver
),
292 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
293 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
296 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
297 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
298 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
299 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
300 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
301 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
302 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
303 pa_strnull(i
->monitor_source_name
),
304 (double) i
->latency
, (double) i
->configured_latency
,
305 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
306 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
307 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
308 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
309 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
310 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
311 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
312 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
317 pa_sink_port_info
**p
;
319 printf(_("\tPorts:\n"));
320 for (p
= i
->ports
; *p
; p
++)
321 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
,
322 get_available_str_ynonly((*p
)->available
));
326 printf(_("\tActive Port: %s\n"),
327 i
->active_port
->name
);
332 printf(_("\tFormats:\n"));
333 for (j
= 0; j
< i
->n_formats
; j
++)
334 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
338 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
340 static const char *state_table
[] = {
341 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
342 [1+PA_SOURCE_RUNNING
] = "RUNNING",
343 [1+PA_SOURCE_IDLE
] = "IDLE",
344 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
348 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
349 cv
[PA_CVOLUME_SNPRINT_MAX
],
350 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
351 v
[PA_VOLUME_SNPRINT_MAX
],
352 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
353 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
354 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
358 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
370 if (nl
&& !short_list_format
)
374 if (short_list_format
) {
375 printf("%u\t%s\t%s\t%s\t%s\n",
378 pa_strnull(i
->driver
),
379 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
380 state_table
[1+i
->state
]);
384 printf(_("Source #%u\n"
387 "\tDescription: %s\n"
389 "\tSample Specification: %s\n"
390 "\tChannel Map: %s\n"
391 "\tOwner Module: %u\n"
395 "\tBase Volume: %s%s%s\n"
396 "\tMonitor of Sink: %s\n"
397 "\tLatency: %0.0f usec, configured %0.0f usec\n"
398 "\tFlags: %s%s%s%s%s%s\n"
399 "\tProperties:\n\t\t%s\n"),
401 state_table
[1+i
->state
],
403 pa_strnull(i
->description
),
404 pa_strnull(i
->driver
),
405 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
406 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
409 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
410 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
411 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
412 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
413 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
414 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
415 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
416 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
417 (double) i
->latency
, (double) i
->configured_latency
,
418 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
419 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
420 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
421 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
422 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
423 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
424 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
429 pa_source_port_info
**p
;
431 printf(_("\tPorts:\n"));
432 for (p
= i
->ports
; *p
; p
++)
433 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
,
434 get_available_str_ynonly((*p
)->available
));
438 printf(_("\tActive Port: %s\n"),
439 i
->active_port
->name
);
444 printf(_("\tFormats:\n"));
445 for (j
= 0; j
< i
->n_formats
; j
++)
446 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
450 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
455 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
467 if (nl
&& !short_list_format
)
471 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
473 if (short_list_format
) {
474 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
478 printf(_("Module #%u\n"
481 "\tUsage counter: %s\n"
482 "\tProperties:\n\t\t%s\n"),
485 i
->argument
? i
->argument
: "",
486 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
487 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
492 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
497 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
509 if (nl
&& !short_list_format
)
513 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
515 if (short_list_format
) {
516 printf("%u\t%s\t%s\n",
518 pa_strnull(i
->driver
),
519 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
523 printf(_("Client #%u\n"
525 "\tOwner Module: %s\n"
526 "\tProperties:\n\t\t%s\n"),
528 pa_strnull(i
->driver
),
529 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
530 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
535 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
540 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
552 if (nl
&& !short_list_format
)
556 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
558 if (short_list_format
) {
559 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
563 printf(_("Card #%u\n"
566 "\tOwner Module: %s\n"
567 "\tProperties:\n\t\t%s\n"),
570 pa_strnull(i
->driver
),
571 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
572 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
575 pa_card_profile_info
*p
;
577 printf(_("\tProfiles:\n"));
578 for (p
= i
->profiles
; p
->name
; p
++)
579 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
582 if (i
->active_profile
)
583 printf(_("\tActive Profile: %s\n"),
584 i
->active_profile
->name
);
587 pa_card_port_info
**p
;
589 printf(_("\tPorts:\n"));
590 for (p
= i
->ports
; *p
; p
++) {
591 pa_card_profile_info
**pr
= (*p
)->profiles
;
592 printf(_("\t\t%s: %s (priority: %u%s)\n"), (*p
)->name
, (*p
)->description
, (*p
)->priority
,
593 get_available_str_ynonly((*p
)->available
));
596 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr
)->name
));
599 printf(", %s", pa_strnull((*pr
)->name
));
610 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
611 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
];
615 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
627 if (nl
&& !short_list_format
)
631 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
632 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
634 if (short_list_format
) {
635 printf("%u\t%u\t%s\t%s\t%s\n",
638 i
->client
!= PA_INVALID_INDEX
? k
: "-",
639 pa_strnull(i
->driver
),
640 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
644 printf(_("Sink Input #%u\n"
646 "\tOwner Module: %s\n"
649 "\tSample Specification: %s\n"
650 "\tChannel Map: %s\n"
657 "\tBuffer Latency: %0.0f usec\n"
658 "\tSink Latency: %0.0f usec\n"
659 "\tResample method: %s\n"
660 "\tProperties:\n\t\t%s\n"),
662 pa_strnull(i
->driver
),
663 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
664 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
666 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
667 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
668 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
669 pa_yes_no(i
->corked
),
671 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
672 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
673 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
674 (double) i
->buffer_usec
,
675 (double) i
->sink_usec
,
676 i
->resample_method
? i
->resample_method
: _("n/a"),
677 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
682 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
683 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
];
687 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
699 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"
730 "\tBuffer Latency: %0.0f usec\n"
731 "\tSource Latency: %0.0f usec\n"
732 "\tResample method: %s\n"
733 "\tProperties:\n\t\t%s\n"),
735 pa_strnull(i
->driver
),
736 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
737 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
739 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
740 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
741 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
742 pa_yes_no(i
->corked
),
744 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
745 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
746 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
747 (double) i
->buffer_usec
,
748 (double) i
->source_usec
,
749 i
->resample_method
? i
->resample_method
: _("n/a"),
750 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
755 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
756 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
];
760 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
772 if (nl
&& !short_list_format
)
776 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
778 if (short_list_format
) {
779 printf("%u\t%s\t%s\t%0.3f\n",
782 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
783 (double) i
->duration
/1000000.0);
787 printf(_("Sample #%u\n"
789 "\tSample Specification: %s\n"
790 "\tChannel Map: %s\n"
794 "\tDuration: %0.1fs\n"
798 "\tProperties:\n\t\t%s\n"),
801 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
802 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
803 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
804 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
805 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
806 (double) i
->duration
/1000000.0,
809 i
->filename
? i
->filename
: _("n/a"),
810 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
815 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
817 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
825 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
826 if (idx
== PA_INVALID_INDEX
) {
827 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
837 static void volume_relative_adjust(pa_cvolume
*cv
) {
838 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
840 /* Relative volume change is additive in case of UINT or PERCENT
841 * and multiplicative for LINEAR or DECIBEL */
842 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
843 pa_volume_t v
= pa_cvolume_avg(cv
);
844 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
845 pa_cvolume_set(cv
, 1, v
);
847 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
848 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
852 static void unload_module_by_name_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
853 static pa_bool_t unloaded
= FALSE
;
856 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
862 if (unloaded
== FALSE
)
863 pa_log(_("Failed to unload module: Module %s not loaded"), module_name
);
870 if (pa_streq(module_name
, i
->name
)) {
873 pa_operation_unref(pa_context_unload_module(c
, i
->index
, simple_callback
, NULL
));
877 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
881 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
892 volume_relative_adjust(&cv
);
893 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
896 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
900 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
911 volume_relative_adjust(&cv
);
912 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
915 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
919 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
930 volume_relative_adjust(&cv
);
931 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
934 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
938 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
949 volume_relative_adjust(&cv
);
950 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
953 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
954 #define MAX_FORMATS 256
956 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
957 pa_format_info
*f_arr
[MAX_FORMATS
];
959 const char *state
= NULL
;
962 while ((format
= pa_split(str
, ";", &state
))) {
963 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
966 pa_log(_("Failed to set format: invalid format string %s"), format
);
974 pa_operation_unref(pa_ext_device_restore_save_formats(c
, PA_DEVICE_TYPE_SINK
, sink
, i
, f_arr
, simple_callback
, NULL
));
980 pa_format_info_free(f_arr
[i
]);
986 pa_format_info_free(f_arr
[i
]);
991 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
994 switch (pa_stream_get_state(s
)) {
995 case PA_STREAM_CREATING
:
996 case PA_STREAM_READY
:
999 case PA_STREAM_TERMINATED
:
1003 case PA_STREAM_FAILED
:
1005 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
1010 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
1013 pa_assert(s
&& length
&& sndfile
);
1015 d
= pa_xmalloc(length
);
1017 pa_assert(sample_length
>= length
);
1018 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
1020 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
1022 pa_log(_("Premature end of file"));
1027 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
1029 sample_length
-= length
;
1031 if (sample_length
<= 0) {
1032 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
1033 pa_stream_finish_upload(sample_stream
);
1037 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
1039 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
1041 case PA_SUBSCRIPTION_EVENT_NEW
:
1044 case PA_SUBSCRIPTION_EVENT_CHANGE
:
1047 case PA_SUBSCRIPTION_EVENT_REMOVE
:
1051 return _("unknown");
1054 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
1056 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1058 case PA_SUBSCRIPTION_EVENT_SINK
:
1061 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1064 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1065 return _("sink-input");
1067 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1068 return _("source-output");
1070 case PA_SUBSCRIPTION_EVENT_MODULE
:
1073 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1076 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1077 return _("sample-cache");
1079 case PA_SUBSCRIPTION_EVENT_SERVER
:
1082 case PA_SUBSCRIPTION_EVENT_CARD
:
1086 return _("unknown");
1089 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1092 printf(_("Event '%s' on %s #%u\n"),
1093 subscription_event_type_to_string(t
),
1094 subscription_event_facility_to_string(t
),
1098 static void context_state_callback(pa_context
*c
, void *userdata
) {
1100 switch (pa_context_get_state(c
)) {
1101 case PA_CONTEXT_CONNECTING
:
1102 case PA_CONTEXT_AUTHORIZING
:
1103 case PA_CONTEXT_SETTING_NAME
:
1106 case PA_CONTEXT_READY
:
1109 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1110 if (short_list_format
)
1115 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1119 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1123 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1127 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1128 pa_assert(sample_stream
);
1130 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1131 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1132 pa_stream_connect_upload(sample_stream
, sample_length
);
1136 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1141 if (pa_streq(list_type
, "modules"))
1142 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1143 else if (pa_streq(list_type
, "sinks"))
1144 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1145 else if (pa_streq(list_type
, "sources"))
1146 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1147 else if (pa_streq(list_type
, "sink-inputs"))
1148 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1149 else if (pa_streq(list_type
, "source-outputs"))
1150 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1151 else if (pa_streq(list_type
, "clients"))
1152 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1153 else if (pa_streq(list_type
, "samples"))
1154 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1155 else if (pa_streq(list_type
, "cards"))
1156 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1158 pa_assert_not_reached();
1161 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1162 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1163 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1164 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1165 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1166 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1167 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1168 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1172 case MOVE_SINK_INPUT
:
1173 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1176 case MOVE_SOURCE_OUTPUT
:
1177 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1181 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1186 pa_operation_unref(pa_context_get_module_info_list(c
, unload_module_by_name_callback
, NULL
));
1188 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1193 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1195 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1198 case SUSPEND_SOURCE
:
1200 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1202 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1205 case SET_CARD_PROFILE
:
1206 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1210 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1213 case SET_SOURCE_PORT
:
1214 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1218 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1221 case SET_SOURCE_MUTE
:
1222 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1225 case SET_SINK_INPUT_MUTE
:
1226 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1229 case SET_SOURCE_OUTPUT_MUTE
:
1230 pa_operation_unref(pa_context_set_source_output_mute(c
, source_output_idx
, mute
, simple_callback
, NULL
));
1233 case SET_SINK_VOLUME
:
1234 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1235 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1238 pa_cvolume_set(&v
, 1, volume
);
1239 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1243 case SET_SOURCE_VOLUME
:
1244 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1245 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1248 pa_cvolume_set(&v
, 1, volume
);
1249 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1253 case SET_SINK_INPUT_VOLUME
:
1254 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1255 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1258 pa_cvolume_set(&v
, 1, volume
);
1259 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1263 case SET_SOURCE_OUTPUT_VOLUME
:
1264 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1265 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1268 pa_cvolume_set(&v
, 1, volume
);
1269 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1273 case SET_SINK_FORMATS
:
1274 set_sink_formats(c
, sink_idx
, formats
);
1278 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1280 pa_operation_unref(pa_context_subscribe(
1282 PA_SUBSCRIPTION_MASK_SINK
|
1283 PA_SUBSCRIPTION_MASK_SOURCE
|
1284 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1285 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1286 PA_SUBSCRIPTION_MASK_MODULE
|
1287 PA_SUBSCRIPTION_MASK_CLIENT
|
1288 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1289 PA_SUBSCRIPTION_MASK_SERVER
|
1290 PA_SUBSCRIPTION_MASK_CARD
,
1296 pa_assert_not_reached();
1300 case PA_CONTEXT_TERMINATED
:
1304 case PA_CONTEXT_FAILED
:
1306 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1311 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1312 pa_log(_("Got SIGINT, exiting."));
1316 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1320 pa_assert(vol_spec
);
1322 pa_assert(vol_flags
);
1324 vs
= pa_xstrdup(vol_spec
);
1326 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1327 if (strchr(vs
, '.'))
1328 *vol_flags
|= VOL_LINEAR
;
1329 if (pa_endswith(vs
, "%")) {
1330 *vol_flags
|= VOL_PERCENT
;
1331 vs
[strlen(vs
)-1] = 0;
1333 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1334 *vol_flags
|= VOL_DECIBEL
;
1335 vs
[strlen(vs
)-2] = 0;
1338 if (pa_atod(vs
, &v
) < 0) {
1339 pa_log(_("Invalid volume specification"));
1346 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1347 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1348 v
+= (double) PA_VOLUME_NORM
;
1349 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1351 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1354 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1355 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1356 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1357 v
= pa_sw_volume_from_linear(v
);
1358 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1359 v
= pa_sw_volume_from_dB(v
);
1361 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1362 pa_log(_("Volume outside permissible range.\n"));
1366 *vol
= (pa_volume_t
) v
;
1371 static void help(const char *argv0
) {
1373 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1374 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1375 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1376 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1377 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1378 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1379 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1380 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1381 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("NAME|#N"));
1382 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1383 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1384 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1385 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1386 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1387 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1388 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0"));
1389 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0"));
1390 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1391 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1394 " -h, --help Show this help\n"
1395 " --version Show version\n\n"
1396 " -s, --server=SERVER The name of the server to connect to\n"
1397 " -n, --client-name=NAME How to call this client on the server\n"));
1404 int main(int argc
, char *argv
[]) {
1405 pa_mainloop
*m
= NULL
;
1407 char *server
= NULL
, *bn
;
1409 static const struct option long_options
[] = {
1410 {"server", 1, NULL
, 's'},
1411 {"client-name", 1, NULL
, 'n'},
1412 {"version", 0, NULL
, ARG_VERSION
},
1413 {"help", 0, NULL
, 'h'},
1417 setlocale(LC_ALL
, "");
1419 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1422 bn
= pa_path_get_filename(argv
[0]);
1424 proplist
= pa_proplist_new();
1426 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1434 printf(_("pactl %s\n"
1435 "Compiled with libpulse %s\n"
1436 "Linked with libpulse %s\n"),
1438 pa_get_headers_version(),
1439 pa_get_library_version());
1445 server
= pa_xstrdup(optarg
);
1451 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1452 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1454 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1468 if (optind
< argc
) {
1469 if (pa_streq(argv
[optind
], "stat")) {
1471 short_list_format
= FALSE
;
1472 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1473 short_list_format
= TRUE
;
1475 } else if (pa_streq(argv
[optind
], "info"))
1478 else if (pa_streq(argv
[optind
], "exit"))
1481 else if (pa_streq(argv
[optind
], "list")) {
1484 for (int i
= optind
+1; i
< argc
; i
++){
1485 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1486 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1487 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1488 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1489 list_type
= pa_xstrdup(argv
[i
]);
1490 } else if (pa_streq(argv
[i
], "short")) {
1491 short_list_format
= TRUE
;
1493 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1498 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1500 action
= UPLOAD_SAMPLE
;
1502 if (optind
+1 >= argc
) {
1503 pa_log(_("Please specify a sample file to load"));
1507 if (optind
+2 < argc
)
1508 sample_name
= pa_xstrdup(argv
[optind
+2]);
1510 char *f
= pa_path_get_filename(argv
[optind
+1]);
1511 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1515 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1516 pa_log(_("Failed to open sound file."));
1520 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1521 pa_log(_("Failed to determine sample specification from file."));
1524 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1526 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1527 if (sample_spec
.channels
> 2)
1528 pa_log(_("Warning: Failed to determine sample specification from file."));
1529 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1532 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1533 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1535 } else if (pa_streq(argv
[optind
], "play-sample")) {
1536 action
= PLAY_SAMPLE
;
1537 if (argc
!= optind
+2 && argc
!= optind
+3) {
1538 pa_log(_("You have to specify a sample name to play"));
1542 sample_name
= pa_xstrdup(argv
[optind
+1]);
1544 if (optind
+2 < argc
)
1545 sink_name
= pa_xstrdup(argv
[optind
+2]);
1547 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1548 action
= REMOVE_SAMPLE
;
1549 if (argc
!= optind
+2) {
1550 pa_log(_("You have to specify a sample name to remove"));
1554 sample_name
= pa_xstrdup(argv
[optind
+1]);
1556 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1557 action
= MOVE_SINK_INPUT
;
1558 if (argc
!= optind
+3) {
1559 pa_log(_("You have to specify a sink input index and a sink"));
1563 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1564 sink_name
= pa_xstrdup(argv
[optind
+2]);
1566 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1567 action
= MOVE_SOURCE_OUTPUT
;
1568 if (argc
!= optind
+3) {
1569 pa_log(_("You have to specify a source output index and a source"));
1573 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1574 source_name
= pa_xstrdup(argv
[optind
+2]);
1576 } else if (pa_streq(argv
[optind
], "load-module")) {
1581 action
= LOAD_MODULE
;
1583 if (argc
<= optind
+1) {
1584 pa_log(_("You have to specify a module name and arguments."));
1588 module_name
= argv
[optind
+1];
1590 for (i
= optind
+2; i
< argc
; i
++)
1591 n
+= strlen(argv
[i
])+1;
1594 p
= module_args
= pa_xmalloc(n
);
1596 for (i
= optind
+2; i
< argc
; i
++)
1597 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1600 } else if (pa_streq(argv
[optind
], "unload-module")) {
1601 action
= UNLOAD_MODULE
;
1603 if (argc
!= optind
+2) {
1604 pa_log(_("You have to specify a module index or name"));
1608 if (pa_atou(argv
[optind
+ 1], &module_index
) < 0)
1609 module_name
= argv
[optind
+ 1];
1611 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1612 action
= SUSPEND_SINK
;
1614 if (argc
> optind
+3 || optind
+1 >= argc
) {
1615 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1619 suspend
= pa_parse_boolean(argv
[argc
-1]);
1621 if (argc
> optind
+2)
1622 sink_name
= pa_xstrdup(argv
[optind
+1]);
1624 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1625 action
= SUSPEND_SOURCE
;
1627 if (argc
> optind
+3 || optind
+1 >= argc
) {
1628 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1632 suspend
= pa_parse_boolean(argv
[argc
-1]);
1634 if (argc
> optind
+2)
1635 source_name
= pa_xstrdup(argv
[optind
+1]);
1636 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1637 action
= SET_CARD_PROFILE
;
1639 if (argc
!= optind
+3) {
1640 pa_log(_("You have to specify a card name/index and a profile name"));
1644 card_name
= pa_xstrdup(argv
[optind
+1]);
1645 profile_name
= pa_xstrdup(argv
[optind
+2]);
1647 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1648 action
= SET_SINK_PORT
;
1650 if (argc
!= optind
+3) {
1651 pa_log(_("You have to specify a sink name/index and a port name"));
1655 sink_name
= pa_xstrdup(argv
[optind
+1]);
1656 port_name
= pa_xstrdup(argv
[optind
+2]);
1658 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1659 action
= SET_SOURCE_PORT
;
1661 if (argc
!= optind
+3) {
1662 pa_log(_("You have to specify a source name/index and a port name"));
1666 source_name
= pa_xstrdup(argv
[optind
+1]);
1667 port_name
= pa_xstrdup(argv
[optind
+2]);
1669 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1670 action
= SET_SINK_VOLUME
;
1672 if (argc
!= optind
+3) {
1673 pa_log(_("You have to specify a sink name/index and a volume"));
1677 sink_name
= pa_xstrdup(argv
[optind
+1]);
1679 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1682 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1683 action
= SET_SOURCE_VOLUME
;
1685 if (argc
!= optind
+3) {
1686 pa_log(_("You have to specify a source name/index and a volume"));
1690 source_name
= pa_xstrdup(argv
[optind
+1]);
1692 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1695 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1696 action
= SET_SINK_INPUT_VOLUME
;
1698 if (argc
!= optind
+3) {
1699 pa_log(_("You have to specify a sink input index and a volume"));
1703 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1704 pa_log(_("Invalid sink input index"));
1708 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1711 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1712 action
= SET_SOURCE_OUTPUT_VOLUME
;
1714 if (argc
!= optind
+3) {
1715 pa_log(_("You have to specify a source output index and a volume"));
1719 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1720 pa_log(_("Invalid source output index"));
1724 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1727 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1729 action
= SET_SINK_MUTE
;
1731 if (argc
!= optind
+3) {
1732 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1736 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1737 pa_log(_("Invalid mute specification"));
1741 sink_name
= pa_xstrdup(argv
[optind
+1]);
1744 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1746 action
= SET_SOURCE_MUTE
;
1748 if (argc
!= optind
+3) {
1749 pa_log(_("You have to specify a source name/index and a mute boolean"));
1753 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1754 pa_log(_("Invalid mute specification"));
1758 source_name
= pa_xstrdup(argv
[optind
+1]);
1761 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1763 action
= SET_SINK_INPUT_MUTE
;
1765 if (argc
!= optind
+3) {
1766 pa_log(_("You have to specify a sink input index and a mute boolean"));
1770 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1771 pa_log(_("Invalid sink input index specification"));
1775 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1776 pa_log(_("Invalid mute specification"));
1782 } else if (pa_streq(argv
[optind
], "set-source-output-mute")) {
1784 action
= SET_SOURCE_OUTPUT_MUTE
;
1786 if (argc
!= optind
+3) {
1787 pa_log(_("You have to specify a source output index and a mute boolean"));
1791 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1792 pa_log(_("Invalid source output index specification"));
1796 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1797 pa_log(_("Invalid mute specification"));
1803 } else if (pa_streq(argv
[optind
], "subscribe"))
1807 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1810 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1811 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1816 action
= SET_SINK_FORMATS
;
1817 formats
= pa_xstrdup(argv
[optind
+2]);
1819 } else if (pa_streq(argv
[optind
], "help")) {
1826 if (action
== NONE
) {
1827 pa_log(_("No valid command specified."));
1831 if (!(m
= pa_mainloop_new())) {
1832 pa_log(_("pa_mainloop_new() failed."));
1836 mainloop_api
= pa_mainloop_get_api(m
);
1838 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1839 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1840 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1841 pa_disable_sigpipe();
1843 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1844 pa_log(_("pa_context_new() failed."));
1848 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1849 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1850 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1854 if (pa_mainloop_run(m
, &ret
) < 0) {
1855 pa_log(_("pa_mainloop_run() failed."));
1861 pa_stream_unref(sample_stream
);
1864 pa_context_unref(context
);
1868 pa_mainloop_free(m
);
1872 pa_xfree(list_type
);
1873 pa_xfree(sample_name
);
1874 pa_xfree(sink_name
);
1875 pa_xfree(source_name
);
1876 pa_xfree(module_args
);
1877 pa_xfree(card_name
);
1878 pa_xfree(profile_name
);
1879 pa_xfree(port_name
);
1886 pa_proplist_free(proplist
);