4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include "polyplib-introspect.h"
29 #include "polyplib-context.h"
30 #include "polyplib-internal.h"
31 #include "pstream-util.h"
35 static void context_stat_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
36 struct pa_operation
*o
= userdata
;
37 struct pa_stat_info i
, *p
= &i
;
38 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
40 if (command
!= PA_COMMAND_REPLY
) {
41 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
45 } else if (pa_tagstruct_getu32(t
, &i
.memblock_total
) < 0 ||
46 pa_tagstruct_getu32(t
, &i
.memblock_total_size
) < 0 ||
47 pa_tagstruct_getu32(t
, &i
.memblock_allocated
) < 0 ||
48 pa_tagstruct_getu32(t
, &i
.memblock_allocated_size
) < 0 ||
49 pa_tagstruct_getu32(t
, &i
.scache_size
) < 0 ||
50 !pa_tagstruct_eof(t
)) {
51 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
56 void (*cb
)(struct pa_context
*s
, const struct pa_stat_info
*i
, void *userdata
) = o
->callback
;
57 cb(o
->context
, p
, o
->userdata
);
62 pa_operation_unref(o
);
65 struct pa_operation
* pa_context_stat(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_stat_info
*i
, void *userdata
), void *userdata
) {
66 return pa_context_send_simple_command(c
, PA_COMMAND_STAT
, context_stat_callback
, cb
, userdata
);
71 static void context_get_server_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
72 struct pa_operation
*o
= userdata
;
73 struct pa_server_info i
, *p
= &i
;
74 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
76 if (command
!= PA_COMMAND_REPLY
) {
77 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
81 } else if (pa_tagstruct_gets(t
, &i
.server_name
) < 0 ||
82 pa_tagstruct_gets(t
, &i
.server_version
) < 0 ||
83 pa_tagstruct_gets(t
, &i
.user_name
) < 0 ||
84 pa_tagstruct_gets(t
, &i
.host_name
) < 0 ||
85 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
86 pa_tagstruct_gets(t
, &i
.default_sink_name
) < 0 ||
87 pa_tagstruct_gets(t
, &i
.default_source_name
) < 0 ||
88 !pa_tagstruct_eof(t
)) {
90 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
95 void (*cb
)(struct pa_context
*s
, const struct pa_server_info
*i
, void *userdata
) = o
->callback
;
96 cb(o
->context
, p
, o
->userdata
);
100 pa_operation_done(o
);
101 pa_operation_unref(o
);
104 struct pa_operation
* pa_context_get_server_info(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_server_info
*i
, void *userdata
), void *userdata
) {
105 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, cb
, userdata
);
110 static void context_get_sink_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
111 struct pa_operation
*o
= userdata
;
113 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
115 if (command
!= PA_COMMAND_REPLY
) {
116 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
122 while (!pa_tagstruct_eof(t
)) {
123 struct pa_sink_info i
;
125 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
126 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
127 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
128 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
129 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
130 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
131 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
132 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
133 pa_tagstruct_get_usec(t
, &i
.latency
) < 0) {
134 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
139 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
140 cb(o
->context
, &i
, 0, o
->userdata
);
146 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
147 cb(o
->context
, NULL
, eof
, o
->userdata
);
151 pa_operation_done(o
);
152 pa_operation_unref(o
);
155 struct pa_operation
* pa_context_get_sink_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
156 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, cb
, userdata
);
159 struct pa_operation
* pa_context_get_sink_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
160 struct pa_tagstruct
*t
;
161 struct pa_operation
*o
;
165 o
= pa_operation_new(c
, NULL
);
167 o
->userdata
= userdata
;
169 t
= pa_tagstruct_new(NULL
, 0);
170 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
171 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
172 pa_tagstruct_putu32(t
, index
);
173 pa_tagstruct_puts(t
, "");
174 pa_pstream_send_tagstruct(c
->pstream
, t
);
175 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
177 return pa_operation_ref(o
);
180 struct pa_operation
* pa_context_get_sink_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
181 struct pa_tagstruct
*t
;
182 struct pa_operation
*o
;
186 o
= pa_operation_new(c
, NULL
);
188 o
->userdata
= userdata
;
190 t
= pa_tagstruct_new(NULL
, 0);
191 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
192 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
193 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
194 pa_tagstruct_puts(t
, name
);
195 pa_pstream_send_tagstruct(c
->pstream
, t
);
196 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
198 return pa_operation_ref(o
);
201 /*** Source info ***/
203 static void context_get_source_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
204 struct pa_operation
*o
= userdata
;
206 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
208 if (command
!= PA_COMMAND_REPLY
) {
209 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
215 while (!pa_tagstruct_eof(t
)) {
216 struct pa_source_info i
;
218 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
219 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
220 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
221 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
222 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
223 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
224 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0) {
225 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
230 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
231 cb(o
->context
, &i
, 0, o
->userdata
);
237 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
238 cb(o
->context
, NULL
, eof
, o
->userdata
);
242 pa_operation_done(o
);
243 pa_operation_unref(o
);
246 struct pa_operation
* pa_context_get_source_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
247 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, cb
, userdata
);
250 struct pa_operation
* pa_context_get_source_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
251 struct pa_tagstruct
*t
;
252 struct pa_operation
*o
;
256 o
= pa_operation_new(c
, NULL
);
258 o
->userdata
= userdata
;
260 t
= pa_tagstruct_new(NULL
, 0);
261 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
262 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
263 pa_tagstruct_putu32(t
, index
);
264 pa_tagstruct_puts(t
, "");
265 pa_pstream_send_tagstruct(c
->pstream
, t
);
266 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
268 return pa_operation_ref(o
);
271 struct pa_operation
* pa_context_get_source_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
272 struct pa_tagstruct
*t
;
273 struct pa_operation
*o
;
277 o
= pa_operation_new(c
, NULL
);
279 o
->userdata
= userdata
;
281 t
= pa_tagstruct_new(NULL
, 0);
282 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
283 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
284 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
285 pa_tagstruct_puts(t
, name
);
286 pa_pstream_send_tagstruct(c
->pstream
, t
);
287 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
289 return pa_operation_ref(o
);
292 /*** Client info ***/
294 static void context_get_client_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
295 struct pa_operation
*o
= userdata
;
297 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
299 if (command
!= PA_COMMAND_REPLY
) {
300 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
306 while (!pa_tagstruct_eof(t
)) {
307 struct pa_client_info i
;
309 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
310 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
311 pa_tagstruct_gets(t
, &i
.protocol_name
) < 0 ||
312 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0) {
313 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
318 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
319 cb(o
->context
, &i
, 0, o
->userdata
);
325 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
326 cb(o
->context
, NULL
, eof
, o
->userdata
);
330 pa_operation_done(o
);
331 pa_operation_unref(o
);
334 struct pa_operation
* pa_context_get_client_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_client_info
*i
, int is_last
, void *userdata
), void *userdata
) {
335 struct pa_tagstruct
*t
;
336 struct pa_operation
*o
;
340 o
= pa_operation_new(c
, NULL
);
342 o
->userdata
= userdata
;
344 t
= pa_tagstruct_new(NULL
, 0);
345 pa_tagstruct_putu32(t
, PA_COMMAND_GET_CLIENT_INFO
);
346 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
347 pa_tagstruct_putu32(t
, index
);
348 pa_pstream_send_tagstruct(c
->pstream
, t
);
349 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_client_info_callback
, o
);
351 return pa_operation_ref(o
);
354 struct pa_operation
* pa_context_get_client_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_client_info
*i
, int is_last
, void *userdata
), void *userdata
) {
355 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, cb
, userdata
);
358 /*** Module info ***/
360 static void context_get_module_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
361 struct pa_operation
*o
= userdata
;
363 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
365 if (command
!= PA_COMMAND_REPLY
) {
366 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
372 while (!pa_tagstruct_eof(t
)) {
373 struct pa_module_info i
;
375 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
376 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
377 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
378 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
379 pa_tagstruct_get_boolean(t
, &i
.auto_unload
) < 0) {
380 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
385 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
386 cb(o
->context
, &i
, 0, o
->userdata
);
392 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
393 cb(o
->context
, NULL
, eof
, o
->userdata
);
397 pa_operation_done(o
);
398 pa_operation_unref(o
);
401 struct pa_operation
* pa_context_get_module_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_module_info
*i
, int is_last
, void *userdata
), void *userdata
) {
402 struct pa_tagstruct
*t
;
403 struct pa_operation
*o
;
407 o
= pa_operation_new(c
, NULL
);
409 o
->userdata
= userdata
;
411 t
= pa_tagstruct_new(NULL
, 0);
412 pa_tagstruct_putu32(t
, PA_COMMAND_GET_MODULE_INFO
);
413 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
414 pa_tagstruct_putu32(t
, index
);
415 pa_pstream_send_tagstruct(c
->pstream
, t
);
416 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_module_info_callback
, o
);
418 return pa_operation_ref(o
);
421 struct pa_operation
* pa_context_get_module_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_module_info
*i
, int is_last
, void *userdata
), void *userdata
) {
422 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, cb
, userdata
);
425 /*** Sink input info ***/
427 static void context_get_sink_input_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
428 struct pa_operation
*o
= userdata
;
430 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
432 if (command
!= PA_COMMAND_REPLY
) {
433 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
439 while (!pa_tagstruct_eof(t
)) {
440 struct pa_sink_input_info i
;
442 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
443 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
444 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
445 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
446 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
447 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
448 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
449 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
450 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0) {
451 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
456 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
457 cb(o
->context
, &i
, 0, o
->userdata
);
463 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
464 cb(o
->context
, NULL
, eof
, o
->userdata
);
468 pa_operation_done(o
);
469 pa_operation_unref(o
);
472 struct pa_operation
* pa_context_get_sink_input_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_input_info
*i
, int is_last
, void *userdata
), void *userdata
) {
473 struct pa_tagstruct
*t
;
474 struct pa_operation
*o
;
478 o
= pa_operation_new(c
, NULL
);
480 o
->userdata
= userdata
;
482 t
= pa_tagstruct_new(NULL
, 0);
483 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INPUT_INFO
);
484 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
485 pa_tagstruct_putu32(t
, index
);
486 pa_pstream_send_tagstruct(c
->pstream
, t
);
487 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_input_info_callback
, o
);
489 return pa_operation_ref(o
);
492 struct pa_operation
* pa_context_get_sink_input_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_input_info
*i
, int is_last
, void *userdata
), void *userdata
) {
493 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO_LIST
, context_get_sink_input_info_callback
, cb
, userdata
);
496 /*** Source output info ***/
498 static void context_get_source_output_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
499 struct pa_operation
*o
= userdata
;
501 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
503 if (command
!= PA_COMMAND_REPLY
) {
504 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
510 while (!pa_tagstruct_eof(t
)) {
511 struct pa_source_output_info i
;
513 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
514 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
515 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
516 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
517 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
518 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0) {
519 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
524 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
525 cb(o
->context
, &i
, 0, o
->userdata
);
531 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
532 cb(o
->context
, NULL
, eof
, o
->userdata
);
536 pa_operation_done(o
);
537 pa_operation_unref(o
);
540 struct pa_operation
* pa_context_get_source_output_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_source_output_info
*i
, int is_last
, void *userdata
), void *userdata
) {
541 struct pa_tagstruct
*t
;
542 struct pa_operation
*o
;
546 o
= pa_operation_new(c
, NULL
);
548 o
->userdata
= userdata
;
550 t
= pa_tagstruct_new(NULL
, 0);
551 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
);
552 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
553 pa_tagstruct_putu32(t
, index
);
554 pa_pstream_send_tagstruct(c
->pstream
, t
);
555 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_output_info_callback
, o
);
557 return pa_operation_ref(o
);
560 struct pa_operation
* pa_context_get_source_output_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_source_output_info
*i
, int is_last
, void *userdata
), void *userdata
) {
561 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
, context_get_source_output_info_callback
, cb
, userdata
);
564 /*** Volume manipulation ***/
566 struct pa_operation
* pa_context_set_sink_volume_by_index(struct pa_context
*c
, uint32_t index
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
567 struct pa_operation
*o
;
568 struct pa_tagstruct
*t
;
570 assert(c
&& index
!= PA_INVALID_INDEX
);
572 o
= pa_operation_new(c
, NULL
);
574 o
->userdata
= userdata
;
576 t
= pa_tagstruct_new(NULL
, 0);
577 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
578 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
579 pa_tagstruct_putu32(t
, index
);
580 pa_tagstruct_puts(t
, "");
581 pa_tagstruct_putu32(t
, volume
);
582 pa_pstream_send_tagstruct(c
->pstream
, t
);
583 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
585 return pa_operation_ref(o
);
588 struct pa_operation
* pa_context_set_sink_volume_by_name(struct pa_context
*c
, const char *name
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
589 struct pa_operation
*o
;
590 struct pa_tagstruct
*t
;
594 o
= pa_operation_new(c
, NULL
);
596 o
->userdata
= userdata
;
598 t
= pa_tagstruct_new(NULL
, 0);
599 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
600 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
601 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
602 pa_tagstruct_puts(t
, name
);
603 pa_tagstruct_putu32(t
, volume
);
604 pa_pstream_send_tagstruct(c
->pstream
, t
);
605 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
607 return pa_operation_ref(o
);
610 struct pa_operation
* pa_context_set_sink_input_volume(struct pa_context
*c
, uint32_t index
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
611 struct pa_operation
*o
;
612 struct pa_tagstruct
*t
;
614 assert(c
&& index
!= PA_INVALID_INDEX
);
616 o
= pa_operation_new(c
, NULL
);
618 o
->userdata
= userdata
;
620 t
= pa_tagstruct_new(NULL
, 0);
621 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_INPUT_VOLUME
);
622 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
623 pa_tagstruct_putu32(t
, index
);
624 pa_tagstruct_putu32(t
, volume
);
625 pa_pstream_send_tagstruct(c
->pstream
, t
);
626 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
628 return pa_operation_ref(o
);
633 static void context_get_sample_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
634 struct pa_operation
*o
= userdata
;
636 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
638 if (command
!= PA_COMMAND_REPLY
) {
639 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
645 while (!pa_tagstruct_eof(t
)) {
646 struct pa_sample_info i
;
648 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
649 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
650 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
651 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
652 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
653 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
654 pa_tagstruct_get_boolean(t
, &i
.lazy
) < 0 ||
655 pa_tagstruct_gets(t
, &i
.filename
) < 0) {
656 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
661 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
662 cb(o
->context
, &i
, 0, o
->userdata
);
668 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
669 cb(o
->context
, NULL
, eof
, o
->userdata
);
673 pa_operation_done(o
);
674 pa_operation_unref(o
);
677 struct pa_operation
* pa_context_get_sample_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
678 struct pa_tagstruct
*t
;
679 struct pa_operation
*o
;
681 assert(c
&& cb
&& name
);
683 o
= pa_operation_new(c
, NULL
);
685 o
->userdata
= userdata
;
687 t
= pa_tagstruct_new(NULL
, 0);
688 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
689 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
690 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
691 pa_tagstruct_puts(t
, name
);
692 pa_pstream_send_tagstruct(c
->pstream
, t
);
693 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
695 return pa_operation_ref(o
);
698 struct pa_operation
* pa_context_get_sample_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
699 struct pa_tagstruct
*t
;
700 struct pa_operation
*o
;
704 o
= pa_operation_new(c
, NULL
);
706 o
->userdata
= userdata
;
708 t
= pa_tagstruct_new(NULL
, 0);
709 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
710 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
711 pa_tagstruct_putu32(t
, index
);
712 pa_tagstruct_puts(t
, "");
713 pa_pstream_send_tagstruct(c
->pstream
, t
);
714 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
716 return pa_operation_ref(o
);
719 struct pa_operation
* pa_context_get_sample_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
720 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, cb
, userdata
);
723 static struct pa_operation
* command_kill(struct pa_context
*c
, uint32_t command
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
724 struct pa_operation
*o
;
725 struct pa_tagstruct
*t
;
727 assert(c
&& index
!= PA_INVALID_INDEX
);
729 o
= pa_operation_new(c
, NULL
);
731 o
->userdata
= userdata
;
733 t
= pa_tagstruct_new(NULL
, 0);
734 pa_tagstruct_putu32(t
, command
);
735 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
736 pa_tagstruct_putu32(t
, index
);
737 pa_pstream_send_tagstruct(c
->pstream
, t
);
738 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
740 return pa_operation_ref(o
);
743 struct pa_operation
* pa_context_kill_client(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
744 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, index
, cb
, userdata
);
747 struct pa_operation
* pa_context_kill_sink_input(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
748 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, index
, cb
, userdata
);
751 struct pa_operation
* pa_context_kill_source_output(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
752 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, index
, cb
, userdata
);
755 static void load_module_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
756 struct pa_operation
*o
= userdata
;
758 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
760 if (command
!= PA_COMMAND_REPLY
) {
761 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
764 } else if (pa_tagstruct_getu32(t
, &index
) < 0 ||
765 !pa_tagstruct_eof(t
)) {
766 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
771 void (*cb
)(struct pa_context
*c
, uint32_t index
, void *userdata
) = o
->callback
;
772 cb(o
->context
, index
, o
->userdata
);
776 pa_operation_done(o
);
777 pa_operation_unref(o
);
780 struct pa_operation
* pa_context_load_module(struct pa_context
*c
, const char*name
, const char *argument
, void (*cb
)(struct pa_context
*c
, uint32_t index
, void *userdata
), void *userdata
) {
781 struct pa_operation
*o
;
782 struct pa_tagstruct
*t
;
784 assert(c
&& name
&& argument
);
786 o
= pa_operation_new(c
, NULL
);
788 o
->userdata
= userdata
;
790 t
= pa_tagstruct_new(NULL
, 0);
791 pa_tagstruct_putu32(t
, PA_COMMAND_LOAD_MODULE
);
792 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
793 pa_tagstruct_puts(t
, name
);
794 pa_tagstruct_puts(t
, argument
);
795 pa_pstream_send_tagstruct(c
->pstream
, t
);
796 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, load_module_callback
, o
);
798 return pa_operation_ref(o
);
801 struct pa_operation
* pa_context_unload_module(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
802 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, index
, cb
, userdata
);
805 /*** Autoload stuff ***/
807 static void context_get_autoload_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
808 struct pa_operation
*o
= userdata
;
810 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
812 if (command
!= PA_COMMAND_REPLY
) {
813 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
819 while (!pa_tagstruct_eof(t
)) {
820 struct pa_autoload_info i
;
822 if (pa_tagstruct_gets(t
, &i
.name
) < 0 ||
823 pa_tagstruct_getu32(t
, &i
.type
) < 0 ||
824 pa_tagstruct_gets(t
, &i
.module
) < 0 ||
825 pa_tagstruct_gets(t
, &i
.argument
) < 0) {
826 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
831 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
832 cb(o
->context
, &i
, 0, o
->userdata
);
838 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
839 cb(o
->context
, NULL
, eof
, o
->userdata
);
843 pa_operation_done(o
);
844 pa_operation_unref(o
);
847 struct pa_operation
* pa_context_get_autoload_info(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, void (*cb
)(struct pa_context
*c
, const struct pa_autoload_info
*i
, int is_last
, void *userdata
), void *userdata
) {
848 struct pa_tagstruct
*t
;
849 struct pa_operation
*o
;
851 assert(c
&& cb
&& name
);
853 o
= pa_operation_new(c
, NULL
);
855 o
->userdata
= userdata
;
857 t
= pa_tagstruct_new(NULL
, 0);
858 pa_tagstruct_putu32(t
, PA_COMMAND_GET_AUTOLOAD_INFO
);
859 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
860 pa_tagstruct_puts(t
, name
);
861 pa_tagstruct_putu32(t
, type
);
862 pa_pstream_send_tagstruct(c
->pstream
, t
);
863 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_autoload_info_callback
, o
);
865 return pa_operation_ref(o
);
868 struct pa_operation
* pa_context_get_autoload_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_autoload_info
*i
, int is_last
, void *userdata
), void *userdata
) {
869 return pa_context_send_simple_command(c
, PA_COMMAND_GET_AUTOLOAD_INFO_LIST
, context_get_autoload_info_callback
, cb
, userdata
);
872 struct pa_operation
* pa_context_add_autoload(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, const char *module
, const char*argument
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
873 struct pa_operation
*o
;
874 struct pa_tagstruct
*t
;
876 assert(c
&& name
&& module
&& argument
);
878 o
= pa_operation_new(c
, NULL
);
880 o
->userdata
= userdata
;
882 t
= pa_tagstruct_new(NULL
, 0);
883 pa_tagstruct_putu32(t
, PA_COMMAND_ADD_AUTOLOAD
);
884 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
885 pa_tagstruct_puts(t
, name
);
886 pa_tagstruct_putu32(t
, type
);
887 pa_tagstruct_puts(t
, module
);
888 pa_tagstruct_puts(t
, argument
);
889 pa_pstream_send_tagstruct(c
->pstream
, t
);
890 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
892 return pa_operation_ref(o
);
895 struct pa_operation
* pa_context_remove_autoload(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
896 struct pa_operation
*o
;
897 struct pa_tagstruct
*t
;
901 o
= pa_operation_new(c
, NULL
);
903 o
->userdata
= userdata
;
905 t
= pa_tagstruct_new(NULL
, 0);
906 pa_tagstruct_putu32(t
, PA_COMMAND_REMOVE_AUTOLOAD
);
907 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
908 pa_tagstruct_puts(t
, name
);
909 pa_tagstruct_putu32(t
, type
);
910 pa_pstream_send_tagstruct(c
->pstream
, t
);
911 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
913 return pa_operation_ref(o
);