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%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 i
->flags
& PA_SINK_SET_FORMATS
? "SET_FORMATS " : "",
301 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
306 pa_sink_port_info
**p
;
308 printf(_("\tPorts:\n"));
309 for (p
= i
->ports
; *p
; p
++)
310 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
314 printf(_("\tActive Port: %s\n"),
315 i
->active_port
->name
);
320 printf(_("\tFormats:\n"));
321 for (j
= 0; j
< i
->n_formats
; j
++)
322 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
326 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
328 static const char *state_table
[] = {
329 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
330 [1+PA_SOURCE_RUNNING
] = "RUNNING",
331 [1+PA_SOURCE_IDLE
] = "IDLE",
332 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
336 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
337 cv
[PA_CVOLUME_SNPRINT_MAX
],
338 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
339 v
[PA_VOLUME_SNPRINT_MAX
],
340 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
341 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
342 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
346 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
358 if (nl
&& !short_list_format
)
362 if (short_list_format
) {
363 printf("%u\t%s\t%s\t%s\t%s\n",
366 pa_strnull(i
->driver
),
367 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
368 state_table
[1+i
->state
]);
372 printf(_("Source #%u\n"
375 "\tDescription: %s\n"
377 "\tSample Specification: %s\n"
378 "\tChannel Map: %s\n"
379 "\tOwner Module: %u\n"
383 "\tBase Volume: %s%s%s\n"
384 "\tMonitor of Sink: %s\n"
385 "\tLatency: %0.0f usec, configured %0.0f usec\n"
386 "\tFlags: %s%s%s%s%s%s\n"
387 "\tProperties:\n\t\t%s\n"),
389 state_table
[1+i
->state
],
391 pa_strnull(i
->description
),
392 pa_strnull(i
->driver
),
393 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
394 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
397 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
398 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
399 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
400 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
401 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
402 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
403 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
404 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
405 (double) i
->latency
, (double) i
->configured_latency
,
406 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
407 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
408 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
409 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
410 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
411 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
412 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
417 pa_source_port_info
**p
;
419 printf(_("\tPorts:\n"));
420 for (p
= i
->ports
; *p
; p
++)
421 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
425 printf(_("\tActive Port: %s\n"),
426 i
->active_port
->name
);
431 printf(_("\tFormats:\n"));
432 for (j
= 0; j
< i
->n_formats
; j
++)
433 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
437 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
442 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
454 if (nl
&& !short_list_format
)
458 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
460 if (short_list_format
) {
461 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
465 printf(_("Module #%u\n"
468 "\tUsage counter: %s\n"
469 "\tProperties:\n\t\t%s\n"),
472 i
->argument
? i
->argument
: "",
473 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
474 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
479 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
484 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
496 if (nl
&& !short_list_format
)
500 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
502 if (short_list_format
) {
503 printf("%u\t%s\t%s\n",
505 pa_strnull(i
->driver
),
506 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
510 printf(_("Client #%u\n"
512 "\tOwner Module: %s\n"
513 "\tProperties:\n\t\t%s\n"),
515 pa_strnull(i
->driver
),
516 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
517 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
522 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
527 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
539 if (nl
&& !short_list_format
)
543 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
545 if (short_list_format
) {
546 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
550 printf(_("Card #%u\n"
553 "\tOwner Module: %s\n"
554 "\tProperties:\n\t\t%s\n"),
557 pa_strnull(i
->driver
),
558 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
559 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
562 pa_card_profile_info
*p
;
564 printf(_("\tProfiles:\n"));
565 for (p
= i
->profiles
; p
->name
; p
++)
566 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
569 if (i
->active_profile
)
570 printf(_("\tActive Profile: %s\n"),
571 i
->active_profile
->name
);
576 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
577 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
];
581 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
593 if (nl
&& !short_list_format
)
597 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
598 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
600 if (short_list_format
) {
601 printf("%u\t%u\t%s\t%s\t%s\n",
604 i
->client
!= PA_INVALID_INDEX
? k
: "-",
605 pa_strnull(i
->driver
),
606 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
610 printf(_("Sink Input #%u\n"
612 "\tOwner Module: %s\n"
615 "\tSample Specification: %s\n"
616 "\tChannel Map: %s\n"
622 "\tBuffer Latency: %0.0f usec\n"
623 "\tSink Latency: %0.0f usec\n"
624 "\tResample method: %s\n"
625 "\tProperties:\n\t\t%s\n"),
627 pa_strnull(i
->driver
),
628 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
629 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
631 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
632 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
633 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
635 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
636 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
637 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
638 (double) i
->buffer_usec
,
639 (double) i
->sink_usec
,
640 i
->resample_method
? i
->resample_method
: _("n/a"),
641 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
646 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
647 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
];
651 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
663 if (nl
&& !short_list_format
)
668 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
669 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
671 if (short_list_format
) {
672 printf("%u\t%u\t%s\t%s\t%s\n",
675 i
->client
!= PA_INVALID_INDEX
? k
: "-",
676 pa_strnull(i
->driver
),
677 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
681 printf(_("Source Output #%u\n"
683 "\tOwner Module: %s\n"
686 "\tSample Specification: %s\n"
687 "\tChannel Map: %s\n"
693 "\tBuffer Latency: %0.0f usec\n"
694 "\tSource Latency: %0.0f usec\n"
695 "\tResample method: %s\n"
696 "\tProperties:\n\t\t%s\n"),
698 pa_strnull(i
->driver
),
699 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
700 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
702 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
703 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
704 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
706 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
707 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
708 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
709 (double) i
->buffer_usec
,
710 (double) i
->source_usec
,
711 i
->resample_method
? i
->resample_method
: _("n/a"),
712 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
717 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
718 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
];
722 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
734 if (nl
&& !short_list_format
)
738 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
740 if (short_list_format
) {
741 printf("%u\t%s\t%s\t%0.3f\n",
744 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
745 (double) i
->duration
/1000000.0);
749 printf(_("Sample #%u\n"
751 "\tSample Specification: %s\n"
752 "\tChannel Map: %s\n"
756 "\tDuration: %0.1fs\n"
760 "\tProperties:\n\t\t%s\n"),
763 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
764 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
765 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
766 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
767 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
768 (double) i
->duration
/1000000.0,
771 i
->filename
? i
->filename
: _("n/a"),
772 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
777 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
779 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
787 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
788 if (idx
== PA_INVALID_INDEX
) {
789 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
799 static void volume_relative_adjust(pa_cvolume
*cv
) {
800 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
802 /* Relative volume change is additive in case of UINT or PERCENT
803 * and multiplicative for LINEAR or DECIBEL */
804 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
805 pa_volume_t v
= pa_cvolume_avg(cv
);
806 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
807 pa_cvolume_set(cv
, 1, v
);
809 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
810 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
814 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
818 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
829 volume_relative_adjust(&cv
);
830 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
833 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
837 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
848 volume_relative_adjust(&cv
);
849 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
852 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
856 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
867 volume_relative_adjust(&cv
);
868 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
871 static void get_source_output_volume_callback(pa_context
*c
, const pa_source_output_info
*o
, int is_last
, void *userdata
) {
875 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
886 volume_relative_adjust(&cv
);
887 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &cv
, simple_callback
, NULL
));
890 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
891 #define MAX_FORMATS 256
893 static void set_sink_formats(pa_context
*c
, uint32_t sink
, const char *str
) {
894 pa_format_info
*f_arr
[MAX_FORMATS
];
896 const char *state
= NULL
;
899 while ((format
= pa_split(str
, ";", &state
))) {
900 pa_format_info
*f
= pa_format_info_from_string(pa_strip(format
));
903 pa_log(_("Failed to set format: invalid format string %s"), format
);
911 pa_operation_unref(pa_ext_device_restore_save_sink_formats(c
, sink
, i
, f_arr
, simple_callback
, NULL
));
917 pa_format_info_free(f_arr
[i
]);
923 pa_format_info_free(f_arr
[i
]);
928 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
931 switch (pa_stream_get_state(s
)) {
932 case PA_STREAM_CREATING
:
933 case PA_STREAM_READY
:
936 case PA_STREAM_TERMINATED
:
940 case PA_STREAM_FAILED
:
942 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
947 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
950 pa_assert(s
&& length
&& sndfile
);
952 d
= pa_xmalloc(length
);
954 pa_assert(sample_length
>= length
);
955 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
957 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
959 pa_log(_("Premature end of file"));
964 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
966 sample_length
-= length
;
968 if (sample_length
<= 0) {
969 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
970 pa_stream_finish_upload(sample_stream
);
974 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
976 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
978 case PA_SUBSCRIPTION_EVENT_NEW
:
981 case PA_SUBSCRIPTION_EVENT_CHANGE
:
984 case PA_SUBSCRIPTION_EVENT_REMOVE
:
991 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
993 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
995 case PA_SUBSCRIPTION_EVENT_SINK
:
998 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1001 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1002 return _("sink-input");
1004 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1005 return _("source-output");
1007 case PA_SUBSCRIPTION_EVENT_MODULE
:
1010 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1013 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1014 return _("sample-cache");
1016 case PA_SUBSCRIPTION_EVENT_SERVER
:
1019 case PA_SUBSCRIPTION_EVENT_CARD
:
1023 return _("unknown");
1026 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1029 printf(_("Event '%s' on %s #%u\n"),
1030 subscription_event_type_to_string(t
),
1031 subscription_event_facility_to_string(t
),
1035 static void context_state_callback(pa_context
*c
, void *userdata
) {
1037 switch (pa_context_get_state(c
)) {
1038 case PA_CONTEXT_CONNECTING
:
1039 case PA_CONTEXT_AUTHORIZING
:
1040 case PA_CONTEXT_SETTING_NAME
:
1043 case PA_CONTEXT_READY
:
1046 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
1047 if (short_list_format
)
1052 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
1056 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
1060 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1064 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1065 pa_assert(sample_stream
);
1067 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1068 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1069 pa_stream_connect_upload(sample_stream
, sample_length
);
1073 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1078 if (pa_streq(list_type
, "modules"))
1079 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1080 else if (pa_streq(list_type
, "sinks"))
1081 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1082 else if (pa_streq(list_type
, "sources"))
1083 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1084 else if (pa_streq(list_type
, "sink-inputs"))
1085 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1086 else if (pa_streq(list_type
, "source-outputs"))
1087 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1088 else if (pa_streq(list_type
, "clients"))
1089 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1090 else if (pa_streq(list_type
, "samples"))
1091 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1092 else if (pa_streq(list_type
, "cards"))
1093 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1095 pa_assert_not_reached();
1098 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1099 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1100 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1101 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1102 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1103 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1104 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1105 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1109 case MOVE_SINK_INPUT
:
1110 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1113 case MOVE_SOURCE_OUTPUT
:
1114 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1118 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1122 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1127 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1129 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1132 case SUSPEND_SOURCE
:
1134 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1136 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1139 case SET_CARD_PROFILE
:
1140 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1144 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1147 case SET_SOURCE_PORT
:
1148 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1152 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1155 case SET_SOURCE_MUTE
:
1156 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1159 case SET_SINK_INPUT_MUTE
:
1160 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1163 case SET_SINK_VOLUME
:
1164 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1165 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1168 pa_cvolume_set(&v
, 1, volume
);
1169 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1173 case SET_SOURCE_VOLUME
:
1174 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1175 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1178 pa_cvolume_set(&v
, 1, volume
);
1179 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1183 case SET_SINK_INPUT_VOLUME
:
1184 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1185 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1188 pa_cvolume_set(&v
, 1, volume
);
1189 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1193 case SET_SOURCE_OUTPUT_VOLUME
:
1194 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1195 pa_operation_unref(pa_context_get_source_output_info(c
, source_output_idx
, get_source_output_volume_callback
, NULL
));
1198 pa_cvolume_set(&v
, 1, volume
);
1199 pa_operation_unref(pa_context_set_source_output_volume(c
, source_output_idx
, &v
, simple_callback
, NULL
));
1203 case SET_SINK_FORMATS
:
1204 set_sink_formats(c
, sink_idx
, formats
);
1208 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1210 pa_operation_unref(pa_context_subscribe(
1212 PA_SUBSCRIPTION_MASK_SINK
|
1213 PA_SUBSCRIPTION_MASK_SOURCE
|
1214 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1215 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1216 PA_SUBSCRIPTION_MASK_MODULE
|
1217 PA_SUBSCRIPTION_MASK_CLIENT
|
1218 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1219 PA_SUBSCRIPTION_MASK_SERVER
|
1220 PA_SUBSCRIPTION_MASK_CARD
,
1226 pa_assert_not_reached();
1230 case PA_CONTEXT_TERMINATED
:
1234 case PA_CONTEXT_FAILED
:
1236 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1241 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1242 pa_log(_("Got SIGINT, exiting."));
1246 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1250 pa_assert(vol_spec
);
1252 pa_assert(vol_flags
);
1254 vs
= pa_xstrdup(vol_spec
);
1256 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1257 if (strchr(vs
, '.'))
1258 *vol_flags
|= VOL_LINEAR
;
1259 if (pa_endswith(vs
, "%")) {
1260 *vol_flags
|= VOL_PERCENT
;
1261 vs
[strlen(vs
)-1] = 0;
1263 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1264 *vol_flags
|= VOL_DECIBEL
;
1265 vs
[strlen(vs
)-2] = 0;
1268 if (pa_atod(vs
, &v
) < 0) {
1269 pa_log(_("Invalid volume specification"));
1276 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1277 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1278 v
+= (double) PA_VOLUME_NORM
;
1279 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1281 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1284 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1285 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1286 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1287 v
= pa_sw_volume_from_linear(v
);
1288 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1289 v
= pa_sw_volume_from_dB(v
);
1291 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1292 pa_log(_("Volume outside permissible range.\n"));
1296 *vol
= (pa_volume_t
) v
;
1301 static void help(const char *argv0
) {
1303 printf("%s %s %s\n", argv0
, _("[options]"), "stat [short]");
1304 printf("%s %s %s\n", argv0
, _("[options]"), "info");
1305 printf("%s %s %s %s\n", argv0
, _("[options]"), "list [short]", _("[TYPE]"));
1306 printf("%s %s %s\n", argv0
, _("[options]"), "exit");
1307 printf("%s %s %s %s\n", argv0
, _("[options]"), "upload-sample", _("FILENAME [NAME]"));
1308 printf("%s %s %s %s\n", argv0
, _("[options]"), "play-sample ", _("NAME [SINK]"));
1309 printf("%s %s %s %s\n", argv0
, _("[options]"), "remove-sample ", _("NAME"));
1310 printf("%s %s %s %s\n", argv0
, _("[options]"), "load-module ", _("NAME [ARGS ...]"));
1311 printf("%s %s %s %s\n", argv0
, _("[options]"), "unload-module ", _("#N"));
1312 printf("%s %s %s %s\n", argv0
, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
1313 printf("%s %s %s %s\n", argv0
, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
1314 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
1315 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
1316 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
1317 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
1318 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0"));
1319 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-input-mute", _("#N 1|0"));
1320 printf("%s %s %s %s\n", argv0
, _("[options]"), "set-sink-formats", _("#N FORMATS"));
1321 printf("%s %s %s\n", argv0
, _("[options]"), "subscribe");
1324 " -h, --help Show this help\n"
1325 " --version Show version\n\n"
1326 " -s, --server=SERVER The name of the server to connect to\n"
1327 " -n, --client-name=NAME How to call this client on the server\n"));
1334 int main(int argc
, char *argv
[]) {
1335 pa_mainloop
*m
= NULL
;
1337 char *server
= NULL
, *bn
;
1339 static const struct option long_options
[] = {
1340 {"server", 1, NULL
, 's'},
1341 {"client-name", 1, NULL
, 'n'},
1342 {"version", 0, NULL
, ARG_VERSION
},
1343 {"help", 0, NULL
, 'h'},
1347 setlocale(LC_ALL
, "");
1348 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1350 bn
= pa_path_get_filename(argv
[0]);
1352 proplist
= pa_proplist_new();
1354 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1362 printf(_("pactl %s\n"
1363 "Compiled with libpulse %s\n"
1364 "Linked with libpulse %s\n"),
1366 pa_get_headers_version(),
1367 pa_get_library_version());
1373 server
= pa_xstrdup(optarg
);
1379 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1380 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1382 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1396 if (optind
< argc
) {
1397 if (pa_streq(argv
[optind
], "stat")) {
1399 short_list_format
= FALSE
;
1400 if (optind
+1 < argc
&& pa_streq(argv
[optind
+1], "short"))
1401 short_list_format
= TRUE
;
1403 } else if (pa_streq(argv
[optind
], "info"))
1406 else if (pa_streq(argv
[optind
], "exit"))
1409 else if (pa_streq(argv
[optind
], "list")) {
1412 for (int i
= optind
+1; i
< argc
; i
++){
1413 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1414 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1415 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1416 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1417 list_type
= pa_xstrdup(argv
[i
]);
1418 } else if (pa_streq(argv
[i
], "short")) {
1419 short_list_format
= TRUE
;
1421 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1426 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1428 action
= UPLOAD_SAMPLE
;
1430 if (optind
+1 >= argc
) {
1431 pa_log(_("Please specify a sample file to load"));
1435 if (optind
+2 < argc
)
1436 sample_name
= pa_xstrdup(argv
[optind
+2]);
1438 char *f
= pa_path_get_filename(argv
[optind
+1]);
1439 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1443 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1444 pa_log(_("Failed to open sound file."));
1448 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1449 pa_log(_("Failed to determine sample specification from file."));
1452 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1454 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1455 if (sample_spec
.channels
> 2)
1456 pa_log(_("Warning: Failed to determine sample specification from file."));
1457 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1460 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1461 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1463 } else if (pa_streq(argv
[optind
], "play-sample")) {
1464 action
= PLAY_SAMPLE
;
1465 if (argc
!= optind
+2 && argc
!= optind
+3) {
1466 pa_log(_("You have to specify a sample name to play"));
1470 sample_name
= pa_xstrdup(argv
[optind
+1]);
1472 if (optind
+2 < argc
)
1473 sink_name
= pa_xstrdup(argv
[optind
+2]);
1475 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1476 action
= REMOVE_SAMPLE
;
1477 if (argc
!= optind
+2) {
1478 pa_log(_("You have to specify a sample name to remove"));
1482 sample_name
= pa_xstrdup(argv
[optind
+1]);
1484 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1485 action
= MOVE_SINK_INPUT
;
1486 if (argc
!= optind
+3) {
1487 pa_log(_("You have to specify a sink input index and a sink"));
1491 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1492 sink_name
= pa_xstrdup(argv
[optind
+2]);
1494 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1495 action
= MOVE_SOURCE_OUTPUT
;
1496 if (argc
!= optind
+3) {
1497 pa_log(_("You have to specify a source output index and a source"));
1501 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1502 source_name
= pa_xstrdup(argv
[optind
+2]);
1504 } else if (pa_streq(argv
[optind
], "load-module")) {
1509 action
= LOAD_MODULE
;
1511 if (argc
<= optind
+1) {
1512 pa_log(_("You have to specify a module name and arguments."));
1516 module_name
= argv
[optind
+1];
1518 for (i
= optind
+2; i
< argc
; i
++)
1519 n
+= strlen(argv
[i
])+1;
1522 p
= module_args
= pa_xmalloc(n
);
1524 for (i
= optind
+2; i
< argc
; i
++)
1525 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1528 } else if (pa_streq(argv
[optind
], "unload-module")) {
1529 action
= UNLOAD_MODULE
;
1531 if (argc
!= optind
+2) {
1532 pa_log(_("You have to specify a module index"));
1536 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1538 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1539 action
= SUSPEND_SINK
;
1541 if (argc
> optind
+3 || optind
+1 >= argc
) {
1542 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1546 suspend
= pa_parse_boolean(argv
[argc
-1]);
1548 if (argc
> optind
+2)
1549 sink_name
= pa_xstrdup(argv
[optind
+1]);
1551 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1552 action
= SUSPEND_SOURCE
;
1554 if (argc
> optind
+3 || optind
+1 >= argc
) {
1555 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1559 suspend
= pa_parse_boolean(argv
[argc
-1]);
1561 if (argc
> optind
+2)
1562 source_name
= pa_xstrdup(argv
[optind
+1]);
1563 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1564 action
= SET_CARD_PROFILE
;
1566 if (argc
!= optind
+3) {
1567 pa_log(_("You have to specify a card name/index and a profile name"));
1571 card_name
= pa_xstrdup(argv
[optind
+1]);
1572 profile_name
= pa_xstrdup(argv
[optind
+2]);
1574 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1575 action
= SET_SINK_PORT
;
1577 if (argc
!= optind
+3) {
1578 pa_log(_("You have to specify a sink name/index and a port name"));
1582 sink_name
= pa_xstrdup(argv
[optind
+1]);
1583 port_name
= pa_xstrdup(argv
[optind
+2]);
1585 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1586 action
= SET_SOURCE_PORT
;
1588 if (argc
!= optind
+3) {
1589 pa_log(_("You have to specify a source name/index and a port name"));
1593 source_name
= pa_xstrdup(argv
[optind
+1]);
1594 port_name
= pa_xstrdup(argv
[optind
+2]);
1596 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1597 action
= SET_SINK_VOLUME
;
1599 if (argc
!= optind
+3) {
1600 pa_log(_("You have to specify a sink name/index and a volume"));
1604 sink_name
= pa_xstrdup(argv
[optind
+1]);
1606 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1609 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1610 action
= SET_SOURCE_VOLUME
;
1612 if (argc
!= optind
+3) {
1613 pa_log(_("You have to specify a source name/index and a volume"));
1617 source_name
= pa_xstrdup(argv
[optind
+1]);
1619 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1622 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1623 action
= SET_SINK_INPUT_VOLUME
;
1625 if (argc
!= optind
+3) {
1626 pa_log(_("You have to specify a sink input index and a volume"));
1630 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1631 pa_log(_("Invalid sink input index"));
1635 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1638 } else if (pa_streq(argv
[optind
], "set-source-output-volume")) {
1639 action
= SET_SOURCE_OUTPUT_VOLUME
;
1641 if (argc
!= optind
+3) {
1642 pa_log(_("You have to specify a source output index and a volume"));
1646 if (pa_atou(argv
[optind
+1], &source_output_idx
) < 0) {
1647 pa_log(_("Invalid source output index"));
1651 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1654 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1656 action
= SET_SINK_MUTE
;
1658 if (argc
!= optind
+3) {
1659 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1663 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1664 pa_log(_("Invalid mute specification"));
1668 sink_name
= pa_xstrdup(argv
[optind
+1]);
1671 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1673 action
= SET_SOURCE_MUTE
;
1675 if (argc
!= optind
+3) {
1676 pa_log(_("You have to specify a source name/index and a mute boolean"));
1680 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1681 pa_log(_("Invalid mute specification"));
1685 source_name
= pa_xstrdup(argv
[optind
+1]);
1688 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1690 action
= SET_SINK_INPUT_MUTE
;
1692 if (argc
!= optind
+3) {
1693 pa_log(_("You have to specify a sink input index and a mute boolean"));
1697 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1698 pa_log(_("Invalid sink input index specification"));
1702 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1703 pa_log(_("Invalid mute specification"));
1709 } else if (pa_streq(argv
[optind
], "subscribe"))
1713 else if (pa_streq(argv
[optind
], "set-sink-formats")) {
1716 if (argc
!= optind
+3 || pa_atoi(argv
[optind
+1], &tmp
) < 0) {
1717 pa_log(_("You have to specify a sink index and a semicolon-separated list of supported formats"));
1722 action
= SET_SINK_FORMATS
;
1723 formats
= pa_xstrdup(argv
[optind
+2]);
1725 } else if (pa_streq(argv
[optind
], "help")) {
1732 if (action
== NONE
) {
1733 pa_log(_("No valid command specified."));
1737 if (!(m
= pa_mainloop_new())) {
1738 pa_log(_("pa_mainloop_new() failed."));
1742 mainloop_api
= pa_mainloop_get_api(m
);
1744 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1745 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1746 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1747 pa_disable_sigpipe();
1749 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1750 pa_log(_("pa_context_new() failed."));
1754 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1755 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1756 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1760 if (pa_mainloop_run(m
, &ret
) < 0) {
1761 pa_log(_("pa_mainloop_run() failed."));
1767 pa_stream_unref(sample_stream
);
1770 pa_context_unref(context
);
1774 pa_mainloop_free(m
);
1778 pa_xfree(list_type
);
1779 pa_xfree(sample_name
);
1780 pa_xfree(sink_name
);
1781 pa_xfree(source_name
);
1782 pa_xfree(module_args
);
1783 pa_xfree(card_name
);
1784 pa_xfree(profile_name
);
1785 pa_xfree(port_name
);
1792 pa_proplist_free(proplist
);