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 in case 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 i
.ports
[j
] = &i
.ports
[0][j
];
209 if (pa_tagstruct_gets(t
, &i
.ports
[j
]->name
) < 0 ||
210 pa_tagstruct_gets(t
, &i
.ports
[j
]->description
) < 0 ||
211 pa_tagstruct_getu32(t
, &i
.ports
[j
]->priority
) < 0) {
216 i
.ports
[j
]->available
= PA_PORT_AVAILABLE_UNKNOWN
;
217 if (o
->context
->version
>= 24) {
219 if (pa_tagstruct_getu32(t
, &av
) < 0 || av
> PA_PORT_AVAILABLE_YES
)
221 i
.ports
[j
]->available
= av
;
228 if (pa_tagstruct_gets(t
, &ap
) < 0)
232 for (j
= 0; j
< i
.n_ports
; j
++)
233 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
234 i
.active_port
= i
.ports
[j
];
240 if (o
->context
->version
>= 21) {
242 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
245 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
247 for (j
= 0; j
< n_formats
; j
++) {
249 i
.formats
[j
] = pa_format_info_new();
251 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
257 i
.flags
= (pa_sink_flags_t
) flags
;
258 i
.state
= (pa_sink_state_t
) state
;
261 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
262 cb(o
->context
, &i
, 0, o
->userdata
);
266 for (j
= 0; j
< i
.n_formats
; j
++)
267 pa_format_info_free(i
.formats
[j
]);
271 pa_xfree(i
.ports
[0]);
274 pa_proplist_free(i
.proplist
);
279 pa_sink_info_cb_t cb
= (pa_sink_info_cb_t
) o
->callback
;
280 cb(o
->context
, NULL
, eol
, o
->userdata
);
284 pa_operation_done(o
);
285 pa_operation_unref(o
);
289 pa_assert(i
.proplist
);
291 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
294 for (j
= 0; j
< i
.n_formats
; j
++)
295 pa_format_info_free(i
.formats
[j
]);
299 pa_xfree(i
.ports
[0]);
302 pa_proplist_free(i
.proplist
);
307 pa_operation
* pa_context_get_sink_info_list(pa_context
*c
, pa_sink_info_cb_t cb
, void *userdata
) {
308 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
311 pa_operation
* pa_context_get_sink_info_by_index(pa_context
*c
, uint32_t idx
, pa_sink_info_cb_t cb
, void *userdata
) {
317 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
320 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
321 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
323 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
325 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
326 pa_tagstruct_putu32(t
, idx
);
327 pa_tagstruct_puts(t
, NULL
);
328 pa_pstream_send_tagstruct(c
->pstream
, t
);
329 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
);
334 pa_operation
* pa_context_get_sink_info_by_name(pa_context
*c
, const char *name
, pa_sink_info_cb_t cb
, void *userdata
) {
340 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
343 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
344 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
345 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
347 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
349 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INFO
, &tag
);
350 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
351 pa_tagstruct_puts(t
, name
);
352 pa_pstream_send_tagstruct(c
->pstream
, t
);
353 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
);
358 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
) {
364 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
366 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
367 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
368 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
369 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
371 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
373 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
374 pa_tagstruct_putu32(t
, idx
);
375 pa_tagstruct_puts(t
, NULL
);
376 pa_tagstruct_puts(t
, port
);
377 pa_pstream_send_tagstruct(c
->pstream
, t
);
378 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
);
383 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
) {
389 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
391 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
392 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
393 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
394 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
396 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
398 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_PORT
, &tag
);
399 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
400 pa_tagstruct_puts(t
, name
);
401 pa_tagstruct_puts(t
, port
);
402 pa_pstream_send_tagstruct(c
->pstream
, t
);
403 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
);
408 /*** Source info ***/
410 static void context_get_source_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
411 pa_operation
*o
= userdata
;
418 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
420 /* For safety in case someone use fail: outside the while loop below */
426 if (command
!= PA_COMMAND_REPLY
) {
427 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
433 while (!pa_tagstruct_eof(t
)) {
440 i
.proplist
= pa_proplist_new();
441 i
.base_volume
= PA_VOLUME_NORM
;
442 i
.n_volume_steps
= PA_VOLUME_NORM
+1;
444 state
= PA_SOURCE_INVALID_STATE
;
445 i
.card
= PA_INVALID_INDEX
;
447 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
448 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
449 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
450 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
451 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
452 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
453 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
454 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
455 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
456 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0 ||
457 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
458 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
459 pa_tagstruct_getu32(t
, &flags
) < 0 ||
460 (o
->context
->version
>= 13 &&
461 (pa_tagstruct_get_proplist(t
, i
.proplist
) < 0 ||
462 pa_tagstruct_get_usec(t
, &i
.configured_latency
) < 0)) ||
463 (o
->context
->version
>= 15 &&
464 (pa_tagstruct_get_volume(t
, &i
.base_volume
) < 0 ||
465 pa_tagstruct_getu32(t
, &state
) < 0 ||
466 pa_tagstruct_getu32(t
, &i
.n_volume_steps
) < 0 ||
467 pa_tagstruct_getu32(t
, &i
.card
) < 0)) ||
468 (o
->context
->version
>= 16 &&
469 (pa_tagstruct_getu32(t
, &i
.n_ports
)))) {
474 if (o
->context
->version
>= 16) {
476 i
.ports
= pa_xnew(pa_source_port_info
*, i
.n_ports
+1);
477 i
.ports
[0] = pa_xnew(pa_source_port_info
, i
.n_ports
);
479 for (j
= 0; j
< i
.n_ports
; j
++) {
480 i
.ports
[j
] = &i
.ports
[0][j
];
482 if (pa_tagstruct_gets(t
, &i
.ports
[j
]->name
) < 0 ||
483 pa_tagstruct_gets(t
, &i
.ports
[j
]->description
) < 0 ||
484 pa_tagstruct_getu32(t
, &i
.ports
[j
]->priority
) < 0) {
489 i
.ports
[j
]->available
= PA_PORT_AVAILABLE_UNKNOWN
;
490 if (o
->context
->version
>= 24) {
492 if (pa_tagstruct_getu32(t
, &av
) < 0 || av
> PA_PORT_AVAILABLE_YES
)
494 i
.ports
[j
]->available
= av
;
501 if (pa_tagstruct_gets(t
, &ap
) < 0)
505 for (j
= 0; j
< i
.n_ports
; j
++)
506 if (pa_streq(i
.ports
[j
]->name
, ap
)) {
507 i
.active_port
= i
.ports
[j
];
513 if (o
->context
->version
>= 22) {
515 if (pa_tagstruct_getu8(t
, &n_formats
) < 0 || n_formats
< 1)
518 i
.formats
= pa_xnew0(pa_format_info
*, n_formats
);
520 for (j
= 0; j
< n_formats
; j
++) {
522 i
.formats
[j
] = pa_format_info_new();
524 if (pa_tagstruct_get_format_info(t
, i
.formats
[j
]) < 0)
530 i
.flags
= (pa_source_flags_t
) flags
;
531 i
.state
= (pa_source_state_t
) state
;
534 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
535 cb(o
->context
, &i
, 0, o
->userdata
);
539 for (j
= 0; j
< i
.n_formats
; j
++)
540 pa_format_info_free(i
.formats
[j
]);
544 pa_xfree(i
.ports
[0]);
547 pa_proplist_free(i
.proplist
);
552 pa_source_info_cb_t cb
= (pa_source_info_cb_t
) o
->callback
;
553 cb(o
->context
, NULL
, eol
, o
->userdata
);
557 pa_operation_done(o
);
558 pa_operation_unref(o
);
562 pa_assert(i
.proplist
);
564 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
567 for (j
= 0; j
< i
.n_formats
; j
++)
568 pa_format_info_free(i
.formats
[j
]);
572 pa_xfree(i
.ports
[0]);
575 pa_proplist_free(i
.proplist
);
580 pa_operation
* pa_context_get_source_info_list(pa_context
*c
, pa_source_info_cb_t cb
, void *userdata
) {
581 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
584 pa_operation
* pa_context_get_source_info_by_index(pa_context
*c
, uint32_t idx
, pa_source_info_cb_t cb
, void *userdata
) {
590 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
593 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
594 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
596 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
598 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
599 pa_tagstruct_putu32(t
, idx
);
600 pa_tagstruct_puts(t
, NULL
);
601 pa_pstream_send_tagstruct(c
->pstream
, t
);
602 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
);
607 pa_operation
* pa_context_get_source_info_by_name(pa_context
*c
, const char *name
, pa_source_info_cb_t cb
, void *userdata
) {
613 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
616 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
617 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
618 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
620 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
622 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_INFO
, &tag
);
623 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
624 pa_tagstruct_puts(t
, name
);
625 pa_pstream_send_tagstruct(c
->pstream
, t
);
626 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
);
631 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
) {
637 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
639 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
640 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
641 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
642 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
644 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
646 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
647 pa_tagstruct_putu32(t
, idx
);
648 pa_tagstruct_puts(t
, NULL
);
649 pa_tagstruct_puts(t
, port
);
650 pa_pstream_send_tagstruct(c
->pstream
, t
);
651 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
);
656 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
) {
662 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
664 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
665 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
666 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
667 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 16, PA_ERR_NOTSUPPORTED
);
669 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
671 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_PORT
, &tag
);
672 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
673 pa_tagstruct_puts(t
, name
);
674 pa_tagstruct_puts(t
, port
);
675 pa_pstream_send_tagstruct(c
->pstream
, t
);
676 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
);
681 /*** Client info ***/
683 static void context_get_client_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
684 pa_operation
*o
= userdata
;
689 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
694 if (command
!= PA_COMMAND_REPLY
) {
695 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
701 while (!pa_tagstruct_eof(t
)) {
705 i
.proplist
= pa_proplist_new();
707 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
708 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
709 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
710 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
711 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
713 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
714 pa_proplist_free(i
.proplist
);
719 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
720 cb(o
->context
, &i
, 0, o
->userdata
);
723 pa_proplist_free(i
.proplist
);
728 pa_client_info_cb_t cb
= (pa_client_info_cb_t
) o
->callback
;
729 cb(o
->context
, NULL
, eol
, o
->userdata
);
733 pa_operation_done(o
);
734 pa_operation_unref(o
);
737 pa_operation
* pa_context_get_client_info(pa_context
*c
, uint32_t idx
, pa_client_info_cb_t cb
, void *userdata
) {
743 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
746 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
747 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
748 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
750 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
752 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CLIENT_INFO
, &tag
);
753 pa_tagstruct_putu32(t
, idx
);
754 pa_pstream_send_tagstruct(c
->pstream
, t
);
755 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
);
760 pa_operation
* pa_context_get_client_info_list(pa_context
*c
, pa_client_info_cb_t cb
, void *userdata
) {
761 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
766 static void card_info_free(pa_card_info
* i
) {
768 pa_proplist_free(i
->proplist
);
770 pa_xfree(i
->profiles
);
775 for (j
= 0; j
< i
->n_ports
; j
++) {
777 if (i
->ports
[j
]->profiles
)
778 pa_xfree(i
->ports
[j
]->profiles
);
779 if (i
->ports
[j
]->proplist
)
780 pa_proplist_free(i
->ports
[j
]->proplist
);
784 pa_xfree(i
->ports
[0]);
789 static int fill_card_port_info(pa_context
*context
, pa_tagstruct
* t
, pa_card_info
* i
) {
792 if (pa_tagstruct_getu32(t
, &i
->n_ports
) < 0)
793 return -PA_ERR_PROTOCOL
;
795 if (i
->n_ports
== 0) {
800 i
->ports
= pa_xnew0(pa_card_port_info
*, i
->n_ports
+1);
801 i
->ports
[0] = pa_xnew0(pa_card_port_info
, i
->n_ports
);
803 for (j
= 0; j
< i
->n_ports
; j
++) {
806 pa_card_port_info
* port
= i
->ports
[j
] = &i
->ports
[0][j
];
808 port
->proplist
= pa_proplist_new();
810 if (pa_tagstruct_gets(t
, &port
->name
) < 0 ||
811 pa_tagstruct_gets(t
, &port
->description
) < 0 ||
812 pa_tagstruct_getu32(t
, &port
->priority
) < 0 ||
813 pa_tagstruct_getu32(t
, &available
) < 0 ||
814 pa_tagstruct_getu8(t
, &direction
) < 0 ||
815 pa_tagstruct_get_proplist(t
, port
->proplist
) < 0 ||
816 pa_tagstruct_getu32(t
, &port
->n_profiles
) < 0) {
818 return -PA_ERR_PROTOCOL
;
821 if (available
> PA_PORT_AVAILABLE_YES
||
822 direction
> PA_DIRECTION_OUTPUT
+ PA_DIRECTION_INPUT
) {
824 return -PA_ERR_PROTOCOL
;
827 port
->direction
= direction
;
828 port
->available
= available
;
830 if (port
->n_profiles
> 0) {
831 port
->profiles
= pa_xnew0(pa_card_profile_info
*, i
->n_profiles
+1);
833 for (k
= 0; k
< port
->n_profiles
; k
++) {
834 const char* profilename
;
836 if (pa_tagstruct_gets(t
, &profilename
) < 0)
837 return -PA_ERR_PROTOCOL
;
839 for (l
= 0; l
< i
->n_profiles
; l
++) {
840 if (pa_streq(i
->profiles
[l
].name
, profilename
)) {
841 port
->profiles
[k
] = &i
->profiles
[l
];
846 if (l
>= i
->n_profiles
)
847 return -PA_ERR_PROTOCOL
;
850 if (context
->version
>= 27) {
851 if (pa_tagstruct_gets64(t
, &port
->latency_offset
) < 0)
852 return -PA_ERR_PROTOCOL
;
854 port
->latency_offset
= 0;
860 static void context_get_card_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
861 pa_operation
*o
= userdata
;
867 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
872 if (command
!= PA_COMMAND_REPLY
) {
873 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
879 while (!pa_tagstruct_eof(t
)) {
885 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
886 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
887 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
888 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
889 pa_tagstruct_getu32(t
, &i
.n_profiles
) < 0) {
891 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
896 if (i
.n_profiles
> 0) {
897 i
.profiles
= pa_xnew0(pa_card_profile_info
, i
.n_profiles
+1);
899 for (j
= 0; j
< i
.n_profiles
; j
++) {
901 if (pa_tagstruct_gets(t
, &i
.profiles
[j
].name
) < 0 ||
902 pa_tagstruct_gets(t
, &i
.profiles
[j
].description
) < 0 ||
903 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sinks
) < 0 ||
904 pa_tagstruct_getu32(t
, &i
.profiles
[j
].n_sources
) < 0 ||
905 pa_tagstruct_getu32(t
, &i
.profiles
[j
].priority
) < 0) {
907 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
913 /* Terminate with an extra NULL entry, just to make sure */
914 i
.profiles
[j
].name
= NULL
;
915 i
.profiles
[j
].description
= NULL
;
918 i
.proplist
= pa_proplist_new();
920 if (pa_tagstruct_gets(t
, &ap
) < 0 ||
921 pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) {
923 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
929 for (j
= 0; j
< i
.n_profiles
; j
++)
930 if (pa_streq(i
.profiles
[j
].name
, ap
)) {
931 i
.active_profile
= &i
.profiles
[j
];
936 if (o
->context
->version
>= 26) {
937 if (fill_card_port_info(o
->context
, t
, &i
) < 0) {
938 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
945 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
946 cb(o
->context
, &i
, 0, o
->userdata
);
954 pa_card_info_cb_t cb
= (pa_card_info_cb_t
) o
->callback
;
955 cb(o
->context
, NULL
, eol
, o
->userdata
);
959 pa_operation_done(o
);
960 pa_operation_unref(o
);
963 pa_operation
* pa_context_get_card_info_by_index(pa_context
*c
, uint32_t idx
, pa_card_info_cb_t cb
, void *userdata
) {
969 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
972 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
973 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
974 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
975 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
977 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
979 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
980 pa_tagstruct_putu32(t
, idx
);
981 pa_tagstruct_puts(t
, NULL
);
982 pa_pstream_send_tagstruct(c
->pstream
, t
);
983 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
);
988 pa_operation
* pa_context_get_card_info_by_name(pa_context
*c
, const char*name
, pa_card_info_cb_t cb
, void *userdata
) {
994 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
997 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
998 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
999 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1000 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
1002 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1004 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_CARD_INFO
, &tag
);
1005 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1006 pa_tagstruct_puts(t
, name
);
1007 pa_pstream_send_tagstruct(c
->pstream
, t
);
1008 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
);
1013 pa_operation
* pa_context_get_card_info_list(pa_context
*c
, pa_card_info_cb_t cb
, void *userdata
) {
1014 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
1016 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CARD_INFO_LIST
, context_get_card_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1019 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
) {
1025 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1027 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1028 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1029 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1030 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
1032 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1034 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
1035 pa_tagstruct_putu32(t
, idx
);
1036 pa_tagstruct_puts(t
, NULL
);
1037 pa_tagstruct_puts(t
, profile
);
1038 pa_pstream_send_tagstruct(c
->pstream
, t
);
1039 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
);
1044 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
) {
1050 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1052 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1053 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1054 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1055 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 15, PA_ERR_NOTSUPPORTED
);
1057 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1059 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_CARD_PROFILE
, &tag
);
1060 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1061 pa_tagstruct_puts(t
, name
);
1062 pa_tagstruct_puts(t
, profile
);
1063 pa_pstream_send_tagstruct(c
->pstream
, t
);
1064 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
);
1069 /*** Module info ***/
1071 static void context_get_module_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1072 pa_operation
*o
= userdata
;
1077 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1082 if (command
!= PA_COMMAND_REPLY
) {
1083 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
1089 while (!pa_tagstruct_eof(t
)) {
1091 bool auto_unload
= false;
1094 i
.proplist
= pa_proplist_new();
1096 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1097 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1098 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
1099 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
1100 (o
->context
->version
< 15 && pa_tagstruct_get_boolean(t
, &auto_unload
) < 0) ||
1101 (o
->context
->version
>= 15 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
1102 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1106 i
.auto_unload
= (int) auto_unload
;
1109 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
1110 cb(o
->context
, &i
, 0, o
->userdata
);
1113 pa_proplist_free(i
.proplist
);
1118 pa_module_info_cb_t cb
= (pa_module_info_cb_t
) o
->callback
;
1119 cb(o
->context
, NULL
, eol
, o
->userdata
);
1123 pa_operation_done(o
);
1124 pa_operation_unref(o
);
1127 pa_operation
* pa_context_get_module_info(pa_context
*c
, uint32_t idx
, pa_module_info_cb_t cb
, void *userdata
) {
1133 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1136 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1137 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1138 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1140 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1142 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_MODULE_INFO
, &tag
);
1143 pa_tagstruct_putu32(t
, idx
);
1144 pa_pstream_send_tagstruct(c
->pstream
, t
);
1145 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
);
1150 pa_operation
* pa_context_get_module_info_list(pa_context
*c
, pa_module_info_cb_t cb
, void *userdata
) {
1151 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1154 /*** Sink input info ***/
1156 static void context_get_sink_input_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1157 pa_operation
*o
= userdata
;
1162 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1167 if (command
!= PA_COMMAND_REPLY
) {
1168 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
1174 while (!pa_tagstruct_eof(t
)) {
1175 pa_sink_input_info i
;
1176 bool mute
= false, corked
= false, has_volume
= false, volume_writable
= true;
1179 i
.proplist
= pa_proplist_new();
1180 i
.format
= pa_format_info_new();
1182 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1183 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1184 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1185 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1186 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
1187 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1188 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1189 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1190 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1191 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0 ||
1192 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1193 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1194 (o
->context
->version
>= 11 && pa_tagstruct_get_boolean(t
, &mute
) < 0) ||
1195 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1196 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1197 (o
->context
->version
>= 20 && (pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1198 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0)) ||
1199 (o
->context
->version
>= 21 && pa_tagstruct_get_format_info(t
, i
.format
) < 0)) {
1201 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1202 pa_proplist_free(i
.proplist
);
1203 pa_format_info_free(i
.format
);
1207 i
.mute
= (int) mute
;
1208 i
.corked
= (int) corked
;
1209 i
.has_volume
= (int) has_volume
;
1210 i
.volume_writable
= (int) volume_writable
;
1213 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1214 cb(o
->context
, &i
, 0, o
->userdata
);
1217 pa_proplist_free(i
.proplist
);
1218 pa_format_info_free(i
.format
);
1223 pa_sink_input_info_cb_t cb
= (pa_sink_input_info_cb_t
) o
->callback
;
1224 cb(o
->context
, NULL
, eol
, o
->userdata
);
1228 pa_operation_done(o
);
1229 pa_operation_unref(o
);
1232 pa_operation
* pa_context_get_sink_input_info(pa_context
*c
, uint32_t idx
, pa_sink_input_info_cb_t cb
, void *userdata
) {
1238 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1241 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1242 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1243 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1245 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1247 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO
, &tag
);
1248 pa_tagstruct_putu32(t
, idx
);
1249 pa_pstream_send_tagstruct(c
->pstream
, t
);
1250 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
);
1255 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
) {
1256 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
);
1259 /*** Source output info ***/
1261 static void context_get_source_output_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1262 pa_operation
*o
= userdata
;
1267 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1272 if (command
!= PA_COMMAND_REPLY
) {
1273 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
1279 while (!pa_tagstruct_eof(t
)) {
1280 pa_source_output_info i
;
1281 bool mute
= false, corked
= false, has_volume
= false, volume_writable
= true;
1284 i
.proplist
= pa_proplist_new();
1285 i
.format
= pa_format_info_new();
1287 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1288 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1289 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
1290 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
1291 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
1292 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1293 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1294 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
1295 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0 ||
1296 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
1297 pa_tagstruct_gets(t
, &i
.driver
) < 0 ||
1298 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0) ||
1299 (o
->context
->version
>= 19 && pa_tagstruct_get_boolean(t
, &corked
) < 0) ||
1300 (o
->context
->version
>= 22 && (pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1301 pa_tagstruct_get_boolean(t
, &mute
) < 0 ||
1302 pa_tagstruct_get_boolean(t
, &has_volume
) < 0 ||
1303 pa_tagstruct_get_boolean(t
, &volume_writable
) < 0 ||
1304 pa_tagstruct_get_format_info(t
, i
.format
) < 0))) {
1306 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1307 pa_proplist_free(i
.proplist
);
1308 pa_format_info_free(i
.format
);
1312 i
.mute
= (int) mute
;
1313 i
.corked
= (int) corked
;
1314 i
.has_volume
= (int) has_volume
;
1315 i
.volume_writable
= (int) volume_writable
;
1318 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1319 cb(o
->context
, &i
, 0, o
->userdata
);
1322 pa_proplist_free(i
.proplist
);
1323 pa_format_info_free(i
.format
);
1328 pa_source_output_info_cb_t cb
= (pa_source_output_info_cb_t
) o
->callback
;
1329 cb(o
->context
, NULL
, eol
, o
->userdata
);
1333 pa_operation_done(o
);
1334 pa_operation_unref(o
);
1337 pa_operation
* pa_context_get_source_output_info(pa_context
*c
, uint32_t idx
, pa_source_output_info_cb_t cb
, void *userdata
) {
1343 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1346 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1347 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1348 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1350 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1352 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
, &tag
);
1353 pa_tagstruct_putu32(t
, idx
);
1354 pa_pstream_send_tagstruct(c
->pstream
, t
);
1355 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
);
1360 pa_operation
* pa_context_get_source_output_info_list(pa_context
*c
, pa_source_output_info_cb_t cb
, void *userdata
) {
1361 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
);
1364 /*** Volume manipulation ***/
1366 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
) {
1372 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1375 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1376 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1377 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1379 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1381 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1382 pa_tagstruct_putu32(t
, idx
);
1383 pa_tagstruct_puts(t
, NULL
);
1384 pa_tagstruct_put_cvolume(t
, volume
);
1385 pa_pstream_send_tagstruct(c
->pstream
, t
);
1386 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
);
1391 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
) {
1397 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1401 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1402 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1403 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1404 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1406 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1408 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_VOLUME
, &tag
);
1409 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1410 pa_tagstruct_puts(t
, name
);
1411 pa_tagstruct_put_cvolume(t
, volume
);
1412 pa_pstream_send_tagstruct(c
->pstream
, t
);
1413 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
);
1418 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
) {
1424 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1426 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1427 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1429 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1431 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1432 pa_tagstruct_putu32(t
, idx
);
1433 pa_tagstruct_puts(t
, NULL
);
1434 pa_tagstruct_put_boolean(t
, mute
);
1435 pa_pstream_send_tagstruct(c
->pstream
, t
);
1436 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
);
1441 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
) {
1447 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1450 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1451 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1452 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1454 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1456 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_MUTE
, &tag
);
1457 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1458 pa_tagstruct_puts(t
, name
);
1459 pa_tagstruct_put_boolean(t
, mute
);
1460 pa_pstream_send_tagstruct(c
->pstream
, t
);
1461 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
);
1466 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
) {
1472 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1475 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1476 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1477 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1478 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1480 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1482 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_VOLUME
, &tag
);
1483 pa_tagstruct_putu32(t
, idx
);
1484 pa_tagstruct_put_cvolume(t
, volume
);
1485 pa_pstream_send_tagstruct(c
->pstream
, t
);
1486 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
);
1491 pa_operation
* pa_context_set_sink_input_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1497 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1499 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1500 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1501 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1502 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
1504 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1506 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SINK_INPUT_MUTE
, &tag
);
1507 pa_tagstruct_putu32(t
, idx
);
1508 pa_tagstruct_put_boolean(t
, mute
);
1509 pa_pstream_send_tagstruct(c
->pstream
, t
);
1510 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
);
1515 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
) {
1521 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1524 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1525 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1526 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1528 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1530 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1531 pa_tagstruct_putu32(t
, idx
);
1532 pa_tagstruct_puts(t
, NULL
);
1533 pa_tagstruct_put_cvolume(t
, volume
);
1534 pa_pstream_send_tagstruct(c
->pstream
, t
);
1535 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
);
1540 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
) {
1546 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1550 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1551 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1552 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1553 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1555 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1557 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_VOLUME
, &tag
);
1558 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1559 pa_tagstruct_puts(t
, name
);
1560 pa_tagstruct_put_cvolume(t
, volume
);
1561 pa_pstream_send_tagstruct(c
->pstream
, t
);
1562 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
);
1567 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
) {
1573 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1575 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1576 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1578 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1580 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1581 pa_tagstruct_putu32(t
, idx
);
1582 pa_tagstruct_puts(t
, NULL
);
1583 pa_tagstruct_put_boolean(t
, mute
);
1584 pa_pstream_send_tagstruct(c
->pstream
, t
);
1585 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
);
1590 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
) {
1596 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1599 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1600 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1601 PA_CHECK_VALIDITY_RETURN_NULL(c
, !name
|| *name
, PA_ERR_INVALID
);
1603 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1605 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_MUTE
, &tag
);
1606 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1607 pa_tagstruct_puts(t
, name
);
1608 pa_tagstruct_put_boolean(t
, mute
);
1609 pa_pstream_send_tagstruct(c
->pstream
, t
);
1610 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
);
1615 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
) {
1621 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1624 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1625 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1626 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1627 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1628 PA_CHECK_VALIDITY_RETURN_NULL(c
, pa_cvolume_valid(volume
), PA_ERR_INVALID
);
1630 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1632 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME
, &tag
);
1633 pa_tagstruct_putu32(t
, idx
);
1634 pa_tagstruct_put_cvolume(t
, volume
);
1635 pa_pstream_send_tagstruct(c
->pstream
, t
);
1636 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
);
1641 pa_operation
* pa_context_set_source_output_mute(pa_context
*c
, uint32_t idx
, int mute
, pa_context_success_cb_t cb
, void *userdata
) {
1647 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1649 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1650 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1651 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1652 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 22, PA_ERR_NOTSUPPORTED
);
1654 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1656 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE
, &tag
);
1657 pa_tagstruct_putu32(t
, idx
);
1658 pa_tagstruct_put_boolean(t
, mute
);
1659 pa_pstream_send_tagstruct(c
->pstream
, t
);
1660 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
);
1665 /** Sample Cache **/
1667 static void context_get_sample_info_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1668 pa_operation
*o
= userdata
;
1673 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1678 if (command
!= PA_COMMAND_REPLY
) {
1679 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
1685 while (!pa_tagstruct_eof(t
)) {
1690 i
.proplist
= pa_proplist_new();
1692 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
1693 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
1694 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
1695 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
1696 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
1697 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
1698 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
1699 pa_tagstruct_get_boolean(t
, &lazy
) < 0 ||
1700 pa_tagstruct_gets(t
, &i
.filename
) < 0 ||
1701 (o
->context
->version
>= 13 && pa_tagstruct_get_proplist(t
, i
.proplist
) < 0)) {
1703 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1707 i
.lazy
= (int) lazy
;
1710 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1711 cb(o
->context
, &i
, 0, o
->userdata
);
1714 pa_proplist_free(i
.proplist
);
1719 pa_sample_info_cb_t cb
= (pa_sample_info_cb_t
) o
->callback
;
1720 cb(o
->context
, NULL
, eol
, o
->userdata
);
1724 pa_operation_done(o
);
1725 pa_operation_unref(o
);
1728 pa_operation
* pa_context_get_sample_info_by_name(pa_context
*c
, const char *name
, pa_sample_info_cb_t cb
, void *userdata
) {
1734 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1737 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1738 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1739 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1741 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1743 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1744 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1745 pa_tagstruct_puts(t
, name
);
1746 pa_pstream_send_tagstruct(c
->pstream
, t
);
1747 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
);
1752 pa_operation
* pa_context_get_sample_info_by_index(pa_context
*c
, uint32_t idx
, pa_sample_info_cb_t cb
, void *userdata
) {
1758 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1761 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1762 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1763 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1765 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1767 t
= pa_tagstruct_command(c
, PA_COMMAND_GET_SAMPLE_INFO
, &tag
);
1768 pa_tagstruct_putu32(t
, idx
);
1769 pa_tagstruct_puts(t
, NULL
);
1770 pa_pstream_send_tagstruct(c
->pstream
, t
);
1771 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
);
1776 pa_operation
* pa_context_get_sample_info_list(pa_context
*c
, pa_sample_info_cb_t cb
, void *userdata
) {
1777 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, (pa_operation_cb_t
) cb
, userdata
);
1780 static pa_operation
* command_kill(pa_context
*c
, uint32_t command
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1786 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1788 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1789 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1790 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1792 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1794 t
= pa_tagstruct_command(c
, command
, &tag
);
1795 pa_tagstruct_putu32(t
, idx
);
1796 pa_pstream_send_tagstruct(c
->pstream
, t
);
1797 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
);
1802 pa_operation
* pa_context_kill_client(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1803 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, idx
, cb
, userdata
);
1806 pa_operation
* pa_context_kill_sink_input(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1807 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, idx
, cb
, userdata
);
1810 pa_operation
* pa_context_kill_source_output(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1811 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, idx
, cb
, userdata
);
1814 static void context_index_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1815 pa_operation
*o
= userdata
;
1820 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
1825 if (command
!= PA_COMMAND_REPLY
) {
1826 if (pa_context_handle_error(o
->context
, command
, t
, false) < 0)
1829 idx
= PA_INVALID_INDEX
;
1830 } else if (pa_tagstruct_getu32(t
, &idx
) ||
1831 !pa_tagstruct_eof(t
)) {
1832 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
1837 pa_context_index_cb_t cb
= (pa_context_index_cb_t
) o
->callback
;
1838 cb(o
->context
, idx
, o
->userdata
);
1842 pa_operation_done(o
);
1843 pa_operation_unref(o
);
1846 pa_operation
* pa_context_load_module(pa_context
*c
, const char*name
, const char *argument
, pa_context_index_cb_t cb
, void *userdata
) {
1852 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1854 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1855 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1856 PA_CHECK_VALIDITY_RETURN_NULL(c
, name
&& *name
, PA_ERR_INVALID
);
1858 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1860 t
= pa_tagstruct_command(c
, PA_COMMAND_LOAD_MODULE
, &tag
);
1861 pa_tagstruct_puts(t
, name
);
1862 pa_tagstruct_puts(t
, argument
);
1863 pa_pstream_send_tagstruct(c
->pstream
, t
);
1864 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_index_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
1869 pa_operation
* pa_context_unload_module(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void *userdata
) {
1870 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, idx
, cb
, userdata
);
1873 pa_operation
* pa_context_set_port_latency_offset(pa_context
*c
, const char *card_name
, const char *port_name
, int64_t offset
, pa_context_success_cb_t cb
, void *userdata
) {
1879 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1881 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1882 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1883 PA_CHECK_VALIDITY_RETURN_NULL(c
, card_name
&& *card_name
, PA_ERR_INVALID
);
1884 PA_CHECK_VALIDITY_RETURN_NULL(c
, port_name
&& *port_name
, PA_ERR_INVALID
);
1885 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 27, PA_ERR_NOTSUPPORTED
);
1887 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1889 t
= pa_tagstruct_command(c
, PA_COMMAND_SET_PORT_LATENCY_OFFSET
, &tag
);
1890 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1891 pa_tagstruct_puts(t
, card_name
);
1892 pa_tagstruct_puts(t
, port_name
);
1893 pa_tagstruct_puts64(t
, offset
);
1894 pa_pstream_send_tagstruct(c
->pstream
, t
);
1895 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
);
1900 /*** Autoload stuff ***/
1902 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name
, "Module auto-loading no longer supported.");
1904 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
) {
1907 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1909 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1912 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index
, "Module auto-loading no longer supported.");
1914 pa_operation
* pa_context_get_autoload_info_by_index(pa_context
*c
, uint32_t idx
, pa_autoload_info_cb_t cb
, void *userdata
) {
1916 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1918 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1921 PA_WARN_REFERENCE(pa_context_get_autoload_info_list
, "Module auto-loading no longer supported.");
1923 pa_operation
* pa_context_get_autoload_info_list(pa_context
*c
, pa_autoload_info_cb_t cb
, void *userdata
) {
1925 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1927 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1930 PA_WARN_REFERENCE(pa_context_add_autoload
, "Module auto-loading no longer supported.");
1932 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
) {
1934 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1936 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1939 PA_WARN_REFERENCE(pa_context_remove_autoload_by_name
, "Module auto-loading no longer supported.");
1941 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
) {
1943 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1945 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1948 PA_WARN_REFERENCE(pa_context_remove_autoload_by_index
, "Module auto-loading no longer supported.");
1950 pa_operation
* pa_context_remove_autoload_by_index(pa_context
*c
, uint32_t idx
, pa_context_success_cb_t cb
, void* userdata
) {
1952 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1954 PA_FAIL_RETURN_NULL(c
, PA_ERR_OBSOLETE
);
1957 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
) {
1963 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1965 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1966 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1967 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1968 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1969 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_name
&& *sink_name
, PA_ERR_INVALID
);
1971 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1973 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
1974 pa_tagstruct_putu32(t
, idx
);
1975 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
1976 pa_tagstruct_puts(t
, sink_name
);
1977 pa_pstream_send_tagstruct(c
->pstream
, t
);
1978 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
);
1983 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
) {
1989 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
1991 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
1992 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
1993 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
1994 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1995 PA_CHECK_VALIDITY_RETURN_NULL(c
, sink_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
1997 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
1999 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SINK_INPUT
, &tag
);
2000 pa_tagstruct_putu32(t
, idx
);
2001 pa_tagstruct_putu32(t
, sink_idx
);
2002 pa_tagstruct_puts(t
, NULL
);
2003 pa_pstream_send_tagstruct(c
->pstream
, t
);
2004 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
);
2009 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
) {
2015 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2017 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2018 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2019 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
2020 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
2021 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_name
&& *source_name
, PA_ERR_INVALID
);
2023 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2025 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
2026 pa_tagstruct_putu32(t
, idx
);
2027 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
2028 pa_tagstruct_puts(t
, source_name
);
2029 pa_pstream_send_tagstruct(c
->pstream
, t
);
2030 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
);
2035 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
) {
2041 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2043 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2044 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2045 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 10, PA_ERR_NOTSUPPORTED
);
2046 PA_CHECK_VALIDITY_RETURN_NULL(c
, idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
2047 PA_CHECK_VALIDITY_RETURN_NULL(c
, source_idx
!= PA_INVALID_INDEX
, PA_ERR_INVALID
);
2049 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2051 t
= pa_tagstruct_command(c
, PA_COMMAND_MOVE_SOURCE_OUTPUT
, &tag
);
2052 pa_tagstruct_putu32(t
, idx
);
2053 pa_tagstruct_putu32(t
, source_idx
);
2054 pa_tagstruct_puts(t
, NULL
);
2055 pa_pstream_send_tagstruct(c
->pstream
, t
);
2056 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
);
2061 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
) {
2067 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2069 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2070 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2071 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2072 PA_CHECK_VALIDITY_RETURN_NULL(c
, !sink_name
|| *sink_name
, PA_ERR_INVALID
);
2074 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2076 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
2077 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
2078 pa_tagstruct_puts(t
, sink_name
);
2079 pa_tagstruct_put_boolean(t
, suspend
);
2080 pa_pstream_send_tagstruct(c
->pstream
, t
);
2081 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
);
2086 pa_operation
* pa_context_suspend_sink_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
2092 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2094 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2095 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2096 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2098 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2100 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SINK
, &tag
);
2101 pa_tagstruct_putu32(t
, idx
);
2102 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
2103 pa_tagstruct_put_boolean(t
, suspend
);
2104 pa_pstream_send_tagstruct(c
->pstream
, t
);
2105 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
);
2110 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
) {
2116 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2118 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2119 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2120 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2121 PA_CHECK_VALIDITY_RETURN_NULL(c
, !source_name
|| *source_name
, PA_ERR_INVALID
);
2123 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2125 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
2126 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
2127 pa_tagstruct_puts(t
, source_name
);
2128 pa_tagstruct_put_boolean(t
, suspend
);
2129 pa_pstream_send_tagstruct(c
->pstream
, t
);
2130 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
);
2135 pa_operation
* pa_context_suspend_source_by_index(pa_context
*c
, uint32_t idx
, int suspend
, pa_context_success_cb_t cb
, void* userdata
) {
2141 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
2143 PA_CHECK_VALIDITY_RETURN_NULL(c
, !pa_detect_fork(), PA_ERR_FORKED
);
2144 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
2145 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 11, PA_ERR_NOTSUPPORTED
);
2147 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
2149 t
= pa_tagstruct_command(c
, PA_COMMAND_SUSPEND_SOURCE
, &tag
);
2150 pa_tagstruct_putu32(t
, idx
);
2151 pa_tagstruct_puts(t
, idx
== PA_INVALID_INDEX
? "" : NULL
);
2152 pa_tagstruct_put_boolean(t
, suspend
);
2153 pa_pstream_send_tagstruct(c
->pstream
, t
);
2154 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
);