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
,
121 static void quit(int ret
) {
122 pa_assert(mainloop_api
);
123 mainloop_api
->quit(mainloop_api
, ret
);
126 static void context_drain_complete(pa_context
*c
, void *userdata
) {
127 pa_context_disconnect(c
);
130 static void drain(void) {
133 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
134 pa_context_disconnect(context
);
136 pa_operation_unref(o
);
139 static void complete_action(void) {
140 pa_assert(actions
> 0);
146 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
147 char s
[PA_BYTES_SNPRINT_MAX
];
149 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
154 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
155 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
157 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
158 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
160 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
161 printf(_("Sample cache size: %s\n"), s
);
166 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
167 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
170 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
175 printf(_("Server String: %s\n"
176 "Library Protocol Version: %u\n"
177 "Server Protocol Version: %u\n"
181 pa_context_get_server(c
),
182 pa_context_get_protocol_version(c
),
183 pa_context_get_server_protocol_version(c
),
184 pa_yes_no(pa_context_is_local(c
)),
185 pa_context_get_index(c
),
186 pa_context_get_tile_size(c
, NULL
));
188 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
189 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
191 printf(_("User Name: %s\n"
194 "Server Version: %s\n"
195 "Default Sample Specification: %s\n"
196 "Default Channel Map: %s\n"
198 "Default Source: %s\n"
199 "Cookie: %04x:%04x\n"),
206 i
->default_sink_name
,
207 i
->default_source_name
,
209 i
->cookie
& 0xFFFFU
);
214 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
216 static const char *state_table
[] = {
217 [1+PA_SINK_INVALID_STATE
] = "n/a",
218 [1+PA_SINK_RUNNING
] = "RUNNING",
219 [1+PA_SINK_IDLE
] = "IDLE",
220 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
224 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
225 cv
[PA_CVOLUME_SNPRINT_MAX
],
226 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
227 v
[PA_VOLUME_SNPRINT_MAX
],
228 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
229 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
230 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
234 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
246 if (nl
&& !short_list_format
)
250 if (short_list_format
) {
251 printf("%u\t%s\t%s\t%s\t%s\n",
254 pa_strnull(i
->driver
),
255 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
256 state_table
[1+i
->state
]);
260 printf(_("Sink #%u\n"
263 "\tDescription: %s\n"
265 "\tSample Specification: %s\n"
266 "\tChannel Map: %s\n"
267 "\tOwner Module: %u\n"
271 "\tBase Volume: %s%s%s\n"
272 "\tMonitor Source: %s\n"
273 "\tLatency: %0.0f usec, configured %0.0f usec\n"
274 "\tFlags: %s%s%s%s%s%s\n"
275 "\tProperties:\n\t\t%s\n"),
277 state_table
[1+i
->state
],
279 pa_strnull(i
->description
),
280 pa_strnull(i
->driver
),
281 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
282 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
285 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
286 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
287 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
288 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
289 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
290 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
291 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
292 pa_strnull(i
->monitor_source_name
),
293 (double) i
->latency
, (double) i
->configured_latency
,
294 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
295 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
296 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
297 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
298 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
299 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
300 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
305 pa_sink_port_info
**p
;
307 printf(_("\tPorts:\n"));
308 for (p
= i
->ports
; *p
; p
++)
309 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
313 printf(_("\tActive Port: %s\n"),
314 i
->active_port
->name
);
319 printf(_("\tFormats:\n"));
320 for (j
= 0; j
< i
->n_formats
; j
++)
321 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
325 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
327 static const char *state_table
[] = {
328 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
329 [1+PA_SOURCE_RUNNING
] = "RUNNING",
330 [1+PA_SOURCE_IDLE
] = "IDLE",
331 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
335 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
336 cv
[PA_CVOLUME_SNPRINT_MAX
],
337 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
338 v
[PA_VOLUME_SNPRINT_MAX
],
339 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
340 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
341 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
345 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
357 if (nl
&& !short_list_format
)
361 if (short_list_format
) {
362 printf("%u\t%s\t%s\t%s\t%s\n",
365 pa_strnull(i
->driver
),
366 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
367 state_table
[1+i
->state
]);
371 printf(_("Source #%u\n"
374 "\tDescription: %s\n"
376 "\tSample Specification: %s\n"
377 "\tChannel Map: %s\n"
378 "\tOwner Module: %u\n"
382 "\tBase Volume: %s%s%s\n"
383 "\tMonitor of Sink: %s\n"
384 "\tLatency: %0.0f usec, configured %0.0f usec\n"
385 "\tFlags: %s%s%s%s%s%s\n"
386 "\tProperties:\n\t\t%s\n"),
388 state_table
[1+i
->state
],
390 pa_strnull(i
->description
),
391 pa_strnull(i
->driver
),
392 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
393 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
396 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
397 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
398 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
399 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
400 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
401 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
402 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
403 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
404 (double) i
->latency
, (double) i
->configured_latency
,
405 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
406 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
407 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
408 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
409 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
410 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
411 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
416 pa_source_port_info
**p
;
418 printf(_("\tPorts:\n"));
419 for (p
= i
->ports
; *p
; p
++)
420 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
424 printf(_("\tActive Port: %s\n"),
425 i
->active_port
->name
);
430 printf(_("\tFormats:\n"));
431 for (j
= 0; j
< i
->n_formats
; j
++)
432 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
436 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
441 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
453 if (nl
&& !short_list_format
)
457 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
459 if (short_list_format
) {
460 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
464 printf(_("Module #%u\n"
467 "\tUsage counter: %s\n"
468 "\tProperties:\n\t\t%s\n"),
471 i
->argument
? i
->argument
: "",
472 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
473 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
478 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
483 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
495 if (nl
&& !short_list_format
)
499 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
501 if (short_list_format
) {
502 printf("%u\t%s\t%s\n",
504 pa_strnull(i
->driver
),
505 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
509 printf(_("Client #%u\n"
511 "\tOwner Module: %s\n"
512 "\tProperties:\n\t\t%s\n"),
514 pa_strnull(i
->driver
),
515 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
516 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
521 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
526 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
538 if (nl
&& !short_list_format
)
542 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
544 if (short_list_format
) {
545 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
549 printf(_("Card #%u\n"
552 "\tOwner Module: %s\n"
553 "\tProperties:\n\t\t%s\n"),
556 pa_strnull(i
->driver
),
557 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
558 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
561 pa_card_profile_info
*p
;
563 printf(_("\tProfiles:\n"));
564 for (p
= i
->profiles
; p
->name
; p
++)
565 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
568 if (i
->active_profile
)
569 printf(_("\tActive Profile: %s\n"),
570 i
->active_profile
->name
);
575 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
576 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
];
580 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
592 if (nl
&& !short_list_format
)
596 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
597 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
599 if (short_list_format
) {
600 printf("%u\t%u\t%s\t%s\t%s\n",
603 i
->client
!= PA_INVALID_INDEX
? k
: "-",
604 pa_strnull(i
->driver
),
605 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
609 printf(_("Sink Input #%u\n"
611 "\tOwner Module: %s\n"
614 "\tSample Specification: %s\n"
615 "\tChannel Map: %s\n"
621 "\tBuffer Latency: %0.0f usec\n"
622 "\tSink Latency: %0.0f usec\n"
623 "\tResample method: %s\n"
624 "\tProperties:\n\t\t%s\n"),
626 pa_strnull(i
->driver
),
627 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
628 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
630 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
631 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
632 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
634 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
635 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
636 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
637 (double) i
->buffer_usec
,
638 (double) i
->sink_usec
,
639 i
->resample_method
? i
->resample_method
: _("n/a"),
640 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
645 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
646 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
];
650 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
662 if (nl
&& !short_list_format
)
667 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
668 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
670 if (short_list_format
) {
671 printf("%u\t%u\t%s\t%s\t%s\n",
674 i
->client
!= PA_INVALID_INDEX
? k
: "-",
675 pa_strnull(i
->driver
),
676 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
680 printf(_("Source Output #%u\n"
682 "\tOwner Module: %s\n"
685 "\tSample Specification: %s\n"
686 "\tChannel Map: %s\n"
692 "\tBuffer Latency: %0.0f usec\n"
693 "\tSource Latency: %0.0f usec\n"
694 "\tResample method: %s\n"
695 "\tProperties:\n\t\t%s\n"),
697 pa_strnull(i
->driver
),
698 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
699 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
701 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
702 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
703 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
705 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
706 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
707 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
708 (double) i
->buffer_usec
,
709 (double) i
->source_usec
,
710 i
->resample_method
? i
->resample_method
: _("n/a"),
711 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
716 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
717 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
];
721 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
733 if (nl
&& !short_list_format
)
737 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
739 if (short_list_format
) {
740 printf("%u\t%s\t%s\t%0.3f\n",
743 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
744 (double) i
->duration
/1000000.0);
748 printf(_("Sample #%u\n"
750 "\tSample Specification: %s\n"
751 "\tChannel Map: %s\n"
755 "\tDuration: %0.1fs\n"
759 "\tProperties:\n\t\t%s\n"),
762 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
763 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
764 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
765 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
766 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
767 (double) i
->duration
/1000000.0,
770 i
->filename
? i
->filename
: _("n/a"),
771 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
776 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
778 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
786 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
787 if (idx
== PA_INVALID_INDEX
) {
788 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
798 static void volume_relative_adjust(pa_cvolume
*cv
) {
799 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
801 /* Relative volume change is additive in case of UINT or PERCENT
802 * and multiplicative for LINEAR or DECIBEL */
803 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
804 pa_volume_t v
= pa_cvolume_avg(cv
);
805 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
806 pa_cvolume_set(cv
, 1, v
);
808 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
809 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
813 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
817 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
828 volume_relative_adjust(&cv
);
829 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
832 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
836 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
847 volume_relative_adjust(&cv
);
848 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
851 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
855 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
866 volume_relative_adjust(&cv
);
867 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
870 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
874 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
885 volume_relative_adjust(&cv
);
886 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
889 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
890 #define MAX_FORMATS 256
892 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
893 pa_format_info
*f_arr
[MAX_FORMATS
];
895 const char *state
= NULL
;
898 while ((format
= pa_split(str
, ";", &state
))) {
899 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
902 pa_log(_("Failed to set format: invalid format string %s"), format
);
910 pa_operation_unref(pa_ext_device_restore_save_sink_formats(c
, sink
, i
, f_arr
, simple_callback
, NULL
));
916 pa_format_info_free(f_arr
[i
]);
922 pa_format_info_free(f_arr
[i
]);
927 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
930 switch (pa_stream_get_state(s
)) {
931 case PA_STREAM_CREATING
:
932 case PA_STREAM_READY
:
935 case PA_STREAM_TERMINATED
:
939 case PA_STREAM_FAILED
:
941 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
946 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
949 pa_assert(s
&& length
&& sndfile
);
951 d
= pa_xmalloc(length
);
953 pa_assert(sample_length
>= length
);
954 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
956 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
958 pa_log(_("Premature end of file"));
963 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
965 sample_length
-= length
;
967 if (sample_length
<= 0) {
968 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
969 pa_stream_finish_upload(sample_stream
);
973 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
975 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
977 case PA_SUBSCRIPTION_EVENT_NEW
:
980 case PA_SUBSCRIPTION_EVENT_CHANGE
:
983 case PA_SUBSCRIPTION_EVENT_REMOVE
:
990 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
992 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
994 case PA_SUBSCRIPTION_EVENT_SINK
:
997 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1000 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1001 return _("sink-input");
1003 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1004 return _("source-output");
1006 case PA_SUBSCRIPTION_EVENT_MODULE
:
1009 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1012 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1013 return _("sample-cache");
1015 case PA_SUBSCRIPTION_EVENT_SERVER
:
1018 case PA_SUBSCRIPTION_EVENT_CARD
:
1022 return _("unknown");
1025 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1028 printf(_("Event '%s' on %s #%u\n"),
1029 subscription_event_type_to_string(t
),
1030 subscription_event_facility_to_string(t
),
1034 static void context_state_callback(pa_context
*c
, void *userdata
) {
1036 switch (pa_context_get_state(c
)) {
1037 case PA_CONTEXT_CONNECTING
:
1038 case PA_CONTEXT_AUTHORIZING
:
1039 case PA_CONTEXT_SETTING_NAME
:
1042 case PA_CONTEXT_READY
:
1045 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1046 if (short_list_format
)
1051 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1055 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1059 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1063 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1064 pa_assert(sample_stream
);
1066 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1067 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1068 pa_stream_connect_upload(sample_stream
, sample_length
);
1072 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1077 if (pa_streq(list_type
, "modules"))
1078 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1079 else if (pa_streq(list_type
, "sinks"))
1080 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1081 else if (pa_streq(list_type
, "sources"))
1082 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1083 else if (pa_streq(list_type
, "sink-inputs"))
1084 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1085 else if (pa_streq(list_type
, "source-outputs"))
1086 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1087 else if (pa_streq(list_type
, "clients"))
1088 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1089 else if (pa_streq(list_type
, "samples"))
1090 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1091 else if (pa_streq(list_type
, "cards"))
1092 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1094 pa_assert_not_reached();
1097 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1098 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1099 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1100 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1101 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1102 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1103 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1104 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1108 case MOVE_SINK_INPUT
:
1109 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1112 case MOVE_SOURCE_OUTPUT
:
1113 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1117 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1121 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1126 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1128 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1131 case SUSPEND_SOURCE
:
1133 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1135 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1138 case SET_CARD_PROFILE
:
1139 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1143 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1146 case SET_SOURCE_PORT
:
1147 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1151 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1154 case SET_SOURCE_MUTE
:
1155 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1158 case SET_SINK_INPUT_MUTE
:
1159 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1162 case SET_SINK_VOLUME
:
1163 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1164 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1167 pa_cvolume_set(&v
, 1, volume
);
1168 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1172 case SET_SOURCE_VOLUME
:
1173 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1174 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1177 pa_cvolume_set(&v
, 1, volume
);
1178 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1182 case SET_SINK_INPUT_VOLUME
:
1183 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1184 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1187 pa_cvolume_set(&v
, 1, volume
);
1188 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1192 case SET_SOURCE_OUTPUT_VOLUME
:
1193 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1194 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1197 pa_cvolume_set(&v
, 1, volume
);
1198 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1202 case SET_SINK_FORMATS
:
1203 set_sink_formats(c
, sink_idx
, formats
);
1207 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1209 pa_operation_unref(pa_context_subscribe(
1211 PA_SUBSCRIPTION_MASK_SINK
|
1212 PA_SUBSCRIPTION_MASK_SOURCE
|
1213 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1214 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1215 PA_SUBSCRIPTION_MASK_MODULE
|
1216 PA_SUBSCRIPTION_MASK_CLIENT
|
1217 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1218 PA_SUBSCRIPTION_MASK_SERVER
|
1219 PA_SUBSCRIPTION_MASK_CARD
,
1225 pa_assert_not_reached();
1229 case PA_CONTEXT_TERMINATED
:
1233 case PA_CONTEXT_FAILED
:
1235 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1240 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1241 pa_log(_("Got SIGINT, exiting."));
1245 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1249 pa_assert(vol_spec
);
1251 pa_assert(vol_flags
);
1253 vs
= pa_xstrdup(vol_spec
);
1255 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1256 if (strchr(vs
, '.'))
1257 *vol_flags
|= VOL_LINEAR
;
1258 if (pa_endswith(vs
, "%")) {
1259 *vol_flags
|= VOL_PERCENT
;
1260 vs
[strlen(vs
)-1] = 0;
1262 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1263 *vol_flags
|= VOL_DECIBEL
;
1264 vs
[strlen(vs
)-2] = 0;
1267 if (pa_atod(vs
, &v
) < 0) {
1268 pa_log(_("Invalid volume specification"));
1275 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1276 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1277 v
+= (double) PA_VOLUME_NORM
;
1278 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1280 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1283 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1284 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1285 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1286 v
= pa_sw_volume_from_linear(v
);
1287 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1288 v
= pa_sw_volume_from_dB(v
);
1290 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1291 pa_log(_("Volume outside permissible range.\n"));
1295 *vol
= (pa_volume_t
) v
;
1300 static void help(const char *argv0
) {
1302 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1303 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1304 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1305 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1306 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1307 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1308 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1309 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1310 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("#N"));
1311 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1312 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1313 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1314 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1315 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1316 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1317 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0"));
1318 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-input-mute", _("#N 1|0"));
1319 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1320 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1323 " -h, --help Show this help\n"
1324 " --version Show version\n\n"
1325 " -s, --server=SERVER The name of the server to connect to\n"
1326 " -n, --client-name=NAME How to call this client on the server\n"));
1333 int main(int argc
, char *argv
[]) {
1334 pa_mainloop
*m
= NULL
;
1336 char *server
= NULL
, *bn
;
1338 static const struct option long_options
[] = {
1339 {"server", 1, NULL
, 's'},
1340 {"client-name", 1, NULL
, 'n'},
1341 {"version", 0, NULL
, ARG_VERSION
},
1342 {"help", 0, NULL
, 'h'},
1346 setlocale(LC_ALL
, "");
1347 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1349 bn
= pa_path_get_filename(argv
[0]);
1351 proplist
= pa_proplist_new();
1353 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1361 printf(_("pactl %s\n"
1362 "Compiled with libpulse %s\n"
1363 "Linked with libpulse %s\n"),
1365 pa_get_headers_version(),
1366 pa_get_library_version());
1372 server
= pa_xstrdup(optarg
);
1378 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1379 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1381 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1395 if (optind
< argc
) {
1396 if (pa_streq(argv
[optind
], "stat")) {
1398 short_list_format
= FALSE
;
1399 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1400 short_list_format
= TRUE
;
1402 } else if (pa_streq(argv
[optind
], "info"))
1405 else if (pa_streq(argv
[optind
], "exit"))
1408 else if (pa_streq(argv
[optind
], "list")) {
1411 for (int i
= optind
+1; i
< argc
; i
++){
1412 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1413 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1414 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1415 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1416 list_type
= pa_xstrdup(argv
[i
]);
1417 } else if (pa_streq(argv
[i
], "short")) {
1418 short_list_format
= TRUE
;
1420 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1425 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1427 action
= UPLOAD_SAMPLE
;
1429 if (optind
+1 >= argc
) {
1430 pa_log(_("Please specify a sample file to load"));
1434 if (optind
+2 < argc
)
1435 sample_name
= pa_xstrdup(argv
[optind
+2]);
1437 char *f
= pa_path_get_filename(argv
[optind
+1]);
1438 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1442 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1443 pa_log(_("Failed to open sound file."));
1447 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1448 pa_log(_("Failed to determine sample specification from file."));
1451 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1453 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1454 if (sample_spec
.channels
> 2)
1455 pa_log(_("Warning: Failed to determine sample specification from file."));
1456 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1459 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1460 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1462 } else if (pa_streq(argv
[optind
], "play-sample")) {
1463 action
= PLAY_SAMPLE
;
1464 if (argc
!= optind
+2 && argc
!= optind
+3) {
1465 pa_log(_("You have to specify a sample name to play"));
1469 sample_name
= pa_xstrdup(argv
[optind
+1]);
1471 if (optind
+2 < argc
)
1472 sink_name
= pa_xstrdup(argv
[optind
+2]);
1474 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1475 action
= REMOVE_SAMPLE
;
1476 if (argc
!= optind
+2) {
1477 pa_log(_("You have to specify a sample name to remove"));
1481 sample_name
= pa_xstrdup(argv
[optind
+1]);
1483 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1484 action
= MOVE_SINK_INPUT
;
1485 if (argc
!= optind
+3) {
1486 pa_log(_("You have to specify a sink input index and a sink"));
1490 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1491 sink_name
= pa_xstrdup(argv
[optind
+2]);
1493 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1494 action
= MOVE_SOURCE_OUTPUT
;
1495 if (argc
!= optind
+3) {
1496 pa_log(_("You have to specify a source output index and a source"));
1500 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1501 source_name
= pa_xstrdup(argv
[optind
+2]);
1503 } else if (pa_streq(argv
[optind
], "load-module")) {
1508 action
= LOAD_MODULE
;
1510 if (argc
<= optind
+1) {
1511 pa_log(_("You have to specify a module name and arguments."));
1515 module_name
= argv
[optind
+1];
1517 for (i
= optind
+2; i
< argc
; i
++)
1518 n
+= strlen(argv
[i
])+1;
1521 p
= module_args
= pa_xmalloc(n
);
1523 for (i
= optind
+2; i
< argc
; i
++)
1524 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1527 } else if (pa_streq(argv
[optind
], "unload-module")) {
1528 action
= UNLOAD_MODULE
;
1530 if (argc
!= optind
+2) {
1531 pa_log(_("You have to specify a module index"));
1535 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1537 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1538 action
= SUSPEND_SINK
;
1540 if (argc
> optind
+3 || optind
+1 >= argc
) {
1541 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1545 suspend
= pa_parse_boolean(argv
[argc
-1]);
1547 if (argc
> optind
+2)
1548 sink_name
= pa_xstrdup(argv
[optind
+1]);
1550 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1551 action
= SUSPEND_SOURCE
;
1553 if (argc
> optind
+3 || optind
+1 >= argc
) {
1554 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1558 suspend
= pa_parse_boolean(argv
[argc
-1]);
1560 if (argc
> optind
+2)
1561 source_name
= pa_xstrdup(argv
[optind
+1]);
1562 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1563 action
= SET_CARD_PROFILE
;
1565 if (argc
!= optind
+3) {
1566 pa_log(_("You have to specify a card name/index and a profile name"));
1570 card_name
= pa_xstrdup(argv
[optind
+1]);
1571 profile_name
= pa_xstrdup(argv
[optind
+2]);
1573 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1574 action
= SET_SINK_PORT
;
1576 if (argc
!= optind
+3) {
1577 pa_log(_("You have to specify a sink name/index and a port name"));
1581 sink_name
= pa_xstrdup(argv
[optind
+1]);
1582 port_name
= pa_xstrdup(argv
[optind
+2]);
1584 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1585 action
= SET_SOURCE_PORT
;
1587 if (argc
!= optind
+3) {
1588 pa_log(_("You have to specify a source name/index and a port name"));
1592 source_name
= pa_xstrdup(argv
[optind
+1]);
1593 port_name
= pa_xstrdup(argv
[optind
+2]);
1595 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1596 action
= SET_SINK_VOLUME
;
1598 if (argc
!= optind
+3) {
1599 pa_log(_("You have to specify a sink name/index and a volume"));
1603 sink_name
= pa_xstrdup(argv
[optind
+1]);
1605 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1608 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1609 action
= SET_SOURCE_VOLUME
;
1611 if (argc
!= optind
+3) {
1612 pa_log(_("You have to specify a source name/index and a volume"));
1616 source_name
= pa_xstrdup(argv
[optind
+1]);
1618 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1621 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1622 action
= SET_SINK_INPUT_VOLUME
;
1624 if (argc
!= optind
+3) {
1625 pa_log(_("You have to specify a sink input index and a volume"));
1629 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1630 pa_log(_("Invalid sink input index"));
1634 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1637 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1638 action
= SET_SOURCE_OUTPUT_VOLUME
;
1640 if (argc
!= optind
+3) {
1641 pa_log(_("You have to specify a source output index and a volume"));
1645 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1646 pa_log(_("Invalid source output index"));
1650 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1653 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1655 action
= SET_SINK_MUTE
;
1657 if (argc
!= optind
+3) {
1658 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1662 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1663 pa_log(_("Invalid mute specification"));
1667 sink_name
= pa_xstrdup(argv
[optind
+1]);
1670 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1672 action
= SET_SOURCE_MUTE
;
1674 if (argc
!= optind
+3) {
1675 pa_log(_("You have to specify a source name/index and a mute boolean"));
1679 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1680 pa_log(_("Invalid mute specification"));
1684 source_name
= pa_xstrdup(argv
[optind
+1]);
1687 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1689 action
= SET_SINK_INPUT_MUTE
;
1691 if (argc
!= optind
+3) {
1692 pa_log(_("You have to specify a sink input index and a mute boolean"));
1696 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1697 pa_log(_("Invalid sink input index specification"));
1701 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1702 pa_log(_("Invalid mute specification"));
1708 } else if (pa_streq(argv
[optind
], "subscribe"))
1712 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1715 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1716 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1721 action
= SET_SINK_FORMATS
;
1722 formats
= pa_xstrdup(argv
[optind
+2]);
1724 } else if (pa_streq(argv
[optind
], "help")) {
1731 if (action
== NONE
) {
1732 pa_log(_("No valid command specified."));
1736 if (!(m
= pa_mainloop_new())) {
1737 pa_log(_("pa_mainloop_new() failed."));
1741 mainloop_api
= pa_mainloop_get_api(m
);
1743 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1744 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1745 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1746 pa_disable_sigpipe();
1748 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1749 pa_log(_("pa_context_new() failed."));
1753 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1754 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1755 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1759 if (pa_mainloop_run(m
, &ret
) < 0) {
1760 pa_log(_("pa_mainloop_run() failed."));
1766 pa_stream_unref(sample_stream
);
1769 pa_context_unref(context
);
1773 pa_mainloop_free(m
);
1777 pa_xfree(list_type
);
1778 pa_xfree(sample_name
);
1779 pa_xfree(sink_name
);
1780 pa_xfree(source_name
);
1781 pa_xfree(module_args
);
1782 pa_xfree(card_name
);
1783 pa_xfree(profile_name
);
1784 pa_xfree(port_name
);
1791 pa_proplist_free(proplist
);