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
38 #include <pulse/pulseaudio.h>
39 #include <pulse/ext-device-restore.h>
41 #include <pulsecore/i18n.h>
42 #include <pulsecore/macro.h>
43 #include <pulsecore/core-util.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/sndfile-util.h>
47 static pa_context
*context
= NULL
;
48 static pa_mainloop_api
*mainloop_api
= NULL
;
63 sink_input_idx
= PA_INVALID_INDEX
,
64 source_output_idx
= PA_INVALID_INDEX
,
65 sink_idx
= PA_INVALID_INDEX
;
67 static pa_bool_t short_list_format
= FALSE
;
68 static uint32_t module_index
;
69 static pa_bool_t suspend
;
70 static pa_bool_t mute
;
71 static pa_volume_t volume
;
72 static enum volume_flags
{
77 VOL_ABSOLUTE
= 0 << 4,
78 VOL_RELATIVE
= 1 << 4,
81 static pa_proplist
*proplist
= NULL
;
83 static SNDFILE
*sndfile
= NULL
;
84 static pa_stream
*sample_stream
= NULL
;
85 static pa_sample_spec sample_spec
;
86 static pa_channel_map channel_map
;
87 static size_t sample_length
= 0;
88 static int actions
= 1;
90 static pa_bool_t nl
= FALSE
;
112 SET_SINK_INPUT_VOLUME
,
113 SET_SOURCE_OUTPUT_VOLUME
,
117 SET_SOURCE_OUTPUT_MUTE
,
122 static void quit(int ret
) {
123 pa_assert(mainloop_api
);
124 mainloop_api
->quit(mainloop_api
, ret
);
127 static void context_drain_complete(pa_context
*c
, void *userdata
) {
128 pa_context_disconnect(c
);
131 static void drain(void) {
134 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
135 pa_context_disconnect(context
);
137 pa_operation_unref(o
);
140 static void complete_action(void) {
141 pa_assert(actions
> 0);
147 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
148 char s
[PA_BYTES_SNPRINT_MAX
];
150 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
155 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
156 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
158 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
159 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
161 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
162 printf(_("Sample cache size: %s\n"), s
);
167 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
168 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
171 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
176 printf(_("Server String: %s\n"
177 "Library Protocol Version: %u\n"
178 "Server Protocol Version: %u\n"
182 pa_context_get_server(c
),
183 pa_context_get_protocol_version(c
),
184 pa_context_get_server_protocol_version(c
),
185 pa_yes_no(pa_context_is_local(c
)),
186 pa_context_get_index(c
),
187 pa_context_get_tile_size(c
, NULL
));
189 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
190 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
192 printf(_("User Name: %s\n"
195 "Server Version: %s\n"
196 "Default Sample Specification: %s\n"
197 "Default Channel Map: %s\n"
199 "Default Source: %s\n"
200 "Cookie: %04x:%04x\n"),
207 i
->default_sink_name
,
208 i
->default_source_name
,
210 i
->cookie
& 0xFFFFU
);
215 static const char* get_available_str_ynonly(int available
)
218 case PA_PORT_AVAILABLE_YES
: return ", available";
219 case PA_PORT_AVAILABLE_NO
: return ", not available";
224 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
226 static const char *state_table
[] = {
227 [1+PA_SINK_INVALID_STATE
] = "n/a",
228 [1+PA_SINK_RUNNING
] = "RUNNING",
229 [1+PA_SINK_IDLE
] = "IDLE",
230 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
234 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
235 cv
[PA_CVOLUME_SNPRINT_MAX
],
236 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
237 v
[PA_VOLUME_SNPRINT_MAX
],
238 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
239 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
240 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
244 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
256 if (nl
&& !short_list_format
)
260 if (short_list_format
) {
261 printf("%u\t%s\t%s\t%s\t%s\n",
264 pa_strnull(i
->driver
),
265 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
266 state_table
[1+i
->state
]);
270 printf(_("Sink #%u\n"
273 "\tDescription: %s\n"
275 "\tSample Specification: %s\n"
276 "\tChannel Map: %s\n"
277 "\tOwner Module: %u\n"
281 "\tBase Volume: %s%s%s\n"
282 "\tMonitor Source: %s\n"
283 "\tLatency: %0.0f usec, configured %0.0f usec\n"
284 "\tFlags: %s%s%s%s%s%s%s\n"
285 "\tProperties:\n\t\t%s\n"),
287 state_table
[1+i
->state
],
289 pa_strnull(i
->description
),
290 pa_strnull(i
->driver
),
291 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
292 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
295 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
296 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
297 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
298 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
299 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
300 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
301 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
302 pa_strnull(i
->monitor_source_name
),
303 (double) i
->latency
, (double) i
->configured_latency
,
304 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
305 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
306 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
307 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
308 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
309 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
310 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
311 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
316 pa_sink_port_info
**p
;
318 printf(_("\tPorts:\n"));
319 for (p
= i
->ports
; *p
; p
++)
320 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
,
321 get_available_str_ynonly((*p
)->available
));
325 printf(_("\tActive Port: %s\n"),
326 i
->active_port
->name
);
331 printf(_("\tFormats:\n"));
332 for (j
= 0; j
< i
->n_formats
; j
++)
333 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
337 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
339 static const char *state_table
[] = {
340 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
341 [1+PA_SOURCE_RUNNING
] = "RUNNING",
342 [1+PA_SOURCE_IDLE
] = "IDLE",
343 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
347 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
348 cv
[PA_CVOLUME_SNPRINT_MAX
],
349 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
350 v
[PA_VOLUME_SNPRINT_MAX
],
351 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
352 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
353 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
357 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
369 if (nl
&& !short_list_format
)
373 if (short_list_format
) {
374 printf("%u\t%s\t%s\t%s\t%s\n",
377 pa_strnull(i
->driver
),
378 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
379 state_table
[1+i
->state
]);
383 printf(_("Source #%u\n"
386 "\tDescription: %s\n"
388 "\tSample Specification: %s\n"
389 "\tChannel Map: %s\n"
390 "\tOwner Module: %u\n"
394 "\tBase Volume: %s%s%s\n"
395 "\tMonitor of Sink: %s\n"
396 "\tLatency: %0.0f usec, configured %0.0f usec\n"
397 "\tFlags: %s%s%s%s%s%s\n"
398 "\tProperties:\n\t\t%s\n"),
400 state_table
[1+i
->state
],
402 pa_strnull(i
->description
),
403 pa_strnull(i
->driver
),
404 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
405 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
408 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
409 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
410 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
411 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
412 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
413 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
414 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
415 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
416 (double) i
->latency
, (double) i
->configured_latency
,
417 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
418 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
419 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
420 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
421 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
422 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
423 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
428 pa_source_port_info
**p
;
430 printf(_("\tPorts:\n"));
431 for (p
= i
->ports
; *p
; p
++)
432 printf("\t\t%s: %s (priority: %u%s)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
,
433 get_available_str_ynonly((*p
)->available
));
437 printf(_("\tActive Port: %s\n"),
438 i
->active_port
->name
);
443 printf(_("\tFormats:\n"));
444 for (j
= 0; j
< i
->n_formats
; j
++)
445 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
449 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
454 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
466 if (nl
&& !short_list_format
)
470 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
472 if (short_list_format
) {
473 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
477 printf(_("Module #%u\n"
480 "\tUsage counter: %s\n"
481 "\tProperties:\n\t\t%s\n"),
484 i
->argument
? i
->argument
: "",
485 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
486 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
491 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
496 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
508 if (nl
&& !short_list_format
)
512 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
514 if (short_list_format
) {
515 printf("%u\t%s\t%s\n",
517 pa_strnull(i
->driver
),
518 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
522 printf(_("Client #%u\n"
524 "\tOwner Module: %s\n"
525 "\tProperties:\n\t\t%s\n"),
527 pa_strnull(i
->driver
),
528 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
529 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
534 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
539 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
551 if (nl
&& !short_list_format
)
555 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
557 if (short_list_format
) {
558 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
562 printf(_("Card #%u\n"
565 "\tOwner Module: %s\n"
566 "\tProperties:\n\t\t%s\n"),
569 pa_strnull(i
->driver
),
570 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
571 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
574 pa_card_profile_info
*p
;
576 printf(_("\tProfiles:\n"));
577 for (p
= i
->profiles
; p
->name
; p
++)
578 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
581 if (i
->active_profile
)
582 printf(_("\tActive Profile: %s\n"),
583 i
->active_profile
->name
);
586 pa_card_port_info
**p
;
588 printf(_("\tPorts:\n"));
589 for (p
= i
->ports
; *p
; p
++) {
590 pa_card_profile_info
**pr
= (*p
)->profiles
;
591 printf(_("\t\t%s: %s (priority: %u%s)\n"), (*p
)->name
, (*p
)->description
, (*p
)->priority
,
592 get_available_str_ynonly((*p
)->available
));
595 printf(_("\t\t\tPart of profile(s): %s"), pa_strnull((*pr
)->name
));
598 printf(", %s", pa_strnull((*pr
)->name
));
609 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
610 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
];
614 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
626 if (nl
&& !short_list_format
)
630 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
631 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
633 if (short_list_format
) {
634 printf("%u\t%u\t%s\t%s\t%s\n",
637 i
->client
!= PA_INVALID_INDEX
? k
: "-",
638 pa_strnull(i
->driver
),
639 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
643 printf(_("Sink Input #%u\n"
645 "\tOwner Module: %s\n"
648 "\tSample Specification: %s\n"
649 "\tChannel Map: %s\n"
655 "\tBuffer Latency: %0.0f usec\n"
656 "\tSink Latency: %0.0f usec\n"
657 "\tResample method: %s\n"
658 "\tProperties:\n\t\t%s\n"),
660 pa_strnull(i
->driver
),
661 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
662 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
664 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
665 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
666 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
668 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
669 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
670 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
671 (double) i
->buffer_usec
,
672 (double) i
->sink_usec
,
673 i
->resample_method
? i
->resample_method
: _("n/a"),
674 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
679 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
680 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
];
684 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
696 if (nl
&& !short_list_format
)
701 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
702 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
704 if (short_list_format
) {
705 printf("%u\t%u\t%s\t%s\t%s\n",
708 i
->client
!= PA_INVALID_INDEX
? k
: "-",
709 pa_strnull(i
->driver
),
710 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
714 printf(_("Source Output #%u\n"
716 "\tOwner Module: %s\n"
719 "\tSample Specification: %s\n"
720 "\tChannel Map: %s\n"
726 "\tBuffer Latency: %0.0f usec\n"
727 "\tSource Latency: %0.0f usec\n"
728 "\tResample method: %s\n"
729 "\tProperties:\n\t\t%s\n"),
731 pa_strnull(i
->driver
),
732 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
733 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
735 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
736 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
737 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
739 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
740 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
741 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
742 (double) i
->buffer_usec
,
743 (double) i
->source_usec
,
744 i
->resample_method
? i
->resample_method
: _("n/a"),
745 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
750 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
751 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
];
755 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
767 if (nl
&& !short_list_format
)
771 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
773 if (short_list_format
) {
774 printf("%u\t%s\t%s\t%0.3f\n",
777 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
778 (double) i
->duration
/1000000.0);
782 printf(_("Sample #%u\n"
784 "\tSample Specification: %s\n"
785 "\tChannel Map: %s\n"
789 "\tDuration: %0.1fs\n"
793 "\tProperties:\n\t\t%s\n"),
796 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
797 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
798 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
799 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
800 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
801 (double) i
->duration
/1000000.0,
804 i
->filename
? i
->filename
: _("n/a"),
805 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
810 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
812 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
820 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
821 if (idx
== PA_INVALID_INDEX
) {
822 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
832 static void volume_relative_adjust(pa_cvolume
*cv
) {
833 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
835 /* Relative volume change is additive in case of UINT or PERCENT
836 * and multiplicative for LINEAR or DECIBEL */
837 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
838 pa_volume_t v
= pa_cvolume_avg(cv
);
839 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
840 pa_cvolume_set(cv
, 1, v
);
842 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
843 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
847 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
851 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
862 volume_relative_adjust(&cv
);
863 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
866 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
870 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
881 volume_relative_adjust(&cv
);
882 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
885 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
889 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
900 volume_relative_adjust(&cv
);
901 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
904 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
908 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
919 volume_relative_adjust(&cv
);
920 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
923 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
924 #define MAX_FORMATS 256
926 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
927 pa_format_info
*f_arr
[MAX_FORMATS
];
929 const char *state
= NULL
;
932 while ((format
= pa_split(str
, ";", &state
))) {
933 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
936 pa_log(_("Failed to set format: invalid format string %s"), format
);
944 pa_operation_unref(pa_ext_device_restore_save_formats(c
, PA_DEVICE_TYPE_SINK
, sink
, i
, f_arr
, simple_callback
, NULL
));
950 pa_format_info_free(f_arr
[i
]);
956 pa_format_info_free(f_arr
[i
]);
961 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
964 switch (pa_stream_get_state(s
)) {
965 case PA_STREAM_CREATING
:
966 case PA_STREAM_READY
:
969 case PA_STREAM_TERMINATED
:
973 case PA_STREAM_FAILED
:
975 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
980 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
983 pa_assert(s
&& length
&& sndfile
);
985 d
= pa_xmalloc(length
);
987 pa_assert(sample_length
>= length
);
988 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
990 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
992 pa_log(_("Premature end of file"));
997 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
999 sample_length
-= length
;
1001 if (sample_length
<= 0) {
1002 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
1003 pa_stream_finish_upload(sample_stream
);
1007 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
1009 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
1011 case PA_SUBSCRIPTION_EVENT_NEW
:
1014 case PA_SUBSCRIPTION_EVENT_CHANGE
:
1017 case PA_SUBSCRIPTION_EVENT_REMOVE
:
1021 return _("unknown");
1024 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
1026 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1028 case PA_SUBSCRIPTION_EVENT_SINK
:
1031 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1034 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1035 return _("sink-input");
1037 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1038 return _("source-output");
1040 case PA_SUBSCRIPTION_EVENT_MODULE
:
1043 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1046 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1047 return _("sample-cache");
1049 case PA_SUBSCRIPTION_EVENT_SERVER
:
1052 case PA_SUBSCRIPTION_EVENT_CARD
:
1056 return _("unknown");
1059 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1062 printf(_("Event '%s' on %s #%u\n"),
1063 subscription_event_type_to_string(t
),
1064 subscription_event_facility_to_string(t
),
1068 static void context_state_callback(pa_context
*c
, void *userdata
) {
1070 switch (pa_context_get_state(c
)) {
1071 case PA_CONTEXT_CONNECTING
:
1072 case PA_CONTEXT_AUTHORIZING
:
1073 case PA_CONTEXT_SETTING_NAME
:
1076 case PA_CONTEXT_READY
:
1079 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1080 if (short_list_format
)
1085 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1089 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1093 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1097 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1098 pa_assert(sample_stream
);
1100 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1101 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1102 pa_stream_connect_upload(sample_stream
, sample_length
);
1106 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1111 if (pa_streq(list_type
, "modules"))
1112 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1113 else if (pa_streq(list_type
, "sinks"))
1114 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1115 else if (pa_streq(list_type
, "sources"))
1116 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1117 else if (pa_streq(list_type
, "sink-inputs"))
1118 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1119 else if (pa_streq(list_type
, "source-outputs"))
1120 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1121 else if (pa_streq(list_type
, "clients"))
1122 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1123 else if (pa_streq(list_type
, "samples"))
1124 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1125 else if (pa_streq(list_type
, "cards"))
1126 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1128 pa_assert_not_reached();
1131 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1132 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1133 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1134 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1135 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1136 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1137 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1138 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1142 case MOVE_SINK_INPUT
:
1143 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1146 case MOVE_SOURCE_OUTPUT
:
1147 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1151 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1155 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1160 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1162 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1165 case SUSPEND_SOURCE
:
1167 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1169 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1172 case SET_CARD_PROFILE
:
1173 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1177 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1180 case SET_SOURCE_PORT
:
1181 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1185 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1188 case SET_SOURCE_MUTE
:
1189 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1192 case SET_SINK_INPUT_MUTE
:
1193 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1196 case SET_SOURCE_OUTPUT_MUTE
:
1197 pa_operation_unref(pa_context_set_source_output_mute(c
, source_output_idx
, mute
, simple_callback
, NULL
));
1200 case SET_SINK_VOLUME
:
1201 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1202 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1205 pa_cvolume_set(&v
, 1, volume
);
1206 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1210 case SET_SOURCE_VOLUME
:
1211 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1212 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1215 pa_cvolume_set(&v
, 1, volume
);
1216 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1220 case SET_SINK_INPUT_VOLUME
:
1221 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1222 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1225 pa_cvolume_set(&v
, 1, volume
);
1226 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1230 case SET_SOURCE_OUTPUT_VOLUME
:
1231 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1232 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1235 pa_cvolume_set(&v
, 1, volume
);
1236 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1240 case SET_SINK_FORMATS
:
1241 set_sink_formats(c
, sink_idx
, formats
);
1245 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1247 pa_operation_unref(pa_context_subscribe(
1249 PA_SUBSCRIPTION_MASK_SINK
|
1250 PA_SUBSCRIPTION_MASK_SOURCE
|
1251 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1252 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1253 PA_SUBSCRIPTION_MASK_MODULE
|
1254 PA_SUBSCRIPTION_MASK_CLIENT
|
1255 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1256 PA_SUBSCRIPTION_MASK_SERVER
|
1257 PA_SUBSCRIPTION_MASK_CARD
,
1263 pa_assert_not_reached();
1267 case PA_CONTEXT_TERMINATED
:
1271 case PA_CONTEXT_FAILED
:
1273 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1278 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1279 pa_log(_("Got SIGINT, exiting."));
1283 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1287 pa_assert(vol_spec
);
1289 pa_assert(vol_flags
);
1291 vs
= pa_xstrdup(vol_spec
);
1293 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1294 if (strchr(vs
, '.'))
1295 *vol_flags
|= VOL_LINEAR
;
1296 if (pa_endswith(vs
, "%")) {
1297 *vol_flags
|= VOL_PERCENT
;
1298 vs
[strlen(vs
)-1] = 0;
1300 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1301 *vol_flags
|= VOL_DECIBEL
;
1302 vs
[strlen(vs
)-2] = 0;
1305 if (pa_atod(vs
, &v
) < 0) {
1306 pa_log(_("Invalid volume specification"));
1313 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1314 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1315 v
+= (double) PA_VOLUME_NORM
;
1316 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1318 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1321 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1322 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1323 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1324 v
= pa_sw_volume_from_linear(v
);
1325 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1326 v
= pa_sw_volume_from_dB(v
);
1328 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1329 pa_log(_("Volume outside permissible range.\n"));
1333 *vol
= (pa_volume_t
) v
;
1338 static void help(const char *argv0
) {
1340 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1341 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1342 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1343 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1344 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1345 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1346 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1347 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1348 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("#N"));
1349 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1350 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1351 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1352 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1353 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1354 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1355 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0"));
1356 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0"));
1357 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1358 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1361 " -h, --help Show this help\n"
1362 " --version Show version\n\n"
1363 " -s, --server=SERVER The name of the server to connect to\n"
1364 " -n, --client-name=NAME How to call this client on the server\n"));
1371 int main(int argc
, char *argv
[]) {
1372 pa_mainloop
*m
= NULL
;
1374 char *server
= NULL
, *bn
;
1376 static const struct option long_options
[] = {
1377 {"server", 1, NULL
, 's'},
1378 {"client-name", 1, NULL
, 'n'},
1379 {"version", 0, NULL
, ARG_VERSION
},
1380 {"help", 0, NULL
, 'h'},
1384 setlocale(LC_ALL
, "");
1386 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1389 bn
= pa_path_get_filename(argv
[0]);
1391 proplist
= pa_proplist_new();
1393 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1401 printf(_("pactl %s\n"
1402 "Compiled with libpulse %s\n"
1403 "Linked with libpulse %s\n"),
1405 pa_get_headers_version(),
1406 pa_get_library_version());
1412 server
= pa_xstrdup(optarg
);
1418 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1419 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1421 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1435 if (optind
< argc
) {
1436 if (pa_streq(argv
[optind
], "stat")) {
1438 short_list_format
= FALSE
;
1439 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1440 short_list_format
= TRUE
;
1442 } else if (pa_streq(argv
[optind
], "info"))
1445 else if (pa_streq(argv
[optind
], "exit"))
1448 else if (pa_streq(argv
[optind
], "list")) {
1451 for (int i
= optind
+1; i
< argc
; i
++){
1452 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1453 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1454 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1455 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1456 list_type
= pa_xstrdup(argv
[i
]);
1457 } else if (pa_streq(argv
[i
], "short")) {
1458 short_list_format
= TRUE
;
1460 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1465 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1467 action
= UPLOAD_SAMPLE
;
1469 if (optind
+1 >= argc
) {
1470 pa_log(_("Please specify a sample file to load"));
1474 if (optind
+2 < argc
)
1475 sample_name
= pa_xstrdup(argv
[optind
+2]);
1477 char *f
= pa_path_get_filename(argv
[optind
+1]);
1478 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1482 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1483 pa_log(_("Failed to open sound file."));
1487 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1488 pa_log(_("Failed to determine sample specification from file."));
1491 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1493 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1494 if (sample_spec
.channels
> 2)
1495 pa_log(_("Warning: Failed to determine sample specification from file."));
1496 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1499 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1500 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1502 } else if (pa_streq(argv
[optind
], "play-sample")) {
1503 action
= PLAY_SAMPLE
;
1504 if (argc
!= optind
+2 && argc
!= optind
+3) {
1505 pa_log(_("You have to specify a sample name to play"));
1509 sample_name
= pa_xstrdup(argv
[optind
+1]);
1511 if (optind
+2 < argc
)
1512 sink_name
= pa_xstrdup(argv
[optind
+2]);
1514 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1515 action
= REMOVE_SAMPLE
;
1516 if (argc
!= optind
+2) {
1517 pa_log(_("You have to specify a sample name to remove"));
1521 sample_name
= pa_xstrdup(argv
[optind
+1]);
1523 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1524 action
= MOVE_SINK_INPUT
;
1525 if (argc
!= optind
+3) {
1526 pa_log(_("You have to specify a sink input index and a sink"));
1530 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1531 sink_name
= pa_xstrdup(argv
[optind
+2]);
1533 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1534 action
= MOVE_SOURCE_OUTPUT
;
1535 if (argc
!= optind
+3) {
1536 pa_log(_("You have to specify a source output index and a source"));
1540 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1541 source_name
= pa_xstrdup(argv
[optind
+2]);
1543 } else if (pa_streq(argv
[optind
], "load-module")) {
1548 action
= LOAD_MODULE
;
1550 if (argc
<= optind
+1) {
1551 pa_log(_("You have to specify a module name and arguments."));
1555 module_name
= argv
[optind
+1];
1557 for (i
= optind
+2; i
< argc
; i
++)
1558 n
+= strlen(argv
[i
])+1;
1561 p
= module_args
= pa_xmalloc(n
);
1563 for (i
= optind
+2; i
< argc
; i
++)
1564 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1567 } else if (pa_streq(argv
[optind
], "unload-module")) {
1568 action
= UNLOAD_MODULE
;
1570 if (argc
!= optind
+2) {
1571 pa_log(_("You have to specify a module index"));
1575 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1577 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1578 action
= SUSPEND_SINK
;
1580 if (argc
> optind
+3 || optind
+1 >= argc
) {
1581 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1585 suspend
= pa_parse_boolean(argv
[argc
-1]);
1587 if (argc
> optind
+2)
1588 sink_name
= pa_xstrdup(argv
[optind
+1]);
1590 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1591 action
= SUSPEND_SOURCE
;
1593 if (argc
> optind
+3 || optind
+1 >= argc
) {
1594 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1598 suspend
= pa_parse_boolean(argv
[argc
-1]);
1600 if (argc
> optind
+2)
1601 source_name
= pa_xstrdup(argv
[optind
+1]);
1602 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1603 action
= SET_CARD_PROFILE
;
1605 if (argc
!= optind
+3) {
1606 pa_log(_("You have to specify a card name/index and a profile name"));
1610 card_name
= pa_xstrdup(argv
[optind
+1]);
1611 profile_name
= pa_xstrdup(argv
[optind
+2]);
1613 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1614 action
= SET_SINK_PORT
;
1616 if (argc
!= optind
+3) {
1617 pa_log(_("You have to specify a sink name/index and a port name"));
1621 sink_name
= pa_xstrdup(argv
[optind
+1]);
1622 port_name
= pa_xstrdup(argv
[optind
+2]);
1624 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1625 action
= SET_SOURCE_PORT
;
1627 if (argc
!= optind
+3) {
1628 pa_log(_("You have to specify a source name/index and a port name"));
1632 source_name
= pa_xstrdup(argv
[optind
+1]);
1633 port_name
= pa_xstrdup(argv
[optind
+2]);
1635 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1636 action
= SET_SINK_VOLUME
;
1638 if (argc
!= optind
+3) {
1639 pa_log(_("You have to specify a sink name/index and a volume"));
1643 sink_name
= pa_xstrdup(argv
[optind
+1]);
1645 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1648 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1649 action
= SET_SOURCE_VOLUME
;
1651 if (argc
!= optind
+3) {
1652 pa_log(_("You have to specify a source name/index and a volume"));
1656 source_name
= pa_xstrdup(argv
[optind
+1]);
1658 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1661 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1662 action
= SET_SINK_INPUT_VOLUME
;
1664 if (argc
!= optind
+3) {
1665 pa_log(_("You have to specify a sink input index and a volume"));
1669 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1670 pa_log(_("Invalid sink input index"));
1674 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1677 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1678 action
= SET_SOURCE_OUTPUT_VOLUME
;
1680 if (argc
!= optind
+3) {
1681 pa_log(_("You have to specify a source output index and a volume"));
1685 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1686 pa_log(_("Invalid source output index"));
1690 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1693 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1695 action
= SET_SINK_MUTE
;
1697 if (argc
!= optind
+3) {
1698 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1702 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1703 pa_log(_("Invalid mute specification"));
1707 sink_name
= pa_xstrdup(argv
[optind
+1]);
1710 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1712 action
= SET_SOURCE_MUTE
;
1714 if (argc
!= optind
+3) {
1715 pa_log(_("You have to specify a source name/index and a mute boolean"));
1719 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1720 pa_log(_("Invalid mute specification"));
1724 source_name
= pa_xstrdup(argv
[optind
+1]);
1727 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1729 action
= SET_SINK_INPUT_MUTE
;
1731 if (argc
!= optind
+3) {
1732 pa_log(_("You have to specify a sink input index and a mute boolean"));
1736 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1737 pa_log(_("Invalid sink input index specification"));
1741 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1742 pa_log(_("Invalid mute specification"));
1748 } else if (pa_streq(argv
[optind
], "set-source-output-mute")) {
1750 action
= SET_SOURCE_OUTPUT_MUTE
;
1752 if (argc
!= optind
+3) {
1753 pa_log(_("You have to specify a source output index and a mute boolean"));
1757 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1758 pa_log(_("Invalid source output index specification"));
1762 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1763 pa_log(_("Invalid mute specification"));
1769 } else if (pa_streq(argv
[optind
], "subscribe"))
1773 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1776 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1777 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1782 action
= SET_SINK_FORMATS
;
1783 formats
= pa_xstrdup(argv
[optind
+2]);
1785 } else if (pa_streq(argv
[optind
], "help")) {
1792 if (action
== NONE
) {
1793 pa_log(_("No valid command specified."));
1797 if (!(m
= pa_mainloop_new())) {
1798 pa_log(_("pa_mainloop_new() failed."));
1802 mainloop_api
= pa_mainloop_get_api(m
);
1804 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1805 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1806 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1807 pa_disable_sigpipe();
1809 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1810 pa_log(_("pa_context_new() failed."));
1814 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1815 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1816 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1820 if (pa_mainloop_run(m
, &ret
) < 0) {
1821 pa_log(_("pa_mainloop_run() failed."));
1827 pa_stream_unref(sample_stream
);
1830 pa_context_unref(context
);
1834 pa_mainloop_free(m
);
1838 pa_xfree(list_type
);
1839 pa_xfree(sample_name
);
1840 pa_xfree(sink_name
);
1841 pa_xfree(source_name
);
1842 pa_xfree(module_args
);
1843 pa_xfree(card_name
);
1844 pa_xfree(profile_name
);
1845 pa_xfree(port_name
);
1852 pa_proplist_free(proplist
);