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 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[0][j].available = PA_PORT_AVAILABLE_UNKNOWN;
215 if (o->context->version >= 24) {
217 if (pa_tagstruct_getu32(t, &av) < 0 || av > PA_PORT_AVAILABLE_YES)
219 i.ports[0][j].available = av;
222 i.ports[j] = &i.ports[0][j];
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 if (pa_tagstruct_gets(t, &i.ports[0][j].name) < 0 ||
481 pa_tagstruct_gets(t, &i.ports[0][j].description) < 0 ||
482 pa_tagstruct_getu32(t, &i.ports[0][j].priority) < 0) {
487 i.ports[0][j].available = PA_PORT_AVAILABLE_UNKNOWN;
488 if (o->context->version >= 24) {
490 if (pa_tagstruct_getu32(t, &av) < 0 || av > PA_PORT_AVAILABLE_YES)
492 i.ports[0][j].available = av;
495 i.ports[j] = &i.ports[0][j];
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)
769 pa_proplist_free(i->proplist);
771 pa_xfree(i->profiles);
776 for (j = 0; j < i->n_ports; j++) {
778 if (i->ports[j]->profiles)
779 pa_xfree(i->ports[j]->profiles);
780 if (i->ports[j]->proplist)
781 pa_proplist_free(i->ports[j]->proplist);
785 pa_xfree(i->ports[0]);
790 static int fill_card_port_info(pa_tagstruct* t, pa_card_info* i)
794 if (pa_tagstruct_getu32(t, &i->n_ports) < 0)
795 return -PA_ERR_PROTOCOL;
797 if (i->n_ports == 0) {
802 i->ports = pa_xnew0(pa_card_port_info*, i->n_ports+1);
803 i->ports[0] = pa_xnew0(pa_card_port_info, i->n_ports);
805 for (j = 0; j < i->n_ports; j++) {
808 pa_card_port_info* port = i->ports[j] = &i->ports[0][j];
810 port->proplist = pa_proplist_new();
812 if (pa_tagstruct_gets(t, &port->name) < 0 ||
813 pa_tagstruct_gets(t, &port->description) < 0 ||
814 pa_tagstruct_getu32(t, &port->priority) < 0 ||
815 pa_tagstruct_getu32(t, &available) < 0 ||
816 pa_tagstruct_getu8(t, &direction) < 0 ||
817 pa_tagstruct_get_proplist(t, port->proplist) < 0 ||
818 pa_tagstruct_getu32(t, &port->n_profiles) < 0) {
820 return -PA_ERR_PROTOCOL;
823 if (available > PA_PORT_AVAILABLE_YES ||
824 direction > PA_DIRECTION_OUTPUT + PA_DIRECTION_INPUT) {
826 return -PA_ERR_PROTOCOL;
829 port->direction = direction;
830 port->available = available;
832 if (port->n_profiles > 0) {
833 port->profiles = pa_xnew0(pa_card_profile_info*, i->n_profiles+1);
835 for (k = 0; k < port->n_profiles; k++) {
836 const char* profilename;
838 if (pa_tagstruct_gets(t, &profilename) < 0)
839 return -PA_ERR_PROTOCOL;
841 for (l = 0; l < i->n_profiles; l++) {
842 if (pa_streq(i->profiles[l].name, profilename)) {
843 port->profiles[k] = &i->profiles[l];
848 if (l >= i->n_profiles)
849 return -PA_ERR_PROTOCOL;
857 static void context_get_card_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
858 pa_operation *o = userdata;
864 pa_assert(PA_REFCNT_VALUE(o) >= 1);
869 if (command != PA_COMMAND_REPLY) {
870 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
876 while (!pa_tagstruct_eof(t)) {
882 if (pa_tagstruct_getu32(t, &i.index) < 0 ||
883 pa_tagstruct_gets(t, &i.name) < 0 ||
884 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
885 pa_tagstruct_gets(t, &i.driver) < 0 ||
886 pa_tagstruct_getu32(t, &i.n_profiles) < 0) {
888 pa_context_fail(o->context, PA_ERR_PROTOCOL);
893 if (i.n_profiles > 0) {
894 i.profiles = pa_xnew0(pa_card_profile_info, i.n_profiles+1);
896 for (j = 0; j < i.n_profiles; j++) {
898 if (pa_tagstruct_gets(t, &i.profiles[j].name) < 0 ||
899 pa_tagstruct_gets(t, &i.profiles[j].description) < 0 ||
900 pa_tagstruct_getu32(t, &i.profiles[j].n_sinks) < 0 ||
901 pa_tagstruct_getu32(t, &i.profiles[j].n_sources) < 0 ||
902 pa_tagstruct_getu32(t, &i.profiles[j].priority) < 0) {
904 pa_context_fail(o->context, PA_ERR_PROTOCOL);
910 /* Terminate with an extra NULL entry, just to make sure */
911 i.profiles[j].name = NULL;
912 i.profiles[j].description = NULL;
915 i.proplist = pa_proplist_new();
917 if (pa_tagstruct_gets(t, &ap) < 0 ||
918 pa_tagstruct_get_proplist(t, i.proplist) < 0) {
920 pa_context_fail(o->context, PA_ERR_PROTOCOL);
926 for (j = 0; j < i.n_profiles; j++)
927 if (pa_streq(i.profiles[j].name, ap)) {
928 i.active_profile = &i.profiles[j];
933 if (o->context->version >= 26) {
934 if (fill_card_port_info(t, &i) < 0) {
935 pa_context_fail(o->context, PA_ERR_PROTOCOL);
942 pa_card_info_cb_t cb = (pa_card_info_cb_t) o->callback;
943 cb(o->context, &i, 0, o->userdata);
951 pa_card_info_cb_t cb = (pa_card_info_cb_t) o->callback;
952 cb(o->context, NULL, eol, o->userdata);
956 pa_operation_done(o);
957 pa_operation_unref(o);
960 pa_operation* pa_context_get_card_info_by_index(pa_context *c, uint32_t idx, pa_card_info_cb_t cb, void *userdata) {
966 pa_assert(PA_REFCNT_VALUE(c) >= 1);
969 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
970 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
971 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
972 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 15, PA_ERR_NOTSUPPORTED);
974 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
976 t = pa_tagstruct_command(c, PA_COMMAND_GET_CARD_INFO, &tag);
977 pa_tagstruct_putu32(t, idx);
978 pa_tagstruct_puts(t, NULL);
979 pa_pstream_send_tagstruct(c->pstream, t);
980 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);
985 pa_operation* pa_context_get_card_info_by_name(pa_context *c, const char*name, pa_card_info_cb_t cb, void *userdata) {
991 pa_assert(PA_REFCNT_VALUE(c) >= 1);
994 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
995 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
996 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
997 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 15, PA_ERR_NOTSUPPORTED);
999 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1001 t = pa_tagstruct_command(c, PA_COMMAND_GET_CARD_INFO, &tag);
1002 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1003 pa_tagstruct_puts(t, name);
1004 pa_pstream_send_tagstruct(c->pstream, t);
1005 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);
1010 pa_operation* pa_context_get_card_info_list(pa_context *c, pa_card_info_cb_t cb, void *userdata) {
1011 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 15, PA_ERR_NOTSUPPORTED);
1013 return pa_context_send_simple_command(c, PA_COMMAND_GET_CARD_INFO_LIST, context_get_card_info_callback, (pa_operation_cb_t) cb, userdata);
1016 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) {
1022 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1024 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1025 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1026 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1027 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 15, PA_ERR_NOTSUPPORTED);
1029 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1031 t = pa_tagstruct_command(c, PA_COMMAND_SET_CARD_PROFILE, &tag);
1032 pa_tagstruct_putu32(t, idx);
1033 pa_tagstruct_puts(t, NULL);
1034 pa_tagstruct_puts(t, profile);
1035 pa_pstream_send_tagstruct(c->pstream, t);
1036 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);
1041 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) {
1047 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1049 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1050 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1051 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
1052 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 15, PA_ERR_NOTSUPPORTED);
1054 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1056 t = pa_tagstruct_command(c, PA_COMMAND_SET_CARD_PROFILE, &tag);
1057 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1058 pa_tagstruct_puts(t, name);
1059 pa_tagstruct_puts(t, profile);
1060 pa_pstream_send_tagstruct(c->pstream, t);
1061 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);
1066 /*** Module info ***/
1068 static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
1069 pa_operation *o = userdata;
1074 pa_assert(PA_REFCNT_VALUE(o) >= 1);
1079 if (command != PA_COMMAND_REPLY) {
1080 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
1086 while (!pa_tagstruct_eof(t)) {
1088 pa_bool_t auto_unload = FALSE;
1091 i.proplist = pa_proplist_new();
1093 if (pa_tagstruct_getu32(t, &i.index) < 0 ||
1094 pa_tagstruct_gets(t, &i.name) < 0 ||
1095 pa_tagstruct_gets(t, &i.argument) < 0 ||
1096 pa_tagstruct_getu32(t, &i.n_used) < 0 ||
1097 (o->context->version < 15 && pa_tagstruct_get_boolean(t, &auto_unload) < 0) ||
1098 (o->context->version >= 15 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
1099 pa_context_fail(o->context, PA_ERR_PROTOCOL);
1103 i.auto_unload = (int) auto_unload;
1106 pa_module_info_cb_t cb = (pa_module_info_cb_t) o->callback;
1107 cb(o->context, &i, 0, o->userdata);
1110 pa_proplist_free(i.proplist);
1115 pa_module_info_cb_t cb = (pa_module_info_cb_t) o->callback;
1116 cb(o->context, NULL, eol, o->userdata);
1120 pa_operation_done(o);
1121 pa_operation_unref(o);
1124 pa_operation* pa_context_get_module_info(pa_context *c, uint32_t idx, pa_module_info_cb_t cb, void *userdata) {
1130 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1133 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1134 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1135 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1137 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1139 t = pa_tagstruct_command(c, PA_COMMAND_GET_MODULE_INFO, &tag);
1140 pa_tagstruct_putu32(t, idx);
1141 pa_pstream_send_tagstruct(c->pstream, t);
1142 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);
1147 pa_operation* pa_context_get_module_info_list(pa_context *c, pa_module_info_cb_t cb, void *userdata) {
1148 return pa_context_send_simple_command(c, PA_COMMAND_GET_MODULE_INFO_LIST, context_get_module_info_callback, (pa_operation_cb_t) cb, userdata);
1151 /*** Sink input info ***/
1153 static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
1154 pa_operation *o = userdata;
1159 pa_assert(PA_REFCNT_VALUE(o) >= 1);
1164 if (command != PA_COMMAND_REPLY) {
1165 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
1171 while (!pa_tagstruct_eof(t)) {
1172 pa_sink_input_info i;
1173 pa_bool_t mute = FALSE, corked = FALSE, has_volume = FALSE, volume_writable = TRUE;
1176 i.proplist = pa_proplist_new();
1177 i.format = pa_format_info_new();
1179 if (pa_tagstruct_getu32(t, &i.index) < 0 ||
1180 pa_tagstruct_gets(t, &i.name) < 0 ||
1181 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
1182 pa_tagstruct_getu32(t, &i.client) < 0 ||
1183 pa_tagstruct_getu32(t, &i.sink) < 0 ||
1184 pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
1185 pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
1186 pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
1187 pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
1188 pa_tagstruct_get_usec(t, &i.sink_usec) < 0 ||
1189 pa_tagstruct_gets(t, &i.resample_method) < 0 ||
1190 pa_tagstruct_gets(t, &i.driver) < 0 ||
1191 (o->context->version >= 11 && pa_tagstruct_get_boolean(t, &mute) < 0) ||
1192 (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0) ||
1193 (o->context->version >= 19 && pa_tagstruct_get_boolean(t, &corked) < 0) ||
1194 (o->context->version >= 20 && (pa_tagstruct_get_boolean(t, &has_volume) < 0 ||
1195 pa_tagstruct_get_boolean(t, &volume_writable) < 0)) ||
1196 (o->context->version >= 21 && pa_tagstruct_get_format_info(t, i.format) < 0)) {
1198 pa_context_fail(o->context, PA_ERR_PROTOCOL);
1199 pa_proplist_free(i.proplist);
1200 pa_format_info_free(i.format);
1204 i.mute = (int) mute;
1205 i.corked = (int) corked;
1206 i.has_volume = (int) has_volume;
1207 i.volume_writable = (int) volume_writable;
1210 pa_sink_input_info_cb_t cb = (pa_sink_input_info_cb_t) o->callback;
1211 cb(o->context, &i, 0, o->userdata);
1214 pa_proplist_free(i.proplist);
1215 pa_format_info_free(i.format);
1220 pa_sink_input_info_cb_t cb = (pa_sink_input_info_cb_t) o->callback;
1221 cb(o->context, NULL, eol, o->userdata);
1225 pa_operation_done(o);
1226 pa_operation_unref(o);
1229 pa_operation* pa_context_get_sink_input_info(pa_context *c, uint32_t idx, pa_sink_input_info_cb_t cb, void *userdata) {
1235 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1238 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1239 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1240 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1242 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1244 t = pa_tagstruct_command(c, PA_COMMAND_GET_SINK_INPUT_INFO, &tag);
1245 pa_tagstruct_putu32(t, idx);
1246 pa_pstream_send_tagstruct(c->pstream, t);
1247 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);
1252 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) {
1253 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);
1256 /*** Source output info ***/
1258 static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
1259 pa_operation *o = userdata;
1264 pa_assert(PA_REFCNT_VALUE(o) >= 1);
1269 if (command != PA_COMMAND_REPLY) {
1270 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
1276 while (!pa_tagstruct_eof(t)) {
1277 pa_source_output_info i;
1278 pa_bool_t mute = FALSE, corked = FALSE, has_volume = FALSE, volume_writable = TRUE;
1281 i.proplist = pa_proplist_new();
1282 i.format = pa_format_info_new();
1284 if (pa_tagstruct_getu32(t, &i.index) < 0 ||
1285 pa_tagstruct_gets(t, &i.name) < 0 ||
1286 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
1287 pa_tagstruct_getu32(t, &i.client) < 0 ||
1288 pa_tagstruct_getu32(t, &i.source) < 0 ||
1289 pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
1290 pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
1291 pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
1292 pa_tagstruct_get_usec(t, &i.source_usec) < 0 ||
1293 pa_tagstruct_gets(t, &i.resample_method) < 0 ||
1294 pa_tagstruct_gets(t, &i.driver) < 0 ||
1295 (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0) ||
1296 (o->context->version >= 19 && pa_tagstruct_get_boolean(t, &corked) < 0) ||
1297 (o->context->version >= 22 && (pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
1298 pa_tagstruct_get_boolean(t, &mute) < 0 ||
1299 pa_tagstruct_get_boolean(t, &has_volume) < 0 ||
1300 pa_tagstruct_get_boolean(t, &volume_writable) < 0 ||
1301 pa_tagstruct_get_format_info(t, i.format) < 0))) {
1303 pa_context_fail(o->context, PA_ERR_PROTOCOL);
1304 pa_proplist_free(i.proplist);
1305 pa_format_info_free(i.format);
1309 i.mute = (int) mute;
1310 i.corked = (int) corked;
1311 i.has_volume = (int) has_volume;
1312 i.volume_writable = (int) volume_writable;
1315 pa_source_output_info_cb_t cb = (pa_source_output_info_cb_t) o->callback;
1316 cb(o->context, &i, 0, o->userdata);
1319 pa_proplist_free(i.proplist);
1320 pa_format_info_free(i.format);
1325 pa_source_output_info_cb_t cb = (pa_source_output_info_cb_t) o->callback;
1326 cb(o->context, NULL, eol, o->userdata);
1330 pa_operation_done(o);
1331 pa_operation_unref(o);
1334 pa_operation* pa_context_get_source_output_info(pa_context *c, uint32_t idx, pa_source_output_info_cb_t cb, void *userdata) {
1340 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1343 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1344 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1345 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1347 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1349 t = pa_tagstruct_command(c, PA_COMMAND_GET_SOURCE_OUTPUT_INFO, &tag);
1350 pa_tagstruct_putu32(t, idx);
1351 pa_pstream_send_tagstruct(c->pstream, t);
1352 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);
1357 pa_operation* pa_context_get_source_output_info_list(pa_context *c, pa_source_output_info_cb_t cb, void *userdata) {
1358 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);
1361 /*** Volume manipulation ***/
1363 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) {
1369 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1372 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1373 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1374 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1376 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1378 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_VOLUME, &tag);
1379 pa_tagstruct_putu32(t, idx);
1380 pa_tagstruct_puts(t, NULL);
1381 pa_tagstruct_put_cvolume(t, volume);
1382 pa_pstream_send_tagstruct(c->pstream, t);
1383 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);
1388 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) {
1394 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1398 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1399 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1400 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1401 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
1403 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1405 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_VOLUME, &tag);
1406 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1407 pa_tagstruct_puts(t, name);
1408 pa_tagstruct_put_cvolume(t, volume);
1409 pa_pstream_send_tagstruct(c->pstream, t);
1410 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);
1415 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) {
1421 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1423 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1424 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1426 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1428 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_MUTE, &tag);
1429 pa_tagstruct_putu32(t, idx);
1430 pa_tagstruct_puts(t, NULL);
1431 pa_tagstruct_put_boolean(t, mute);
1432 pa_pstream_send_tagstruct(c->pstream, t);
1433 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);
1438 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) {
1444 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1447 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1448 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1449 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
1451 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1453 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_MUTE, &tag);
1454 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1455 pa_tagstruct_puts(t, name);
1456 pa_tagstruct_put_boolean(t, mute);
1457 pa_pstream_send_tagstruct(c->pstream, t);
1458 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);
1463 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) {
1469 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1472 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1473 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1474 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1475 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1477 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1479 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_INPUT_VOLUME, &tag);
1480 pa_tagstruct_putu32(t, idx);
1481 pa_tagstruct_put_cvolume(t, volume);
1482 pa_pstream_send_tagstruct(c->pstream, t);
1483 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);
1488 pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) {
1494 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1496 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1497 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1498 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1499 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);
1501 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1503 t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_INPUT_MUTE, &tag);
1504 pa_tagstruct_putu32(t, idx);
1505 pa_tagstruct_put_boolean(t, mute);
1506 pa_pstream_send_tagstruct(c->pstream, t);
1507 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);
1512 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) {
1518 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1521 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1522 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1523 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1525 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1527 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_VOLUME, &tag);
1528 pa_tagstruct_putu32(t, idx);
1529 pa_tagstruct_puts(t, NULL);
1530 pa_tagstruct_put_cvolume(t, volume);
1531 pa_pstream_send_tagstruct(c->pstream, t);
1532 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);
1537 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) {
1543 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1547 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1548 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1549 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1550 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
1552 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1554 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_VOLUME, &tag);
1555 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1556 pa_tagstruct_puts(t, name);
1557 pa_tagstruct_put_cvolume(t, volume);
1558 pa_pstream_send_tagstruct(c->pstream, t);
1559 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);
1564 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) {
1570 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1572 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1573 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1575 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1577 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_MUTE, &tag);
1578 pa_tagstruct_putu32(t, idx);
1579 pa_tagstruct_puts(t, NULL);
1580 pa_tagstruct_put_boolean(t, mute);
1581 pa_pstream_send_tagstruct(c->pstream, t);
1582 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);
1587 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) {
1593 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1596 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1597 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1598 PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
1600 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1602 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_MUTE, &tag);
1603 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1604 pa_tagstruct_puts(t, name);
1605 pa_tagstruct_put_boolean(t, mute);
1606 pa_pstream_send_tagstruct(c->pstream, t);
1607 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);
1612 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) {
1618 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1621 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1622 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1623 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1624 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 22, PA_ERR_NOTSUPPORTED);
1625 PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
1627 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1629 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME, &tag);
1630 pa_tagstruct_putu32(t, idx);
1631 pa_tagstruct_put_cvolume(t, volume);
1632 pa_pstream_send_tagstruct(c->pstream, t);
1633 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);
1638 pa_operation* pa_context_set_source_output_mute(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) {
1644 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1646 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1647 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1648 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1649 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 22, PA_ERR_NOTSUPPORTED);
1651 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1653 t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE, &tag);
1654 pa_tagstruct_putu32(t, idx);
1655 pa_tagstruct_put_boolean(t, mute);
1656 pa_pstream_send_tagstruct(c->pstream, t);
1657 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);
1662 /** Sample Cache **/
1664 static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
1665 pa_operation *o = userdata;
1670 pa_assert(PA_REFCNT_VALUE(o) >= 1);
1675 if (command != PA_COMMAND_REPLY) {
1676 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
1682 while (!pa_tagstruct_eof(t)) {
1684 pa_bool_t lazy = FALSE;
1687 i.proplist = pa_proplist_new();
1689 if (pa_tagstruct_getu32(t, &i.index) < 0 ||
1690 pa_tagstruct_gets(t, &i.name) < 0 ||
1691 pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
1692 pa_tagstruct_get_usec(t, &i.duration) < 0 ||
1693 pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
1694 pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
1695 pa_tagstruct_getu32(t, &i.bytes) < 0 ||
1696 pa_tagstruct_get_boolean(t, &lazy) < 0 ||
1697 pa_tagstruct_gets(t, &i.filename) < 0 ||
1698 (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
1700 pa_context_fail(o->context, PA_ERR_PROTOCOL);
1704 i.lazy = (int) lazy;
1707 pa_sample_info_cb_t cb = (pa_sample_info_cb_t) o->callback;
1708 cb(o->context, &i, 0, o->userdata);
1711 pa_proplist_free(i.proplist);
1716 pa_sample_info_cb_t cb = (pa_sample_info_cb_t) o->callback;
1717 cb(o->context, NULL, eol, o->userdata);
1721 pa_operation_done(o);
1722 pa_operation_unref(o);
1725 pa_operation* pa_context_get_sample_info_by_name(pa_context *c, const char *name, pa_sample_info_cb_t cb, void *userdata) {
1731 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1734 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1735 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1736 PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID);
1738 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1740 t = pa_tagstruct_command(c, PA_COMMAND_GET_SAMPLE_INFO, &tag);
1741 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1742 pa_tagstruct_puts(t, name);
1743 pa_pstream_send_tagstruct(c->pstream, t);
1744 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);
1749 pa_operation* pa_context_get_sample_info_by_index(pa_context *c, uint32_t idx, pa_sample_info_cb_t cb, void *userdata) {
1755 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1758 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1759 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1760 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1762 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1764 t = pa_tagstruct_command(c, PA_COMMAND_GET_SAMPLE_INFO, &tag);
1765 pa_tagstruct_putu32(t, idx);
1766 pa_tagstruct_puts(t, NULL);
1767 pa_pstream_send_tagstruct(c->pstream, t);
1768 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);
1773 pa_operation* pa_context_get_sample_info_list(pa_context *c, pa_sample_info_cb_t cb, void *userdata) {
1774 return pa_context_send_simple_command(c, PA_COMMAND_GET_SAMPLE_INFO_LIST, context_get_sample_info_callback, (pa_operation_cb_t) cb, userdata);
1777 static pa_operation* command_kill(pa_context *c, uint32_t command, uint32_t idx, pa_context_success_cb_t cb, void *userdata) {
1783 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1785 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1786 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1787 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1789 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1791 t = pa_tagstruct_command(c, command, &tag);
1792 pa_tagstruct_putu32(t, idx);
1793 pa_pstream_send_tagstruct(c->pstream, t);
1794 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);
1799 pa_operation* pa_context_kill_client(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) {
1800 return command_kill(c, PA_COMMAND_KILL_CLIENT, idx, cb, userdata);
1803 pa_operation* pa_context_kill_sink_input(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) {
1804 return command_kill(c, PA_COMMAND_KILL_SINK_INPUT, idx, cb, userdata);
1807 pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) {
1808 return command_kill(c, PA_COMMAND_KILL_SOURCE_OUTPUT, idx, cb, userdata);
1811 static void context_index_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
1812 pa_operation *o = userdata;
1817 pa_assert(PA_REFCNT_VALUE(o) >= 1);
1822 if (command != PA_COMMAND_REPLY) {
1823 if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
1826 idx = PA_INVALID_INDEX;
1827 } else if (pa_tagstruct_getu32(t, &idx) ||
1828 !pa_tagstruct_eof(t)) {
1829 pa_context_fail(o->context, PA_ERR_PROTOCOL);
1834 pa_context_index_cb_t cb = (pa_context_index_cb_t) o->callback;
1835 cb(o->context, idx, o->userdata);
1840 pa_operation_done(o);
1841 pa_operation_unref(o);
1844 pa_operation* pa_context_load_module(pa_context *c, const char*name, const char *argument, pa_context_index_cb_t cb, void *userdata) {
1850 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1852 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1853 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1854 PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID);
1856 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1858 t = pa_tagstruct_command(c, PA_COMMAND_LOAD_MODULE, &tag);
1859 pa_tagstruct_puts(t, name);
1860 pa_tagstruct_puts(t, argument);
1861 pa_pstream_send_tagstruct(c->pstream, t);
1862 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, context_index_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
1867 pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) {
1868 return command_kill(c, PA_COMMAND_UNLOAD_MODULE, idx, cb, userdata);
1871 /*** Autoload stuff ***/
1873 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name, "Module auto-loading no longer supported.");
1875 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) {
1878 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1880 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1883 PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index, "Module auto-loading no longer supported.");
1885 pa_operation* pa_context_get_autoload_info_by_index(pa_context *c, uint32_t idx, pa_autoload_info_cb_t cb, void *userdata) {
1887 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1889 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1892 PA_WARN_REFERENCE(pa_context_get_autoload_info_list, "Module auto-loading no longer supported.");
1894 pa_operation* pa_context_get_autoload_info_list(pa_context *c, pa_autoload_info_cb_t cb, void *userdata) {
1896 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1898 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1901 PA_WARN_REFERENCE(pa_context_add_autoload, "Module auto-loading no longer supported.");
1903 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) {
1905 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1907 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1910 PA_WARN_REFERENCE(pa_context_remove_autoload_by_name, "Module auto-loading no longer supported.");
1912 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) {
1914 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1916 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1919 PA_WARN_REFERENCE(pa_context_remove_autoload_by_index, "Module auto-loading no longer supported.");
1921 pa_operation* pa_context_remove_autoload_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void* userdata) {
1923 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1925 PA_FAIL_RETURN_NULL(c, PA_ERR_OBSOLETE);
1928 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) {
1934 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1936 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1937 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1938 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 10, PA_ERR_NOTSUPPORTED);
1939 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1940 PA_CHECK_VALIDITY_RETURN_NULL(c, sink_name && *sink_name, PA_ERR_INVALID);
1942 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1944 t = pa_tagstruct_command(c, PA_COMMAND_MOVE_SINK_INPUT, &tag);
1945 pa_tagstruct_putu32(t, idx);
1946 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1947 pa_tagstruct_puts(t, sink_name);
1948 pa_pstream_send_tagstruct(c->pstream, t);
1949 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);
1954 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) {
1960 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1962 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1963 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1964 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 10, PA_ERR_NOTSUPPORTED);
1965 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1966 PA_CHECK_VALIDITY_RETURN_NULL(c, sink_idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1968 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1970 t = pa_tagstruct_command(c, PA_COMMAND_MOVE_SINK_INPUT, &tag);
1971 pa_tagstruct_putu32(t, idx);
1972 pa_tagstruct_putu32(t, sink_idx);
1973 pa_tagstruct_puts(t, NULL);
1974 pa_pstream_send_tagstruct(c->pstream, t);
1975 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);
1980 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) {
1986 pa_assert(PA_REFCNT_VALUE(c) >= 1);
1988 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
1989 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
1990 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 10, PA_ERR_NOTSUPPORTED);
1991 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
1992 PA_CHECK_VALIDITY_RETURN_NULL(c, source_name && *source_name, PA_ERR_INVALID);
1994 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
1996 t = pa_tagstruct_command(c, PA_COMMAND_MOVE_SOURCE_OUTPUT, &tag);
1997 pa_tagstruct_putu32(t, idx);
1998 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
1999 pa_tagstruct_puts(t, source_name);
2000 pa_pstream_send_tagstruct(c->pstream, t);
2001 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);
2006 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) {
2012 pa_assert(PA_REFCNT_VALUE(c) >= 1);
2014 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
2015 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
2016 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 10, PA_ERR_NOTSUPPORTED);
2017 PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
2018 PA_CHECK_VALIDITY_RETURN_NULL(c, source_idx != PA_INVALID_INDEX, PA_ERR_INVALID);
2020 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
2022 t = pa_tagstruct_command(c, PA_COMMAND_MOVE_SOURCE_OUTPUT, &tag);
2023 pa_tagstruct_putu32(t, idx);
2024 pa_tagstruct_putu32(t, source_idx);
2025 pa_tagstruct_puts(t, NULL);
2026 pa_pstream_send_tagstruct(c->pstream, t);
2027 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);
2032 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) {
2038 pa_assert(PA_REFCNT_VALUE(c) >= 1);
2040 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
2041 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
2042 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);
2043 PA_CHECK_VALIDITY_RETURN_NULL(c, !sink_name || *sink_name, PA_ERR_INVALID);
2045 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
2047 t = pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SINK, &tag);
2048 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
2049 pa_tagstruct_puts(t, sink_name);
2050 pa_tagstruct_put_boolean(t, suspend);
2051 pa_pstream_send_tagstruct(c->pstream, t);
2052 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);
2057 pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata) {
2063 pa_assert(PA_REFCNT_VALUE(c) >= 1);
2065 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
2066 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
2067 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);
2069 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
2071 t = pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SINK, &tag);
2072 pa_tagstruct_putu32(t, idx);
2073 pa_tagstruct_puts(t, idx == PA_INVALID_INDEX ? "" : NULL);
2074 pa_tagstruct_put_boolean(t, suspend);
2075 pa_pstream_send_tagstruct(c->pstream, t);
2076 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);
2081 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) {
2087 pa_assert(PA_REFCNT_VALUE(c) >= 1);
2089 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
2090 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
2091 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);
2092 PA_CHECK_VALIDITY_RETURN_NULL(c, !source_name || *source_name, PA_ERR_INVALID);
2094 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
2096 t = pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SOURCE, &tag);
2097 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
2098 pa_tagstruct_puts(t, source_name);
2099 pa_tagstruct_put_boolean(t, suspend);
2100 pa_pstream_send_tagstruct(c->pstream, t);
2101 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);
2106 pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata) {
2112 pa_assert(PA_REFCNT_VALUE(c) >= 1);
2114 PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
2115 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
2116 PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);
2118 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
2120 t = pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SOURCE, &tag);
2121 pa_tagstruct_putu32(t, idx);
2122 pa_tagstruct_puts(t, idx == PA_INVALID_INDEX ? "" : NULL);
2123 pa_tagstruct_put_boolean(t, suspend);
2124 pa_pstream_send_tagstruct(c->pstream, t);
2125 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);