2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
39 #include <pulse/i18n.h>
40 #include <pulse/pulseaudio.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
;
62 sink_input_idx
= PA_INVALID_INDEX
,
63 source_output_idx
= PA_INVALID_INDEX
;
65 static pa_bool_t short_list_format
= FALSE
;
66 static uint32_t module_index
;
67 static pa_bool_t suspend
;
68 static pa_bool_t mute
;
69 static pa_volume_t volume
;
70 static enum volume_flags
{
75 VOL_ABSOLUTE
= 0 << 4,
76 VOL_RELATIVE
= 1 << 4,
79 static pa_proplist
*proplist
= NULL
;
81 static SNDFILE
*sndfile
= NULL
;
82 static pa_stream
*sample_stream
= NULL
;
83 static pa_sample_spec sample_spec
;
84 static pa_channel_map channel_map
;
85 static size_t sample_length
= 0;
86 static int actions
= 1;
88 static pa_bool_t nl
= FALSE
;
110 SET_SINK_INPUT_VOLUME
,
117 static void quit(int ret
) {
118 pa_assert(mainloop_api
);
119 mainloop_api
->quit(mainloop_api
, ret
);
122 static void context_drain_complete(pa_context
*c
, void *userdata
) {
123 pa_context_disconnect(c
);
126 static void drain(void) {
129 if (!(o
= pa_context_drain(context
, context_drain_complete
, NULL
)))
130 pa_context_disconnect(context
);
132 pa_operation_unref(o
);
135 static void complete_action(void) {
136 pa_assert(actions
> 0);
142 static void stat_callback(pa_context
*c
, const pa_stat_info
*i
, void *userdata
) {
143 char s
[PA_BYTES_SNPRINT_MAX
];
145 pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c
)));
150 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_total_size
);
151 printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i
->memblock_total
, s
);
153 pa_bytes_snprint(s
, sizeof(s
), i
->memblock_allocated_size
);
154 printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i
->memblock_allocated
, s
);
156 pa_bytes_snprint(s
, sizeof(s
), i
->scache_size
);
157 printf(_("Sample cache size: %s\n"), s
);
162 static void get_server_info_callback(pa_context
*c
, const pa_server_info
*i
, void *useerdata
) {
163 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
166 pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c
)));
171 printf(_("Server String: %s\n"
172 "Library Protocol Version: %u\n"
173 "Server Protocol Version: %u\n"
177 pa_context_get_server(c
),
178 pa_context_get_protocol_version(c
),
179 pa_context_get_server_protocol_version(c
),
180 pa_yes_no(pa_context_is_local(c
)),
181 pa_context_get_index(c
),
182 pa_context_get_tile_size(c
, NULL
));
184 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
);
185 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
);
187 printf(_("User Name: %s\n"
190 "Server Version: %s\n"
191 "Default Sample Specification: %s\n"
192 "Default Channel Map: %s\n"
194 "Default Source: %s\n"
195 "Cookie: %04x:%04x\n"),
202 i
->default_sink_name
,
203 i
->default_source_name
,
205 i
->cookie
& 0xFFFFU
);
210 static void get_sink_info_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
212 static const char *state_table
[] = {
213 [1+PA_SINK_INVALID_STATE
] = "n/a",
214 [1+PA_SINK_RUNNING
] = "RUNNING",
215 [1+PA_SINK_IDLE
] = "IDLE",
216 [1+PA_SINK_SUSPENDED
] = "SUSPENDED"
220 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
221 cv
[PA_CVOLUME_SNPRINT_MAX
],
222 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
223 v
[PA_VOLUME_SNPRINT_MAX
],
224 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
225 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
226 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
230 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
242 if (nl
&& !short_list_format
)
246 if (short_list_format
) {
247 printf("%u\t%s\t%s\t%s\t%s\n",
250 pa_strnull(i
->driver
),
251 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
252 state_table
[1+i
->state
]);
256 printf(_("Sink #%u\n"
259 "\tDescription: %s\n"
261 "\tSample Specification: %s\n"
262 "\tChannel Map: %s\n"
263 "\tOwner Module: %u\n"
267 "\tBase Volume: %s%s%s\n"
268 "\tMonitor Source: %s\n"
269 "\tLatency: %0.0f usec, configured %0.0f usec\n"
270 "\tFlags: %s%s%s%s%s%s\n"
271 "\tProperties:\n\t\t%s\n"),
273 state_table
[1+i
->state
],
275 pa_strnull(i
->description
),
276 pa_strnull(i
->driver
),
277 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
278 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
281 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
282 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
283 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
284 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
285 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
286 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
287 i
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
288 pa_strnull(i
->monitor_source_name
),
289 (double) i
->latency
, (double) i
->configured_latency
,
290 i
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
291 i
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
292 i
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
293 i
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
294 i
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
295 i
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
296 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
301 pa_sink_port_info
**p
;
303 printf(_("\tPorts:\n"));
304 for (p
= i
->ports
; *p
; p
++)
305 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
309 printf(_("\tActive Port: %s\n"),
310 i
->active_port
->name
);
315 printf(_("\tFormats:\n"));
316 for (j
= 0; j
< i
->n_formats
; j
++)
317 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
321 static void get_source_info_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
323 static const char *state_table
[] = {
324 [1+PA_SOURCE_INVALID_STATE
] = "n/a",
325 [1+PA_SOURCE_RUNNING
] = "RUNNING",
326 [1+PA_SOURCE_IDLE
] = "IDLE",
327 [1+PA_SOURCE_SUSPENDED
] = "SUSPENDED"
331 s
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
332 cv
[PA_CVOLUME_SNPRINT_MAX
],
333 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
334 v
[PA_VOLUME_SNPRINT_MAX
],
335 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
336 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
],
337 f
[PA_FORMAT_INFO_SNPRINT_MAX
];
341 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
353 if (nl
&& !short_list_format
)
357 if (short_list_format
) {
358 printf("%u\t%s\t%s\t%s\t%s\n",
361 pa_strnull(i
->driver
),
362 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
363 state_table
[1+i
->state
]);
367 printf(_("Source #%u\n"
370 "\tDescription: %s\n"
372 "\tSample Specification: %s\n"
373 "\tChannel Map: %s\n"
374 "\tOwner Module: %u\n"
378 "\tBase Volume: %s%s%s\n"
379 "\tMonitor of Sink: %s\n"
380 "\tLatency: %0.0f usec, configured %0.0f usec\n"
381 "\tFlags: %s%s%s%s%s%s\n"
382 "\tProperties:\n\t\t%s\n"),
384 state_table
[1+i
->state
],
386 pa_strnull(i
->description
),
387 pa_strnull(i
->driver
),
388 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
389 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
392 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
393 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
394 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
) : "",
395 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
396 pa_volume_snprint(v
, sizeof(v
), i
->base_volume
),
397 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
398 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), i
->base_volume
) : "",
399 i
->monitor_of_sink_name
? i
->monitor_of_sink_name
: _("n/a"),
400 (double) i
->latency
, (double) i
->configured_latency
,
401 i
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
402 i
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
403 i
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
404 i
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
405 i
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
406 i
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
407 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
412 pa_source_port_info
**p
;
414 printf(_("\tPorts:\n"));
415 for (p
= i
->ports
; *p
; p
++)
416 printf("\t\t%s: %s (priority. %u)\n", (*p
)->name
, (*p
)->description
, (*p
)->priority
);
420 printf(_("\tActive Port: %s\n"),
421 i
->active_port
->name
);
426 printf(_("\tFormats:\n"));
427 for (j
= 0; j
< i
->n_formats
; j
++)
428 printf("\t\t%s\n", pa_format_info_snprint(f
, sizeof(f
), i
->formats
[j
]));
432 static void get_module_info_callback(pa_context
*c
, const pa_module_info
*i
, int is_last
, void *userdata
) {
437 pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c
)));
449 if (nl
&& !short_list_format
)
453 pa_snprintf(t
, sizeof(t
), "%u", i
->n_used
);
455 if (short_list_format
) {
456 printf("%u\t%s\t%s\t\n", i
->index
, i
->name
, i
->argument
? i
->argument
: "");
460 printf(_("Module #%u\n"
463 "\tUsage counter: %s\n"
464 "\tProperties:\n\t\t%s\n"),
467 i
->argument
? i
->argument
: "",
468 i
->n_used
!= PA_INVALID_INDEX
? t
: _("n/a"),
469 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
474 static void get_client_info_callback(pa_context
*c
, const pa_client_info
*i
, int is_last
, void *userdata
) {
479 pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c
)));
491 if (nl
&& !short_list_format
)
495 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
497 if (short_list_format
) {
498 printf("%u\t%s\t%s\n",
500 pa_strnull(i
->driver
),
501 pa_strnull(pa_proplist_gets(i
->proplist
, PA_PROP_APPLICATION_PROCESS_BINARY
)));
505 printf(_("Client #%u\n"
507 "\tOwner Module: %s\n"
508 "\tProperties:\n\t\t%s\n"),
510 pa_strnull(i
->driver
),
511 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
512 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
517 static void get_card_info_callback(pa_context
*c
, const pa_card_info
*i
, int is_last
, void *userdata
) {
522 pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c
)));
534 if (nl
&& !short_list_format
)
538 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
540 if (short_list_format
) {
541 printf("%u\t%s\t%s\n", i
->index
, i
->name
, pa_strnull(i
->driver
));
545 printf(_("Card #%u\n"
548 "\tOwner Module: %s\n"
549 "\tProperties:\n\t\t%s\n"),
552 pa_strnull(i
->driver
),
553 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
554 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
557 pa_card_profile_info
*p
;
559 printf(_("\tProfiles:\n"));
560 for (p
= i
->profiles
; p
->name
; p
++)
561 printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p
->name
, p
->description
, p
->n_sinks
, p
->n_sources
, p
->priority
);
564 if (i
->active_profile
)
565 printf(_("\tActive Profile: %s\n"),
566 i
->active_profile
->name
);
571 static void get_sink_input_info_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
572 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
];
576 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
588 if (nl
&& !short_list_format
)
592 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
593 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
595 if (short_list_format
) {
596 printf("%u\t%u\t%s\t%s\t%s\n",
599 i
->client
!= PA_INVALID_INDEX
? k
: "-",
600 pa_strnull(i
->driver
),
601 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
605 printf(_("Sink Input #%u\n"
607 "\tOwner Module: %s\n"
610 "\tSample Specification: %s\n"
611 "\tChannel Map: %s\n"
617 "\tBuffer Latency: %0.0f usec\n"
618 "\tSink Latency: %0.0f usec\n"
619 "\tResample method: %s\n"
620 "\tProperties:\n\t\t%s\n"),
622 pa_strnull(i
->driver
),
623 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
624 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
626 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
627 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
628 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
630 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
631 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
632 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
633 (double) i
->buffer_usec
,
634 (double) i
->sink_usec
,
635 i
->resample_method
? i
->resample_method
: _("n/a"),
636 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
641 static void get_source_output_info_callback(pa_context
*c
, const pa_source_output_info
*i
, int is_last
, void *userdata
) {
642 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
];
646 pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c
)));
658 if (nl
&& !short_list_format
)
663 pa_snprintf(t
, sizeof(t
), "%u", i
->owner_module
);
664 pa_snprintf(k
, sizeof(k
), "%u", i
->client
);
666 if (short_list_format
) {
667 printf("%u\t%u\t%s\t%s\t%s\n",
670 i
->client
!= PA_INVALID_INDEX
? k
: "-",
671 pa_strnull(i
->driver
),
672 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
));
676 printf(_("Source Output #%u\n"
678 "\tOwner Module: %s\n"
681 "\tSample Specification: %s\n"
682 "\tChannel Map: %s\n"
688 "\tBuffer Latency: %0.0f usec\n"
689 "\tSource Latency: %0.0f usec\n"
690 "\tResample method: %s\n"
691 "\tProperties:\n\t\t%s\n"),
693 pa_strnull(i
->driver
),
694 i
->owner_module
!= PA_INVALID_INDEX
? t
: _("n/a"),
695 i
->client
!= PA_INVALID_INDEX
? k
: _("n/a"),
697 pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
),
698 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
699 pa_format_info_snprint(f
, sizeof(f
), i
->format
),
701 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
702 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
703 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
704 (double) i
->buffer_usec
,
705 (double) i
->source_usec
,
706 i
->resample_method
? i
->resample_method
: _("n/a"),
707 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
712 static void get_sample_info_callback(pa_context
*c
, const pa_sample_info
*i
, int is_last
, void *userdata
) {
713 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
];
717 pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c
)));
729 if (nl
&& !short_list_format
)
733 pa_bytes_snprint(t
, sizeof(t
), i
->bytes
);
735 if (short_list_format
) {
736 printf("%u\t%s\t%s\t%0.3f\n",
739 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : "-",
740 (double) i
->duration
/1000000.0);
744 printf(_("Sample #%u\n"
746 "\tSample Specification: %s\n"
747 "\tChannel Map: %s\n"
751 "\tDuration: %0.1fs\n"
755 "\tProperties:\n\t\t%s\n"),
758 pa_sample_spec_valid(&i
->sample_spec
) ? pa_sample_spec_snprint(s
, sizeof(s
), &i
->sample_spec
) : _("n/a"),
759 pa_sample_spec_valid(&i
->sample_spec
) ? pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
) : _("n/a"),
760 pa_cvolume_snprint(cv
, sizeof(cv
), &i
->volume
),
761 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &i
->volume
),
762 pa_cvolume_get_balance(&i
->volume
, &i
->channel_map
),
763 (double) i
->duration
/1000000.0,
766 i
->filename
? i
->filename
: _("n/a"),
767 pl
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t"));
772 static void simple_callback(pa_context
*c
, int success
, void *userdata
) {
774 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
782 static void index_callback(pa_context
*c
, uint32_t idx
, void *userdata
) {
783 if (idx
== PA_INVALID_INDEX
) {
784 pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c
)));
794 static void volume_relative_adjust(pa_cvolume
*cv
) {
795 pa_assert((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
);
797 /* Relative volume change is additive in case of UINT or PERCENT
798 * and multiplicative for LINEAR or DECIBEL */
799 if ((volume_flags
& 0x0F) == VOL_UINT
|| (volume_flags
& 0x0F) == VOL_PERCENT
) {
800 pa_volume_t v
= pa_cvolume_avg(cv
);
801 v
= v
+ volume
< PA_VOLUME_NORM
? PA_VOLUME_MUTED
: v
+ volume
- PA_VOLUME_NORM
;
802 pa_cvolume_set(cv
, 1, v
);
804 if ((volume_flags
& 0x0F) == VOL_LINEAR
|| (volume_flags
& 0x0F) == VOL_DECIBEL
) {
805 pa_sw_cvolume_multiply_scalar(cv
, cv
, volume
);
809 static void get_sink_volume_callback(pa_context
*c
, const pa_sink_info
*i
, int is_last
, void *userdata
) {
813 pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c
)));
824 volume_relative_adjust(&cv
);
825 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &cv
, simple_callback
, NULL
));
828 static void get_source_volume_callback(pa_context
*c
, const pa_source_info
*i
, int is_last
, void *userdata
) {
832 pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c
)));
843 volume_relative_adjust(&cv
);
844 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &cv
, simple_callback
, NULL
));
847 static void get_sink_input_volume_callback(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
) {
851 pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c
)));
862 volume_relative_adjust(&cv
);
863 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &cv
, simple_callback
, NULL
));
866 static void stream_state_callback(pa_stream
*s
, void *userdata
) {
869 switch (pa_stream_get_state(s
)) {
870 case PA_STREAM_CREATING
:
871 case PA_STREAM_READY
:
874 case PA_STREAM_TERMINATED
:
878 case PA_STREAM_FAILED
:
880 pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s
))));
885 static void stream_write_callback(pa_stream
*s
, size_t length
, void *userdata
) {
888 pa_assert(s
&& length
&& sndfile
);
890 d
= pa_xmalloc(length
);
892 pa_assert(sample_length
>= length
);
893 l
= (sf_count_t
) (length
/pa_frame_size(&sample_spec
));
895 if ((sf_readf_float(sndfile
, d
, l
)) != l
) {
897 pa_log(_("Premature end of file"));
902 pa_stream_write(s
, d
, length
, pa_xfree
, 0, PA_SEEK_RELATIVE
);
904 sample_length
-= length
;
906 if (sample_length
<= 0) {
907 pa_stream_set_write_callback(sample_stream
, NULL
, NULL
);
908 pa_stream_finish_upload(sample_stream
);
912 static const char *subscription_event_type_to_string(pa_subscription_event_type_t t
) {
914 switch (t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) {
916 case PA_SUBSCRIPTION_EVENT_NEW
:
919 case PA_SUBSCRIPTION_EVENT_CHANGE
:
922 case PA_SUBSCRIPTION_EVENT_REMOVE
:
929 static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t
) {
931 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
933 case PA_SUBSCRIPTION_EVENT_SINK
:
936 case PA_SUBSCRIPTION_EVENT_SOURCE
:
939 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
940 return _("sink-input");
942 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
943 return _("source-output");
945 case PA_SUBSCRIPTION_EVENT_MODULE
:
948 case PA_SUBSCRIPTION_EVENT_CLIENT
:
951 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
952 return _("sample-cache");
954 case PA_SUBSCRIPTION_EVENT_SERVER
:
957 case PA_SUBSCRIPTION_EVENT_CARD
:
964 static void context_subscribe_callback(pa_context
*c
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
967 printf(_("Event '%s' on %s #%u\n"),
968 subscription_event_type_to_string(t
),
969 subscription_event_facility_to_string(t
),
973 static void context_state_callback(pa_context
*c
, void *userdata
) {
975 switch (pa_context_get_state(c
)) {
976 case PA_CONTEXT_CONNECTING
:
977 case PA_CONTEXT_AUTHORIZING
:
978 case PA_CONTEXT_SETTING_NAME
:
981 case PA_CONTEXT_READY
:
984 pa_operation_unref(pa_context_stat(c
, stat_callback
, NULL
));
988 pa_operation_unref(pa_context_get_server_info(c
, get_server_info_callback
, NULL
));
992 pa_operation_unref(pa_context_play_sample(c
, sample_name
, sink_name
, PA_VOLUME_NORM
, simple_callback
, NULL
));
996 pa_operation_unref(pa_context_remove_sample(c
, sample_name
, simple_callback
, NULL
));
1000 sample_stream
= pa_stream_new(c
, sample_name
, &sample_spec
, NULL
);
1001 pa_assert(sample_stream
);
1003 pa_stream_set_state_callback(sample_stream
, stream_state_callback
, NULL
);
1004 pa_stream_set_write_callback(sample_stream
, stream_write_callback
, NULL
);
1005 pa_stream_connect_upload(sample_stream
, sample_length
);
1009 pa_operation_unref(pa_context_exit_daemon(c
, simple_callback
, NULL
));
1014 if (pa_streq(list_type
, "modules"))
1015 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1016 else if (pa_streq(list_type
, "sinks"))
1017 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1018 else if (pa_streq(list_type
, "sources"))
1019 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1020 else if (pa_streq(list_type
, "sink-inputs"))
1021 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1022 else if (pa_streq(list_type
, "source-outputs"))
1023 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1024 else if (pa_streq(list_type
, "clients"))
1025 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1026 else if (pa_streq(list_type
, "samples"))
1027 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1028 else if (pa_streq(list_type
, "cards"))
1029 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1031 pa_assert_not_reached();
1034 pa_operation_unref(pa_context_get_module_info_list(c
, get_module_info_callback
, NULL
));
1035 pa_operation_unref(pa_context_get_sink_info_list(c
, get_sink_info_callback
, NULL
));
1036 pa_operation_unref(pa_context_get_source_info_list(c
, get_source_info_callback
, NULL
));
1037 pa_operation_unref(pa_context_get_sink_input_info_list(c
, get_sink_input_info_callback
, NULL
));
1038 pa_operation_unref(pa_context_get_source_output_info_list(c
, get_source_output_info_callback
, NULL
));
1039 pa_operation_unref(pa_context_get_client_info_list(c
, get_client_info_callback
, NULL
));
1040 pa_operation_unref(pa_context_get_sample_info_list(c
, get_sample_info_callback
, NULL
));
1041 pa_operation_unref(pa_context_get_card_info_list(c
, get_card_info_callback
, NULL
));
1045 case MOVE_SINK_INPUT
:
1046 pa_operation_unref(pa_context_move_sink_input_by_name(c
, sink_input_idx
, sink_name
, simple_callback
, NULL
));
1049 case MOVE_SOURCE_OUTPUT
:
1050 pa_operation_unref(pa_context_move_source_output_by_name(c
, source_output_idx
, source_name
, simple_callback
, NULL
));
1054 pa_operation_unref(pa_context_load_module(c
, module_name
, module_args
, index_callback
, NULL
));
1058 pa_operation_unref(pa_context_unload_module(c
, module_index
, simple_callback
, NULL
));
1063 pa_operation_unref(pa_context_suspend_sink_by_name(c
, sink_name
, suspend
, simple_callback
, NULL
));
1065 pa_operation_unref(pa_context_suspend_sink_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1068 case SUSPEND_SOURCE
:
1070 pa_operation_unref(pa_context_suspend_source_by_name(c
, source_name
, suspend
, simple_callback
, NULL
));
1072 pa_operation_unref(pa_context_suspend_source_by_index(c
, PA_INVALID_INDEX
, suspend
, simple_callback
, NULL
));
1075 case SET_CARD_PROFILE
:
1076 pa_operation_unref(pa_context_set_card_profile_by_name(c
, card_name
, profile_name
, simple_callback
, NULL
));
1080 pa_operation_unref(pa_context_set_sink_port_by_name(c
, sink_name
, port_name
, simple_callback
, NULL
));
1083 case SET_SOURCE_PORT
:
1084 pa_operation_unref(pa_context_set_source_port_by_name(c
, source_name
, port_name
, simple_callback
, NULL
));
1088 pa_operation_unref(pa_context_set_sink_mute_by_name(c
, sink_name
, mute
, simple_callback
, NULL
));
1091 case SET_SOURCE_MUTE
:
1092 pa_operation_unref(pa_context_set_source_mute_by_name(c
, source_name
, mute
, simple_callback
, NULL
));
1095 case SET_SINK_INPUT_MUTE
:
1096 pa_operation_unref(pa_context_set_sink_input_mute(c
, sink_input_idx
, mute
, simple_callback
, NULL
));
1099 case SET_SINK_VOLUME
:
1100 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1101 pa_operation_unref(pa_context_get_sink_info_by_name(c
, sink_name
, get_sink_volume_callback
, NULL
));
1104 pa_cvolume_set(&v
, 1, volume
);
1105 pa_operation_unref(pa_context_set_sink_volume_by_name(c
, sink_name
, &v
, simple_callback
, NULL
));
1109 case SET_SOURCE_VOLUME
:
1110 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1111 pa_operation_unref(pa_context_get_source_info_by_name(c
, source_name
, get_source_volume_callback
, NULL
));
1114 pa_cvolume_set(&v
, 1, volume
);
1115 pa_operation_unref(pa_context_set_source_volume_by_name(c
, source_name
, &v
, simple_callback
, NULL
));
1119 case SET_SINK_INPUT_VOLUME
:
1120 if ((volume_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1121 pa_operation_unref(pa_context_get_sink_input_info(c
, sink_input_idx
, get_sink_input_volume_callback
, NULL
));
1124 pa_cvolume_set(&v
, 1, volume
);
1125 pa_operation_unref(pa_context_set_sink_input_volume(c
, sink_input_idx
, &v
, simple_callback
, NULL
));
1130 pa_context_set_subscribe_callback(c
, context_subscribe_callback
, NULL
);
1132 pa_operation_unref(pa_context_subscribe(
1134 PA_SUBSCRIPTION_MASK_SINK
|
1135 PA_SUBSCRIPTION_MASK_SOURCE
|
1136 PA_SUBSCRIPTION_MASK_SINK_INPUT
|
1137 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
|
1138 PA_SUBSCRIPTION_MASK_MODULE
|
1139 PA_SUBSCRIPTION_MASK_CLIENT
|
1140 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE
|
1141 PA_SUBSCRIPTION_MASK_SERVER
|
1142 PA_SUBSCRIPTION_MASK_CARD
,
1148 pa_assert_not_reached();
1152 case PA_CONTEXT_TERMINATED
:
1156 case PA_CONTEXT_FAILED
:
1158 pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c
)));
1163 static void exit_signal_callback(pa_mainloop_api
*m
, pa_signal_event
*e
, int sig
, void *userdata
) {
1164 pa_log(_("Got SIGINT, exiting."));
1168 static int parse_volume(const char *vol_spec
, pa_volume_t
*vol
, enum volume_flags
*vol_flags
) {
1172 pa_assert(vol_spec
);
1174 pa_assert(vol_flags
);
1176 vs
= pa_xstrdup(vol_spec
);
1178 *vol_flags
= (pa_startswith(vs
, "+") || pa_startswith(vs
, "-")) ? VOL_RELATIVE
: VOL_ABSOLUTE
;
1179 if (strchr(vs
, '.'))
1180 *vol_flags
|= VOL_LINEAR
;
1181 if (pa_endswith(vs
, "%")) {
1182 *vol_flags
|= VOL_PERCENT
;
1183 vs
[strlen(vs
)-1] = 0;
1185 if (pa_endswith(vs
, "db") || pa_endswith(vs
, "dB")) {
1186 *vol_flags
|= VOL_DECIBEL
;
1187 vs
[strlen(vs
)-2] = 0;
1190 if (pa_atod(vs
, &v
) < 0) {
1191 pa_log(_("Invalid volume specification"));
1198 if ((*vol_flags
& VOL_RELATIVE
) == VOL_RELATIVE
) {
1199 if ((*vol_flags
& 0x0F) == VOL_UINT
)
1200 v
+= (double) PA_VOLUME_NORM
;
1201 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1203 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1206 if ((*vol_flags
& 0x0F) == VOL_PERCENT
)
1207 v
= v
* (double) PA_VOLUME_NORM
/ 100;
1208 if ((*vol_flags
& 0x0F) == VOL_LINEAR
)
1209 v
= pa_sw_volume_from_linear(v
);
1210 if ((*vol_flags
& 0x0F) == VOL_DECIBEL
)
1211 v
= pa_sw_volume_from_dB(v
);
1213 if (!PA_VOLUME_IS_VALID((pa_volume_t
) v
)) {
1214 pa_log(_("Volume outside permissible range.\n"));
1218 *vol
= (pa_volume_t
) v
;
1223 static void help(const char *argv0
) {
1225 printf(_("%s [options] stat\n"
1226 "%s [options] info\n"
1227 "%s [options] list [short] [TYPE]\n"
1228 "%s [options] exit\n"
1229 "%s [options] upload-sample FILENAME [NAME]\n"
1230 "%s [options] play-sample NAME [SINK]\n"
1231 "%s [options] remove-sample NAME\n"
1232 "%s [options] move-sink-input SINKINPUT SINK\n"
1233 "%s [options] move-source-output SOURCEOUTPUT SOURCE\n"
1234 "%s [options] load-module NAME [ARGS ...]\n"
1235 "%s [options] unload-module MODULE\n"
1236 "%s [options] suspend-sink SINK 1|0\n"
1237 "%s [options] suspend-source SOURCE 1|0\n"
1238 "%s [options] set-card-profile CARD PROFILE\n"
1239 "%s [options] set-sink-port SINK PORT\n"
1240 "%s [options] set-source-port SOURCE PORT\n"
1241 "%s [options] set-sink-volume SINK VOLUME\n"
1242 "%s [options] set-source-volume SOURCE VOLUME\n"
1243 "%s [options] set-sink-input-volume SINKINPUT VOLUME\n"
1244 "%s [options] set-sink-mute SINK 1|0\n"
1245 "%s [options] set-source-mute SOURCE 1|0\n"
1246 "%s [options] set-sink-input-mute SINKINPUT 1|0\n"
1247 "%s [options] subscribe\n\n"
1248 " -h, --help Show this help\n"
1249 " --version Show version\n\n"
1250 " -s, --server=SERVER The name of the server to connect to\n"
1251 " -n, --client-name=NAME How to call this client on the server\n"),
1252 argv0
, argv0
, argv0
, argv0
, argv0
,
1253 argv0
, argv0
, argv0
, argv0
, argv0
,
1254 argv0
, argv0
, argv0
, argv0
, argv0
,
1255 argv0
, argv0
, argv0
, argv0
, argv0
,
1256 argv0
, argv0
, argv0
);
1263 int main(int argc
, char *argv
[]) {
1264 pa_mainloop
*m
= NULL
;
1266 char *server
= NULL
, *bn
;
1268 static const struct option long_options
[] = {
1269 {"server", 1, NULL
, 's'},
1270 {"client-name", 1, NULL
, 'n'},
1271 {"version", 0, NULL
, ARG_VERSION
},
1272 {"help", 0, NULL
, 'h'},
1276 setlocale(LC_ALL
, "");
1277 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
1279 bn
= pa_path_get_filename(argv
[0]);
1281 proplist
= pa_proplist_new();
1283 while ((c
= getopt_long(argc
, argv
, "s:n:h", long_options
, NULL
)) != -1) {
1291 printf(_("pactl %s\n"
1292 "Compiled with libpulse %s\n"
1293 "Linked with libpulse %s\n"),
1295 pa_get_headers_version(),
1296 pa_get_library_version());
1302 server
= pa_xstrdup(optarg
);
1308 if (!(t
= pa_locale_to_utf8(optarg
)) ||
1309 pa_proplist_sets(proplist
, PA_PROP_APPLICATION_NAME
, t
) < 0) {
1311 pa_log(_("Invalid client name '%s'"), t
? t
: optarg
);
1325 if (optind
< argc
) {
1326 if (pa_streq(argv
[optind
], "stat"))
1329 else if (pa_streq(argv
[optind
], "info"))
1332 else if (pa_streq(argv
[optind
], "exit"))
1335 else if (pa_streq(argv
[optind
], "list")) {
1338 for (int i
= optind
+1; i
< argc
; i
++){
1339 if (pa_streq(argv
[i
], "modules") || pa_streq(argv
[i
], "clients") ||
1340 pa_streq(argv
[i
], "sinks") || pa_streq(argv
[i
], "sink-inputs") ||
1341 pa_streq(argv
[i
], "sources") || pa_streq(argv
[i
], "source-outputs") ||
1342 pa_streq(argv
[i
], "samples") || pa_streq(argv
[i
], "cards")) {
1343 list_type
= pa_xstrdup(argv
[i
]);
1344 } else if (pa_streq(argv
[i
], "short")) {
1345 short_list_format
= TRUE
;
1347 pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
1352 } else if (pa_streq(argv
[optind
], "upload-sample")) {
1354 action
= UPLOAD_SAMPLE
;
1356 if (optind
+1 >= argc
) {
1357 pa_log(_("Please specify a sample file to load"));
1361 if (optind
+2 < argc
)
1362 sample_name
= pa_xstrdup(argv
[optind
+2]);
1364 char *f
= pa_path_get_filename(argv
[optind
+1]);
1365 sample_name
= pa_xstrndup(f
, strcspn(f
, "."));
1369 if (!(sndfile
= sf_open(argv
[optind
+1], SFM_READ
, &sfi
))) {
1370 pa_log(_("Failed to open sound file."));
1374 if (pa_sndfile_read_sample_spec(sndfile
, &sample_spec
) < 0) {
1375 pa_log(_("Failed to determine sample specification from file."));
1378 sample_spec
.format
= PA_SAMPLE_FLOAT32
;
1380 if (pa_sndfile_read_channel_map(sndfile
, &channel_map
) < 0) {
1381 if (sample_spec
.channels
> 2)
1382 pa_log(_("Warning: Failed to determine sample specification from file."));
1383 pa_channel_map_init_extend(&channel_map
, sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
1386 pa_assert(pa_channel_map_compatible(&channel_map
, &sample_spec
));
1387 sample_length
= (size_t) sfi
.frames
*pa_frame_size(&sample_spec
);
1389 } else if (pa_streq(argv
[optind
], "play-sample")) {
1390 action
= PLAY_SAMPLE
;
1391 if (argc
!= optind
+2 && argc
!= optind
+3) {
1392 pa_log(_("You have to specify a sample name to play"));
1396 sample_name
= pa_xstrdup(argv
[optind
+1]);
1398 if (optind
+2 < argc
)
1399 sink_name
= pa_xstrdup(argv
[optind
+2]);
1401 } else if (pa_streq(argv
[optind
], "remove-sample")) {
1402 action
= REMOVE_SAMPLE
;
1403 if (argc
!= optind
+2) {
1404 pa_log(_("You have to specify a sample name to remove"));
1408 sample_name
= pa_xstrdup(argv
[optind
+1]);
1410 } else if (pa_streq(argv
[optind
], "move-sink-input")) {
1411 action
= MOVE_SINK_INPUT
;
1412 if (argc
!= optind
+3) {
1413 pa_log(_("You have to specify a sink input index and a sink"));
1417 sink_input_idx
= (uint32_t) atoi(argv
[optind
+1]);
1418 sink_name
= pa_xstrdup(argv
[optind
+2]);
1420 } else if (pa_streq(argv
[optind
], "move-source-output")) {
1421 action
= MOVE_SOURCE_OUTPUT
;
1422 if (argc
!= optind
+3) {
1423 pa_log(_("You have to specify a source output index and a source"));
1427 source_output_idx
= (uint32_t) atoi(argv
[optind
+1]);
1428 source_name
= pa_xstrdup(argv
[optind
+2]);
1430 } else if (pa_streq(argv
[optind
], "load-module")) {
1435 action
= LOAD_MODULE
;
1437 if (argc
<= optind
+1) {
1438 pa_log(_("You have to specify a module name and arguments."));
1442 module_name
= argv
[optind
+1];
1444 for (i
= optind
+2; i
< argc
; i
++)
1445 n
+= strlen(argv
[i
])+1;
1448 p
= module_args
= pa_xmalloc(n
);
1450 for (i
= optind
+2; i
< argc
; i
++)
1451 p
+= sprintf(p
, "%s%s", p
== module_args
? "" : " ", argv
[i
]);
1454 } else if (pa_streq(argv
[optind
], "unload-module")) {
1455 action
= UNLOAD_MODULE
;
1457 if (argc
!= optind
+2) {
1458 pa_log(_("You have to specify a module index"));
1462 module_index
= (uint32_t) atoi(argv
[optind
+1]);
1464 } else if (pa_streq(argv
[optind
], "suspend-sink")) {
1465 action
= SUSPEND_SINK
;
1467 if (argc
> optind
+3 || optind
+1 >= argc
) {
1468 pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
1472 suspend
= pa_parse_boolean(argv
[argc
-1]);
1474 if (argc
> optind
+2)
1475 sink_name
= pa_xstrdup(argv
[optind
+1]);
1477 } else if (pa_streq(argv
[optind
], "suspend-source")) {
1478 action
= SUSPEND_SOURCE
;
1480 if (argc
> optind
+3 || optind
+1 >= argc
) {
1481 pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
1485 suspend
= pa_parse_boolean(argv
[argc
-1]);
1487 if (argc
> optind
+2)
1488 source_name
= pa_xstrdup(argv
[optind
+1]);
1489 } else if (pa_streq(argv
[optind
], "set-card-profile")) {
1490 action
= SET_CARD_PROFILE
;
1492 if (argc
!= optind
+3) {
1493 pa_log(_("You have to specify a card name/index and a profile name"));
1497 card_name
= pa_xstrdup(argv
[optind
+1]);
1498 profile_name
= pa_xstrdup(argv
[optind
+2]);
1500 } else if (pa_streq(argv
[optind
], "set-sink-port")) {
1501 action
= SET_SINK_PORT
;
1503 if (argc
!= optind
+3) {
1504 pa_log(_("You have to specify a sink name/index and a port name"));
1508 sink_name
= pa_xstrdup(argv
[optind
+1]);
1509 port_name
= pa_xstrdup(argv
[optind
+2]);
1511 } else if (pa_streq(argv
[optind
], "set-source-port")) {
1512 action
= SET_SOURCE_PORT
;
1514 if (argc
!= optind
+3) {
1515 pa_log(_("You have to specify a source name/index and a port name"));
1519 source_name
= pa_xstrdup(argv
[optind
+1]);
1520 port_name
= pa_xstrdup(argv
[optind
+2]);
1522 } else if (pa_streq(argv
[optind
], "set-sink-volume")) {
1523 action
= SET_SINK_VOLUME
;
1525 if (argc
!= optind
+3) {
1526 pa_log(_("You have to specify a sink name/index and a volume"));
1530 sink_name
= pa_xstrdup(argv
[optind
+1]);
1532 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1535 } else if (pa_streq(argv
[optind
], "set-source-volume")) {
1536 action
= SET_SOURCE_VOLUME
;
1538 if (argc
!= optind
+3) {
1539 pa_log(_("You have to specify a source name/index and a volume"));
1543 source_name
= pa_xstrdup(argv
[optind
+1]);
1545 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1548 } else if (pa_streq(argv
[optind
], "set-sink-input-volume")) {
1549 action
= SET_SINK_INPUT_VOLUME
;
1551 if (argc
!= optind
+3) {
1552 pa_log(_("You have to specify a sink input index and a volume"));
1556 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1557 pa_log(_("Invalid sink input index"));
1561 if (parse_volume(argv
[optind
+2], &volume
, &volume_flags
) < 0)
1564 } else if (pa_streq(argv
[optind
], "set-sink-mute")) {
1566 action
= SET_SINK_MUTE
;
1568 if (argc
!= optind
+3) {
1569 pa_log(_("You have to specify a sink name/index and a mute boolean"));
1573 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1574 pa_log(_("Invalid mute specification"));
1578 sink_name
= pa_xstrdup(argv
[optind
+1]);
1581 } else if (pa_streq(argv
[optind
], "set-source-mute")) {
1583 action
= SET_SOURCE_MUTE
;
1585 if (argc
!= optind
+3) {
1586 pa_log(_("You have to specify a source name/index and a mute boolean"));
1590 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1591 pa_log(_("Invalid mute specification"));
1595 source_name
= pa_xstrdup(argv
[optind
+1]);
1598 } else if (pa_streq(argv
[optind
], "set-sink-input-mute")) {
1600 action
= SET_SINK_INPUT_MUTE
;
1602 if (argc
!= optind
+3) {
1603 pa_log(_("You have to specify a sink input index and a mute boolean"));
1607 if (pa_atou(argv
[optind
+1], &sink_input_idx
) < 0) {
1608 pa_log(_("Invalid sink input index specification"));
1612 if ((b
= pa_parse_boolean(argv
[optind
+2])) < 0) {
1613 pa_log(_("Invalid mute specification"));
1619 } else if (pa_streq(argv
[optind
], "subscribe"))
1623 else if (pa_streq(argv
[optind
], "help")) {
1630 if (action
== NONE
) {
1631 pa_log(_("No valid command specified."));
1635 if (!(m
= pa_mainloop_new())) {
1636 pa_log(_("pa_mainloop_new() failed."));
1640 mainloop_api
= pa_mainloop_get_api(m
);
1642 pa_assert_se(pa_signal_init(mainloop_api
) == 0);
1643 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
1644 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
1645 pa_disable_sigpipe();
1647 if (!(context
= pa_context_new_with_proplist(mainloop_api
, NULL
, proplist
))) {
1648 pa_log(_("pa_context_new() failed."));
1652 pa_context_set_state_callback(context
, context_state_callback
, NULL
);
1653 if (pa_context_connect(context
, server
, 0, NULL
) < 0) {
1654 pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context
)));
1658 if (pa_mainloop_run(m
, &ret
) < 0) {
1659 pa_log(_("pa_mainloop_run() failed."));
1665 pa_stream_unref(sample_stream
);
1668 pa_context_unref(context
);
1672 pa_mainloop_free(m
);
1676 pa_xfree(list_type
);
1677 pa_xfree(sample_name
);
1678 pa_xfree(sink_name
);
1679 pa_xfree(source_name
);
1680 pa_xfree(module_args
);
1681 pa_xfree(card_name
);
1682 pa_xfree(profile_name
);
1683 pa_xfree(port_name
);
1689 pa_proplist_free(proplist
);