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
27 #include <pulse/context.h>
28 #include <pulse/xmalloc.h>
29 #include <pulse/fork-detect.h>
31 #include <pulsecore/macro.h>
32 #include <pulsecore/core-util.h>
33 #include <pulsecore/pstream-util.h>
36 #include "introspect.h"
40 static void context_stat_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
41 pa_operation
*o
= userdata
;
42 pa_stat_info i
, *p
= &i
;
46 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
53 if (command
!= PA_COMMAND_REPLY
) {
54 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
58 } else if (pa_tagstruct_getu32(t
, &i
.memblock_total
) < 0 ||
59 pa_tagstruct_getu32(t
, &i
.memblock_total_size
) < 0 ||
60 pa_tagstruct_getu32(t
, &i
.memblock_allocated
) < 0 ||
61 pa_tagstruct_getu32(t
, &i
.memblock_allocated_size
) < 0 ||
62 pa_tagstruct_getu32(t
, &i
.scache_size
) < 0 ||
63 !pa_tagstruct_eof(t
)) {
64 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
69 pa_stat_info_cb_t cb
= (pa_stat_info_cb_t
) o
->callback
;
70 cb(o
->context
, p
, o
->userdata
);
75 pa_operation_unref(o
);
78 pa_operation
* pa_context_stat(pa_context
*c
, pa_stat_info_cb_t cb
, void *userdata
) {
79 return pa_context_send_simple_command(c
, PA_COMMAND_STAT
, context_stat_callback
, (pa_operation_cb_t
) cb
, userdata
);
84 static void context_get_server_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
85 pa_operation
*o
= userdata
;
86 pa_server_info i
, *p
= &i
;
90 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
97 if (command
!= PA_COMMAND_REPLY
) {
98 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
102 } else if (pa_tagstruct_gets(t
, &i
.server_name
) < 0 ||
103 pa_tagstruct_gets(t
, &i
.server_version
) < 0 ||
104 pa_tagstruct_gets(t
, &i
.user_name
) < 0 ||
105 pa_tagstruct_gets(t
, &i
.host_name
) < 0 ||
106 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
107 pa_tagstruct_gets(t
, &i
.default_sink_name
) < 0 ||
108 pa_tagstruct_gets(t
, &i
.default_source_name
) < 0 ||
109 pa_tagstruct_getu32(t
, &i
.cookie
) < 0 ||
110 (o
->context
->version
>= 15 &&
111 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0) ||
112 !pa_tagstruct_eof(t
)) {
114 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
118 if (p
&& o
->context
->version
< 15)
119 pa_channel_map_init_extend(&i
.channel_map
, i
.sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
122 pa_server_info_cb_t cb
= (pa_server_info_cb_t
) o
->callback
;
123 cb(o
->context
, p
, o
->userdata
);
127 pa_operation_done(o
);
128 pa_operation_unref(o
);
131 pa_operation
* pa_context_get_server_info(pa_context
*c
, pa_server_info_cb_t cb
, void *userdata
) {
132 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
137 static void context_get_sink_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
138 pa_operation
*o
= userdata
;
145 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
147 /* For safety incase someone use fail: outside the while loop below */
153 if (command
!= PA_COMMAND_REPLY
) {
154 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
160 while (!pa_tagstruct_eof(t
)) {
164 const char *ap
= NULL
;
167 i
.proplist
= pa_proplist_new();
168 i
.base_volume
= PA_VOLUME_NORM
;
169 i
.n_volume_steps
= PA_VOLUME_NORM
+1;
171 state
= PA_SINK_INVALID_STATE
;
172 i
.card
= PA_INVALID_INDEX
;
174 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
175 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
176 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
177 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
178 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
179 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
180 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
181 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
182 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
183 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
184 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
185 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
186 pa_tagstruct_getu32(t
, &flags
) < 0 ||
187 (o
->context
->version
>= 13 &&
188 (pa_tagstruct_get_proplist(t
, i
.proplist
) < 0 ||
189 pa_tagstruct_get_usec(t
, &i
.configured_latency
) < 0)) ||
190 (o
->context
->version
>= 15 &&
191 (pa_tagstruct_get_volume(t
, &i
.base_volume
) < 0 ||
192 pa_tagstruct_getu32(t
, &state
) < 0 ||
193 pa_tagstruct_getu32(t
, &i
.n_volume_steps
) < 0 ||
194 pa_tagstruct_getu32(t
, &i
.card
) < 0)) ||
195 (o
->context
->version
>= 16 &&
196 (pa_tagstruct_getu32(t
, &i
.n_ports
)))) {
201 if (o
->context
->version
>= 16) {
203 i
.ports
= pa_xnew(pa_sink_port_info
*, i
.n_ports
+1);
204 i
.ports
[0] = pa_xnew(pa_sink_port_info
, i
.n_ports
);
206 for (j
= 0; j
< i
.n_ports
; j
++) {
207 if (pa_tagstruct_gets(t
, &i
.ports
[0][j
].name
) < 0 ||
208 pa_tagstruct_gets(t
, &i
.ports
[0][j
].description
) < 0 ||
209 pa_tagstruct_getu32(t
, &i
.ports
[0][j
].priority
) < 0) {
214 i
.ports
[j
] = &i
.ports
[0][j
];
220 if (pa_tagstruct_gets(t
, &ap
) < 0)
224 for (j
= 0; j
< i
.n_ports
; j
++)
225 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
226 i
.active_port
= i
.ports
[j
];
232 if (o
->context
->version
>= 21) {
234 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
237 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
239 for (j
= 0; j
< n_formats
; j
++) {
241 i
.formats
[j
] = pa_format_info_new();
243 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
249 i
.flags
= (pa_sink_flags_t
) flags
;
250 i
.state
= (pa_sink_state_t
) state
;
253 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
254 cb(o
->context
, &i
, 0, o
->userdata
);
258 for (j
= 0; j
< i
.n_formats
; j
++)
259 pa_format_info_free(i
.formats
[j
]);
263 pa_xfree(i
.ports
[0]);
266 pa_proplist_free(i
.proplist
);
271 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
272 cb(o
->context
, NULL
, eol
, o
->userdata
);
276 pa_operation_done(o
);
277 pa_operation_unref(o
);
281 pa_assert(i
.proplist
);
283 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
286 for (j
= 0; j
< i
.n_formats
; j
++)
287 pa_format_info_free(i
.formats
[j
]);
291 pa_xfree(i
.ports
[0]);
294 pa_proplist_free(i
.proplist
);
299 pa_operation
* pa_context_get_sink_info_list(pa_context
*c
, pa_sink_info_cb_t cb
, void *userdata
) {
300 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
303 pa_operation
* pa_context_get_sink_info_by_index(pa_context
*c
, uint32_t idx
, pa_sink_info_cb_t cb
, void *userdata
) {
309 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
312 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
313 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
315 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
317 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
318 pa_tagstruct_putu32(t
, idx
);
319 pa_tagstruct_puts(t
, NULL
);
320 pa_pstream_send_tagstruct(c
->pstream
, t
);
321 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
);
326 pa_operation
* pa_context_get_sink_info_by_name(pa_context
*c
, const char *name
, pa_sink_info_cb_t cb
, void *userdata
) {
332 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
335 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
336 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
337 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
339 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
341 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
342 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
343 pa_tagstruct_puts(t
, name
);
344 pa_pstream_send_tagstruct(c
->pstream
, t
);
345 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
);
350 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
) {
356 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
358 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
359 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
360 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
361 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
363 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
365 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
366 pa_tagstruct_putu32(t
, idx
);
367 pa_tagstruct_puts(t
, NULL
);
368 pa_tagstruct_puts(t
, port
);
369 pa_pstream_send_tagstruct(c
->pstream
, t
);
370 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
);
375 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
) {
381 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
383 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
384 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
385 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
386 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
388 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
390 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
391 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
392 pa_tagstruct_puts(t
, name
);
393 pa_tagstruct_puts(t
, port
);
394 pa_pstream_send_tagstruct(c
->pstream
, t
);
395 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
);
400 /*** Source info ***/
402 static void context_get_source_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
403 pa_operation
*o
= userdata
;
410 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
412 /* For safety incase someone use fail: outside the while loop below */
418 if (command
!= PA_COMMAND_REPLY
) {
419 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
425 while (!pa_tagstruct_eof(t
)) {
432 i
.proplist
= pa_proplist_new();
433 i
.base_volume
= PA_VOLUME_NORM
;
434 i
.n_volume_steps
= PA_VOLUME_NORM
+1;
436 state
= PA_SOURCE_INVALID_STATE
;
437 i
.card
= PA_INVALID_INDEX
;
439 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
440 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
441 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
442 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
443 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
444 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
445 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
446 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
447 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
448 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0 ||
449 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
450 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
451 pa_tagstruct_getu32(t
, &flags
) < 0 ||
452 (o
->context
->version
>= 13 &&
453 (pa_tagstruct_get_proplist(t
, i
.proplist
) < 0 ||
454 pa_tagstruct_get_usec(t
, &i
.configured_latency
) < 0)) ||
455 (o
->context
->version
>= 15 &&
456 (pa_tagstruct_get_volume(t
, &i
.base_volume
) < 0 ||
457 pa_tagstruct_getu32(t
, &state
) < 0 ||
458 pa_tagstruct_getu32(t
, &i
.n_volume_steps
) < 0 ||
459 pa_tagstruct_getu32(t
, &i
.card
) < 0)) ||
460 (o
->context
->version
>= 16 &&
461 (pa_tagstruct_getu32(t
, &i
.n_ports
)))) {
466 if (o
->context
->version
>= 16) {
468 i
.ports
= pa_xnew(pa_source_port_info
*, i
.n_ports
+1);
469 i
.ports
[0] = pa_xnew(pa_source_port_info
, i
.n_ports
);
471 for (j
= 0; j
< i
.n_ports
; j
++) {
472 if (pa_tagstruct_gets(t
, &i
.ports
[0][j
].name
) < 0 ||
473 pa_tagstruct_gets(t
, &i
.ports
[0][j
].description
) < 0 ||
474 pa_tagstruct_getu32(t
, &i
.ports
[0][j
].priority
) < 0) {
479 i
.ports
[j
] = &i
.ports
[0][j
];
485 if (pa_tagstruct_gets(t
, &ap
) < 0)
489 for (j
= 0; j
< i
.n_ports
; j
++)
490 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
491 i
.active_port
= i
.ports
[j
];
497 if (o
->context
->version
>= 22) {
499 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
502 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
504 for (j
= 0; j
< n_formats
; j
++) {
506 i
.formats
[j
] = pa_format_info_new();
508 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
514 i
.flags
= (pa_source_flags_t
) flags
;
515 i
.state
= (pa_source_state_t
) state
;
518 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
519 cb(o
->context
, &i
, 0, o
->userdata
);
523 for (j
= 0; j
< i
.n_formats
; j
++)
524 pa_format_info_free(i
.formats
[j
]);
528 pa_xfree(i
.ports
[0]);
531 pa_proplist_free(i
.proplist
);
536 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
537 cb(o
->context
, NULL
, eol
, o
->userdata
);
541 pa_operation_done(o
);
542 pa_operation_unref(o
);
546 pa_assert(i
.proplist
);
548 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
551 for (j
= 0; j
< i
.n_formats
; j
++)
552 pa_format_info_free(i
.formats
[j
]);
556 pa_xfree(i
.ports
[0]);
559 pa_proplist_free(i
.proplist
);
564 pa_operation
* pa_context_get_source_info_list(pa_context
*c
, pa_source_info_cb_t cb
, void *userdata
) {
565 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
568 pa_operation
* pa_context_get_source_info_by_index(pa_context
*c
, uint32_t idx
, pa_source_info_cb_t cb
, void *userdata
) {
574 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
577 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
578 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
580 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
582 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
583 pa_tagstruct_putu32(t
, idx
);
584 pa_tagstruct_puts(t
, NULL
);
585 pa_pstream_send_tagstruct(c
->pstream
, t
);
586 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
);
591 pa_operation
* pa_context_get_source_info_by_name(pa_context
*c
, const char *name
, pa_source_info_cb_t cb
, void *userdata
) {
597 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
600 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
601 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
602 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
604 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
606 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
607 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
608 pa_tagstruct_puts(t
, name
);
609 pa_pstream_send_tagstruct(c
->pstream
, t
);
610 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
);
615 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
) {
621 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
623 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
624 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
625 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
626 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
628 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
630 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
631 pa_tagstruct_putu32(t
, idx
);
632 pa_tagstruct_puts(t
, NULL
);
633 pa_tagstruct_puts(t
, port
);
634 pa_pstream_send_tagstruct(c
->pstream
, t
);
635 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
);
640 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
) {
646 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
648 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
649 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
650 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
651 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
653 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
655 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
656 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
657 pa_tagstruct_puts(t
, name
);
658 pa_tagstruct_puts(t
, port
);
659 pa_pstream_send_tagstruct(c
->pstream
, t
);
660 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
);
665 /*** Client info ***/
667 static void context_get_client_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
668 pa_operation
*o
= userdata
;
673 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
678 if (command
!= PA_COMMAND_REPLY
) {
679 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
685 while (!pa_tagstruct_eof(t
)) {
689 i
.proplist
= pa_proplist_new();
691 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
692 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
693 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
694 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
695 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
697 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
698 pa_proplist_free(i
.proplist
);
703 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
704 cb(o
->context
, &i
, 0, o
->userdata
);
707 pa_proplist_free(i
.proplist
);
712 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
713 cb(o
->context
, NULL
, eol
, o
->userdata
);
717 pa_operation_done(o
);
718 pa_operation_unref(o
);
721 pa_operation
* pa_context_get_client_info(pa_context
*c
, uint32_t idx
, pa_client_info_cb_t cb
, void *userdata
) {
727 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
730 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
731 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
732 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
734 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
736 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CLIENT_INFO
, &tag
);
737 pa_tagstruct_putu32(t
, idx
);
738 pa_pstream_send_tagstruct(c
->pstream
, t
);
739 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
);
744 pa_operation
* pa_context_get_client_info_list(pa_context
*c
, pa_client_info_cb_t cb
, void *userdata
) {
745 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
750 static void context_get_card_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
751 pa_operation
*o
= userdata
;
756 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
761 if (command
!= PA_COMMAND_REPLY
) {
762 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
768 while (!pa_tagstruct_eof(t
)) {
775 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
776 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
777 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
778 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
779 pa_tagstruct_getu32(t
, &i
.n_profiles
) < 0) {
781 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
785 if (i
.n_profiles
> 0) {
786 i
.profiles
= pa_xnew0(pa_card_profile_info
, i
.n_profiles
+1);
788 for (j
= 0; j
< i
.n_profiles
; j
++) {
790 if (pa_tagstruct_gets(t
, &i
.profiles
[j
].name
) < 0 ||
791 pa_tagstruct_gets(t
, &i
.profiles
[j
].description
) < 0 ||
792 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sinks
) < 0 ||
793 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sources
) < 0 ||
794 pa_tagstruct_getu32(t
, &i
.profiles
[j
].priority
) < 0) {
796 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
797 pa_xfree(i
.profiles
);
802 /* Terminate with an extra NULL entry, just to make sure */
803 i
.profiles
[j
].name
= NULL
;
804 i
.profiles
[j
].description
= NULL
;
807 i
.proplist
= pa_proplist_new();
809 if (pa_tagstruct_gets(t
, &ap
) < 0 ||
810 pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) {
812 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
813 pa_xfree(i
.profiles
);
814 pa_proplist_free(i
.proplist
);
819 for (j
= 0; j
< i
.n_profiles
; j
++)
820 if (pa_streq(i
.profiles
[j
].name
, ap
)) {
821 i
.active_profile
= &i
.profiles
[j
];
827 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
828 cb(o
->context
, &i
, 0, o
->userdata
);
831 pa_proplist_free(i
.proplist
);
832 pa_xfree(i
.profiles
);
837 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
838 cb(o
->context
, NULL
, eol
, o
->userdata
);
842 pa_operation_done(o
);
843 pa_operation_unref(o
);
846 pa_operation
* pa_context_get_card_info_by_index(pa_context
*c
, uint32_t idx
, pa_card_info_cb_t cb
, void *userdata
) {
852 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
855 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
856 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
857 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
858 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
860 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
862 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
863 pa_tagstruct_putu32(t
, idx
);
864 pa_tagstruct_puts(t
, NULL
);
865 pa_pstream_send_tagstruct(c
->pstream
, t
);
866 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
);
871 pa_operation
* pa_context_get_card_info_by_name(pa_context
*c
, const char*name
, pa_card_info_cb_t cb
, void *userdata
) {
877 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
880 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
881 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
882 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
883 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
885 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
887 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
888 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
889 pa_tagstruct_puts(t
, name
);
890 pa_pstream_send_tagstruct(c
->pstream
, t
);
891 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
);
896 pa_operation
* pa_context_get_card_info_list(pa_context
*c
, pa_card_info_cb_t cb
, void *userdata
) {
897 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
899 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CARD_INFO_LIST
, context_get_card_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
902 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
) {
908 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
910 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
911 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
912 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
913 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
915 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
917 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
918 pa_tagstruct_putu32(t
, idx
);
919 pa_tagstruct_puts(t
, NULL
);
920 pa_tagstruct_puts(t
, profile
);
921 pa_pstream_send_tagstruct(c
->pstream
, t
);
922 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
);
927 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
) {
933 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
935 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
936 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
937 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
938 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
940 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
942 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
943 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
944 pa_tagstruct_puts(t
, name
);
945 pa_tagstruct_puts(t
, profile
);
946 pa_pstream_send_tagstruct(c
->pstream
, t
);
947 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
);
952 /*** Module info ***/
954 static void context_get_module_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
955 pa_operation
*o
= userdata
;
960 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
965 if (command
!= PA_COMMAND_REPLY
) {
966 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
972 while (!pa_tagstruct_eof(t
)) {
974 pa_bool_t auto_unload
= FALSE
;
977 i
.proplist
= pa_proplist_new();
979 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
980 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
981 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
982 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
983 (o
->context
->version
< 15 && pa_tagstruct_get_boolean(t
, &auto_unload
) < 0) ||
984 (o
->context
->version
>= 15 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
985 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
989 i
.auto_unload
= (int) auto_unload
;
992 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
993 cb(o
->context
, &i
, 0, o
->userdata
);
996 pa_proplist_free(i
.proplist
);
1001 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
1002 cb(o
->context
, NULL
, eol
, o
->userdata
);
1006 pa_operation_done(o
);
1007 pa_operation_unref(o
);
1010 pa_operation
* pa_context_get_module_info(pa_context
*c
, uint32_t idx
, pa_module_info_cb_t cb
, void *userdata
) {
1016 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1019 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1020 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1021 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1023 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1025 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_MODULE_INFO
, &tag
);
1026 pa_tagstruct_putu32(t
, idx
);
1027 pa_pstream_send_tagstruct(c
->pstream
, t
);
1028 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
);
1033 pa_operation
* pa_context_get_module_info_list(pa_context
*c
, pa_module_info_cb_t cb
, void *userdata
) {
1034 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1037 /*** Sink input info ***/
1039 static void context_get_sink_input_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1040 pa_operation
*o
= userdata
;
1045 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1050 if (command
!= PA_COMMAND_REPLY
) {
1051 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1057 while (!pa_tagstruct_eof(t
)) {
1058 pa_sink_input_info i
;
1059 pa_bool_t mute
= FALSE
, corked
= FALSE
, has_volume
= FALSE
, volume_writable
= TRUE
;
1062 i
.proplist
= pa_proplist_new();
1063 i
.format
= pa_format_info_new();
1065 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1066 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1067 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1068 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1069 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
1070 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1071 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1072 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1073 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1074 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0 ||
1075 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1076 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1077 (o
->context
->version
>= 11 && pa_tagstruct_get_boolean(t
, &mute
) < 0) ||
1078 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1079 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1080 (o
->context
->version
>= 20 && (pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1081 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0)) ||
1082 (o
->context
->version
>= 21 && pa_tagstruct_get_format_info(t
, i
.format
) < 0)) {
1084 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1085 pa_proplist_free(i
.proplist
);
1086 pa_format_info_free(i
.format
);
1090 i
.mute
= (int) mute
;
1091 i
.corked
= (int) corked
;
1092 i
.has_volume
= (int) has_volume
;
1093 i
.volume_writable
= (int) volume_writable
;
1096 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1097 cb(o
->context
, &i
, 0, o
->userdata
);
1100 pa_proplist_free(i
.proplist
);
1101 pa_format_info_free(i
.format
);
1106 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1107 cb(o
->context
, NULL
, eol
, o
->userdata
);
1111 pa_operation_done(o
);
1112 pa_operation_unref(o
);
1115 pa_operation
* pa_context_get_sink_input_info(pa_context
*c
, uint32_t idx
, pa_sink_input_info_cb_t cb
, void *userdata
) {
1121 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1124 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1125 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1126 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1128 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1130 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO
, &tag
);
1131 pa_tagstruct_putu32(t
, idx
);
1132 pa_pstream_send_tagstruct(c
->pstream
, t
);
1133 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
);
1138 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
) {
1139 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
);
1142 /*** Source output info ***/
1144 static void context_get_source_output_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1145 pa_operation
*o
= userdata
;
1150 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1155 if (command
!= PA_COMMAND_REPLY
) {
1156 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1162 while (!pa_tagstruct_eof(t
)) {
1163 pa_source_output_info i
;
1164 pa_bool_t mute
= FALSE
, corked
= FALSE
, has_volume
= FALSE
, volume_writable
= TRUE
;
1167 i
.proplist
= pa_proplist_new();
1168 i
.format
= pa_format_info_new();
1170 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1171 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1172 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1173 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1174 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
1175 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1176 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1177 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1178 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0 ||
1179 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1180 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1181 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1182 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1183 (o
->context
->version
>= 22 && (pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1184 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
1185 pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1186 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0 ||
1187 pa_tagstruct_get_format_info(t
, i
.format
) < 0))) {
1189 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1190 pa_proplist_free(i
.proplist
);
1191 pa_format_info_free(i
.format
);
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
);
1206 pa_format_info_free(i
.format
);
1211 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1212 cb(o
->context
, NULL
, eol
, o
->userdata
);
1216 pa_operation_done(o
);
1217 pa_operation_unref(o
);
1220 pa_operation
* pa_context_get_source_output_info(pa_context
*c
, uint32_t idx
, pa_source_output_info_cb_t cb
, void *userdata
) {
1226 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1229 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1230 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1231 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1233 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1235 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
, &tag
);
1236 pa_tagstruct_putu32(t
, idx
);
1237 pa_pstream_send_tagstruct(c
->pstream
, t
);
1238 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
);
1243 pa_operation
* pa_context_get_source_output_info_list(pa_context
*c
, pa_source_output_info_cb_t cb
, void *userdata
) {
1244 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
);
1247 /*** Volume manipulation ***/
1249 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
) {
1255 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1258 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1259 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1260 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1262 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1264 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1265 pa_tagstruct_putu32(t
, idx
);
1266 pa_tagstruct_puts(t
, NULL
);
1267 pa_tagstruct_put_cvolume(t
, volume
);
1268 pa_pstream_send_tagstruct(c
->pstream
, t
);
1269 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
);
1274 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
) {
1280 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1284 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1285 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1286 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1287 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1289 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1291 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1292 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1293 pa_tagstruct_puts(t
, name
);
1294 pa_tagstruct_put_cvolume(t
, volume
);
1295 pa_pstream_send_tagstruct(c
->pstream
, t
);
1296 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
);
1301 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
) {
1307 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1309 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1310 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1312 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1314 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1315 pa_tagstruct_putu32(t
, idx
);
1316 pa_tagstruct_puts(t
, NULL
);
1317 pa_tagstruct_put_boolean(t
, mute
);
1318 pa_pstream_send_tagstruct(c
->pstream
, t
);
1319 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
);
1324 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
) {
1330 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1333 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1334 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1335 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1337 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1339 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1340 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1341 pa_tagstruct_puts(t
, name
);
1342 pa_tagstruct_put_boolean(t
, mute
);
1343 pa_pstream_send_tagstruct(c
->pstream
, t
);
1344 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
);
1349 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
) {
1355 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1358 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1359 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1360 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1361 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1363 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1365 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_VOLUME
, &tag
);
1366 pa_tagstruct_putu32(t
, idx
);
1367 pa_tagstruct_put_cvolume(t
, volume
);
1368 pa_pstream_send_tagstruct(c
->pstream
, t
);
1369 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
);
1374 pa_operation
* pa_context_set_sink_input_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1380 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1382 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1383 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1384 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1385 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1387 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1389 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_MUTE
, &tag
);
1390 pa_tagstruct_putu32(t
, idx
);
1391 pa_tagstruct_put_boolean(t
, mute
);
1392 pa_pstream_send_tagstruct(c
->pstream
, t
);
1393 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
);
1398 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
) {
1404 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1407 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1408 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1409 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1411 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1413 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1414 pa_tagstruct_putu32(t
, idx
);
1415 pa_tagstruct_puts(t
, NULL
);
1416 pa_tagstruct_put_cvolume(t
, volume
);
1417 pa_pstream_send_tagstruct(c
->pstream
, t
);
1418 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
);
1423 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
) {
1429 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1433 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1434 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1435 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1436 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1438 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1440 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1441 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1442 pa_tagstruct_puts(t
, name
);
1443 pa_tagstruct_put_cvolume(t
, volume
);
1444 pa_pstream_send_tagstruct(c
->pstream
, t
);
1445 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
);
1450 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
) {
1456 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1458 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1459 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1461 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1463 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1464 pa_tagstruct_putu32(t
, idx
);
1465 pa_tagstruct_puts(t
, NULL
);
1466 pa_tagstruct_put_boolean(t
, mute
);
1467 pa_pstream_send_tagstruct(c
->pstream
, t
);
1468 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
);
1473 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
) {
1479 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1482 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1483 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1484 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1486 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1488 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1489 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1490 pa_tagstruct_puts(t
, name
);
1491 pa_tagstruct_put_boolean(t
, mute
);
1492 pa_pstream_send_tagstruct(c
->pstream
, t
);
1493 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
);
1498 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
) {
1504 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1507 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1508 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1509 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1510 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1511 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1513 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1515 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME
, &tag
);
1516 pa_tagstruct_putu32(t
, idx
);
1517 pa_tagstruct_put_cvolume(t
, volume
);
1518 pa_pstream_send_tagstruct(c
->pstream
, t
);
1519 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
);
1524 pa_operation
* pa_context_set_source_output_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1530 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1532 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1533 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1534 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1535 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1537 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1539 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE
, &tag
);
1540 pa_tagstruct_putu32(t
, idx
);
1541 pa_tagstruct_put_boolean(t
, mute
);
1542 pa_pstream_send_tagstruct(c
->pstream
, t
);
1543 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
);
1548 /** Sample Cache **/
1550 static void context_get_sample_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1551 pa_operation
*o
= userdata
;
1556 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1561 if (command
!= PA_COMMAND_REPLY
) {
1562 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1568 while (!pa_tagstruct_eof(t
)) {
1570 pa_bool_t lazy
= FALSE
;
1573 i
.proplist
= pa_proplist_new();
1575 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1576 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1577 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1578 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
1579 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1580 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1581 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
1582 pa_tagstruct_get_boolean(t
, &lazy
) < 0 ||
1583 pa_tagstruct_gets(t
, &i
.filename
) < 0 ||
1584 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
1586 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1590 i
.lazy
= (int) lazy
;
1593 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1594 cb(o
->context
, &i
, 0, o
->userdata
);
1597 pa_proplist_free(i
.proplist
);
1602 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1603 cb(o
->context
, NULL
, eol
, o
->userdata
);
1607 pa_operation_done(o
);
1608 pa_operation_unref(o
);
1611 pa_operation
* pa_context_get_sample_info_by_name(pa_context
*c
, const char *name
, pa_sample_info_cb_t cb
, void *userdata
) {
1617 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1620 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1621 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1622 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1624 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1626 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1627 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1628 pa_tagstruct_puts(t
, name
);
1629 pa_pstream_send_tagstruct(c
->pstream
, t
);
1630 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
);
1635 pa_operation
* pa_context_get_sample_info_by_index(pa_context
*c
, uint32_t idx
, pa_sample_info_cb_t cb
, void *userdata
) {
1641 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1644 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1645 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1646 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1648 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1650 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1651 pa_tagstruct_putu32(t
, idx
);
1652 pa_tagstruct_puts(t
, NULL
);
1653 pa_pstream_send_tagstruct(c
->pstream
, t
);
1654 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
);
1659 pa_operation
* pa_context_get_sample_info_list(pa_context
*c
, pa_sample_info_cb_t cb
, void *userdata
) {
1660 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1663 static pa_operation
* command_kill(pa_context
*c
, uint32_t command
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1669 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1671 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1672 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1673 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1675 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1677 t
= pa_tagstruct_command(c
, command
, &tag
);
1678 pa_tagstruct_putu32(t
, idx
);
1679 pa_pstream_send_tagstruct(c
->pstream
, t
);
1680 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
);
1685 pa_operation
* pa_context_kill_client(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1686 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, idx
, cb
, userdata
);
1689 pa_operation
* pa_context_kill_sink_input(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1690 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, idx
, cb
, userdata
);
1693 pa_operation
* pa_context_kill_source_output(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1694 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, idx
, cb
, userdata
);
1697 static void context_index_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1698 pa_operation
*o
= userdata
;
1703 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1708 if (command
!= PA_COMMAND_REPLY
) {
1709 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
1712 idx
= PA_INVALID_INDEX
;
1713 } else if (pa_tagstruct_getu32(t
, &idx
) ||
1714 !pa_tagstruct_eof(t
)) {
1715 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1720 pa_context_index_cb_t cb
= (pa_context_index_cb_t
) o
->callback
;
1721 cb(o
->context
, idx
, o
->userdata
);
1726 pa_operation_done(o
);
1727 pa_operation_unref(o
);
1730 pa_operation
* pa_context_load_module(pa_context
*c
, const char*name
, const char *argument
, pa_context_index_cb_t cb
, void *userdata
) {
1736 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1738 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1739 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1740 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1742 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1744 t
= pa_tagstruct_command(c
, PA_COMMAND_LOAD_MODULE
, &tag
);
1745 pa_tagstruct_puts(t
, name
);
1746 pa_tagstruct_puts(t
, argument
);
1747 pa_pstream_send_tagstruct(c
->pstream
, t
);
1748 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_index_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1753 pa_operation
* pa_context_unload_module(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1754 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, idx
, cb
, userdata
);
1757 /*** Autoload stuff ***/
1759 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name
, "Module auto-loading no longer supported.");
1761 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
) {
1764 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1766 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1769 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index
, "Module auto-loading no longer supported.");
1771 pa_operation
* pa_context_get_autoload_info_by_index(pa_context
*c
, uint32_t idx
, pa_autoload_info_cb_t cb
, void *userdata
) {
1773 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1775 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1778 PA_WARN_REFERENCE(pa_context_get_autoload_info_list
, "Module auto-loading no longer supported.");
1780 pa_operation
* pa_context_get_autoload_info_list(pa_context
*c
, pa_autoload_info_cb_t cb
, void *userdata
) {
1782 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1784 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1787 PA_WARN_REFERENCE(pa_context_add_autoload
, "Module auto-loading no longer supported.");
1789 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
) {
1791 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1793 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1796 PA_WARN_REFERENCE(pa_context_remove_autoload_by_name
, "Module auto-loading no longer supported.");
1798 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
) {
1800 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1802 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1805 PA_WARN_REFERENCE(pa_context_remove_autoload_by_index
, "Module auto-loading no longer supported.");
1807 pa_operation
* pa_context_remove_autoload_by_index(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void* userdata
) {
1809 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1811 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1814 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
) {
1820 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1822 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1823 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1824 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1825 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1826 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_name
&& *sink_name
, PA_ERR_INVALID
);
1828 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1830 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1831 pa_tagstruct_putu32(t
, idx
);
1832 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1833 pa_tagstruct_puts(t
, sink_name
);
1834 pa_pstream_send_tagstruct(c
->pstream
, t
);
1835 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
);
1840 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
) {
1846 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1848 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1849 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1850 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1851 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1852 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1854 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1856 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1857 pa_tagstruct_putu32(t
, idx
);
1858 pa_tagstruct_putu32(t
, sink_idx
);
1859 pa_tagstruct_puts(t
, NULL
);
1860 pa_pstream_send_tagstruct(c
->pstream
, t
);
1861 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
);
1866 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
) {
1872 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1874 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1875 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1876 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1877 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1878 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_name
&& *source_name
, PA_ERR_INVALID
);
1880 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1882 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1883 pa_tagstruct_putu32(t
, idx
);
1884 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1885 pa_tagstruct_puts(t
, source_name
);
1886 pa_pstream_send_tagstruct(c
->pstream
, t
);
1887 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
);
1892 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
) {
1898 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1900 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1901 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1902 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1903 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1904 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1906 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1908 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
1909 pa_tagstruct_putu32(t
, idx
);
1910 pa_tagstruct_putu32(t
, source_idx
);
1911 pa_tagstruct_puts(t
, NULL
);
1912 pa_pstream_send_tagstruct(c
->pstream
, t
);
1913 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
);
1918 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
) {
1924 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1926 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1927 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1928 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1929 PA_CHECK_VALIDITY_RETURN_NULL(c
, !sink_name
|| *sink_name
, PA_ERR_INVALID
);
1931 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1933 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1934 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1935 pa_tagstruct_puts(t
, sink_name
);
1936 pa_tagstruct_put_boolean(t
, suspend
);
1937 pa_pstream_send_tagstruct(c
->pstream
, t
);
1938 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
);
1943 pa_operation
* pa_context_suspend_sink_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1949 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1951 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1952 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1953 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1955 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1957 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
1958 pa_tagstruct_putu32(t
, idx
);
1959 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
1960 pa_tagstruct_put_boolean(t
, suspend
);
1961 pa_pstream_send_tagstruct(c
->pstream
, t
);
1962 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
);
1967 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
) {
1973 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1975 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1976 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1977 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1978 PA_CHECK_VALIDITY_RETURN_NULL(c
, !source_name
|| *source_name
, PA_ERR_INVALID
);
1980 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1982 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
1983 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1984 pa_tagstruct_puts(t
, source_name
);
1985 pa_tagstruct_put_boolean(t
, suspend
);
1986 pa_pstream_send_tagstruct(c
->pstream
, t
);
1987 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
);
1992 pa_operation
* pa_context_suspend_source_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
1998 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2000 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2001 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2002 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2004 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2006 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
2007 pa_tagstruct_putu32(t
, idx
);
2008 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
2009 pa_tagstruct_put_boolean(t
, suspend
);
2010 pa_pstream_send_tagstruct(c
->pstream
, t
);
2011 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
);