2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulse/context.h>
30 #include <pulse/gccmacro.h>
31 #include <pulse/xmalloc.h>
32 #include <pulse/fork-detect.h>
34 #include <pulsecore/macro.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/pstream-util.h>
39 #include "introspect.h"
43 static void context_stat_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
44 pa_operation
*o
= userdata
;
45 pa_stat_info i
, *p
= &i
;
49 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
56 if (command
!= PA_COMMAND_REPLY
) {
57 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
61 } else if (pa_tagstruct_getu32(t
, &i
.memblock_total
) < 0 ||
62 pa_tagstruct_getu32(t
, &i
.memblock_total_size
) < 0 ||
63 pa_tagstruct_getu32(t
, &i
.memblock_allocated
) < 0 ||
64 pa_tagstruct_getu32(t
, &i
.memblock_allocated_size
) < 0 ||
65 pa_tagstruct_getu32(t
, &i
.scache_size
) < 0 ||
66 !pa_tagstruct_eof(t
)) {
67 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
72 pa_stat_info_cb_t cb
= (pa_stat_info_cb_t
) o
->callback
;
73 cb(o
->context
, p
, o
->userdata
);
78 pa_operation_unref(o
);
81 pa_operation
* pa_context_stat(pa_context
*c
, pa_stat_info_cb_t cb
, void *userdata
) {
82 return pa_context_send_simple_command(c
, PA_COMMAND_STAT
, context_stat_callback
, (pa_operation_cb_t
) cb
, userdata
);
87 static void context_get_server_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
88 pa_operation
*o
= userdata
;
89 pa_server_info i
, *p
= &i
;
93 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
100 if (command
!= PA_COMMAND_REPLY
) {
101 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
105 } else if (pa_tagstruct_gets(t
, &i
.server_name
) < 0 ||
106 pa_tagstruct_gets(t
, &i
.server_version
) < 0 ||
107 pa_tagstruct_gets(t
, &i
.user_name
) < 0 ||
108 pa_tagstruct_gets(t
, &i
.host_name
) < 0 ||
109 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
110 pa_tagstruct_gets(t
, &i
.default_sink_name
) < 0 ||
111 pa_tagstruct_gets(t
, &i
.default_source_name
) < 0 ||
112 pa_tagstruct_getu32(t
, &i
.cookie
) < 0 ||
113 (o
->context
->version
>= 15 &&
114 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0) ||
115 !pa_tagstruct_eof(t
)) {
117 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
121 if (p
&& o
->context
->version
< 15)
122 pa_channel_map_init_extend(&i
.channel_map
, i
.sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
125 pa_server_info_cb_t cb
= (pa_server_info_cb_t
) o
->callback
;
126 cb(o
->context
, p
, o
->userdata
);
130 pa_operation_done(o
);
131 pa_operation_unref(o
);
134 pa_operation
* pa_context_get_server_info(pa_context
*c
, pa_server_info_cb_t cb
, void *userdata
) {
135 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
140 static void context_get_sink_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
141 pa_operation
*o
= userdata
;
148 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
150 /* For safety incase someone use fail: outside the while loop below */
156 if (command
!= PA_COMMAND_REPLY
) {
157 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
163 while (!pa_tagstruct_eof(t
)) {
167 const char *ap
= NULL
;
170 i
.proplist
= pa_proplist_new();
171 i
.base_volume
= PA_VOLUME_NORM
;
172 i
.n_volume_steps
= PA_VOLUME_NORM
+1;
174 state
= PA_SINK_INVALID_STATE
;
175 i
.card
= PA_INVALID_INDEX
;
177 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
178 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
179 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
180 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
181 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
182 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
183 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
184 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
185 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
186 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
187 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
188 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
189 pa_tagstruct_getu32(t
, &flags
) < 0 ||
190 (o
->context
->version
>= 13 &&
191 (pa_tagstruct_get_proplist(t
, i
.proplist
) < 0 ||
192 pa_tagstruct_get_usec(t
, &i
.configured_latency
) < 0)) ||
193 (o
->context
->version
>= 15 &&
194 (pa_tagstruct_get_volume(t
, &i
.base_volume
) < 0 ||
195 pa_tagstruct_getu32(t
, &state
) < 0 ||
196 pa_tagstruct_getu32(t
, &i
.n_volume_steps
) < 0 ||
197 pa_tagstruct_getu32(t
, &i
.card
) < 0)) ||
198 (o
->context
->version
>= 16 &&
199 (pa_tagstruct_getu32(t
, &i
.n_ports
)))) {
204 if (o
->context
->version
>= 16) {
206 i
.ports
= pa_xnew(pa_sink_port_info
*, i
.n_ports
+1);
207 i
.ports
[0] = pa_xnew(pa_sink_port_info
, i
.n_ports
);
209 for (j
= 0; j
< i
.n_ports
; j
++) {
210 if (pa_tagstruct_gets(t
, &i
.ports
[0][j
].name
) < 0 ||
211 pa_tagstruct_gets(t
, &i
.ports
[0][j
].description
) < 0 ||
212 pa_tagstruct_getu32(t
, &i
.ports
[0][j
].priority
) < 0) {
217 i
.ports
[j
] = &i
.ports
[0][j
];
223 if (pa_tagstruct_gets(t
, &ap
) < 0)
227 for (j
= 0; j
< i
.n_ports
; j
++)
228 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
229 i
.active_port
= i
.ports
[j
];
235 if (o
->context
->version
>= 21) {
237 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
240 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
242 for (j
= 0; j
< n_formats
; j
++) {
244 i
.formats
[j
] = pa_format_info_new();
246 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
252 i
.flags
= (pa_sink_flags_t
) flags
;
253 i
.state
= (pa_sink_state_t
) state
;
256 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
257 cb(o
->context
, &i
, 0, o
->userdata
);
261 for (j
= 0; j
< i
.n_formats
; j
++)
262 pa_format_info_free(i
.formats
[j
]);
266 pa_xfree(i
.ports
[0]);
269 pa_proplist_free(i
.proplist
);
274 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
275 cb(o
->context
, NULL
, eol
, o
->userdata
);
279 pa_operation_done(o
);
280 pa_operation_unref(o
);
284 pa_assert(i
.proplist
);
286 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
289 for (j
= 0; j
< i
.n_formats
; j
++)
290 pa_format_info_free(i
.formats
[j
]);
294 pa_xfree(i
.ports
[0]);
297 pa_proplist_free(i
.proplist
);
302 pa_operation
* pa_context_get_sink_info_list(pa_context
*c
, pa_sink_info_cb_t cb
, void *userdata
) {
303 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
306 pa_operation
* pa_context_get_sink_info_by_index(pa_context
*c
, uint32_t idx
, pa_sink_info_cb_t cb
, void *userdata
) {
312 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
315 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
316 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
318 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
320 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
321 pa_tagstruct_putu32(t
, idx
);
322 pa_tagstruct_puts(t
, NULL
);
323 pa_pstream_send_tagstruct(c
->pstream
, t
);
324 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
329 pa_operation
* pa_context_get_sink_info_by_name(pa_context
*c
, const char *name
, pa_sink_info_cb_t cb
, void *userdata
) {
335 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
338 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
339 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
340 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
342 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
344 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
345 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
346 pa_tagstruct_puts(t
, name
);
347 pa_pstream_send_tagstruct(c
->pstream
, t
);
348 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
353 pa_operation
* pa_context_set_sink_port_by_index(pa_context
*c
, uint32_t idx
, const char*port
, pa_context_success_cb_t cb
, void *userdata
) {
359 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
361 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
362 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
363 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
364 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
366 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
368 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
369 pa_tagstruct_putu32(t
, idx
);
370 pa_tagstruct_puts(t
, NULL
);
371 pa_tagstruct_puts(t
, port
);
372 pa_pstream_send_tagstruct(c
->pstream
, t
);
373 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
378 pa_operation
* pa_context_set_sink_port_by_name(pa_context
*c
, const char *name
, const char*port
, pa_context_success_cb_t cb
, void *userdata
) {
384 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
386 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
387 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
388 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
389 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
391 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
393 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
394 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
395 pa_tagstruct_puts(t
, name
);
396 pa_tagstruct_puts(t
, port
);
397 pa_pstream_send_tagstruct(c
->pstream
, t
);
398 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
403 /*** Source info ***/
405 static void context_get_source_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
406 pa_operation
*o
= userdata
;
413 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
415 /* For safety incase someone use fail: outside the while loop below */
421 if (command
!= PA_COMMAND_REPLY
) {
422 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
428 while (!pa_tagstruct_eof(t
)) {
435 i
.proplist
= pa_proplist_new();
436 i
.base_volume
= PA_VOLUME_NORM
;
437 i
.n_volume_steps
= PA_VOLUME_NORM
+1;
439 state
= PA_SOURCE_INVALID_STATE
;
440 i
.card
= PA_INVALID_INDEX
;
442 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
443 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
444 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
445 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
446 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
447 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
448 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
449 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
450 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
451 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0 ||
452 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
453 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
454 pa_tagstruct_getu32(t
, &flags
) < 0 ||
455 (o
->context
->version
>= 13 &&
456 (pa_tagstruct_get_proplist(t
, i
.proplist
) < 0 ||
457 pa_tagstruct_get_usec(t
, &i
.configured_latency
) < 0)) ||
458 (o
->context
->version
>= 15 &&
459 (pa_tagstruct_get_volume(t
, &i
.base_volume
) < 0 ||
460 pa_tagstruct_getu32(t
, &state
) < 0 ||
461 pa_tagstruct_getu32(t
, &i
.n_volume_steps
) < 0 ||
462 pa_tagstruct_getu32(t
, &i
.card
) < 0)) ||
463 (o
->context
->version
>= 16 &&
464 (pa_tagstruct_getu32(t
, &i
.n_ports
)))) {
469 if (o
->context
->version
>= 16) {
471 i
.ports
= pa_xnew(pa_source_port_info
*, i
.n_ports
+1);
472 i
.ports
[0] = pa_xnew(pa_source_port_info
, i
.n_ports
);
474 for (j
= 0; j
< i
.n_ports
; j
++) {
475 if (pa_tagstruct_gets(t
, &i
.ports
[0][j
].name
) < 0 ||
476 pa_tagstruct_gets(t
, &i
.ports
[0][j
].description
) < 0 ||
477 pa_tagstruct_getu32(t
, &i
.ports
[0][j
].priority
) < 0) {
482 i
.ports
[j
] = &i
.ports
[0][j
];
488 if (pa_tagstruct_gets(t
, &ap
) < 0)
492 for (j
= 0; j
< i
.n_ports
; j
++)
493 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
494 i
.active_port
= i
.ports
[j
];
500 if (o
->context
->version
>= 22) {
502 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
505 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
507 for (j
= 0; j
< n_formats
; j
++) {
509 i
.formats
[j
] = pa_format_info_new();
511 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
517 i
.flags
= (pa_source_flags_t
) flags
;
518 i
.state
= (pa_source_state_t
) state
;
521 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
522 cb(o
->context
, &i
, 0, o
->userdata
);
526 for (j
= 0; j
< i
.n_formats
; j
++)
527 pa_format_info_free(i
.formats
[j
]);
531 pa_xfree(i
.ports
[0]);
534 pa_proplist_free(i
.proplist
);
539 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
540 cb(o
->context
, NULL
, eol
, o
->userdata
);
544 pa_operation_done(o
);
545 pa_operation_unref(o
);
549 pa_assert(i
.proplist
);
551 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
554 for (j
= 0; j
< i
.n_formats
; j
++)
555 pa_format_info_free(i
.formats
[j
]);
559 pa_xfree(i
.ports
[0]);
562 pa_proplist_free(i
.proplist
);
567 pa_operation
* pa_context_get_source_info_list(pa_context
*c
, pa_source_info_cb_t cb
, void *userdata
) {
568 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
571 pa_operation
* pa_context_get_source_info_by_index(pa_context
*c
, uint32_t idx
, pa_source_info_cb_t cb
, void *userdata
) {
577 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
580 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
581 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
583 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
585 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
586 pa_tagstruct_putu32(t
, idx
);
587 pa_tagstruct_puts(t
, NULL
);
588 pa_pstream_send_tagstruct(c
->pstream
, t
);
589 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
594 pa_operation
* pa_context_get_source_info_by_name(pa_context
*c
, const char *name
, pa_source_info_cb_t cb
, void *userdata
) {
600 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
603 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
604 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
605 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
607 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
609 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
610 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
611 pa_tagstruct_puts(t
, name
);
612 pa_pstream_send_tagstruct(c
->pstream
, t
);
613 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
618 pa_operation
* pa_context_set_source_port_by_index(pa_context
*c
, uint32_t idx
, const char*port
, pa_context_success_cb_t cb
, void *userdata
) {
624 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
626 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
627 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
628 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
629 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
631 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
633 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
634 pa_tagstruct_putu32(t
, idx
);
635 pa_tagstruct_puts(t
, NULL
);
636 pa_tagstruct_puts(t
, port
);
637 pa_pstream_send_tagstruct(c
->pstream
, t
);
638 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
643 pa_operation
* pa_context_set_source_port_by_name(pa_context
*c
, const char *name
, const char*port
, pa_context_success_cb_t cb
, void *userdata
) {
649 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
651 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
652 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
653 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
654 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
656 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
658 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
659 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
660 pa_tagstruct_puts(t
, name
);
661 pa_tagstruct_puts(t
, port
);
662 pa_pstream_send_tagstruct(c
->pstream
, t
);
663 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
668 /*** Client info ***/
670 static void context_get_client_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
671 pa_operation
*o
= userdata
;
676 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
681 if (command
!= PA_COMMAND_REPLY
) {
682 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
688 while (!pa_tagstruct_eof(t
)) {
692 i
.proplist
= pa_proplist_new();
694 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
695 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
696 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
697 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
698 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
700 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
701 pa_proplist_free(i
.proplist
);
706 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
707 cb(o
->context
, &i
, 0, o
->userdata
);
710 pa_proplist_free(i
.proplist
);
715 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
716 cb(o
->context
, NULL
, eol
, o
->userdata
);
720 pa_operation_done(o
);
721 pa_operation_unref(o
);
724 pa_operation
* pa_context_get_client_info(pa_context
*c
, uint32_t idx
, pa_client_info_cb_t cb
, void *userdata
) {
730 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
733 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
734 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
735 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
737 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
739 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CLIENT_INFO
, &tag
);
740 pa_tagstruct_putu32(t
, idx
);
741 pa_pstream_send_tagstruct(c
->pstream
, t
);
742 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_client_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
747 pa_operation
* pa_context_get_client_info_list(pa_context
*c
, pa_client_info_cb_t cb
, void *userdata
) {
748 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
753 static void context_get_card_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
754 pa_operation
*o
= userdata
;
759 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
764 if (command
!= PA_COMMAND_REPLY
) {
765 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
771 while (!pa_tagstruct_eof(t
)) {
778 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
779 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
780 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
781 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
782 pa_tagstruct_getu32(t
, &i
.n_profiles
) < 0) {
784 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
788 if (i
.n_profiles
> 0) {
789 i
.profiles
= pa_xnew0(pa_card_profile_info
, i
.n_profiles
+1);
791 for (j
= 0; j
< i
.n_profiles
; j
++) {
793 if (pa_tagstruct_gets(t
, &i
.profiles
[j
].name
) < 0 ||
794 pa_tagstruct_gets(t
, &i
.profiles
[j
].description
) < 0 ||
795 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sinks
) < 0 ||
796 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sources
) < 0 ||
797 pa_tagstruct_getu32(t
, &i
.profiles
[j
].priority
) < 0) {
799 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
800 pa_xfree(i
.profiles
);
805 /* Terminate with an extra NULL entry, just to make sure */
806 i
.profiles
[j
].name
= NULL
;
807 i
.profiles
[j
].description
= NULL
;
810 i
.proplist
= pa_proplist_new();
812 if (pa_tagstruct_gets(t
, &ap
) < 0 ||
813 pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) {
815 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
816 pa_xfree(i
.profiles
);
817 pa_proplist_free(i
.proplist
);
822 for (j
= 0; j
< i
.n_profiles
; j
++)
823 if (pa_streq(i
.profiles
[j
].name
, ap
)) {
824 i
.active_profile
= &i
.profiles
[j
];
830 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
831 cb(o
->context
, &i
, 0, o
->userdata
);
834 pa_proplist_free(i
.proplist
);
835 pa_xfree(i
.profiles
);
840 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
841 cb(o
->context
, NULL
, eol
, o
->userdata
);
845 pa_operation_done(o
);
846 pa_operation_unref(o
);
849 pa_operation
* pa_context_get_card_info_by_index(pa_context
*c
, uint32_t idx
, pa_card_info_cb_t cb
, void *userdata
) {
855 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
858 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
859 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
860 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
861 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
863 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
865 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
866 pa_tagstruct_putu32(t
, idx
);
867 pa_tagstruct_puts(t
, NULL
);
868 pa_pstream_send_tagstruct(c
->pstream
, t
);
869 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_card_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
874 pa_operation
* pa_context_get_card_info_by_name(pa_context
*c
, const char*name
, pa_card_info_cb_t cb
, void *userdata
) {
880 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
883 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
884 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
885 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
886 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
888 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
890 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
891 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
892 pa_tagstruct_puts(t
, name
);
893 pa_pstream_send_tagstruct(c
->pstream
, t
);
894 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_card_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
899 pa_operation
* pa_context_get_card_info_list(pa_context
*c
, pa_card_info_cb_t cb
, void *userdata
) {
900 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
902 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CARD_INFO_LIST
, context_get_card_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
905 pa_operation
* pa_context_set_card_profile_by_index(pa_context
*c
, uint32_t idx
, const char*profile
, pa_context_success_cb_t cb
, void *userdata
) {
911 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
913 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
914 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
915 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
916 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
918 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
920 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
921 pa_tagstruct_putu32(t
, idx
);
922 pa_tagstruct_puts(t
, NULL
);
923 pa_tagstruct_puts(t
, profile
);
924 pa_pstream_send_tagstruct(c
->pstream
, t
);
925 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
930 pa_operation
* pa_context_set_card_profile_by_name(pa_context
*c
, const char *name
, const char*profile
, pa_context_success_cb_t cb
, void *userdata
) {
936 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
938 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
939 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
940 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
941 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
943 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
945 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
946 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
947 pa_tagstruct_puts(t
, name
);
948 pa_tagstruct_puts(t
, profile
);
949 pa_pstream_send_tagstruct(c
->pstream
, t
);
950 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
955 /*** Module info ***/
957 static void context_get_module_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
958 pa_operation
*o
= userdata
;
963 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
968 if (command
!= PA_COMMAND_REPLY
) {
969 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
975 while (!pa_tagstruct_eof(t
)) {
977 pa_bool_t auto_unload
= FALSE
;
980 i
.proplist
= pa_proplist_new();
982 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
983 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
984 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
985 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
986 (o
->context
->version
< 15 && pa_tagstruct_get_boolean(t
, &auto_unload
) < 0) ||
987 (o
->context
->version
>= 15 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
988 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
992 i
.auto_unload
= (int) auto_unload
;
995 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
996 cb(o
->context
, &i
, 0, o
->userdata
);
999 pa_proplist_free(i
.proplist
);
1004 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
1005 cb(o
->context
, NULL
, eol
, o
->userdata
);
1009 pa_operation_done(o
);
1010 pa_operation_unref(o
);
1013 pa_operation
* pa_context_get_module_info(pa_context
*c
, uint32_t idx
, pa_module_info_cb_t cb
, void *userdata
) {
1019 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1022 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1023 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1024 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1026 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1028 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_MODULE_INFO
, &tag
);
1029 pa_tagstruct_putu32(t
, idx
);
1030 pa_pstream_send_tagstruct(c
->pstream
, t
);
1031 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_module_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1036 pa_operation
* pa_context_get_module_info_list(pa_context
*c
, pa_module_info_cb_t cb
, void *userdata
) {
1037 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1040 /*** Sink input info ***/
1042 static void context_get_sink_input_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1043 pa_operation
*o
= userdata
;
1048 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1053 if (command
!= PA_COMMAND_REPLY
) {
1054 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1060 while (!pa_tagstruct_eof(t
)) {
1061 pa_sink_input_info i
;
1062 pa_bool_t mute
= FALSE
, corked
= FALSE
, has_volume
= FALSE
, volume_writable
= TRUE
;
1065 i
.proplist
= pa_proplist_new();
1066 i
.format
= pa_format_info_new();
1068 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1069 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1070 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1071 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1072 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
1073 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1074 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1075 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1076 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1077 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0 ||
1078 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1079 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1080 (o
->context
->version
>= 11 && pa_tagstruct_get_boolean(t
, &mute
) < 0) ||
1081 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1082 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1083 (o
->context
->version
>= 20 && (pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1084 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0)) ||
1085 (o
->context
->version
>= 21 && pa_tagstruct_get_format_info(t
, i
.format
) < 0)) {
1087 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1088 pa_proplist_free(i
.proplist
);
1089 pa_format_info_free(i
.format
);
1093 i
.mute
= (int) mute
;
1094 i
.corked
= (int) corked
;
1095 i
.has_volume
= (int) has_volume
;
1096 i
.volume_writable
= (int) volume_writable
;
1099 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1100 cb(o
->context
, &i
, 0, o
->userdata
);
1103 pa_proplist_free(i
.proplist
);
1104 pa_format_info_free(i
.format
);
1109 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1110 cb(o
->context
, NULL
, eol
, o
->userdata
);
1114 pa_operation_done(o
);
1115 pa_operation_unref(o
);
1118 pa_operation
* pa_context_get_sink_input_info(pa_context
*c
, uint32_t idx
, pa_sink_input_info_cb_t cb
, void *userdata
) {
1124 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1127 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1128 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1129 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1131 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1133 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO
, &tag
);
1134 pa_tagstruct_putu32(t
, idx
);
1135 pa_pstream_send_tagstruct(c
->pstream
, t
);
1136 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_input_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1141 pa_operation
* pa_context_get_sink_input_info_list(pa_context
*c
, void (*cb
)(pa_context
*c
, const pa_sink_input_info
*i
, int is_last
, void *userdata
), void *userdata
) {
1142 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO_LIST
, context_get_sink_input_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1145 /*** Source output info ***/
1147 static void context_get_source_output_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1148 pa_operation
*o
= userdata
;
1153 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1158 if (command
!= PA_COMMAND_REPLY
) {
1159 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1165 while (!pa_tagstruct_eof(t
)) {
1166 pa_source_output_info i
;
1167 pa_bool_t mute
= FALSE
, corked
= FALSE
, has_volume
= FALSE
, volume_writable
= TRUE
;
1170 i
.proplist
= pa_proplist_new();
1172 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1173 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1174 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1175 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1176 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
1177 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1178 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1179 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1180 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0 ||
1181 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1182 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1183 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1184 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1185 (o
->context
->version
>= 22 && (pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1186 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
1187 pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1188 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0))) {
1190 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1191 pa_proplist_free(i
.proplist
);
1195 i
.mute
= (int) mute
;
1196 i
.corked
= (int) corked
;
1197 i
.has_volume
= (int) has_volume
;
1198 i
.volume_writable
= (int) volume_writable
;
1201 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1202 cb(o
->context
, &i
, 0, o
->userdata
);
1205 pa_proplist_free(i
.proplist
);
1210 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1211 cb(o
->context
, NULL
, eol
, o
->userdata
);
1215 pa_operation_done(o
);
1216 pa_operation_unref(o
);
1219 pa_operation
* pa_context_get_source_output_info(pa_context
*c
, uint32_t idx
, pa_source_output_info_cb_t cb
, void *userdata
) {
1225 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1228 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1229 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1230 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1232 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1234 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
, &tag
);
1235 pa_tagstruct_putu32(t
, idx
);
1236 pa_pstream_send_tagstruct(c
->pstream
, t
);
1237 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_output_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1242 pa_operation
* pa_context_get_source_output_info_list(pa_context
*c
, pa_source_output_info_cb_t cb
, void *userdata
) {
1243 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
, context_get_source_output_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1246 /*** Volume manipulation ***/
1248 pa_operation
* pa_context_set_sink_volume_by_index(pa_context
*c
, uint32_t idx
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1254 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1257 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1258 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1259 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1261 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1263 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1264 pa_tagstruct_putu32(t
, idx
);
1265 pa_tagstruct_puts(t
, NULL
);
1266 pa_tagstruct_put_cvolume(t
, volume
);
1267 pa_pstream_send_tagstruct(c
->pstream
, t
);
1268 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1273 pa_operation
* pa_context_set_sink_volume_by_name(pa_context
*c
, const char *name
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1279 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1283 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1284 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1285 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1286 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1288 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1290 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1291 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1292 pa_tagstruct_puts(t
, name
);
1293 pa_tagstruct_put_cvolume(t
, volume
);
1294 pa_pstream_send_tagstruct(c
->pstream
, t
);
1295 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1300 pa_operation
* pa_context_set_sink_mute_by_index(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1306 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1308 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1309 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1311 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1313 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1314 pa_tagstruct_putu32(t
, idx
);
1315 pa_tagstruct_puts(t
, NULL
);
1316 pa_tagstruct_put_boolean(t
, mute
);
1317 pa_pstream_send_tagstruct(c
->pstream
, t
);
1318 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1323 pa_operation
* pa_context_set_sink_mute_by_name(pa_context
*c
, const char *name
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1329 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1332 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1333 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1334 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1336 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1338 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1339 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1340 pa_tagstruct_puts(t
, name
);
1341 pa_tagstruct_put_boolean(t
, mute
);
1342 pa_pstream_send_tagstruct(c
->pstream
, t
);
1343 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1348 pa_operation
* pa_context_set_sink_input_volume(pa_context
*c
, uint32_t idx
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1354 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1357 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1358 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1359 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1360 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1362 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1364 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_VOLUME
, &tag
);
1365 pa_tagstruct_putu32(t
, idx
);
1366 pa_tagstruct_put_cvolume(t
, volume
);
1367 pa_pstream_send_tagstruct(c
->pstream
, t
);
1368 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1373 pa_operation
* pa_context_set_sink_input_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1379 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1381 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1382 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1383 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1384 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1386 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1388 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_MUTE
, &tag
);
1389 pa_tagstruct_putu32(t
, idx
);
1390 pa_tagstruct_put_boolean(t
, mute
);
1391 pa_pstream_send_tagstruct(c
->pstream
, t
);
1392 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1397 pa_operation
* pa_context_set_source_volume_by_index(pa_context
*c
, uint32_t idx
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1403 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1406 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1407 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1408 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1410 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1412 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1413 pa_tagstruct_putu32(t
, idx
);
1414 pa_tagstruct_puts(t
, NULL
);
1415 pa_tagstruct_put_cvolume(t
, volume
);
1416 pa_pstream_send_tagstruct(c
->pstream
, t
);
1417 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1422 pa_operation
* pa_context_set_source_volume_by_name(pa_context
*c
, const char *name
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1428 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1432 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1433 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1434 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1435 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1437 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1439 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1440 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1441 pa_tagstruct_puts(t
, name
);
1442 pa_tagstruct_put_cvolume(t
, volume
);
1443 pa_pstream_send_tagstruct(c
->pstream
, t
);
1444 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1449 pa_operation
* pa_context_set_source_mute_by_index(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1455 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1457 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1458 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1460 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1462 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1463 pa_tagstruct_putu32(t
, idx
);
1464 pa_tagstruct_puts(t
, NULL
);
1465 pa_tagstruct_put_boolean(t
, mute
);
1466 pa_pstream_send_tagstruct(c
->pstream
, t
);
1467 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1472 pa_operation
* pa_context_set_source_mute_by_name(pa_context
*c
, const char *name
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1478 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1481 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1482 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1483 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1485 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1487 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1488 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1489 pa_tagstruct_puts(t
, name
);
1490 pa_tagstruct_put_boolean(t
, mute
);
1491 pa_pstream_send_tagstruct(c
->pstream
, t
);
1492 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1497 pa_operation
* pa_context_set_source_output_volume(pa_context
*c
, uint32_t idx
, const pa_cvolume
*volume
, pa_context_success_cb_t cb
, void *userdata
) {
1503 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1506 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1507 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1508 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1509 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1510 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1512 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1514 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME
, &tag
);
1515 pa_tagstruct_putu32(t
, idx
);
1516 pa_tagstruct_put_cvolume(t
, volume
);
1517 pa_pstream_send_tagstruct(c
->pstream
, t
);
1518 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1523 pa_operation
* pa_context_set_source_output_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1529 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1531 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1532 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1533 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1534 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1536 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1538 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE
, &tag
);
1539 pa_tagstruct_putu32(t
, idx
);
1540 pa_tagstruct_put_boolean(t
, mute
);
1541 pa_pstream_send_tagstruct(c
->pstream
, t
);
1542 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1547 /** Sample Cache **/
1549 static void context_get_sample_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1550 pa_operation
*o
= userdata
;
1555 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1560 if (command
!= PA_COMMAND_REPLY
) {
1561 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1567 while (!pa_tagstruct_eof(t
)) {
1569 pa_bool_t lazy
= FALSE
;
1572 i
.proplist
= pa_proplist_new();
1574 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1575 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1576 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1577 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
1578 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1579 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1580 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
1581 pa_tagstruct_get_boolean(t
, &lazy
) < 0 ||
1582 pa_tagstruct_gets(t
, &i
.filename
) < 0 ||
1583 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
1585 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1589 i
.lazy
= (int) lazy
;
1592 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1593 cb(o
->context
, &i
, 0, o
->userdata
);
1596 pa_proplist_free(i
.proplist
);
1601 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1602 cb(o
->context
, NULL
, eol
, o
->userdata
);
1606 pa_operation_done(o
);
1607 pa_operation_unref(o
);
1610 pa_operation
* pa_context_get_sample_info_by_name(pa_context
*c
, const char *name
, pa_sample_info_cb_t cb
, void *userdata
) {
1616 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1619 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1620 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1621 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1623 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1625 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1626 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1627 pa_tagstruct_puts(t
, name
);
1628 pa_pstream_send_tagstruct(c
->pstream
, t
);
1629 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1634 pa_operation
* pa_context_get_sample_info_by_index(pa_context
*c
, uint32_t idx
, pa_sample_info_cb_t cb
, void *userdata
) {
1640 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1643 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1644 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1645 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1647 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1649 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1650 pa_tagstruct_putu32(t
, idx
);
1651 pa_tagstruct_puts(t
, NULL
);
1652 pa_pstream_send_tagstruct(c
->pstream
, t
);
1653 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1658 pa_operation
* pa_context_get_sample_info_list(pa_context
*c
, pa_sample_info_cb_t cb
, void *userdata
) {
1659 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1662 static pa_operation
* command_kill(pa_context
*c
, uint32_t command
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1668 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1670 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1671 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1672 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1674 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1676 t
= pa_tagstruct_command(c
, command
, &tag
);
1677 pa_tagstruct_putu32(t
, idx
);
1678 pa_pstream_send_tagstruct(c
->pstream
, t
);
1679 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1684 pa_operation
* pa_context_kill_client(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1685 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, idx
, cb
, userdata
);
1688 pa_operation
* pa_context_kill_sink_input(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1689 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, idx
, cb
, userdata
);
1692 pa_operation
* pa_context_kill_source_output(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1693 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, idx
, cb
, userdata
);
1696 static void context_index_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1697 pa_operation
*o
= userdata
;
1702 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1707 if (command
!= PA_COMMAND_REPLY
) {
1708 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1711 idx
= PA_INVALID_INDEX
;
1712 } else if (pa_tagstruct_getu32(t
, &idx
) ||
1713 !pa_tagstruct_eof(t
)) {
1714 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1719 pa_context_index_cb_t cb
= (pa_context_index_cb_t
) o
->callback
;
1720 cb(o
->context
, idx
, o
->userdata
);
1725 pa_operation_done(o
);
1726 pa_operation_unref(o
);
1729 pa_operation
* pa_context_load_module(pa_context
*c
, const char*name
, const char *argument
, pa_context_index_cb_t cb
, void *userdata
) {
1735 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1737 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1738 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1739 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1741 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1743 t
= pa_tagstruct_command(c
, PA_COMMAND_LOAD_MODULE
, &tag
);
1744 pa_tagstruct_puts(t
, name
);
1745 pa_tagstruct_puts(t
, argument
);
1746 pa_pstream_send_tagstruct(c
->pstream
, t
);
1747 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_index_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1752 pa_operation
* pa_context_unload_module(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1753 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, idx
, cb
, userdata
);
1756 /*** Autoload stuff ***/
1758 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name
, "Module auto-loading no longer supported.");
1760 pa_operation
* pa_context_get_autoload_info_by_name(pa_context
*c
, const char *name
, pa_autoload_type_t type
, pa_autoload_info_cb_t cb
, void *userdata
) {
1763 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1765 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1768 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index
, "Module auto-loading no longer supported.");
1770 pa_operation
* pa_context_get_autoload_info_by_index(pa_context
*c
, uint32_t idx
, pa_autoload_info_cb_t cb
, void *userdata
) {
1772 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1774 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1777 PA_WARN_REFERENCE(pa_context_get_autoload_info_list
, "Module auto-loading no longer supported.");
1779 pa_operation
* pa_context_get_autoload_info_list(pa_context
*c
, pa_autoload_info_cb_t cb
, void *userdata
) {
1781 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1783 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1786 PA_WARN_REFERENCE(pa_context_add_autoload
, "Module auto-loading no longer supported.");
1788 pa_operation
* pa_context_add_autoload(pa_context
*c
, const char *name
, pa_autoload_type_t type
, const char *module
, const char*argument
, pa_context_index_cb_t cb
, void* userdata
) {
1790 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1792 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1795 PA_WARN_REFERENCE(pa_context_remove_autoload_by_name
, "Module auto-loading no longer supported.");
1797 pa_operation
* pa_context_remove_autoload_by_name(pa_context
*c
, const char *name
, pa_autoload_type_t type
, pa_context_success_cb_t cb
, void* userdata
) {
1799 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1801 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1804 PA_WARN_REFERENCE(pa_context_remove_autoload_by_index
, "Module auto-loading no longer supported.");
1806 pa_operation
* pa_context_remove_autoload_by_index(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void* userdata
) {
1808 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1810 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1813 pa_operation
* pa_context_move_sink_input_by_name(pa_context
*c
, uint32_t idx
, const char *sink_name
, pa_context_success_cb_t cb
, void* userdata
) {
1819 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1821 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1822 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1823 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1824 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1825 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_name
&& *sink_name
, PA_ERR_INVALID
);
1827 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1829 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1830 pa_tagstruct_putu32(t
, idx
);
1831 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1832 pa_tagstruct_puts(t
, sink_name
);
1833 pa_pstream_send_tagstruct(c
->pstream
, t
);
1834 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1839 pa_operation
* pa_context_move_sink_input_by_index(pa_context
*c
, uint32_t idx
, uint32_t sink_idx
, pa_context_success_cb_t cb
, void* userdata
) {
1845 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1847 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1848 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1849 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1850 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1851 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1853 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1855 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1856 pa_tagstruct_putu32(t
, idx
);
1857 pa_tagstruct_putu32(t
, sink_idx
);
1858 pa_tagstruct_puts(t
, NULL
);
1859 pa_pstream_send_tagstruct(c
->pstream
, t
);
1860 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1865 pa_operation
* pa_context_move_source_output_by_name(pa_context
*c
, uint32_t idx
, const char *source_name
, pa_context_success_cb_t cb
, void* userdata
) {
1871 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1873 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1874 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1875 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1876 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1877 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_name
&& *source_name
, PA_ERR_INVALID
);
1879 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1881 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1882 pa_tagstruct_putu32(t
, idx
);
1883 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1884 pa_tagstruct_puts(t
, source_name
);
1885 pa_pstream_send_tagstruct(c
->pstream
, t
);
1886 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1891 pa_operation
* pa_context_move_source_output_by_index(pa_context
*c
, uint32_t idx
, uint32_t source_idx
, pa_context_success_cb_t cb
, void* userdata
) {
1897 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1899 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1900 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1901 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1902 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1903 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1905 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1907 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1908 pa_tagstruct_putu32(t
, idx
);
1909 pa_tagstruct_putu32(t
, source_idx
);
1910 pa_tagstruct_puts(t
, NULL
);
1911 pa_pstream_send_tagstruct(c
->pstream
, t
);
1912 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1917 pa_operation
* pa_context_suspend_sink_by_name(pa_context
*c
, const char *sink_name
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1923 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1925 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1926 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1927 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1928 PA_CHECK_VALIDITY_RETURN_NULL(c
, !sink_name
|| *sink_name
, PA_ERR_INVALID
);
1930 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1932 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1933 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1934 pa_tagstruct_puts(t
, sink_name
);
1935 pa_tagstruct_put_boolean(t
, suspend
);
1936 pa_pstream_send_tagstruct(c
->pstream
, t
);
1937 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1942 pa_operation
* pa_context_suspend_sink_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1948 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1950 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1951 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1952 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1954 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1956 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1957 pa_tagstruct_putu32(t
, idx
);
1958 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
1959 pa_tagstruct_put_boolean(t
, suspend
);
1960 pa_pstream_send_tagstruct(c
->pstream
, t
);
1961 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1966 pa_operation
* pa_context_suspend_source_by_name(pa_context
*c
, const char *source_name
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1972 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1974 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1975 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1976 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1977 PA_CHECK_VALIDITY_RETURN_NULL(c
, !source_name
|| *source_name
, PA_ERR_INVALID
);
1979 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1981 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
1982 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1983 pa_tagstruct_puts(t
, source_name
);
1984 pa_tagstruct_put_boolean(t
, suspend
);
1985 pa_pstream_send_tagstruct(c
->pstream
, t
);
1986 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1991 pa_operation
* pa_context_suspend_source_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1997 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1999 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2000 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2001 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2003 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2005 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
2006 pa_tagstruct_putu32(t
, idx
);
2007 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
2008 pa_tagstruct_put_boolean(t
, suspend
);
2009 pa_pstream_send_tagstruct(c
->pstream
, t
);
2010 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);