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();
1171 i
.format
= pa_format_info_new();
1173 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1174 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1175 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1176 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1177 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
1178 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1179 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1180 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1181 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0 ||
1182 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1183 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1184 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1185 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1186 (o
->context
->version
>= 22 && (pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1187 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
1188 pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1189 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0 ||
1190 pa_tagstruct_get_format_info(t
, i
.format
) < 0))) {
1192 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1193 pa_proplist_free(i
.proplist
);
1194 pa_format_info_free(i
.format
);
1198 i
.mute
= (int) mute
;
1199 i
.corked
= (int) corked
;
1200 i
.has_volume
= (int) has_volume
;
1201 i
.volume_writable
= (int) volume_writable
;
1204 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1205 cb(o
->context
, &i
, 0, o
->userdata
);
1208 pa_proplist_free(i
.proplist
);
1209 pa_format_info_free(i
.format
);
1214 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1215 cb(o
->context
, NULL
, eol
, o
->userdata
);
1219 pa_operation_done(o
);
1220 pa_operation_unref(o
);
1223 pa_operation
* pa_context_get_source_output_info(pa_context
*c
, uint32_t idx
, pa_source_output_info_cb_t cb
, void *userdata
) {
1229 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1232 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1233 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1234 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1236 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1238 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
, &tag
);
1239 pa_tagstruct_putu32(t
, idx
);
1240 pa_pstream_send_tagstruct(c
->pstream
, t
);
1241 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
);
1246 pa_operation
* pa_context_get_source_output_info_list(pa_context
*c
, pa_source_output_info_cb_t cb
, void *userdata
) {
1247 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
);
1250 /*** Volume manipulation ***/
1252 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
) {
1258 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1261 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1262 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1263 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1265 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1267 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1268 pa_tagstruct_putu32(t
, idx
);
1269 pa_tagstruct_puts(t
, NULL
);
1270 pa_tagstruct_put_cvolume(t
, volume
);
1271 pa_pstream_send_tagstruct(c
->pstream
, t
);
1272 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
);
1277 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
) {
1283 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1287 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1288 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1289 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1290 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1292 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1294 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1295 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1296 pa_tagstruct_puts(t
, name
);
1297 pa_tagstruct_put_cvolume(t
, volume
);
1298 pa_pstream_send_tagstruct(c
->pstream
, t
);
1299 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
);
1304 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
) {
1310 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1312 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1313 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1315 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1317 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1318 pa_tagstruct_putu32(t
, idx
);
1319 pa_tagstruct_puts(t
, NULL
);
1320 pa_tagstruct_put_boolean(t
, mute
);
1321 pa_pstream_send_tagstruct(c
->pstream
, t
);
1322 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
);
1327 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
) {
1333 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1336 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1337 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1338 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1340 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1342 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1343 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1344 pa_tagstruct_puts(t
, name
);
1345 pa_tagstruct_put_boolean(t
, mute
);
1346 pa_pstream_send_tagstruct(c
->pstream
, t
);
1347 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
);
1352 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
) {
1358 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1361 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1362 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1363 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1364 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1366 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1368 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_VOLUME
, &tag
);
1369 pa_tagstruct_putu32(t
, idx
);
1370 pa_tagstruct_put_cvolume(t
, volume
);
1371 pa_pstream_send_tagstruct(c
->pstream
, t
);
1372 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
);
1377 pa_operation
* pa_context_set_sink_input_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1383 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1385 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1386 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1387 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1388 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1390 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1392 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_MUTE
, &tag
);
1393 pa_tagstruct_putu32(t
, idx
);
1394 pa_tagstruct_put_boolean(t
, mute
);
1395 pa_pstream_send_tagstruct(c
->pstream
, t
);
1396 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
);
1401 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
) {
1407 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1410 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1411 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1412 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1414 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1416 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1417 pa_tagstruct_putu32(t
, idx
);
1418 pa_tagstruct_puts(t
, NULL
);
1419 pa_tagstruct_put_cvolume(t
, volume
);
1420 pa_pstream_send_tagstruct(c
->pstream
, t
);
1421 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
);
1426 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
) {
1432 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1436 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1437 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1438 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1439 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1441 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1443 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1444 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1445 pa_tagstruct_puts(t
, name
);
1446 pa_tagstruct_put_cvolume(t
, volume
);
1447 pa_pstream_send_tagstruct(c
->pstream
, t
);
1448 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
);
1453 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
) {
1459 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1461 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1462 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1464 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1466 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1467 pa_tagstruct_putu32(t
, idx
);
1468 pa_tagstruct_puts(t
, NULL
);
1469 pa_tagstruct_put_boolean(t
, mute
);
1470 pa_pstream_send_tagstruct(c
->pstream
, t
);
1471 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
);
1476 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
) {
1482 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1485 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1486 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1487 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1489 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1491 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1492 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1493 pa_tagstruct_puts(t
, name
);
1494 pa_tagstruct_put_boolean(t
, mute
);
1495 pa_pstream_send_tagstruct(c
->pstream
, t
);
1496 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
);
1501 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
) {
1507 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1510 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1511 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1512 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1513 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1514 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1516 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1518 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME
, &tag
);
1519 pa_tagstruct_putu32(t
, idx
);
1520 pa_tagstruct_put_cvolume(t
, volume
);
1521 pa_pstream_send_tagstruct(c
->pstream
, t
);
1522 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
);
1527 pa_operation
* pa_context_set_source_output_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1533 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1535 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1536 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1537 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1538 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1540 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1542 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE
, &tag
);
1543 pa_tagstruct_putu32(t
, idx
);
1544 pa_tagstruct_put_boolean(t
, mute
);
1545 pa_pstream_send_tagstruct(c
->pstream
, t
);
1546 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
);
1551 /** Sample Cache **/
1553 static void context_get_sample_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1554 pa_operation
*o
= userdata
;
1559 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1564 if (command
!= PA_COMMAND_REPLY
) {
1565 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1571 while (!pa_tagstruct_eof(t
)) {
1573 pa_bool_t lazy
= FALSE
;
1576 i
.proplist
= pa_proplist_new();
1578 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1579 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1580 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1581 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
1582 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1583 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1584 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
1585 pa_tagstruct_get_boolean(t
, &lazy
) < 0 ||
1586 pa_tagstruct_gets(t
, &i
.filename
) < 0 ||
1587 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
1589 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1593 i
.lazy
= (int) lazy
;
1596 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1597 cb(o
->context
, &i
, 0, o
->userdata
);
1600 pa_proplist_free(i
.proplist
);
1605 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1606 cb(o
->context
, NULL
, eol
, o
->userdata
);
1610 pa_operation_done(o
);
1611 pa_operation_unref(o
);
1614 pa_operation
* pa_context_get_sample_info_by_name(pa_context
*c
, const char *name
, pa_sample_info_cb_t cb
, void *userdata
) {
1620 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1623 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1624 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1625 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1627 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1629 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1630 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1631 pa_tagstruct_puts(t
, name
);
1632 pa_pstream_send_tagstruct(c
->pstream
, t
);
1633 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
);
1638 pa_operation
* pa_context_get_sample_info_by_index(pa_context
*c
, uint32_t idx
, pa_sample_info_cb_t cb
, void *userdata
) {
1644 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1647 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1648 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1649 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1651 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1653 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1654 pa_tagstruct_putu32(t
, idx
);
1655 pa_tagstruct_puts(t
, NULL
);
1656 pa_pstream_send_tagstruct(c
->pstream
, t
);
1657 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
);
1662 pa_operation
* pa_context_get_sample_info_list(pa_context
*c
, pa_sample_info_cb_t cb
, void *userdata
) {
1663 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1666 static pa_operation
* command_kill(pa_context
*c
, uint32_t command
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1672 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1674 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1675 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1676 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1678 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1680 t
= pa_tagstruct_command(c
, command
, &tag
);
1681 pa_tagstruct_putu32(t
, idx
);
1682 pa_pstream_send_tagstruct(c
->pstream
, t
);
1683 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
);
1688 pa_operation
* pa_context_kill_client(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1689 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, idx
, cb
, userdata
);
1692 pa_operation
* pa_context_kill_sink_input(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1693 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, idx
, cb
, userdata
);
1696 pa_operation
* pa_context_kill_source_output(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1697 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, idx
, cb
, userdata
);
1700 static void context_index_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1701 pa_operation
*o
= userdata
;
1706 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1711 if (command
!= PA_COMMAND_REPLY
) {
1712 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1715 idx
= PA_INVALID_INDEX
;
1716 } else if (pa_tagstruct_getu32(t
, &idx
) ||
1717 !pa_tagstruct_eof(t
)) {
1718 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1723 pa_context_index_cb_t cb
= (pa_context_index_cb_t
) o
->callback
;
1724 cb(o
->context
, idx
, o
->userdata
);
1729 pa_operation_done(o
);
1730 pa_operation_unref(o
);
1733 pa_operation
* pa_context_load_module(pa_context
*c
, const char*name
, const char *argument
, pa_context_index_cb_t cb
, void *userdata
) {
1739 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1741 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1742 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1743 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1745 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1747 t
= pa_tagstruct_command(c
, PA_COMMAND_LOAD_MODULE
, &tag
);
1748 pa_tagstruct_puts(t
, name
);
1749 pa_tagstruct_puts(t
, argument
);
1750 pa_pstream_send_tagstruct(c
->pstream
, t
);
1751 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_index_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1756 pa_operation
* pa_context_unload_module(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1757 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, idx
, cb
, userdata
);
1760 /*** Autoload stuff ***/
1762 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name
, "Module auto-loading no longer supported.");
1764 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
) {
1767 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1769 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1772 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index
, "Module auto-loading no longer supported.");
1774 pa_operation
* pa_context_get_autoload_info_by_index(pa_context
*c
, uint32_t idx
, pa_autoload_info_cb_t cb
, void *userdata
) {
1776 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1778 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1781 PA_WARN_REFERENCE(pa_context_get_autoload_info_list
, "Module auto-loading no longer supported.");
1783 pa_operation
* pa_context_get_autoload_info_list(pa_context
*c
, pa_autoload_info_cb_t cb
, void *userdata
) {
1785 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1787 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1790 PA_WARN_REFERENCE(pa_context_add_autoload
, "Module auto-loading no longer supported.");
1792 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
) {
1794 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1796 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1799 PA_WARN_REFERENCE(pa_context_remove_autoload_by_name
, "Module auto-loading no longer supported.");
1801 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
) {
1803 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1805 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1808 PA_WARN_REFERENCE(pa_context_remove_autoload_by_index
, "Module auto-loading no longer supported.");
1810 pa_operation
* pa_context_remove_autoload_by_index(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void* userdata
) {
1812 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1814 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1817 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
) {
1823 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1825 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1826 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1827 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1828 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1829 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_name
&& *sink_name
, PA_ERR_INVALID
);
1831 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1833 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1834 pa_tagstruct_putu32(t
, idx
);
1835 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1836 pa_tagstruct_puts(t
, sink_name
);
1837 pa_pstream_send_tagstruct(c
->pstream
, t
);
1838 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
);
1843 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
) {
1849 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1851 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1852 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1853 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1854 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1855 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1857 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1859 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1860 pa_tagstruct_putu32(t
, idx
);
1861 pa_tagstruct_putu32(t
, sink_idx
);
1862 pa_tagstruct_puts(t
, NULL
);
1863 pa_pstream_send_tagstruct(c
->pstream
, t
);
1864 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
);
1869 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
) {
1875 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1877 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1878 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1879 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1880 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1881 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_name
&& *source_name
, PA_ERR_INVALID
);
1883 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1885 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1886 pa_tagstruct_putu32(t
, idx
);
1887 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1888 pa_tagstruct_puts(t
, source_name
);
1889 pa_pstream_send_tagstruct(c
->pstream
, t
);
1890 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
);
1895 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
) {
1901 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1903 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1904 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1905 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1906 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1907 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1909 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1911 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1912 pa_tagstruct_putu32(t
, idx
);
1913 pa_tagstruct_putu32(t
, source_idx
);
1914 pa_tagstruct_puts(t
, NULL
);
1915 pa_pstream_send_tagstruct(c
->pstream
, t
);
1916 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
);
1921 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
) {
1927 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1929 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1930 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1931 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1932 PA_CHECK_VALIDITY_RETURN_NULL(c
, !sink_name
|| *sink_name
, PA_ERR_INVALID
);
1934 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1936 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1937 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1938 pa_tagstruct_puts(t
, sink_name
);
1939 pa_tagstruct_put_boolean(t
, suspend
);
1940 pa_pstream_send_tagstruct(c
->pstream
, t
);
1941 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
);
1946 pa_operation
* pa_context_suspend_sink_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1952 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1954 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1955 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1956 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1958 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1960 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1961 pa_tagstruct_putu32(t
, idx
);
1962 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
1963 pa_tagstruct_put_boolean(t
, suspend
);
1964 pa_pstream_send_tagstruct(c
->pstream
, t
);
1965 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
);
1970 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
) {
1976 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1978 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1979 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1980 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1981 PA_CHECK_VALIDITY_RETURN_NULL(c
, !source_name
|| *source_name
, PA_ERR_INVALID
);
1983 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1985 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
1986 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1987 pa_tagstruct_puts(t
, source_name
);
1988 pa_tagstruct_put_boolean(t
, suspend
);
1989 pa_pstream_send_tagstruct(c
->pstream
, t
);
1990 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
);
1995 pa_operation
* pa_context_suspend_source_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
2001 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2003 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2004 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2005 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2007 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2009 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
2010 pa_tagstruct_putu32(t
, idx
);
2011 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
2012 pa_tagstruct_put_boolean(t
, suspend
);
2013 pa_pstream_send_tagstruct(c
->pstream
, t
);
2014 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
);