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_getu32(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_getu32(t
, &i
.buffer_usec
) < 0 ||
450 pa_tagstruct_getu32(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_getu32(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_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
659 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
660 cb(o
->context
, &i
, 0, o
->userdata
);
666 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
667 cb(o
->context
, NULL
, eof
, o
->userdata
);
671 pa_operation_done(o
);
672 pa_operation_unref(o
);
675 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
) {
676 struct pa_tagstruct
*t
;
677 struct pa_operation
*o
;
679 assert(c
&& cb
&& name
);
681 o
= pa_operation_new(c
, NULL
);
683 o
->userdata
= userdata
;
685 t
= pa_tagstruct_new(NULL
, 0);
686 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
687 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
688 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
689 pa_tagstruct_puts(t
, name
);
690 pa_pstream_send_tagstruct(c
->pstream
, t
);
691 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
693 return pa_operation_ref(o
);
696 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
) {
697 struct pa_tagstruct
*t
;
698 struct pa_operation
*o
;
702 o
= pa_operation_new(c
, NULL
);
704 o
->userdata
= userdata
;
706 t
= pa_tagstruct_new(NULL
, 0);
707 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
708 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
709 pa_tagstruct_putu32(t
, index
);
710 pa_tagstruct_puts(t
, "");
711 pa_pstream_send_tagstruct(c
->pstream
, t
);
712 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
714 return pa_operation_ref(o
);
717 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
) {
718 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, cb
, userdata
);