4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 #include <pulse/timeval.h>
35 #include <pulse/version.h>
36 #include <pulse/utf8.h>
37 #include <pulse/util.h>
38 #include <pulse/xmalloc.h>
40 #include <pulsecore/native-common.h>
41 #include <pulsecore/packet.h>
42 #include <pulsecore/client.h>
43 #include <pulsecore/source-output.h>
44 #include <pulsecore/sink-input.h>
45 #include <pulsecore/pstream.h>
46 #include <pulsecore/tagstruct.h>
47 #include <pulsecore/pdispatch.h>
48 #include <pulsecore/pstream-util.h>
49 #include <pulsecore/authkey.h>
50 #include <pulsecore/namereg.h>
51 #include <pulsecore/core-scache.h>
52 #include <pulsecore/core-subscribe.h>
53 #include <pulsecore/log.h>
54 #include <pulsecore/autoload.h>
55 #include <pulsecore/authkey-prop.h>
56 #include <pulsecore/strlist.h>
57 #include <pulsecore/props.h>
58 #include <pulsecore/sample-util.h>
59 #include <pulsecore/llist.h>
60 #include <pulsecore/creds.h>
61 #include <pulsecore/core-util.h>
62 #include <pulsecore/ipacl.h>
63 #include <pulsecore/thread-mq.h>
65 #include "protocol-native.h"
67 /* Kick a client if it doesn't authenticate within this time */
68 #define AUTH_TIMEOUT 60
70 /* Don't accept more connection than this */
71 #define MAX_CONNECTIONS 64
73 #define MAX_MEMBLOCKQ_LENGTH (4*1024*1024) /* 4MB */
74 #define DEFAULT_TLENGTH_MSEC 2000 /* 2s */
75 #define DEFAULT_PROCESS_MSEC 20 /* 20ms */
76 #define DEFAULT_FRAGSIZE_MSEC DEFAULT_TLENGTH_MSEC
78 typedef struct connection connection
;
79 struct pa_protocol_native
;
81 typedef struct record_stream
{
84 connection
*connection
;
87 pa_source_output
*source_output
;
88 pa_memblockq
*memblockq
;
90 pa_usec_t source_latency
;
93 typedef struct output_stream
{
97 typedef struct playback_stream
{
100 connection
*connection
;
103 pa_sink_input
*sink_input
;
104 pa_memblockq
*memblockq
;
105 pa_bool_t drain_request
;
111 pa_usec_t sink_latency
;
113 /* Only updated after SINK_INPUT_MESSAGE_UPDATE_LATENCY */
114 int64_t read_index
, write_index
;
115 size_t render_memblockq_length
;
118 typedef struct upload_stream
{
119 output_stream parent
;
121 connection
*connection
;
124 pa_memchunk memchunk
;
127 pa_sample_spec sample_spec
;
128 pa_channel_map channel_map
;
129 pa_proplist
*proplist
;
135 pa_bool_t authorized
;
137 pa_protocol_native
*protocol
;
140 pa_pdispatch
*pdispatch
;
141 pa_idxset
*record_streams
, *output_streams
;
142 uint32_t rrobin_index
;
143 pa_subscription
*subscription
;
144 pa_time_event
*auth_timeout_event
;
147 PA_DECLARE_CLASS(record_stream
);
148 #define RECORD_STREAM(o) (record_stream_cast(o))
149 static PA_DEFINE_CHECK_TYPE(record_stream
, pa_msgobject
);
151 PA_DECLARE_CLASS(output_stream
);
152 #define OUTPUT_STREAM(o) (output_stream_cast(o))
153 static PA_DEFINE_CHECK_TYPE(output_stream
, pa_msgobject
);
155 PA_DECLARE_CLASS(playback_stream
);
156 #define PLAYBACK_STREAM(o) (playback_stream_cast(o))
157 static PA_DEFINE_CHECK_TYPE(playback_stream
, output_stream
);
159 PA_DECLARE_CLASS(upload_stream
);
160 #define UPLOAD_STREAM(o) (upload_stream_cast(o))
161 static PA_DEFINE_CHECK_TYPE(upload_stream
, output_stream
);
163 PA_DECLARE_CLASS(connection
);
164 #define CONNECTION(o) (connection_cast(o))
165 static PA_DEFINE_CHECK_TYPE(connection
, pa_msgobject
);
167 struct pa_protocol_native
{
171 pa_socket_server
*server
;
172 pa_idxset
*connections
;
173 uint8_t auth_cookie
[PA_NATIVE_COOKIE_LENGTH
];
174 pa_bool_t auth_cookie_in_property
;
178 pa_ip_acl
*auth_ip_acl
;
182 SINK_INPUT_MESSAGE_POST_DATA
= PA_SINK_INPUT_MESSAGE_MAX
, /* data from main loop to sink input */
183 SINK_INPUT_MESSAGE_DRAIN
, /* disabled prebuf, get playback started. */
184 SINK_INPUT_MESSAGE_FLUSH
,
185 SINK_INPUT_MESSAGE_TRIGGER
,
186 SINK_INPUT_MESSAGE_SEEK
,
187 SINK_INPUT_MESSAGE_PREBUF_FORCE
,
188 SINK_INPUT_MESSAGE_UPDATE_LATENCY
192 PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, /* data requested from sink input from the main loop */
193 PLAYBACK_STREAM_MESSAGE_UNDERFLOW
,
194 PLAYBACK_STREAM_MESSAGE_OVERFLOW
,
195 PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
,
196 PLAYBACK_STREAM_MESSAGE_STARTED
200 RECORD_STREAM_MESSAGE_POST_DATA
/* data from source output to main loop */
204 CONNECTION_MESSAGE_RELEASE
,
205 CONNECTION_MESSAGE_REVOKE
208 static int sink_input_pop_cb(pa_sink_input
*i
, size_t length
, pa_memchunk
*chunk
);
209 static void sink_input_kill_cb(pa_sink_input
*i
);
210 static void sink_input_suspend_cb(pa_sink_input
*i
, pa_bool_t suspend
);
211 static void sink_input_moved_cb(pa_sink_input
*i
);
212 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
);
213 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
);
216 static void send_memblock(connection
*c
);
217 static void request_bytes(struct playback_stream
*s
);
219 static void source_output_kill_cb(pa_source_output
*o
);
220 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
);
221 static void source_output_suspend_cb(pa_source_output
*o
, pa_bool_t suspend
);
222 static void source_output_moved_cb(pa_source_output
*o
);
223 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
);
225 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
);
227 static void command_exit(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
228 static void command_create_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
229 static void command_drain_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
230 static void command_create_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
231 static void command_delete_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
232 static void command_auth(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
233 static void command_set_client_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
234 static void command_lookup(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
235 static void command_stat(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
236 static void command_get_playback_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
237 static void command_get_record_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
238 static void command_create_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
239 static void command_finish_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
240 static void command_play_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
241 static void command_remove_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
242 static void command_get_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
243 static void command_get_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
244 static void command_get_server_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
245 static void command_subscribe(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
246 static void command_set_volume(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
247 static void command_set_mute(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
248 static void command_cork_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
249 static void command_trigger_or_flush_or_prebuf_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
250 static void command_set_default_sink_or_source(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
251 static void command_set_stream_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
252 static void command_kill(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
253 static void command_load_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
254 static void command_unload_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
255 static void command_add_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
256 static void command_remove_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
257 static void command_get_autoload_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
258 static void command_get_autoload_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
259 static void command_cork_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
260 static void command_flush_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
261 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
262 static void command_suspend(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
263 static void command_set_stream_buffer_attr(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
264 static void command_update_stream_sample_rate(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
265 static void command_update_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
266 static void command_remove_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
268 static const pa_pdispatch_cb_t command_table
[PA_COMMAND_MAX
] = {
269 [PA_COMMAND_ERROR
] = NULL
,
270 [PA_COMMAND_TIMEOUT
] = NULL
,
271 [PA_COMMAND_REPLY
] = NULL
,
272 [PA_COMMAND_CREATE_PLAYBACK_STREAM
] = command_create_playback_stream
,
273 [PA_COMMAND_DELETE_PLAYBACK_STREAM
] = command_delete_stream
,
274 [PA_COMMAND_DRAIN_PLAYBACK_STREAM
] = command_drain_playback_stream
,
275 [PA_COMMAND_CREATE_RECORD_STREAM
] = command_create_record_stream
,
276 [PA_COMMAND_DELETE_RECORD_STREAM
] = command_delete_stream
,
277 [PA_COMMAND_AUTH
] = command_auth
,
278 [PA_COMMAND_REQUEST
] = NULL
,
279 [PA_COMMAND_EXIT
] = command_exit
,
280 [PA_COMMAND_SET_CLIENT_NAME
] = command_set_client_name
,
281 [PA_COMMAND_LOOKUP_SINK
] = command_lookup
,
282 [PA_COMMAND_LOOKUP_SOURCE
] = command_lookup
,
283 [PA_COMMAND_STAT
] = command_stat
,
284 [PA_COMMAND_GET_PLAYBACK_LATENCY
] = command_get_playback_latency
,
285 [PA_COMMAND_GET_RECORD_LATENCY
] = command_get_record_latency
,
286 [PA_COMMAND_CREATE_UPLOAD_STREAM
] = command_create_upload_stream
,
287 [PA_COMMAND_DELETE_UPLOAD_STREAM
] = command_delete_stream
,
288 [PA_COMMAND_FINISH_UPLOAD_STREAM
] = command_finish_upload_stream
,
289 [PA_COMMAND_PLAY_SAMPLE
] = command_play_sample
,
290 [PA_COMMAND_REMOVE_SAMPLE
] = command_remove_sample
,
291 [PA_COMMAND_GET_SINK_INFO
] = command_get_info
,
292 [PA_COMMAND_GET_SOURCE_INFO
] = command_get_info
,
293 [PA_COMMAND_GET_CLIENT_INFO
] = command_get_info
,
294 [PA_COMMAND_GET_MODULE_INFO
] = command_get_info
,
295 [PA_COMMAND_GET_SINK_INPUT_INFO
] = command_get_info
,
296 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO
] = command_get_info
,
297 [PA_COMMAND_GET_SAMPLE_INFO
] = command_get_info
,
298 [PA_COMMAND_GET_SINK_INFO_LIST
] = command_get_info_list
,
299 [PA_COMMAND_GET_SOURCE_INFO_LIST
] = command_get_info_list
,
300 [PA_COMMAND_GET_MODULE_INFO_LIST
] = command_get_info_list
,
301 [PA_COMMAND_GET_CLIENT_INFO_LIST
] = command_get_info_list
,
302 [PA_COMMAND_GET_SINK_INPUT_INFO_LIST
] = command_get_info_list
,
303 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
] = command_get_info_list
,
304 [PA_COMMAND_GET_SAMPLE_INFO_LIST
] = command_get_info_list
,
305 [PA_COMMAND_GET_SERVER_INFO
] = command_get_server_info
,
306 [PA_COMMAND_SUBSCRIBE
] = command_subscribe
,
308 [PA_COMMAND_SET_SINK_VOLUME
] = command_set_volume
,
309 [PA_COMMAND_SET_SINK_INPUT_VOLUME
] = command_set_volume
,
310 [PA_COMMAND_SET_SOURCE_VOLUME
] = command_set_volume
,
312 [PA_COMMAND_SET_SINK_MUTE
] = command_set_mute
,
313 [PA_COMMAND_SET_SINK_INPUT_MUTE
] = command_set_mute
,
314 [PA_COMMAND_SET_SOURCE_MUTE
] = command_set_mute
,
316 [PA_COMMAND_SUSPEND_SINK
] = command_suspend
,
317 [PA_COMMAND_SUSPEND_SOURCE
] = command_suspend
,
319 [PA_COMMAND_CORK_PLAYBACK_STREAM
] = command_cork_playback_stream
,
320 [PA_COMMAND_FLUSH_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
321 [PA_COMMAND_TRIGGER_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
322 [PA_COMMAND_PREBUF_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
324 [PA_COMMAND_CORK_RECORD_STREAM
] = command_cork_record_stream
,
325 [PA_COMMAND_FLUSH_RECORD_STREAM
] = command_flush_record_stream
,
327 [PA_COMMAND_SET_DEFAULT_SINK
] = command_set_default_sink_or_source
,
328 [PA_COMMAND_SET_DEFAULT_SOURCE
] = command_set_default_sink_or_source
,
329 [PA_COMMAND_SET_PLAYBACK_STREAM_NAME
] = command_set_stream_name
,
330 [PA_COMMAND_SET_RECORD_STREAM_NAME
] = command_set_stream_name
,
331 [PA_COMMAND_KILL_CLIENT
] = command_kill
,
332 [PA_COMMAND_KILL_SINK_INPUT
] = command_kill
,
333 [PA_COMMAND_KILL_SOURCE_OUTPUT
] = command_kill
,
334 [PA_COMMAND_LOAD_MODULE
] = command_load_module
,
335 [PA_COMMAND_UNLOAD_MODULE
] = command_unload_module
,
336 [PA_COMMAND_GET_AUTOLOAD_INFO
] = command_get_autoload_info
,
337 [PA_COMMAND_GET_AUTOLOAD_INFO_LIST
] = command_get_autoload_info_list
,
338 [PA_COMMAND_ADD_AUTOLOAD
] = command_add_autoload
,
339 [PA_COMMAND_REMOVE_AUTOLOAD
] = command_remove_autoload
,
341 [PA_COMMAND_MOVE_SINK_INPUT
] = command_move_stream
,
342 [PA_COMMAND_MOVE_SOURCE_OUTPUT
] = command_move_stream
,
344 [PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR
] = command_set_stream_buffer_attr
,
345 [PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR
] = command_set_stream_buffer_attr
,
347 [PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE
] = command_update_stream_sample_rate
,
348 [PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE
] = command_update_stream_sample_rate
,
350 [PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST
] = command_update_proplist
,
351 [PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST
] = command_update_proplist
,
352 [PA_COMMAND_UPDATE_CLIENT_PROPLIST
] = command_update_proplist
,
354 [PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
] = command_remove_proplist
,
355 [PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
] = command_remove_proplist
,
356 [PA_COMMAND_REMOVE_CLIENT_PROPLIST
] = command_remove_proplist
,
359 /* structure management */
361 static void upload_stream_unlink(upload_stream
*s
) {
367 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
368 s
->connection
= NULL
;
369 upload_stream_unref(s
);
372 static void upload_stream_free(pa_object
*o
) {
373 upload_stream
*s
= UPLOAD_STREAM(o
);
376 upload_stream_unlink(s
);
381 pa_proplist_free(s
->proplist
);
383 if (s
->memchunk
.memblock
)
384 pa_memblock_unref(s
->memchunk
.memblock
);
389 static upload_stream
* upload_stream_new(
391 const pa_sample_spec
*ss
,
392 const pa_channel_map
*map
,
402 pa_assert(length
> 0);
405 s
= pa_msgobject_new(upload_stream
);
406 s
->parent
.parent
.parent
.free
= upload_stream_free
;
408 s
->sample_spec
= *ss
;
409 s
->channel_map
= *map
;
410 s
->name
= pa_xstrdup(name
);
411 pa_memchunk_reset(&s
->memchunk
);
413 s
->proplist
= pa_proplist_copy(p
);
414 pa_proplist_update(s
->proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
416 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
421 static void record_stream_unlink(record_stream
*s
) {
427 if (s
->source_output
) {
428 pa_source_output_unlink(s
->source_output
);
429 pa_source_output_unref(s
->source_output
);
430 s
->source_output
= NULL
;
433 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->record_streams
, s
, NULL
) == s
);
434 s
->connection
= NULL
;
435 record_stream_unref(s
);
438 static void record_stream_free(pa_object
*o
) {
439 record_stream
*s
= RECORD_STREAM(o
);
442 record_stream_unlink(s
);
444 pa_memblockq_free(s
->memblockq
);
448 static int record_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
449 record_stream
*s
= RECORD_STREAM(o
);
450 record_stream_assert_ref(s
);
457 case RECORD_STREAM_MESSAGE_POST_DATA
:
459 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
460 /* pa_log_warn("Failed to push data into output queue."); */
464 if (!pa_pstream_is_pending(s
->connection
->pstream
))
465 send_memblock(s
->connection
);
473 static void fix_record_buffer_attr_pre(record_stream
*s
, pa_bool_t adjust_latency
, uint32_t *maxlength
, uint32_t *fragsize
) {
475 pa_assert(maxlength
);
478 if (*maxlength
<= 0 || *maxlength
> MAX_MEMBLOCKQ_LENGTH
)
479 *maxlength
= MAX_MEMBLOCKQ_LENGTH
;
482 *fragsize
= pa_usec_to_bytes(DEFAULT_FRAGSIZE_MSEC
*PA_USEC_PER_MSEC
, &s
->source_output
->sample_spec
);
484 if (adjust_latency
) {
485 pa_usec_t fragsize_usec
;
487 /* So, the user asked us to adjust the latency according to
488 * what the source can provide. Half the latency will be
489 * spent on the hw buffer, half of it in the async buffer
490 * queue we maintain for each client. */
492 fragsize_usec
= pa_bytes_to_usec(*fragsize
, &s
->source_output
->sample_spec
);
494 s
->source_latency
= pa_source_output_set_requested_latency(s
->source_output
, fragsize_usec
/2);
496 if (fragsize_usec
>= s
->source_latency
*2)
497 fragsize_usec
-= s
->source_latency
;
499 fragsize_usec
= s
->source_latency
;
501 *fragsize
= pa_usec_to_bytes(fragsize_usec
, &s
->source_output
->sample_spec
);
503 s
->source_latency
= 0;
506 static void fix_record_buffer_attr_post(record_stream
*s
, uint32_t *maxlength
, uint32_t *fragsize
) {
510 pa_assert(maxlength
);
513 *maxlength
= pa_memblockq_get_maxlength(s
->memblockq
);
515 base
= pa_frame_size(&s
->source_output
->sample_spec
);
517 s
->fragment_size
= (*fragsize
/base
)*base
;
518 if (s
->fragment_size
<= 0)
519 s
->fragment_size
= base
;
521 if (s
->fragment_size
> *maxlength
)
522 s
->fragment_size
= *maxlength
;
524 *fragsize
= s
->fragment_size
;
527 static record_stream
* record_stream_new(
532 pa_bool_t peak_detect
,
535 pa_source_output_flags_t flags
,
537 pa_bool_t adjust_latency
,
538 pa_sink_input
*direct_on_input
) {
541 pa_source_output
*source_output
;
543 pa_source_output_new_data data
;
547 pa_assert(maxlength
);
550 pa_source_output_new_data_init(&data
);
552 pa_proplist_update(data
.proplist
, PA_UPDATE_REPLACE
, p
);
553 pa_proplist_update(data
.proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
554 data
.driver
= __FILE__
;
555 data
.module
= c
->protocol
->module
;
556 data
.client
= c
->client
;
557 data
.source
= source
;
558 data
.direct_on_input
= direct_on_input
;
559 pa_source_output_new_data_set_sample_spec(&data
, ss
);
560 pa_source_output_new_data_set_channel_map(&data
, map
);
562 data
.resample_method
= PA_RESAMPLER_PEAKS
;
564 source_output
= pa_source_output_new(c
->protocol
->core
, &data
, flags
);
566 pa_source_output_new_data_done(&data
);
571 s
= pa_msgobject_new(record_stream
);
572 s
->parent
.parent
.free
= record_stream_free
;
573 s
->parent
.process_msg
= record_stream_process_msg
;
575 s
->source_output
= source_output
;
577 s
->source_output
->push
= source_output_push_cb
;
578 s
->source_output
->kill
= source_output_kill_cb
;
579 s
->source_output
->get_latency
= source_output_get_latency_cb
;
580 s
->source_output
->moved
= source_output_moved_cb
;
581 s
->source_output
->suspend
= source_output_suspend_cb
;
582 s
->source_output
->userdata
= s
;
584 fix_record_buffer_attr_pre(s
, adjust_latency
, maxlength
, fragsize
);
586 s
->memblockq
= pa_memblockq_new(
590 base
= pa_frame_size(&source_output
->sample_spec
),
596 fix_record_buffer_attr_post(s
, maxlength
, fragsize
);
598 *ss
= s
->source_output
->sample_spec
;
599 *map
= s
->source_output
->channel_map
;
601 pa_idxset_put(c
->record_streams
, s
, &s
->index
);
603 pa_log_info("Final latency %0.2f ms = %0.2f ms + %0.2f ms",
604 ((double) pa_bytes_to_usec(s
->fragment_size
, &source_output
->sample_spec
) + (double) s
->source_latency
) / PA_USEC_PER_MSEC
,
605 (double) pa_bytes_to_usec(s
->fragment_size
, &source_output
->sample_spec
) / PA_USEC_PER_MSEC
,
606 (double) s
->source_latency
/ PA_USEC_PER_MSEC
);
608 pa_source_output_put(s
->source_output
);
612 static void playback_stream_unlink(playback_stream
*s
) {
619 pa_sink_input_unlink(s
->sink_input
);
620 pa_sink_input_unref(s
->sink_input
);
621 s
->sink_input
= NULL
;
624 if (s
->drain_request
)
625 pa_pstream_send_error(s
->connection
->pstream
, s
->drain_tag
, PA_ERR_NOENTITY
);
627 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
628 s
->connection
= NULL
;
629 playback_stream_unref(s
);
632 static void playback_stream_free(pa_object
* o
) {
633 playback_stream
*s
= PLAYBACK_STREAM(o
);
636 playback_stream_unlink(s
);
638 pa_memblockq_free(s
->memblockq
);
642 static int playback_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
643 playback_stream
*s
= PLAYBACK_STREAM(o
);
644 playback_stream_assert_ref(s
);
650 case PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
: {
655 if ((l
= pa_atomic_load(&s
->missing
)) <= 0)
658 if (pa_atomic_cmpxchg(&s
->missing
, l
, 0))
665 t
= pa_tagstruct_new(NULL
, 0);
666 pa_tagstruct_putu32(t
, PA_COMMAND_REQUEST
);
667 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
668 pa_tagstruct_putu32(t
, s
->index
);
669 pa_tagstruct_putu32(t
, l
);
670 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
672 /* pa_log("Requesting %lu bytes", (unsigned long) l); */
676 case PLAYBACK_STREAM_MESSAGE_UNDERFLOW
: {
679 /* Report that we're empty */
680 t
= pa_tagstruct_new(NULL
, 0);
681 pa_tagstruct_putu32(t
, PA_COMMAND_UNDERFLOW
);
682 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
683 pa_tagstruct_putu32(t
, s
->index
);
684 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
688 case PLAYBACK_STREAM_MESSAGE_OVERFLOW
: {
691 /* Notify the user we're overflowed*/
692 t
= pa_tagstruct_new(NULL
, 0);
693 pa_tagstruct_putu32(t
, PA_COMMAND_OVERFLOW
);
694 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
695 pa_tagstruct_putu32(t
, s
->index
);
696 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
700 case PLAYBACK_STREAM_MESSAGE_STARTED
:
702 if (s
->connection
->version
>= 13) {
705 /* Notify the user we're overflowed*/
706 t
= pa_tagstruct_new(NULL
, 0);
707 pa_tagstruct_putu32(t
, PA_COMMAND_STARTED
);
708 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
709 pa_tagstruct_putu32(t
, s
->index
);
710 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
715 case PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
:
716 pa_pstream_send_simple_ack(s
->connection
->pstream
, PA_PTR_TO_UINT(userdata
));
723 static void fix_playback_buffer_attr_pre(playback_stream
*s
, pa_bool_t adjust_latency
, uint32_t *maxlength
, uint32_t *tlength
, uint32_t* prebuf
, uint32_t* minreq
) {
725 pa_usec_t tlength_usec
, minreq_usec
, sink_usec
;
728 pa_assert(maxlength
);
733 if (*maxlength
<= 0 || *maxlength
> MAX_MEMBLOCKQ_LENGTH
)
734 *maxlength
= MAX_MEMBLOCKQ_LENGTH
;
736 *tlength
= pa_usec_to_bytes(DEFAULT_TLENGTH_MSEC
*PA_USEC_PER_MSEC
, &s
->sink_input
->sample_spec
);
738 *minreq
= pa_usec_to_bytes(DEFAULT_PROCESS_MSEC
*PA_USEC_PER_MSEC
, &s
->sink_input
->sample_spec
);
740 frame_size
= pa_frame_size(&s
->sink_input
->sample_spec
);
742 *minreq
= frame_size
;
743 if (*tlength
< *minreq
+frame_size
)
744 *tlength
= *minreq
+frame_size
;
746 tlength_usec
= pa_bytes_to_usec(*tlength
, &s
->sink_input
->sample_spec
);
747 minreq_usec
= pa_bytes_to_usec(*minreq
, &s
->sink_input
->sample_spec
);
749 pa_log_info("Requested tlength=%0.2f ms, minreq=%0.2f ms",
750 (double) tlength_usec
/ PA_USEC_PER_MSEC
,
751 (double) minreq_usec
/ PA_USEC_PER_MSEC
);
753 if (adjust_latency
) {
755 /* So, the user asked us to adjust the latency of the stream
756 * buffer according to the what the sink can provide. The
757 * tlength passed in shall be the overall latency. Roughly
758 * half the latency will be spent on the hw buffer, the other
759 * half of it in the async buffer queue we maintain for each
760 * client. In between we'll have a safety space of size
761 * 2*minreq. Why the 2*minreq? When the hw buffer is completey
762 * empty and needs to be filled, then our buffer must have
763 * enough data to fulfill this request immediatly and thus
764 * have at least the same tlength as the size of the hw
765 * buffer. It additionally needs space for 2 times minreq
766 * because if the buffer ran empty and a partial fillup
767 * happens immediately on the next iteration we need to be
768 * able to fulfill it and give the application also minreq
769 * time to fill it up again for the next request Makes 2 times
770 * minreq in plus.. */
772 if (tlength_usec
> minreq_usec
*2)
773 sink_usec
= (tlength_usec
- minreq_usec
*2)/2;
779 /* Ok, the user didn't ask us to adjust the latency, but we
780 * still need to make sure that the parameters from the user
783 if (tlength_usec
> minreq_usec
*2)
784 sink_usec
= (tlength_usec
- minreq_usec
*2);
789 s
->sink_latency
= pa_sink_input_set_requested_latency(s
->sink_input
, sink_usec
);
791 if (adjust_latency
) {
792 /* Ok, we didn't necessarily get what we were asking for, so
793 * let's subtract from what we asked for for the remaining
796 if (tlength_usec
>= s
->sink_latency
)
797 tlength_usec
-= s
->sink_latency
;
800 if (tlength_usec
< s
->sink_latency
+ 2*minreq_usec
)
801 tlength_usec
= s
->sink_latency
+ 2*minreq_usec
;
803 *tlength
= pa_usec_to_bytes(tlength_usec
, &s
->sink_input
->sample_spec
);
804 *minreq
= pa_usec_to_bytes(minreq_usec
, &s
->sink_input
->sample_spec
);
807 *minreq
+= frame_size
;
808 *tlength
+= frame_size
*2;
811 if (*tlength
<= *minreq
)
812 *tlength
= *minreq
*2 + frame_size
;
818 static void fix_playback_buffer_attr_post(playback_stream
*s
, uint32_t *maxlength
, uint32_t *tlength
, uint32_t* prebuf
, uint32_t* minreq
) {
820 pa_assert(maxlength
);
825 *maxlength
= (uint32_t) pa_memblockq_get_maxlength(s
->memblockq
);
826 *tlength
= (uint32_t) pa_memblockq_get_tlength(s
->memblockq
);
827 *prebuf
= (uint32_t) pa_memblockq_get_prebuf(s
->memblockq
);
828 *minreq
= (uint32_t) pa_memblockq_get_minreq(s
->memblockq
);
833 static playback_stream
* playback_stream_new(
846 pa_sink_input_flags_t flags
,
848 pa_bool_t adjust_latency
) {
850 playback_stream
*s
, *ssync
;
851 pa_sink_input
*sink_input
;
855 pa_sink_input_new_data data
;
859 pa_assert(maxlength
);
867 /* Find syncid group */
868 for (ssync
= pa_idxset_first(c
->output_streams
, &idx
); ssync
; ssync
= pa_idxset_next(c
->output_streams
, &idx
)) {
870 if (!playback_stream_isinstance(ssync
))
873 if (ssync
->syncid
== syncid
)
877 /* Synced streams must connect to the same sink */
881 sink
= ssync
->sink_input
->sink
;
882 else if (sink
!= ssync
->sink_input
->sink
)
886 pa_sink_input_new_data_init(&data
);
888 pa_proplist_update(data
.proplist
, PA_UPDATE_REPLACE
, p
);
889 pa_proplist_update(data
.proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
890 data
.driver
= __FILE__
;
891 data
.module
= c
->protocol
->module
;
892 data
.client
= c
->client
;
894 pa_sink_input_new_data_set_sample_spec(&data
, ss
);
895 pa_sink_input_new_data_set_channel_map(&data
, map
);
896 pa_sink_input_new_data_set_volume(&data
, volume
);
897 pa_sink_input_new_data_set_muted(&data
, muted
);
898 data
.sync_base
= ssync
? ssync
->sink_input
: NULL
;
900 sink_input
= pa_sink_input_new(c
->protocol
->core
, &data
, flags
);
902 pa_sink_input_new_data_done(&data
);
907 s
= pa_msgobject_new(playback_stream
);
908 s
->parent
.parent
.parent
.free
= playback_stream_free
;
909 s
->parent
.parent
.process_msg
= playback_stream_process_msg
;
912 s
->sink_input
= sink_input
;
914 s
->sink_input
->parent
.process_msg
= sink_input_process_msg
;
915 s
->sink_input
->pop
= sink_input_pop_cb
;
916 s
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
917 s
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
918 s
->sink_input
->kill
= sink_input_kill_cb
;
919 s
->sink_input
->moved
= sink_input_moved_cb
;
920 s
->sink_input
->suspend
= sink_input_suspend_cb
;
921 s
->sink_input
->userdata
= s
;
923 start_index
= ssync
? pa_memblockq_get_read_index(ssync
->memblockq
) : 0;
925 fix_playback_buffer_attr_pre(s
, adjust_latency
, maxlength
, tlength
, prebuf
, minreq
);
926 pa_sink_input_get_silence(sink_input
, &silence
);
928 s
->memblockq
= pa_memblockq_new(
932 pa_frame_size(&sink_input
->sample_spec
),
938 pa_memblock_unref(silence
.memblock
);
939 fix_playback_buffer_attr_post(s
, maxlength
, tlength
, prebuf
, minreq
);
941 *missing
= (uint32_t) pa_memblockq_pop_missing(s
->memblockq
);
943 *ss
= s
->sink_input
->sample_spec
;
944 *map
= s
->sink_input
->channel_map
;
946 pa_atomic_store(&s
->missing
, 0);
947 s
->drain_request
= FALSE
;
949 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
951 pa_log_info("Final latency %0.2f ms = %0.2f ms + 2*%0.2f ms + %0.2f ms",
952 ((double) pa_bytes_to_usec(*tlength
, &sink_input
->sample_spec
) + (double) s
->sink_latency
) / PA_USEC_PER_MSEC
,
953 (double) pa_bytes_to_usec(*tlength
-*minreq
*2, &sink_input
->sample_spec
) / PA_USEC_PER_MSEC
,
954 (double) pa_bytes_to_usec(*minreq
, &sink_input
->sample_spec
) / PA_USEC_PER_MSEC
,
955 (double) s
->sink_latency
/ PA_USEC_PER_MSEC
);
957 pa_sink_input_put(s
->sink_input
);
961 static int connection_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
962 connection
*c
= CONNECTION(o
);
963 connection_assert_ref(c
);
970 case CONNECTION_MESSAGE_REVOKE
:
971 pa_pstream_send_revoke(c
->pstream
, PA_PTR_TO_UINT(userdata
));
974 case CONNECTION_MESSAGE_RELEASE
:
975 pa_pstream_send_release(c
->pstream
, PA_PTR_TO_UINT(userdata
));
982 static void connection_unlink(connection
*c
) {
991 while ((r
= pa_idxset_first(c
->record_streams
, NULL
)))
992 record_stream_unlink(r
);
994 while ((o
= pa_idxset_first(c
->output_streams
, NULL
)))
995 if (playback_stream_isinstance(o
))
996 playback_stream_unlink(PLAYBACK_STREAM(o
));
998 upload_stream_unlink(UPLOAD_STREAM(o
));
1000 if (c
->subscription
)
1001 pa_subscription_free(c
->subscription
);
1004 pa_pstream_unlink(c
->pstream
);
1006 if (c
->auth_timeout_event
) {
1007 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
1008 c
->auth_timeout_event
= NULL
;
1011 pa_assert_se(pa_idxset_remove_by_data(c
->protocol
->connections
, c
, NULL
) == c
);
1013 connection_unref(c
);
1016 static void connection_free(pa_object
*o
) {
1017 connection
*c
= CONNECTION(o
);
1021 connection_unlink(c
);
1023 pa_idxset_free(c
->record_streams
, NULL
, NULL
);
1024 pa_idxset_free(c
->output_streams
, NULL
, NULL
);
1026 pa_pdispatch_unref(c
->pdispatch
);
1027 pa_pstream_unref(c
->pstream
);
1028 pa_client_free(c
->client
);
1033 /* Called from thread context */
1034 static void request_bytes(playback_stream
*s
) {
1035 size_t m
, previous_missing
;
1037 playback_stream_assert_ref(s
);
1039 m
= pa_memblockq_pop_missing(s
->memblockq
);
1044 /* pa_log("request_bytes(%lu)", (unsigned long) m); */
1046 previous_missing
= pa_atomic_add(&s
->missing
, m
);
1048 if (pa_memblockq_prebuf_active(s
->memblockq
) ||
1049 (previous_missing
< s
->minreq
&& previous_missing
+m
>= s
->minreq
))
1050 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, NULL
, 0, NULL
, NULL
);
1053 static void send_memblock(connection
*c
) {
1057 start
= PA_IDXSET_INVALID
;
1061 if (!(r
= RECORD_STREAM(pa_idxset_rrobin(c
->record_streams
, &c
->rrobin_index
))))
1064 if (start
== PA_IDXSET_INVALID
)
1065 start
= c
->rrobin_index
;
1066 else if (start
== c
->rrobin_index
)
1069 if (pa_memblockq_peek(r
->memblockq
, &chunk
) >= 0) {
1070 pa_memchunk schunk
= chunk
;
1072 if (schunk
.length
> r
->fragment_size
)
1073 schunk
.length
= r
->fragment_size
;
1075 pa_pstream_send_memblock(c
->pstream
, r
->index
, 0, PA_SEEK_RELATIVE
, &schunk
);
1077 pa_memblockq_drop(r
->memblockq
, schunk
.length
);
1078 pa_memblock_unref(schunk
.memblock
);
1085 static void send_playback_stream_killed(playback_stream
*p
) {
1087 playback_stream_assert_ref(p
);
1089 t
= pa_tagstruct_new(NULL
, 0);
1090 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_KILLED
);
1091 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1092 pa_tagstruct_putu32(t
, p
->index
);
1093 pa_pstream_send_tagstruct(p
->connection
->pstream
, t
);
1096 static void send_record_stream_killed(record_stream
*r
) {
1098 record_stream_assert_ref(r
);
1100 t
= pa_tagstruct_new(NULL
, 0);
1101 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_KILLED
);
1102 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1103 pa_tagstruct_putu32(t
, r
->index
);
1104 pa_pstream_send_tagstruct(r
->connection
->pstream
, t
);
1107 /*** sink input callbacks ***/
1109 static void handle_seek(playback_stream
*s
, int64_t indexw
) {
1110 playback_stream_assert_ref(s
);
1112 /* pa_log("handle_seek: %llu -- %i", (unsigned long long) s->sink_input->thread_info.underrun_for, pa_memblockq_is_readable(s->memblockq)); */
1114 if (s
->sink_input
->thread_info
.underrun_for
> 0) {
1116 /* pa_log("%lu vs. %lu", (unsigned long) pa_memblockq_get_length(s->memblockq), (unsigned long) pa_memblockq_get_prebuf(s->memblockq)); */
1118 if (pa_memblockq_is_readable(s
->memblockq
)) {
1120 /* We just ended an underrun, let's ask the sink
1121 * for a complete rewind rewrite */
1123 pa_log_debug("Requesting rewind due to end of underrun.");
1124 pa_sink_input_request_rewind(s
->sink_input
,
1125 s
->sink_input
->thread_info
.underrun_for
== (size_t) -1 ? 0 : s
->sink_input
->thread_info
.underrun_for
,
1132 indexr
= pa_memblockq_get_read_index(s
->memblockq
);
1134 if (indexw
< indexr
) {
1135 /* OK, the sink already asked for this data, so
1136 * let's have it usk us again */
1138 pa_log_debug("Requesting rewind due to rewrite.");
1139 pa_sink_input_request_rewind(s
->sink_input
, indexr
- indexw
, TRUE
, FALSE
);
1146 /* Called from thread context */
1147 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
) {
1148 pa_sink_input
*i
= PA_SINK_INPUT(o
);
1151 pa_sink_input_assert_ref(i
);
1152 s
= PLAYBACK_STREAM(i
->userdata
);
1153 playback_stream_assert_ref(s
);
1157 case SINK_INPUT_MESSAGE_SEEK
: {
1160 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1161 pa_memblockq_seek(s
->memblockq
, offset
, PA_PTR_TO_UINT(userdata
));
1163 handle_seek(s
, windex
);
1167 case SINK_INPUT_MESSAGE_POST_DATA
: {
1172 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1174 /* pa_log("sink input post: %lu %lli", (unsigned long) chunk->length, (long long) windex); */
1176 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
1177 pa_log_warn("Failed to push data into queue");
1178 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_OVERFLOW
, NULL
, 0, NULL
, NULL
);
1179 pa_memblockq_seek(s
->memblockq
, chunk
->length
, PA_SEEK_RELATIVE
);
1182 handle_seek(s
, windex
);
1184 /* pa_log("sink input post2: %lu", (unsigned long) pa_memblockq_get_length(s->memblockq)); */
1189 case SINK_INPUT_MESSAGE_DRAIN
:
1190 case SINK_INPUT_MESSAGE_FLUSH
:
1191 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
1192 case SINK_INPUT_MESSAGE_TRIGGER
: {
1195 pa_sink_input
*isync
;
1196 void (*func
)(pa_memblockq
*bq
);
1199 case SINK_INPUT_MESSAGE_FLUSH
:
1200 func
= pa_memblockq_flush
;
1203 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
1204 func
= pa_memblockq_prebuf_force
;
1207 case SINK_INPUT_MESSAGE_DRAIN
:
1208 case SINK_INPUT_MESSAGE_TRIGGER
:
1209 func
= pa_memblockq_prebuf_disable
;
1213 pa_assert_not_reached();
1216 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1218 handle_seek(s
, windex
);
1220 /* Do the same for all other members in the sync group */
1221 for (isync
= i
->sync_prev
; isync
; isync
= isync
->sync_prev
) {
1222 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
1223 windex
= pa_memblockq_get_write_index(ssync
->memblockq
);
1224 func(ssync
->memblockq
);
1225 handle_seek(ssync
, windex
);
1228 for (isync
= i
->sync_next
; isync
; isync
= isync
->sync_next
) {
1229 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
1230 windex
= pa_memblockq_get_write_index(ssync
->memblockq
);
1231 func(ssync
->memblockq
);
1232 handle_seek(ssync
, windex
);
1235 if (code
== SINK_INPUT_MESSAGE_DRAIN
) {
1236 if (!pa_memblockq_is_readable(s
->memblockq
))
1237 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
, userdata
, 0, NULL
, NULL
);
1239 s
->drain_tag
= PA_PTR_TO_UINT(userdata
);
1240 s
->drain_request
= TRUE
;
1247 case SINK_INPUT_MESSAGE_UPDATE_LATENCY
:
1249 s
->read_index
= pa_memblockq_get_read_index(s
->memblockq
);
1250 s
->write_index
= pa_memblockq_get_write_index(s
->memblockq
);
1251 s
->render_memblockq_length
= pa_memblockq_get_length(s
->sink_input
->thread_info
.render_memblockq
);
1254 case PA_SINK_INPUT_MESSAGE_SET_STATE
: {
1257 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1259 pa_memblockq_prebuf_force(s
->memblockq
);
1261 handle_seek(s
, windex
);
1263 /* Fall through to the default handler */
1267 case PA_SINK_INPUT_MESSAGE_GET_LATENCY
: {
1268 pa_usec_t
*r
= userdata
;
1270 *r
= pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &i
->sample_spec
);
1272 /* Fall through, the default handler will add in the extra
1273 * latency added by the resampler */
1278 return pa_sink_input_process_msg(o
, code
, userdata
, offset
, chunk
);
1281 /* Called from thread context */
1282 static int sink_input_pop_cb(pa_sink_input
*i
, size_t nbytes
, pa_memchunk
*chunk
) {
1285 pa_sink_input_assert_ref(i
);
1286 s
= PLAYBACK_STREAM(i
->userdata
);
1287 playback_stream_assert_ref(s
);
1290 if (pa_memblockq_peek(s
->memblockq
, chunk
) < 0) {
1292 /* pa_log("UNDERRUN: %lu", pa_memblockq_get_length(s->memblockq)); */
1294 if (s
->drain_request
&& pa_sink_input_safe_to_remove(i
)) {
1295 s
->drain_request
= FALSE
;
1296 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
, PA_UINT_TO_PTR(s
->drain_tag
), 0, NULL
, NULL
);
1297 } else if (i
->thread_info
.playing_for
> 0)
1298 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_UNDERFLOW
, NULL
, 0, NULL
, NULL
);
1300 /* pa_log("adding %llu bytes", (unsigned long long) nbytes); */
1307 /* pa_log("NOTUNDERRUN %lu", (unsigned long) chunk->length); */
1309 chunk
->length
= PA_MIN(nbytes
, chunk
->length
);
1311 if (i
->thread_info
.underrun_for
> 0)
1312 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_STARTED
, NULL
, 0, NULL
, NULL
);
1314 pa_memblockq_drop(s
->memblockq
, chunk
->length
);
1320 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
1323 pa_sink_input_assert_ref(i
);
1324 s
= PLAYBACK_STREAM(i
->userdata
);
1325 playback_stream_assert_ref(s
);
1327 /* If we are in an underrun, then we don't rewind */
1328 if (i
->thread_info
.underrun_for
> 0)
1331 pa_memblockq_rewind(s
->memblockq
, nbytes
);
1334 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
1337 pa_sink_input_assert_ref(i
);
1338 s
= PLAYBACK_STREAM(i
->userdata
);
1339 playback_stream_assert_ref(s
);
1341 pa_memblockq_set_maxrewind(s
->memblockq
, nbytes
);
1344 /* Called from main context */
1345 static void sink_input_kill_cb(pa_sink_input
*i
) {
1348 pa_sink_input_assert_ref(i
);
1349 s
= PLAYBACK_STREAM(i
->userdata
);
1350 playback_stream_assert_ref(s
);
1352 send_playback_stream_killed(s
);
1353 playback_stream_unlink(s
);
1356 /* Called from main context */
1357 static void sink_input_suspend_cb(pa_sink_input
*i
, pa_bool_t suspend
) {
1361 pa_sink_input_assert_ref(i
);
1362 s
= PLAYBACK_STREAM(i
->userdata
);
1363 playback_stream_assert_ref(s
);
1365 if (s
->connection
->version
< 12)
1368 t
= pa_tagstruct_new(NULL
, 0);
1369 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_SUSPENDED
);
1370 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1371 pa_tagstruct_putu32(t
, s
->index
);
1372 pa_tagstruct_put_boolean(t
, suspend
);
1373 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1376 /* Called from main context */
1377 static void sink_input_moved_cb(pa_sink_input
*i
) {
1380 uint32_t maxlength
, tlength
, prebuf
, minreq
;
1382 pa_sink_input_assert_ref(i
);
1383 s
= PLAYBACK_STREAM(i
->userdata
);
1384 playback_stream_assert_ref(s
);
1386 maxlength
= (uint32_t) pa_memblockq_get_maxlength(s
->memblockq
);
1387 tlength
= (uint32_t) pa_memblockq_get_tlength(s
->memblockq
);
1388 prebuf
= (uint32_t) pa_memblockq_get_prebuf(s
->memblockq
);
1389 minreq
= (uint32_t) pa_memblockq_get_minreq(s
->memblockq
);
1391 fix_playback_buffer_attr_pre(s
, TRUE
, &maxlength
, &tlength
, &prebuf
, &minreq
);
1392 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
1393 pa_memblockq_set_tlength(s
->memblockq
, tlength
);
1394 pa_memblockq_set_prebuf(s
->memblockq
, prebuf
);
1395 pa_memblockq_set_minreq(s
->memblockq
, minreq
);
1396 fix_playback_buffer_attr_post(s
, &maxlength
, &tlength
, &prebuf
, &minreq
);
1398 if (s
->connection
->version
< 12)
1401 t
= pa_tagstruct_new(NULL
, 0);
1402 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_MOVED
);
1403 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1404 pa_tagstruct_putu32(t
, s
->index
);
1405 pa_tagstruct_putu32(t
, i
->sink
->index
);
1406 pa_tagstruct_puts(t
, i
->sink
->name
);
1407 pa_tagstruct_put_boolean(t
, pa_sink_get_state(i
->sink
) == PA_SINK_SUSPENDED
);
1409 if (s
->connection
->version
>= 13) {
1410 pa_tagstruct_putu32(t
, maxlength
);
1411 pa_tagstruct_putu32(t
, tlength
);
1412 pa_tagstruct_putu32(t
, prebuf
);
1413 pa_tagstruct_putu32(t
, minreq
);
1414 pa_tagstruct_put_usec(t
, s
->sink_latency
);
1417 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1420 /*** source_output callbacks ***/
1422 /* Called from thread context */
1423 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
) {
1426 pa_source_output_assert_ref(o
);
1427 s
= RECORD_STREAM(o
->userdata
);
1428 record_stream_assert_ref(s
);
1431 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), RECORD_STREAM_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
1434 static void source_output_kill_cb(pa_source_output
*o
) {
1437 pa_source_output_assert_ref(o
);
1438 s
= RECORD_STREAM(o
->userdata
);
1439 record_stream_assert_ref(s
);
1441 send_record_stream_killed(s
);
1442 record_stream_unlink(s
);
1445 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
) {
1448 pa_source_output_assert_ref(o
);
1449 s
= RECORD_STREAM(o
->userdata
);
1450 record_stream_assert_ref(s
);
1452 /*pa_log("get_latency: %u", pa_memblockq_get_length(s->memblockq));*/
1454 return pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &o
->sample_spec
);
1457 /* Called from main context */
1458 static void source_output_suspend_cb(pa_source_output
*o
, pa_bool_t suspend
) {
1462 pa_source_output_assert_ref(o
);
1463 s
= RECORD_STREAM(o
->userdata
);
1464 record_stream_assert_ref(s
);
1466 if (s
->connection
->version
< 12)
1469 t
= pa_tagstruct_new(NULL
, 0);
1470 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_SUSPENDED
);
1471 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1472 pa_tagstruct_putu32(t
, s
->index
);
1473 pa_tagstruct_put_boolean(t
, suspend
);
1474 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1477 /* Called from main context */
1478 static void source_output_moved_cb(pa_source_output
*o
) {
1481 uint32_t maxlength
, fragsize
;
1483 pa_source_output_assert_ref(o
);
1484 s
= RECORD_STREAM(o
->userdata
);
1485 record_stream_assert_ref(s
);
1487 fragsize
= (uint32_t) s
->fragment_size
;
1488 maxlength
= (uint32_t) pa_memblockq_get_length(s
->memblockq
);
1490 fix_record_buffer_attr_pre(s
, TRUE
, &maxlength
, &fragsize
);
1491 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
1492 fix_record_buffer_attr_post(s
, &maxlength
, &fragsize
);
1494 if (s
->connection
->version
< 12)
1497 t
= pa_tagstruct_new(NULL
, 0);
1498 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_MOVED
);
1499 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1500 pa_tagstruct_putu32(t
, s
->index
);
1501 pa_tagstruct_putu32(t
, o
->source
->index
);
1502 pa_tagstruct_puts(t
, o
->source
->name
);
1503 pa_tagstruct_put_boolean(t
, pa_source_get_state(o
->source
) == PA_SOURCE_SUSPENDED
);
1505 if (s
->connection
->version
>= 13) {
1506 pa_tagstruct_putu32(t
, maxlength
);
1507 pa_tagstruct_putu32(t
, fragsize
);
1508 pa_tagstruct_put_usec(t
, s
->source_latency
);
1511 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1514 /*** pdispatch callbacks ***/
1516 static void protocol_error(connection
*c
) {
1517 pa_log("protocol error, kicking client");
1518 connection_unlink(c
);
1521 #define CHECK_VALIDITY(pstream, expression, tag, error) do { \
1522 if (!(expression)) { \
1523 pa_pstream_send_error((pstream), (tag), (error)); \
1528 static pa_tagstruct
*reply_new(uint32_t tag
) {
1529 pa_tagstruct
*reply
;
1531 reply
= pa_tagstruct_new(NULL
, 0);
1532 pa_tagstruct_putu32(reply
, PA_COMMAND_REPLY
);
1533 pa_tagstruct_putu32(reply
, tag
);
1537 static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1538 connection
*c
= CONNECTION(userdata
);
1540 uint32_t maxlength
, tlength
, prebuf
, minreq
, sink_index
, syncid
, missing
;
1541 const char *name
= NULL
, *sink_name
;
1544 pa_tagstruct
*reply
;
1545 pa_sink
*sink
= NULL
;
1553 fix_channels
= FALSE
,
1555 variable_rate
= FALSE
,
1557 adjust_latency
= FALSE
;
1559 pa_sink_input_flags_t flags
= 0;
1562 connection_assert_ref(c
);
1565 if ((c
->version
< 13 && (pa_tagstruct_gets(t
, &name
) < 0 || !name
)) ||
1568 PA_TAG_SAMPLE_SPEC
, &ss
,
1569 PA_TAG_CHANNEL_MAP
, &map
,
1570 PA_TAG_U32
, &sink_index
,
1571 PA_TAG_STRING
, &sink_name
,
1572 PA_TAG_U32
, &maxlength
,
1573 PA_TAG_BOOLEAN
, &corked
,
1574 PA_TAG_U32
, &tlength
,
1575 PA_TAG_U32
, &prebuf
,
1576 PA_TAG_U32
, &minreq
,
1577 PA_TAG_U32
, &syncid
,
1578 PA_TAG_CVOLUME
, &volume
,
1579 PA_TAG_INVALID
) < 0) {
1585 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1586 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(sink_name
)), tag
, PA_ERR_INVALID
);
1587 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1588 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1589 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
1590 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
&& volume
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1592 p
= pa_proplist_new();
1595 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
1597 if (c
->version
>= 12) {
1598 /* Since 0.9.8 the user can ask for a couple of additional flags */
1600 if (pa_tagstruct_get_boolean(t
, &no_remap
) < 0 ||
1601 pa_tagstruct_get_boolean(t
, &no_remix
) < 0 ||
1602 pa_tagstruct_get_boolean(t
, &fix_format
) < 0 ||
1603 pa_tagstruct_get_boolean(t
, &fix_rate
) < 0 ||
1604 pa_tagstruct_get_boolean(t
, &fix_channels
) < 0 ||
1605 pa_tagstruct_get_boolean(t
, &no_move
) < 0 ||
1606 pa_tagstruct_get_boolean(t
, &variable_rate
) < 0) {
1609 pa_proplist_free(p
);
1614 if (c
->version
>= 13) {
1616 if (pa_tagstruct_get_boolean(t
, &muted
) < 0 ||
1617 pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0 ||
1618 pa_tagstruct_get_proplist(t
, p
) < 0) {
1620 pa_proplist_free(p
);
1625 if (!pa_tagstruct_eof(t
)) {
1627 pa_proplist_free(p
);
1631 if (sink_index
!= PA_INVALID_INDEX
) {
1633 if (!(sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
))) {
1634 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1635 pa_proplist_free(p
);
1639 } else if (sink_name
) {
1641 if (!(sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1))) {
1642 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1643 pa_proplist_free(p
);
1649 (corked
? PA_SINK_INPUT_START_CORKED
: 0) |
1650 (no_remap
? PA_SINK_INPUT_NO_REMAP
: 0) |
1651 (no_remix
? PA_SINK_INPUT_NO_REMIX
: 0) |
1652 (fix_format
? PA_SINK_INPUT_FIX_FORMAT
: 0) |
1653 (fix_rate
? PA_SINK_INPUT_FIX_RATE
: 0) |
1654 (fix_channels
? PA_SINK_INPUT_FIX_CHANNELS
: 0) |
1655 (no_move
? PA_SINK_INPUT_DONT_MOVE
: 0) |
1656 (variable_rate
? PA_SINK_INPUT_VARIABLE_RATE
: 0);
1658 s
= playback_stream_new(c
, sink
, &ss
, &map
, &maxlength
, &tlength
, &prebuf
, &minreq
, &volume
, muted
, syncid
, &missing
, flags
, p
, adjust_latency
);
1659 pa_proplist_free(p
);
1661 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1663 reply
= reply_new(tag
);
1664 pa_tagstruct_putu32(reply
, s
->index
);
1665 pa_assert(s
->sink_input
);
1666 pa_tagstruct_putu32(reply
, s
->sink_input
->index
);
1667 pa_tagstruct_putu32(reply
, missing
);
1669 /* pa_log("initial request is %u", missing); */
1671 if (c
->version
>= 9) {
1672 /* Since 0.9.0 we support sending the buffer metrics back to the client */
1674 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1675 pa_tagstruct_putu32(reply
, (uint32_t) tlength
);
1676 pa_tagstruct_putu32(reply
, (uint32_t) prebuf
);
1677 pa_tagstruct_putu32(reply
, (uint32_t) minreq
);
1680 if (c
->version
>= 12) {
1681 /* Since 0.9.8 we support sending the chosen sample
1682 * spec/channel map/device/suspend status back to the
1685 pa_tagstruct_put_sample_spec(reply
, &ss
);
1686 pa_tagstruct_put_channel_map(reply
, &map
);
1688 pa_tagstruct_putu32(reply
, s
->sink_input
->sink
->index
);
1689 pa_tagstruct_puts(reply
, s
->sink_input
->sink
->name
);
1691 pa_tagstruct_put_boolean(reply
, pa_sink_get_state(s
->sink_input
->sink
) == PA_SINK_SUSPENDED
);
1694 if (c
->version
>= 13)
1695 pa_tagstruct_put_usec(reply
, s
->sink_latency
);
1697 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1700 static void command_delete_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1701 connection
*c
= CONNECTION(userdata
);
1704 connection_assert_ref(c
);
1707 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
1708 !pa_tagstruct_eof(t
)) {
1713 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1717 case PA_COMMAND_DELETE_PLAYBACK_STREAM
: {
1719 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !playback_stream_isinstance(s
)) {
1720 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1724 playback_stream_unlink(s
);
1728 case PA_COMMAND_DELETE_RECORD_STREAM
: {
1730 if (!(s
= pa_idxset_get_by_index(c
->record_streams
, channel
))) {
1731 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1735 record_stream_unlink(s
);
1739 case PA_COMMAND_DELETE_UPLOAD_STREAM
: {
1742 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !upload_stream_isinstance(s
)) {
1743 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1747 upload_stream_unlink(s
);
1752 pa_assert_not_reached();
1755 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1758 static void command_create_record_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1759 connection
*c
= CONNECTION(userdata
);
1761 uint32_t maxlength
, fragment_size
;
1762 uint32_t source_index
;
1763 const char *name
= NULL
, *source_name
;
1766 pa_tagstruct
*reply
;
1767 pa_source
*source
= NULL
;
1774 fix_channels
= FALSE
,
1776 variable_rate
= FALSE
,
1777 adjust_latency
= FALSE
,
1778 peak_detect
= FALSE
;
1779 pa_source_output_flags_t flags
= 0;
1781 uint32_t direct_on_input_idx
= PA_INVALID_INDEX
;
1782 pa_sink_input
*direct_on_input
= NULL
;
1784 connection_assert_ref(c
);
1787 if ((c
->version
< 13 && (pa_tagstruct_gets(t
, &name
) < 0 || !name
)) ||
1788 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
1789 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
1790 pa_tagstruct_getu32(t
, &source_index
) < 0 ||
1791 pa_tagstruct_gets(t
, &source_name
) < 0 ||
1792 pa_tagstruct_getu32(t
, &maxlength
) < 0 ||
1793 pa_tagstruct_get_boolean(t
, &corked
) < 0 ||
1794 pa_tagstruct_getu32(t
, &fragment_size
) < 0) {
1799 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1800 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1801 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1802 CHECK_VALIDITY(c
->pstream
, source_index
!= PA_INVALID_INDEX
|| !source_name
|| (*source_name
&& pa_utf8_valid(source_name
)), tag
, PA_ERR_INVALID
);
1803 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1805 p
= pa_proplist_new();
1808 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
1810 if (c
->version
>= 12) {
1811 /* Since 0.9.8 the user can ask for a couple of additional flags */
1813 if (pa_tagstruct_get_boolean(t
, &no_remap
) < 0 ||
1814 pa_tagstruct_get_boolean(t
, &no_remix
) < 0 ||
1815 pa_tagstruct_get_boolean(t
, &fix_format
) < 0 ||
1816 pa_tagstruct_get_boolean(t
, &fix_rate
) < 0 ||
1817 pa_tagstruct_get_boolean(t
, &fix_channels
) < 0 ||
1818 pa_tagstruct_get_boolean(t
, &no_move
) < 0 ||
1819 pa_tagstruct_get_boolean(t
, &variable_rate
) < 0) {
1822 pa_proplist_free(p
);
1827 if (c
->version
>= 13) {
1829 if (pa_tagstruct_get_boolean(t
, &peak_detect
) < 0 ||
1830 pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0 ||
1831 pa_tagstruct_get_proplist(t
, p
) < 0 ||
1832 pa_tagstruct_getu32(t
, &direct_on_input_idx
) < 0) {
1834 pa_proplist_free(p
);
1839 if (!pa_tagstruct_eof(t
)) {
1841 pa_proplist_free(p
);
1845 if (source_index
!= PA_INVALID_INDEX
) {
1847 if (!(source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, source_index
))) {
1848 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1849 pa_proplist_free(p
);
1853 } else if (source_name
) {
1855 if (!(source
= pa_namereg_get(c
->protocol
->core
, source_name
, PA_NAMEREG_SOURCE
, 1))) {
1856 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1857 pa_proplist_free(p
);
1862 if (direct_on_input_idx
!= PA_INVALID_INDEX
) {
1864 if (!(direct_on_input
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, direct_on_input_idx
))) {
1865 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1866 pa_proplist_free(p
);
1872 (corked
? PA_SOURCE_OUTPUT_START_CORKED
: 0) |
1873 (no_remap
? PA_SOURCE_OUTPUT_NO_REMAP
: 0) |
1874 (no_remix
? PA_SOURCE_OUTPUT_NO_REMIX
: 0) |
1875 (fix_format
? PA_SOURCE_OUTPUT_FIX_FORMAT
: 0) |
1876 (fix_rate
? PA_SOURCE_OUTPUT_FIX_RATE
: 0) |
1877 (fix_channels
? PA_SOURCE_OUTPUT_FIX_CHANNELS
: 0) |
1878 (no_move
? PA_SOURCE_OUTPUT_DONT_MOVE
: 0) |
1879 (variable_rate
? PA_SOURCE_OUTPUT_VARIABLE_RATE
: 0);
1881 s
= record_stream_new(c
, source
, &ss
, &map
, peak_detect
, &maxlength
, &fragment_size
, flags
, p
, adjust_latency
, direct_on_input
);
1882 pa_proplist_free(p
);
1884 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1886 reply
= reply_new(tag
);
1887 pa_tagstruct_putu32(reply
, s
->index
);
1888 pa_assert(s
->source_output
);
1889 pa_tagstruct_putu32(reply
, s
->source_output
->index
);
1891 if (c
->version
>= 9) {
1892 /* Since 0.9 we support sending the buffer metrics back to the client */
1894 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1895 pa_tagstruct_putu32(reply
, (uint32_t) fragment_size
);
1898 if (c
->version
>= 12) {
1899 /* Since 0.9.8 we support sending the chosen sample
1900 * spec/channel map/device/suspend status back to the
1903 pa_tagstruct_put_sample_spec(reply
, &ss
);
1904 pa_tagstruct_put_channel_map(reply
, &map
);
1906 pa_tagstruct_putu32(reply
, s
->source_output
->source
->index
);
1907 pa_tagstruct_puts(reply
, s
->source_output
->source
->name
);
1909 pa_tagstruct_put_boolean(reply
, pa_source_get_state(s
->source_output
->source
) == PA_SOURCE_SUSPENDED
);
1912 if (c
->version
>= 13)
1913 pa_tagstruct_put_usec(reply
, s
->source_latency
);
1915 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1918 static void command_exit(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1919 connection
*c
= CONNECTION(userdata
);
1921 connection_assert_ref(c
);
1924 if (!pa_tagstruct_eof(t
)) {
1929 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1931 c
->protocol
->core
->mainloop
->quit(c
->protocol
->core
->mainloop
, 0);
1932 pa_pstream_send_simple_ack(c
->pstream
, tag
); /* nonsense */
1935 static void command_auth(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1936 connection
*c
= CONNECTION(userdata
);
1938 pa_tagstruct
*reply
;
1941 connection_assert_ref(c
);
1944 if (pa_tagstruct_getu32(t
, &c
->version
) < 0 ||
1945 pa_tagstruct_get_arbitrary(t
, &cookie
, PA_NATIVE_COOKIE_LENGTH
) < 0 ||
1946 !pa_tagstruct_eof(t
)) {
1951 /* Minimum supported version */
1952 if (c
->version
< 8) {
1953 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_VERSION
);
1957 pa_snprintf(tmp
, sizeof(tmp
), "%u", c
->version
);
1958 pa_proplist_sets(c
->client
->proplist
, "native-protocol.version", tmp
);
1960 if (!c
->authorized
) {
1961 pa_bool_t success
= FALSE
;
1964 const pa_creds
*creds
;
1966 if ((creds
= pa_pdispatch_creds(pd
))) {
1967 if (creds
->uid
== getuid())
1969 else if (c
->protocol
->auth_group
) {
1973 if ((gid
= pa_get_gid_of_group(c
->protocol
->auth_group
)) == (gid_t
) -1)
1974 pa_log_warn("Failed to get GID of group '%s'", c
->protocol
->auth_group
);
1975 else if (gid
== creds
->gid
)
1979 if ((r
= pa_uid_in_group(creds
->uid
, c
->protocol
->auth_group
)) < 0)
1980 pa_log_warn("Failed to check group membership.");
1986 pa_log_info("Got credentials: uid=%lu gid=%lu success=%i",
1987 (unsigned long) creds
->uid
,
1988 (unsigned long) creds
->gid
,
1991 if (c
->version
>= 10 &&
1992 pa_mempool_is_shared(c
->protocol
->core
->mempool
) &&
1993 creds
->uid
== getuid()) {
1995 pa_pstream_enable_shm(c
->pstream
, TRUE
);
1996 pa_log_info("Enabled SHM for new connection");
2002 if (!success
&& memcmp(c
->protocol
->auth_cookie
, cookie
, PA_NATIVE_COOKIE_LENGTH
) == 0)
2006 pa_log_warn("Denied access to client with invalid authorization data.");
2007 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_ACCESS
);
2011 c
->authorized
= TRUE
;
2012 if (c
->auth_timeout_event
) {
2013 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
2014 c
->auth_timeout_event
= NULL
;
2018 reply
= reply_new(tag
);
2019 pa_tagstruct_putu32(reply
, PA_PROTOCOL_VERSION
);
2023 /* SHM support is only enabled after both sides made sure they are the same user. */
2027 ucred
.uid
= getuid();
2028 ucred
.gid
= getgid();
2030 pa_pstream_send_tagstruct_with_creds(c
->pstream
, reply
, &ucred
);
2033 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2037 static void command_set_client_name(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2038 connection
*c
= CONNECTION(userdata
);
2039 const char *name
= NULL
;
2041 pa_tagstruct
*reply
;
2043 connection_assert_ref(c
);
2046 p
= pa_proplist_new();
2048 if ((c
->version
< 13 && pa_tagstruct_gets(t
, &name
) < 0) ||
2049 (c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) ||
2050 !pa_tagstruct_eof(t
)) {
2053 pa_proplist_free(p
);
2058 if (pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, name
) < 0) {
2059 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
2060 pa_proplist_free(p
);
2064 pa_proplist_update(c
->client
->proplist
, PA_UPDATE_REPLACE
, p
);
2065 pa_proplist_free(p
);
2067 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
2069 reply
= reply_new(tag
);
2071 if (c
->version
>= 13)
2072 pa_tagstruct_putu32(reply
, c
->client
->index
);
2074 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2077 static void command_lookup(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2078 connection
*c
= CONNECTION(userdata
);
2080 uint32_t idx
= PA_IDXSET_INVALID
;
2082 connection_assert_ref(c
);
2085 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2086 !pa_tagstruct_eof(t
)) {
2091 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2092 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2094 if (command
== PA_COMMAND_LOOKUP_SINK
) {
2096 if ((sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1)))
2100 pa_assert(command
== PA_COMMAND_LOOKUP_SOURCE
);
2101 if ((source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1)))
2102 idx
= source
->index
;
2105 if (idx
== PA_IDXSET_INVALID
)
2106 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2108 pa_tagstruct
*reply
;
2109 reply
= reply_new(tag
);
2110 pa_tagstruct_putu32(reply
, idx
);
2111 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2115 static void command_drain_playback_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2116 connection
*c
= CONNECTION(userdata
);
2120 connection_assert_ref(c
);
2123 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2124 !pa_tagstruct_eof(t
)) {
2129 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2130 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2131 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2132 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2134 pa_asyncmsgq_post(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_DRAIN
, PA_UINT_TO_PTR(tag
), 0, NULL
, NULL
);
2137 static void command_stat(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2138 connection
*c
= CONNECTION(userdata
);
2139 pa_tagstruct
*reply
;
2140 const pa_mempool_stat
*stat
;
2142 connection_assert_ref(c
);
2145 if (!pa_tagstruct_eof(t
)) {
2150 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2152 stat
= pa_mempool_get_stat(c
->protocol
->core
->mempool
);
2154 reply
= reply_new(tag
);
2155 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_allocated
));
2156 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->allocated_size
));
2157 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_accumulated
));
2158 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->accumulated_size
));
2159 pa_tagstruct_putu32(reply
, pa_scache_total_size(c
->protocol
->core
));
2160 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2163 static void command_get_playback_latency(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2164 connection
*c
= CONNECTION(userdata
);
2165 pa_tagstruct
*reply
;
2167 struct timeval tv
, now
;
2171 connection_assert_ref(c
);
2174 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2175 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
2176 !pa_tagstruct_eof(t
)) {
2181 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2182 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2183 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2184 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2185 CHECK_VALIDITY(c
->pstream
, pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_UPDATE_LATENCY
, s
, 0, NULL
) == 0, tag
, PA_ERR_NOENTITY
)
2187 reply
= reply_new(tag
);
2189 latency
= pa_sink_get_latency(s
->sink_input
->sink
);
2190 latency
+= pa_bytes_to_usec(s
->render_memblockq_length
, &s
->sink_input
->sample_spec
);
2192 pa_tagstruct_put_usec(reply
, latency
);
2194 pa_tagstruct_put_usec(reply
, 0);
2195 pa_tagstruct_put_boolean(reply
, s
->sink_input
->thread_info
.playing_for
> 0);
2196 pa_tagstruct_put_timeval(reply
, &tv
);
2197 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
2198 pa_tagstruct_puts64(reply
, s
->write_index
);
2199 pa_tagstruct_puts64(reply
, s
->read_index
);
2201 if (c
->version
>= 13) {
2202 pa_tagstruct_putu64(reply
, s
->sink_input
->thread_info
.underrun_for
);
2203 pa_tagstruct_putu64(reply
, s
->sink_input
->thread_info
.playing_for
);
2206 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2209 static void command_get_record_latency(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2210 connection
*c
= CONNECTION(userdata
);
2211 pa_tagstruct
*reply
;
2213 struct timeval tv
, now
;
2216 connection_assert_ref(c
);
2219 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2220 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
2221 !pa_tagstruct_eof(t
)) {
2226 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2227 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
2228 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2230 reply
= reply_new(tag
);
2231 pa_tagstruct_put_usec(reply
, s
->source_output
->source
->monitor_of
? pa_sink_get_latency(s
->source_output
->source
->monitor_of
) : 0);
2232 pa_tagstruct_put_usec(reply
, pa_source_get_latency(s
->source_output
->source
));
2233 pa_tagstruct_put_boolean(reply
, pa_source_get_state(s
->source_output
->source
) == PA_SOURCE_RUNNING
);
2234 pa_tagstruct_put_timeval(reply
, &tv
);
2235 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
2236 pa_tagstruct_puts64(reply
, pa_memblockq_get_write_index(s
->memblockq
));
2237 pa_tagstruct_puts64(reply
, pa_memblockq_get_read_index(s
->memblockq
));
2238 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2241 static void command_create_upload_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2242 connection
*c
= CONNECTION(userdata
);
2245 const char *name
= NULL
;
2248 pa_tagstruct
*reply
;
2251 connection_assert_ref(c
);
2254 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2255 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
2256 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
2257 pa_tagstruct_getu32(t
, &length
) < 0) {
2262 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2263 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
2264 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
2265 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
2266 CHECK_VALIDITY(c
->pstream
, (length
% pa_frame_size(&ss
)) == 0 && length
> 0, tag
, PA_ERR_INVALID
);
2267 CHECK_VALIDITY(c
->pstream
, length
<= PA_SCACHE_ENTRY_SIZE_MAX
, tag
, PA_ERR_TOOLARGE
);
2269 p
= pa_proplist_new();
2271 if (c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) {
2273 pa_proplist_free(p
);
2277 if (c
->version
< 13)
2278 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
2280 if (!(name
= pa_proplist_gets(p
, PA_PROP_EVENT_ID
)))
2281 name
= pa_proplist_gets(p
, PA_PROP_MEDIA_NAME
);
2283 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2285 s
= upload_stream_new(c
, &ss
, &map
, name
, length
, p
);
2286 pa_proplist_free(p
);
2288 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
2290 reply
= reply_new(tag
);
2291 pa_tagstruct_putu32(reply
, s
->index
);
2292 pa_tagstruct_putu32(reply
, length
);
2293 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2296 static void command_finish_upload_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2297 connection
*c
= CONNECTION(userdata
);
2302 connection_assert_ref(c
);
2305 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
2306 !pa_tagstruct_eof(t
)) {
2311 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2313 s
= pa_idxset_get_by_index(c
->output_streams
, channel
);
2314 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2315 CHECK_VALIDITY(c
->pstream
, upload_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2317 if (pa_scache_add_item(c
->protocol
->core
, s
->name
, &s
->sample_spec
, &s
->channel_map
, &s
->memchunk
, s
->proplist
, &idx
) < 0)
2318 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INTERNAL
);
2320 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2322 upload_stream_unlink(s
);
2325 static void command_play_sample(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2326 connection
*c
= CONNECTION(userdata
);
2327 uint32_t sink_index
;
2330 const char *name
, *sink_name
;
2333 pa_tagstruct
*reply
;
2335 connection_assert_ref(c
);
2338 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2340 if (pa_tagstruct_getu32(t
, &sink_index
) < 0 ||
2341 pa_tagstruct_gets(t
, &sink_name
) < 0 ||
2342 pa_tagstruct_getu32(t
, &volume
) < 0 ||
2343 pa_tagstruct_gets(t
, &name
) < 0) {
2348 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2349 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2351 if (sink_index
!= PA_INVALID_INDEX
)
2352 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
);
2354 sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1);
2356 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
2358 p
= pa_proplist_new();
2360 if ((c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) ||
2361 !pa_tagstruct_eof(t
)) {
2363 pa_proplist_free(p
);
2367 if (pa_scache_play_item(c
->protocol
->core
, name
, sink
, volume
, p
, &idx
) < 0) {
2368 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2369 pa_proplist_free(p
);
2373 pa_proplist_free(p
);
2375 reply
= reply_new(tag
);
2377 if (c
->version
>= 13)
2378 pa_tagstruct_putu32(reply
, idx
);
2380 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2383 static void command_remove_sample(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2384 connection
*c
= CONNECTION(userdata
);
2387 connection_assert_ref(c
);
2390 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2391 !pa_tagstruct_eof(t
)) {
2396 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2397 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2399 if (pa_scache_remove_item(c
->protocol
->core
, name
) < 0) {
2400 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2404 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2407 static void fixup_sample_spec(connection
*c
, pa_sample_spec
*fixed
, const pa_sample_spec
*original
) {
2410 pa_assert(original
);
2414 if (c
->version
< 12) {
2415 /* Before protocol version 12 we didn't support S32 samples,
2416 * so we need to lie about this to the client */
2418 if (fixed
->format
== PA_SAMPLE_S32LE
)
2419 fixed
->format
= PA_SAMPLE_FLOAT32LE
;
2420 if (fixed
->format
== PA_SAMPLE_S32BE
)
2421 fixed
->format
= PA_SAMPLE_FLOAT32BE
;
2425 static void sink_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_sink
*sink
) {
2426 pa_sample_spec fixed_ss
;
2429 pa_sink_assert_ref(sink
);
2431 fixup_sample_spec(c
, &fixed_ss
, &sink
->sample_spec
);
2435 PA_TAG_U32
, sink
->index
,
2436 PA_TAG_STRING
, sink
->name
,
2437 PA_TAG_STRING
, pa_strnull(pa_proplist_gets(sink
->proplist
, PA_PROP_DEVICE_DESCRIPTION
)),
2438 PA_TAG_SAMPLE_SPEC
, &fixed_ss
,
2439 PA_TAG_CHANNEL_MAP
, &sink
->channel_map
,
2440 PA_TAG_U32
, sink
->module
? sink
->module
->index
: PA_INVALID_INDEX
,
2441 PA_TAG_CVOLUME
, pa_sink_get_volume(sink
),
2442 PA_TAG_BOOLEAN
, pa_sink_get_mute(sink
),
2443 PA_TAG_U32
, sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
2444 PA_TAG_STRING
, sink
->monitor_source
? sink
->monitor_source
->name
: NULL
,
2445 PA_TAG_USEC
, pa_sink_get_latency(sink
),
2446 PA_TAG_STRING
, sink
->driver
,
2447 PA_TAG_U32
, sink
->flags
,
2450 if (c
->version
>= 13) {
2451 pa_tagstruct_put_proplist(t
, sink
->proplist
);
2452 pa_tagstruct_put_usec(t
, pa_sink_get_requested_latency(sink
));
2456 static void source_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_source
*source
) {
2457 pa_sample_spec fixed_ss
;
2460 pa_source_assert_ref(source
);
2462 fixup_sample_spec(c
, &fixed_ss
, &source
->sample_spec
);
2466 PA_TAG_U32
, source
->index
,
2467 PA_TAG_STRING
, source
->name
,
2468 PA_TAG_STRING
, pa_strnull(pa_proplist_gets(source
->proplist
, PA_PROP_DEVICE_DESCRIPTION
)),
2469 PA_TAG_SAMPLE_SPEC
, &fixed_ss
,
2470 PA_TAG_CHANNEL_MAP
, &source
->channel_map
,
2471 PA_TAG_U32
, source
->module
? source
->module
->index
: PA_INVALID_INDEX
,
2472 PA_TAG_CVOLUME
, pa_source_get_volume(source
),
2473 PA_TAG_BOOLEAN
, pa_source_get_mute(source
),
2474 PA_TAG_U32
, source
->monitor_of
? source
->monitor_of
->index
: PA_INVALID_INDEX
,
2475 PA_TAG_STRING
, source
->monitor_of
? source
->monitor_of
->name
: NULL
,
2476 PA_TAG_USEC
, pa_source_get_latency(source
),
2477 PA_TAG_STRING
, source
->driver
,
2478 PA_TAG_U32
, source
->flags
,
2481 if (c
->version
>= 13) {
2482 pa_tagstruct_put_proplist(t
, source
->proplist
);
2483 pa_tagstruct_put_usec(t
, pa_source_get_requested_latency(source
));
2488 static void client_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_client
*client
) {
2492 pa_tagstruct_putu32(t
, client
->index
);
2493 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(client
->proplist
, PA_PROP_APPLICATION_NAME
)));
2494 pa_tagstruct_putu32(t
, client
->module
? client
->module
->index
: PA_INVALID_INDEX
);
2495 pa_tagstruct_puts(t
, client
->driver
);
2497 if (c
->version
>= 13)
2498 pa_tagstruct_put_proplist(t
, client
->proplist
);
2502 static void module_fill_tagstruct(pa_tagstruct
*t
, pa_module
*module
) {
2506 pa_tagstruct_putu32(t
, module
->index
);
2507 pa_tagstruct_puts(t
, module
->name
);
2508 pa_tagstruct_puts(t
, module
->argument
);
2509 pa_tagstruct_putu32(t
, module
->n_used
);
2510 pa_tagstruct_put_boolean(t
, module
->auto_unload
);
2513 static void sink_input_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_sink_input
*s
) {
2514 pa_sample_spec fixed_ss
;
2517 pa_sink_input_assert_ref(s
);
2519 fixup_sample_spec(c
, &fixed_ss
, &s
->sample_spec
);
2521 pa_tagstruct_putu32(t
, s
->index
);
2522 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(s
->proplist
, PA_PROP_MEDIA_NAME
)));
2523 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
2524 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
2525 pa_tagstruct_putu32(t
, s
->sink
->index
);
2526 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2527 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
2528 pa_tagstruct_put_cvolume(t
, &s
->volume
);
2529 pa_tagstruct_put_usec(t
, pa_sink_input_get_latency(s
));
2530 pa_tagstruct_put_usec(t
, pa_sink_get_latency(s
->sink
));
2531 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_sink_input_get_resample_method(s
)));
2532 pa_tagstruct_puts(t
, s
->driver
);
2533 if (c
->version
>= 11)
2534 pa_tagstruct_put_boolean(t
, pa_sink_input_get_mute(s
));
2535 if (c
->version
>= 13)
2536 pa_tagstruct_put_proplist(t
, s
->proplist
);
2539 static void source_output_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_source_output
*s
) {
2540 pa_sample_spec fixed_ss
;
2543 pa_source_output_assert_ref(s
);
2545 fixup_sample_spec(c
, &fixed_ss
, &s
->sample_spec
);
2547 pa_tagstruct_putu32(t
, s
->index
);
2548 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(s
->proplist
, PA_PROP_MEDIA_NAME
)));
2549 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
2550 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
2551 pa_tagstruct_putu32(t
, s
->source
->index
);
2552 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2553 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
2554 pa_tagstruct_put_usec(t
, pa_source_output_get_latency(s
));
2555 pa_tagstruct_put_usec(t
, pa_source_get_latency(s
->source
));
2556 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_source_output_get_resample_method(s
)));
2557 pa_tagstruct_puts(t
, s
->driver
);
2559 if (c
->version
>= 13)
2560 pa_tagstruct_put_proplist(t
, s
->proplist
);
2563 static void scache_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_scache_entry
*e
) {
2564 pa_sample_spec fixed_ss
;
2569 if (e
->memchunk
.memblock
)
2570 fixup_sample_spec(c
, &fixed_ss
, &e
->sample_spec
);
2572 memset(&fixed_ss
, 0, sizeof(fixed_ss
));
2574 pa_tagstruct_putu32(t
, e
->index
);
2575 pa_tagstruct_puts(t
, e
->name
);
2576 pa_tagstruct_put_cvolume(t
, &e
->volume
);
2577 pa_tagstruct_put_usec(t
, e
->memchunk
.memblock
? pa_bytes_to_usec(e
->memchunk
.length
, &e
->sample_spec
) : NULL
);
2578 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2579 pa_tagstruct_put_channel_map(t
, &e
->channel_map
);
2580 pa_tagstruct_putu32(t
, e
->memchunk
.length
);
2581 pa_tagstruct_put_boolean(t
, e
->lazy
);
2582 pa_tagstruct_puts(t
, e
->filename
);
2584 if (c
->version
>= 13)
2585 pa_tagstruct_put_proplist(t
, e
->proplist
);
2588 static void command_get_info(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2589 connection
*c
= CONNECTION(userdata
);
2591 pa_sink
*sink
= NULL
;
2592 pa_source
*source
= NULL
;
2593 pa_client
*client
= NULL
;
2594 pa_module
*module
= NULL
;
2595 pa_sink_input
*si
= NULL
;
2596 pa_source_output
*so
= NULL
;
2597 pa_scache_entry
*sce
= NULL
;
2599 pa_tagstruct
*reply
;
2601 connection_assert_ref(c
);
2604 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2605 (command
!= PA_COMMAND_GET_CLIENT_INFO
&&
2606 command
!= PA_COMMAND_GET_MODULE_INFO
&&
2607 command
!= PA_COMMAND_GET_SINK_INPUT_INFO
&&
2608 command
!= PA_COMMAND_GET_SOURCE_OUTPUT_INFO
&&
2609 pa_tagstruct_gets(t
, &name
) < 0) ||
2610 !pa_tagstruct_eof(t
)) {
2615 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2616 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2618 if (command
== PA_COMMAND_GET_SINK_INFO
) {
2619 if (idx
!= PA_INVALID_INDEX
)
2620 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2622 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2623 } else if (command
== PA_COMMAND_GET_SOURCE_INFO
) {
2624 if (idx
!= PA_INVALID_INDEX
)
2625 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2627 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2628 } else if (command
== PA_COMMAND_GET_CLIENT_INFO
)
2629 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
2630 else if (command
== PA_COMMAND_GET_MODULE_INFO
)
2631 module
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
2632 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO
)
2633 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2634 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO
)
2635 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
2637 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO
);
2638 if (idx
!= PA_INVALID_INDEX
)
2639 sce
= pa_idxset_get_by_index(c
->protocol
->core
->scache
, idx
);
2641 sce
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SAMPLE
, 0);
2644 if (!sink
&& !source
&& !client
&& !module
&& !si
&& !so
&& !sce
) {
2645 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2649 reply
= reply_new(tag
);
2651 sink_fill_tagstruct(c
, reply
, sink
);
2653 source_fill_tagstruct(c
, reply
, source
);
2655 client_fill_tagstruct(c
, reply
, client
);
2657 module_fill_tagstruct(reply
, module
);
2659 sink_input_fill_tagstruct(c
, reply
, si
);
2661 source_output_fill_tagstruct(c
, reply
, so
);
2663 scache_fill_tagstruct(c
, reply
, sce
);
2664 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2667 static void command_get_info_list(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2668 connection
*c
= CONNECTION(userdata
);
2672 pa_tagstruct
*reply
;
2674 connection_assert_ref(c
);
2677 if (!pa_tagstruct_eof(t
)) {
2682 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2684 reply
= reply_new(tag
);
2686 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
2687 i
= c
->protocol
->core
->sinks
;
2688 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
2689 i
= c
->protocol
->core
->sources
;
2690 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
2691 i
= c
->protocol
->core
->clients
;
2692 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
2693 i
= c
->protocol
->core
->modules
;
2694 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
2695 i
= c
->protocol
->core
->sink_inputs
;
2696 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
2697 i
= c
->protocol
->core
->source_outputs
;
2699 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
2700 i
= c
->protocol
->core
->scache
;
2704 for (p
= pa_idxset_first(i
, &idx
); p
; p
= pa_idxset_next(i
, &idx
)) {
2705 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
2706 sink_fill_tagstruct(c
, reply
, p
);
2707 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
2708 source_fill_tagstruct(c
, reply
, p
);
2709 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
2710 client_fill_tagstruct(c
, reply
, p
);
2711 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
2712 module_fill_tagstruct(reply
, p
);
2713 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
2714 sink_input_fill_tagstruct(c
, reply
, p
);
2715 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
2716 source_output_fill_tagstruct(c
, reply
, p
);
2718 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
2719 scache_fill_tagstruct(c
, reply
, p
);
2724 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2727 static void command_get_server_info(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2728 connection
*c
= CONNECTION(userdata
);
2729 pa_tagstruct
*reply
;
2732 pa_sample_spec fixed_ss
;
2734 connection_assert_ref(c
);
2737 if (!pa_tagstruct_eof(t
)) {
2742 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2744 reply
= reply_new(tag
);
2745 pa_tagstruct_puts(reply
, PACKAGE_NAME
);
2746 pa_tagstruct_puts(reply
, PACKAGE_VERSION
);
2747 pa_tagstruct_puts(reply
, pa_get_user_name(txt
, sizeof(txt
)));
2748 pa_tagstruct_puts(reply
, pa_get_host_name(txt
, sizeof(txt
)));
2750 fixup_sample_spec(c
, &fixed_ss
, &c
->protocol
->core
->default_sample_spec
);
2751 pa_tagstruct_put_sample_spec(reply
, &fixed_ss
);
2753 n
= pa_namereg_get_default_sink_name(c
->protocol
->core
);
2754 pa_tagstruct_puts(reply
, n
);
2755 n
= pa_namereg_get_default_source_name(c
->protocol
->core
);
2756 pa_tagstruct_puts(reply
, n
);
2758 pa_tagstruct_putu32(reply
, c
->protocol
->core
->cookie
);
2760 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2763 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t e
, uint32_t idx
, void *userdata
) {
2765 connection
*c
= CONNECTION(userdata
);
2767 connection_assert_ref(c
);
2769 t
= pa_tagstruct_new(NULL
, 0);
2770 pa_tagstruct_putu32(t
, PA_COMMAND_SUBSCRIBE_EVENT
);
2771 pa_tagstruct_putu32(t
, (uint32_t) -1);
2772 pa_tagstruct_putu32(t
, e
);
2773 pa_tagstruct_putu32(t
, idx
);
2774 pa_pstream_send_tagstruct(c
->pstream
, t
);
2777 static void command_subscribe(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2778 connection
*c
= CONNECTION(userdata
);
2779 pa_subscription_mask_t m
;
2781 connection_assert_ref(c
);
2784 if (pa_tagstruct_getu32(t
, &m
) < 0 ||
2785 !pa_tagstruct_eof(t
)) {
2790 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2791 CHECK_VALIDITY(c
->pstream
, (m
& ~PA_SUBSCRIPTION_MASK_ALL
) == 0, tag
, PA_ERR_INVALID
);
2793 if (c
->subscription
)
2794 pa_subscription_free(c
->subscription
);
2797 c
->subscription
= pa_subscription_new(c
->protocol
->core
, m
, subscription_cb
, c
);
2798 pa_assert(c
->subscription
);
2800 c
->subscription
= NULL
;
2802 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2805 static void command_set_volume(
2806 PA_GCC_UNUSED pa_pdispatch
*pd
,
2812 connection
*c
= CONNECTION(userdata
);
2815 pa_sink
*sink
= NULL
;
2816 pa_source
*source
= NULL
;
2817 pa_sink_input
*si
= NULL
;
2818 const char *name
= NULL
;
2820 connection_assert_ref(c
);
2823 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2824 (command
== PA_COMMAND_SET_SINK_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2825 (command
== PA_COMMAND_SET_SOURCE_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2826 pa_tagstruct_get_cvolume(t
, &volume
) ||
2827 !pa_tagstruct_eof(t
)) {
2832 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2833 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2834 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
2838 case PA_COMMAND_SET_SINK_VOLUME
:
2839 if (idx
!= PA_INVALID_INDEX
)
2840 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2842 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2845 case PA_COMMAND_SET_SOURCE_VOLUME
:
2846 if (idx
!= PA_INVALID_INDEX
)
2847 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2849 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2852 case PA_COMMAND_SET_SINK_INPUT_VOLUME
:
2853 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2857 pa_assert_not_reached();
2860 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2863 pa_sink_set_volume(sink
, &volume
);
2865 pa_source_set_volume(source
, &volume
);
2867 pa_sink_input_set_volume(si
, &volume
);
2869 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2872 static void command_set_mute(
2873 PA_GCC_UNUSED pa_pdispatch
*pd
,
2879 connection
*c
= CONNECTION(userdata
);
2882 pa_sink
*sink
= NULL
;
2883 pa_source
*source
= NULL
;
2884 pa_sink_input
*si
= NULL
;
2885 const char *name
= NULL
;
2887 connection_assert_ref(c
);
2890 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2891 (command
== PA_COMMAND_SET_SINK_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2892 (command
== PA_COMMAND_SET_SOURCE_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2893 pa_tagstruct_get_boolean(t
, &mute
) ||
2894 !pa_tagstruct_eof(t
)) {
2899 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2900 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2904 case PA_COMMAND_SET_SINK_MUTE
:
2906 if (idx
!= PA_INVALID_INDEX
)
2907 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2909 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2913 case PA_COMMAND_SET_SOURCE_MUTE
:
2914 if (idx
!= PA_INVALID_INDEX
)
2915 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2917 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2921 case PA_COMMAND_SET_SINK_INPUT_MUTE
:
2922 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2926 pa_assert_not_reached();
2929 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2932 pa_sink_set_mute(sink
, mute
);
2934 pa_source_set_mute(source
, mute
);
2936 pa_sink_input_set_mute(si
, mute
);
2938 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2941 static void command_cork_playback_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2942 connection
*c
= CONNECTION(userdata
);
2947 connection_assert_ref(c
);
2950 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2951 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
2952 !pa_tagstruct_eof(t
)) {
2957 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2958 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2959 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2960 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2961 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2963 pa_sink_input_cork(s
->sink_input
, b
);
2964 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2967 static void command_trigger_or_flush_or_prebuf_playback_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2968 connection
*c
= CONNECTION(userdata
);
2972 connection_assert_ref(c
);
2975 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2976 !pa_tagstruct_eof(t
)) {
2981 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2982 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2983 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2984 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2985 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2988 case PA_COMMAND_FLUSH_PLAYBACK_STREAM
:
2989 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_FLUSH
, NULL
, 0, NULL
);
2992 case PA_COMMAND_PREBUF_PLAYBACK_STREAM
:
2993 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_PREBUF_FORCE
, NULL
, 0, NULL
);
2996 case PA_COMMAND_TRIGGER_PLAYBACK_STREAM
:
2997 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_TRIGGER
, NULL
, 0, NULL
);
3001 pa_assert_not_reached();
3004 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3007 static void command_cork_record_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3008 connection
*c
= CONNECTION(userdata
);
3013 connection_assert_ref(c
);
3016 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3017 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
3018 !pa_tagstruct_eof(t
)) {
3023 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3024 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3025 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3027 pa_source_output_cork(s
->source_output
, b
);
3028 pa_memblockq_prebuf_force(s
->memblockq
);
3029 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3032 static void command_flush_record_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3033 connection
*c
= CONNECTION(userdata
);
3037 connection_assert_ref(c
);
3040 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3041 !pa_tagstruct_eof(t
)) {
3046 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3047 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3048 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3050 pa_memblockq_flush(s
->memblockq
);
3051 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3054 static void command_set_stream_buffer_attr(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3055 connection
*c
= CONNECTION(userdata
);
3057 uint32_t maxlength
, tlength
, prebuf
, minreq
, fragsize
;
3058 pa_tagstruct
*reply
;
3060 connection_assert_ref(c
);
3063 if (pa_tagstruct_getu32(t
, &idx
) < 0) {
3068 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3070 if (command
== PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR
) {
3072 pa_bool_t adjust_latency
= FALSE
;
3074 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3075 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3076 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3078 if (pa_tagstruct_get(
3080 PA_TAG_U32
, &maxlength
,
3081 PA_TAG_U32
, &tlength
,
3082 PA_TAG_U32
, &prebuf
,
3083 PA_TAG_U32
, &minreq
,
3084 PA_TAG_INVALID
) < 0 ||
3085 (c
->version
>= 13 && pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0) ||
3086 !pa_tagstruct_eof(t
)) {
3091 fix_playback_buffer_attr_pre(s
, adjust_latency
, &maxlength
, &tlength
, &prebuf
, &minreq
);
3092 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
3093 pa_memblockq_set_tlength(s
->memblockq
, tlength
);
3094 pa_memblockq_set_prebuf(s
->memblockq
, prebuf
);
3095 pa_memblockq_set_minreq(s
->memblockq
, minreq
);
3096 fix_playback_buffer_attr_post(s
, &maxlength
, &tlength
, &prebuf
, &minreq
);
3098 reply
= reply_new(tag
);
3099 pa_tagstruct_putu32(reply
, maxlength
);
3100 pa_tagstruct_putu32(reply
, tlength
);
3101 pa_tagstruct_putu32(reply
, prebuf
);
3102 pa_tagstruct_putu32(reply
, minreq
);
3104 if (c
->version
>= 13)
3105 pa_tagstruct_put_usec(reply
, s
->sink_latency
);
3109 pa_bool_t adjust_latency
= FALSE
;
3110 pa_assert(command
== PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR
);
3112 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3113 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3115 if (pa_tagstruct_get(
3117 PA_TAG_U32
, &maxlength
,
3118 PA_TAG_U32
, &fragsize
,
3119 PA_TAG_INVALID
) < 0 ||
3120 (c
->version
>= 13 && pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0) ||
3121 !pa_tagstruct_eof(t
)) {
3126 fix_record_buffer_attr_pre(s
, adjust_latency
, &maxlength
, &fragsize
);
3127 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
3128 fix_record_buffer_attr_post(s
, &maxlength
, &fragsize
);
3130 reply
= reply_new(tag
);
3131 pa_tagstruct_putu32(reply
, maxlength
);
3132 pa_tagstruct_putu32(reply
, fragsize
);
3134 if (c
->version
>= 13)
3135 pa_tagstruct_put_usec(reply
, s
->source_latency
);
3138 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3141 static void command_update_stream_sample_rate(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3142 connection
*c
= CONNECTION(userdata
);
3146 connection_assert_ref(c
);
3149 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3150 pa_tagstruct_getu32(t
, &rate
) < 0 ||
3151 !pa_tagstruct_eof(t
)) {
3156 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3157 CHECK_VALIDITY(c
->pstream
, rate
> 0 && rate
<= PA_RATE_MAX
, tag
, PA_ERR_INVALID
);
3159 if (command
== PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE
) {
3162 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3163 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3164 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3166 pa_sink_input_set_rate(s
->sink_input
, rate
);
3170 pa_assert(command
== PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE
);
3172 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3173 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3175 pa_source_output_set_rate(s
->source_output
, rate
);
3178 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3181 static void command_update_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3182 connection
*c
= CONNECTION(userdata
);
3187 connection_assert_ref(c
);
3190 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3192 p
= pa_proplist_new();
3194 if (command
== PA_COMMAND_UPDATE_CLIENT_PROPLIST
) {
3196 if (pa_tagstruct_getu32(t
, &mode
) < 0 ||
3197 pa_tagstruct_get_proplist(t
, p
) < 0 ||
3198 !pa_tagstruct_eof(t
)) {
3200 pa_proplist_free(p
);
3206 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3207 pa_tagstruct_getu32(t
, &mode
) < 0 ||
3208 pa_tagstruct_get_proplist(t
, p
) < 0 ||
3209 !pa_tagstruct_eof(t
)) {
3211 pa_proplist_free(p
);
3216 CHECK_VALIDITY(c
->pstream
, mode
== PA_UPDATE_SET
|| mode
== PA_UPDATE_MERGE
|| mode
== PA_UPDATE_REPLACE
, tag
, PA_ERR_INVALID
);
3218 if (command
== PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST
) {
3221 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3222 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3223 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3225 pa_proplist_update(s
->sink_input
->proplist
, mode
, p
);
3226 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->sink_input
->index
);
3228 } else if (command
== PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST
) {
3231 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3232 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3234 pa_proplist_update(s
->source_output
->proplist
, mode
, p
);
3235 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->source_output
->index
);
3237 pa_assert(command
== PA_COMMAND_UPDATE_CLIENT_PROPLIST
);
3239 pa_proplist_update(c
->client
->proplist
, mode
, p
);
3240 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
3243 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3246 static void command_remove_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3247 connection
*c
= CONNECTION(userdata
);
3249 unsigned changed
= 0;
3251 pa_strlist
*l
= NULL
;
3253 connection_assert_ref(c
);
3256 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3258 if (command
!= PA_COMMAND_REMOVE_CLIENT_PROPLIST
) {
3260 if (pa_tagstruct_getu32(t
, &idx
) < 0) {
3266 if (command
== PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
) {
3269 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3270 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3271 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3273 p
= s
->sink_input
->proplist
;
3275 } else if (command
== PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
) {
3278 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3279 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3281 p
= s
->source_output
->proplist
;
3283 pa_assert(command
== PA_COMMAND_REMOVE_CLIENT_PROPLIST
);
3285 p
= c
->client
->proplist
;
3291 if (pa_tagstruct_gets(t
, &k
) < 0) {
3300 l
= pa_strlist_prepend(l
, k
);
3303 if (!pa_tagstruct_eof(t
)) {
3312 l
= pa_strlist_pop(l
, &z
);
3317 changed
+= pa_proplist_unset(p
, z
) >= 0;
3321 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3324 if (command
== PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
) {
3327 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3328 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->sink_input
->index
);
3330 } else if (command
== PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
) {
3333 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3334 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->source_output
->index
);
3337 pa_assert(command
== PA_COMMAND_REMOVE_CLIENT_PROPLIST
);
3338 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
3343 static void command_set_default_sink_or_source(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3344 connection
*c
= CONNECTION(userdata
);
3347 connection_assert_ref(c
);
3350 if (pa_tagstruct_gets(t
, &s
) < 0 ||
3351 !pa_tagstruct_eof(t
)) {
3356 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3357 CHECK_VALIDITY(c
->pstream
, !s
|| (*s
&& pa_utf8_valid(s
)), tag
, PA_ERR_INVALID
);
3359 pa_namereg_set_default(c
->protocol
->core
, s
, command
== PA_COMMAND_SET_DEFAULT_SOURCE
? PA_NAMEREG_SOURCE
: PA_NAMEREG_SINK
);
3360 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3363 static void command_set_stream_name(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3364 connection
*c
= CONNECTION(userdata
);
3368 connection_assert_ref(c
);
3371 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3372 pa_tagstruct_gets(t
, &name
) < 0 ||
3373 !pa_tagstruct_eof(t
)) {
3378 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3379 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3381 if (command
== PA_COMMAND_SET_PLAYBACK_STREAM_NAME
) {
3384 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3385 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3386 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3388 pa_sink_input_set_name(s
->sink_input
, name
);
3392 pa_assert(command
== PA_COMMAND_SET_RECORD_STREAM_NAME
);
3394 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3395 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3397 pa_source_output_set_name(s
->source_output
, name
);
3400 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3403 static void command_kill(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3404 connection
*c
= CONNECTION(userdata
);
3407 connection_assert_ref(c
);
3410 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3411 !pa_tagstruct_eof(t
)) {
3416 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3418 if (command
== PA_COMMAND_KILL_CLIENT
) {
3421 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
3422 CHECK_VALIDITY(c
->pstream
, client
, tag
, PA_ERR_NOENTITY
);
3425 pa_client_kill(client
);
3427 } else if (command
== PA_COMMAND_KILL_SINK_INPUT
) {
3430 s
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
3431 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3434 pa_sink_input_kill(s
);
3436 pa_source_output
*s
;
3438 pa_assert(command
== PA_COMMAND_KILL_SOURCE_OUTPUT
);
3440 s
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
3441 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3444 pa_source_output_kill(s
);
3447 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3448 connection_unref(c
);
3451 static void command_load_module(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3452 connection
*c
= CONNECTION(userdata
);
3454 const char *name
, *argument
;
3455 pa_tagstruct
*reply
;
3457 connection_assert_ref(c
);
3460 if (pa_tagstruct_gets(t
, &name
) < 0 ||
3461 pa_tagstruct_gets(t
, &argument
) < 0 ||
3462 !pa_tagstruct_eof(t
)) {
3467 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3468 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
) && !strchr(name
, '/'), tag
, PA_ERR_INVALID
);
3469 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
3471 if (!(m
= pa_module_load(c
->protocol
->core
, name
, argument
))) {
3472 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_MODINITFAILED
);
3476 reply
= reply_new(tag
);
3477 pa_tagstruct_putu32(reply
, m
->index
);
3478 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3481 static void command_unload_module(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3482 connection
*c
= CONNECTION(userdata
);
3486 connection_assert_ref(c
);
3489 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3490 !pa_tagstruct_eof(t
)) {
3495 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3496 m
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
3497 CHECK_VALIDITY(c
->pstream
, m
, tag
, PA_ERR_NOENTITY
);
3499 pa_module_unload_request(m
);
3500 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3503 static void command_add_autoload(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3504 connection
*c
= CONNECTION(userdata
);
3505 const char *name
, *module
, *argument
;
3508 pa_tagstruct
*reply
;
3510 connection_assert_ref(c
);
3513 if (pa_tagstruct_gets(t
, &name
) < 0 ||
3514 pa_tagstruct_getu32(t
, &type
) < 0 ||
3515 pa_tagstruct_gets(t
, &module
) < 0 ||
3516 pa_tagstruct_gets(t
, &argument
) < 0 ||
3517 !pa_tagstruct_eof(t
)) {
3522 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3523 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3524 CHECK_VALIDITY(c
->pstream
, type
== 0 || type
== 1, tag
, PA_ERR_INVALID
);
3525 CHECK_VALIDITY(c
->pstream
, module
&& *module
&& pa_utf8_valid(module
), tag
, PA_ERR_INVALID
);
3526 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
3528 if (pa_autoload_add(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
, module
, argument
, &idx
) < 0) {
3529 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
3533 reply
= reply_new(tag
);
3534 pa_tagstruct_putu32(reply
, idx
);
3535 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3538 static void command_remove_autoload(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3539 connection
*c
= CONNECTION(userdata
);
3540 const char *name
= NULL
;
3541 uint32_t type
, idx
= PA_IDXSET_INVALID
;
3544 connection_assert_ref(c
);
3547 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
3548 (pa_tagstruct_gets(t
, &name
) < 0 ||
3549 pa_tagstruct_getu32(t
, &type
) < 0)) ||
3550 !pa_tagstruct_eof(t
)) {
3555 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3556 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
3557 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& pa_utf8_valid(name
) && (type
== 0 || type
== 1)), tag
, PA_ERR_INVALID
);
3560 r
= pa_autoload_remove_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
3562 r
= pa_autoload_remove_by_index(c
->protocol
->core
, idx
);
3564 CHECK_VALIDITY(c
->pstream
, r
>= 0, tag
, PA_ERR_NOENTITY
);
3566 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3569 static void autoload_fill_tagstruct(pa_tagstruct
*t
, const pa_autoload_entry
*e
) {
3572 pa_tagstruct_putu32(t
, e
->index
);
3573 pa_tagstruct_puts(t
, e
->name
);
3574 pa_tagstruct_putu32(t
, e
->type
== PA_NAMEREG_SINK
? 0 : 1);
3575 pa_tagstruct_puts(t
, e
->module
);
3576 pa_tagstruct_puts(t
, e
->argument
);
3579 static void command_get_autoload_info(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3580 connection
*c
= CONNECTION(userdata
);
3581 const pa_autoload_entry
*a
= NULL
;
3584 pa_tagstruct
*reply
;
3586 connection_assert_ref(c
);
3589 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
3590 (pa_tagstruct_gets(t
, &name
) < 0 ||
3591 pa_tagstruct_getu32(t
, &type
) < 0)) ||
3592 !pa_tagstruct_eof(t
)) {
3597 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3598 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
3599 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& (type
== 0 || type
== 1) && pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
3602 a
= pa_autoload_get_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
3604 a
= pa_autoload_get_by_index(c
->protocol
->core
, idx
);
3606 CHECK_VALIDITY(c
->pstream
, a
, tag
, PA_ERR_NOENTITY
);
3608 reply
= reply_new(tag
);
3609 autoload_fill_tagstruct(reply
, a
);
3610 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3613 static void command_get_autoload_info_list(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3614 connection
*c
= CONNECTION(userdata
);
3615 pa_tagstruct
*reply
;
3617 connection_assert_ref(c
);
3620 if (!pa_tagstruct_eof(t
)) {
3625 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3627 reply
= reply_new(tag
);
3629 if (c
->protocol
->core
->autoload_hashmap
) {
3630 pa_autoload_entry
*a
;
3633 while ((a
= pa_hashmap_iterate(c
->protocol
->core
->autoload_hashmap
, &state
, NULL
)))
3634 autoload_fill_tagstruct(reply
, a
);
3637 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3640 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3641 connection
*c
= CONNECTION(userdata
);
3642 uint32_t idx
= PA_INVALID_INDEX
, idx_device
= PA_INVALID_INDEX
;
3643 const char *name
= NULL
;
3645 connection_assert_ref(c
);
3648 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3649 pa_tagstruct_getu32(t
, &idx_device
) < 0 ||
3650 pa_tagstruct_gets(t
, &name
) < 0 ||
3651 !pa_tagstruct_eof(t
)) {
3656 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3657 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
3658 CHECK_VALIDITY(c
->pstream
, idx_device
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
3660 if (command
== PA_COMMAND_MOVE_SINK_INPUT
) {
3661 pa_sink_input
*si
= NULL
;
3662 pa_sink
*sink
= NULL
;
3664 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
3666 if (idx_device
!= PA_INVALID_INDEX
)
3667 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx_device
);
3669 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
3671 CHECK_VALIDITY(c
->pstream
, si
&& sink
, tag
, PA_ERR_NOENTITY
);
3673 if (pa_sink_input_move_to(si
, sink
) < 0) {
3674 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3678 pa_source_output
*so
= NULL
;
3681 pa_assert(command
== PA_COMMAND_MOVE_SOURCE_OUTPUT
);
3683 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
3685 if (idx_device
!= PA_INVALID_INDEX
)
3686 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx_device
);
3688 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
3690 CHECK_VALIDITY(c
->pstream
, so
&& source
, tag
, PA_ERR_NOENTITY
);
3692 if (pa_source_output_move_to(so
, source
) < 0) {
3693 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3698 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3701 static void command_suspend(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3702 connection
*c
= CONNECTION(userdata
);
3703 uint32_t idx
= PA_INVALID_INDEX
;
3704 const char *name
= NULL
;
3707 connection_assert_ref(c
);
3710 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3711 pa_tagstruct_gets(t
, &name
) < 0 ||
3712 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
3713 !pa_tagstruct_eof(t
)) {
3718 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3719 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| !*name
|| pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3721 if (command
== PA_COMMAND_SUSPEND_SINK
) {
3723 if (idx
== PA_INVALID_INDEX
&& name
&& !*name
) {
3725 if (pa_sink_suspend_all(c
->protocol
->core
, b
) < 0) {
3726 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3730 pa_sink
*sink
= NULL
;
3732 if (idx
!= PA_INVALID_INDEX
)
3733 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
3735 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
3737 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
3739 if (pa_sink_suspend(sink
, b
) < 0) {
3740 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3746 pa_assert(command
== PA_COMMAND_SUSPEND_SOURCE
);
3748 if (idx
== PA_INVALID_INDEX
&& name
&& !*name
) {
3750 if (pa_source_suspend_all(c
->protocol
->core
, b
) < 0) {
3751 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3758 if (idx
!= PA_INVALID_INDEX
)
3759 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
3761 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
3763 CHECK_VALIDITY(c
->pstream
, source
, tag
, PA_ERR_NOENTITY
);
3765 if (pa_source_suspend(source
, b
) < 0) {
3766 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3772 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3775 /*** pstream callbacks ***/
3777 static void pstream_packet_callback(pa_pstream
*p
, pa_packet
*packet
, const pa_creds
*creds
, void *userdata
) {
3778 connection
*c
= CONNECTION(userdata
);
3782 connection_assert_ref(c
);
3784 if (pa_pdispatch_run(c
->pdispatch
, packet
, creds
, c
) < 0) {
3785 pa_log("invalid packet.");
3786 connection_unlink(c
);
3790 static void pstream_memblock_callback(pa_pstream
*p
, uint32_t channel
, int64_t offset
, pa_seek_mode_t seek
, const pa_memchunk
*chunk
, void *userdata
) {
3791 connection
*c
= CONNECTION(userdata
);
3792 output_stream
*stream
;
3796 connection_assert_ref(c
);
3798 if (!(stream
= OUTPUT_STREAM(pa_idxset_get_by_index(c
->output_streams
, channel
)))) {
3799 pa_log("client sent block for invalid stream.");
3804 if (playback_stream_isinstance(stream
)) {
3805 playback_stream
*ps
= PLAYBACK_STREAM(stream
);
3807 if (seek
!= PA_SEEK_RELATIVE
|| offset
!= 0)
3808 pa_asyncmsgq_post(ps
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(ps
->sink_input
), SINK_INPUT_MESSAGE_SEEK
, PA_UINT_TO_PTR(seek
), offset
, NULL
, NULL
);
3810 pa_asyncmsgq_post(ps
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(ps
->sink_input
), SINK_INPUT_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
3813 upload_stream
*u
= UPLOAD_STREAM(stream
);
3816 if (!u
->memchunk
.memblock
) {
3817 if (u
->length
== chunk
->length
) {
3818 u
->memchunk
= *chunk
;
3819 pa_memblock_ref(u
->memchunk
.memblock
);
3822 u
->memchunk
.memblock
= pa_memblock_new(c
->protocol
->core
->mempool
, u
->length
);
3823 u
->memchunk
.index
= u
->memchunk
.length
= 0;
3827 pa_assert(u
->memchunk
.memblock
);
3830 if (l
> chunk
->length
)
3836 dst
= pa_memblock_acquire(u
->memchunk
.memblock
);
3837 src
= pa_memblock_acquire(chunk
->memblock
);
3839 memcpy((uint8_t*) dst
+ u
->memchunk
.index
+ u
->memchunk
.length
,
3840 (uint8_t*) src
+chunk
->index
, l
);
3842 pa_memblock_release(u
->memchunk
.memblock
);
3843 pa_memblock_release(chunk
->memblock
);
3845 u
->memchunk
.length
+= l
;
3851 static void pstream_die_callback(pa_pstream
*p
, void *userdata
) {
3852 connection
*c
= CONNECTION(userdata
);
3855 connection_assert_ref(c
);
3857 connection_unlink(c
);
3858 pa_log_info("connection died.");
3861 static void pstream_drain_callback(pa_pstream
*p
, void *userdata
) {
3862 connection
*c
= CONNECTION(userdata
);
3865 connection_assert_ref(c
);
3870 static void pstream_revoke_callback(pa_pstream
*p
, uint32_t block_id
, void *userdata
) {
3873 if (!(q
= pa_thread_mq_get()))
3874 pa_pstream_send_revoke(p
, block_id
);
3876 pa_asyncmsgq_post(q
->outq
, PA_MSGOBJECT(userdata
), CONNECTION_MESSAGE_REVOKE
, PA_UINT_TO_PTR(block_id
), 0, NULL
, NULL
);
3879 static void pstream_release_callback(pa_pstream
*p
, uint32_t block_id
, void *userdata
) {
3882 if (!(q
= pa_thread_mq_get()))
3883 pa_pstream_send_release(p
, block_id
);
3885 pa_asyncmsgq_post(q
->outq
, PA_MSGOBJECT(userdata
), CONNECTION_MESSAGE_RELEASE
, PA_UINT_TO_PTR(block_id
), 0, NULL
, NULL
);
3888 /*** client callbacks ***/
3890 static void client_kill_cb(pa_client
*c
) {
3893 connection_unlink(CONNECTION(c
->userdata
));
3896 /*** socket server callbacks ***/
3898 static void auth_timeout(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
3899 connection
*c
= CONNECTION(userdata
);
3903 connection_assert_ref(c
);
3904 pa_assert(c
->auth_timeout_event
== e
);
3907 connection_unlink(c
);
3910 static void on_connection(PA_GCC_UNUSED pa_socket_server
*s
, pa_iochannel
*io
, void *userdata
) {
3911 pa_protocol_native
*p
= userdata
;
3913 char cname
[256], pname
[128];
3918 if (pa_idxset_size(p
->connections
)+1 > MAX_CONNECTIONS
) {
3919 pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS
);
3920 pa_iochannel_free(io
);
3924 c
= pa_msgobject_new(connection
);
3925 c
->parent
.parent
.free
= connection_free
;
3926 c
->parent
.process_msg
= connection_process_msg
;
3928 c
->authorized
= p
->public;
3930 if (!c
->authorized
&& p
->auth_ip_acl
&& pa_ip_acl_check(p
->auth_ip_acl
, pa_iochannel_get_recv_fd(io
)) > 0) {
3931 pa_log_info("Client authenticated by IP ACL.");
3932 c
->authorized
= TRUE
;
3935 if (!c
->authorized
) {
3937 pa_gettimeofday(&tv
);
3938 tv
.tv_sec
+= AUTH_TIMEOUT
;
3939 c
->auth_timeout_event
= p
->core
->mainloop
->time_new(p
->core
->mainloop
, &tv
, auth_timeout
, c
);
3941 c
->auth_timeout_event
= NULL
;
3945 pa_iochannel_socket_peer_to_string(io
, pname
, sizeof(pname
));
3946 pa_snprintf(cname
, sizeof(cname
), "Native client (%s)", pname
);
3947 c
->client
= pa_client_new(p
->core
, __FILE__
, cname
);
3948 pa_proplist_sets(c
->client
->proplist
, "native-protocol.peer", pname
);
3949 c
->client
->kill
= client_kill_cb
;
3950 c
->client
->userdata
= c
;
3951 c
->client
->module
= p
->module
;
3953 c
->pstream
= pa_pstream_new(p
->core
->mainloop
, io
, p
->core
->mempool
);
3955 pa_pstream_set_recieve_packet_callback(c
->pstream
, pstream_packet_callback
, c
);
3956 pa_pstream_set_recieve_memblock_callback(c
->pstream
, pstream_memblock_callback
, c
);
3957 pa_pstream_set_die_callback(c
->pstream
, pstream_die_callback
, c
);
3958 pa_pstream_set_drain_callback(c
->pstream
, pstream_drain_callback
, c
);
3959 pa_pstream_set_revoke_callback(c
->pstream
, pstream_revoke_callback
, c
);
3960 pa_pstream_set_release_callback(c
->pstream
, pstream_release_callback
, c
);
3962 c
->pdispatch
= pa_pdispatch_new(p
->core
->mainloop
, command_table
, PA_COMMAND_MAX
);
3964 c
->record_streams
= pa_idxset_new(NULL
, NULL
);
3965 c
->output_streams
= pa_idxset_new(NULL
, NULL
);
3967 c
->rrobin_index
= PA_IDXSET_INVALID
;
3968 c
->subscription
= NULL
;
3970 pa_idxset_put(p
->connections
, c
, NULL
);
3973 if (pa_iochannel_creds_supported(io
))
3974 pa_iochannel_creds_enable(io
);
3979 /*** module entry points ***/
3981 static int load_key(pa_protocol_native
*p
, const char*fn
) {
3984 p
->auth_cookie_in_property
= FALSE
;
3986 if (!fn
&& pa_authkey_prop_get(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0) {
3987 pa_log_info("using already loaded auth cookie.");
3988 pa_authkey_prop_ref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
3989 p
->auth_cookie_in_property
= TRUE
;
3994 fn
= PA_NATIVE_COOKIE_FILE
;
3996 if (pa_authkey_load_auto(fn
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) < 0)
3999 pa_log_info("loading cookie from disk.");
4001 if (pa_authkey_prop_put(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0)
4002 p
->auth_cookie_in_property
= TRUE
;
4007 static pa_protocol_native
* protocol_new_internal(pa_core
*c
, pa_module
*m
, pa_modargs
*ma
) {
4008 pa_protocol_native
*p
;
4009 pa_bool_t
public = FALSE
;
4015 if (pa_modargs_get_value_boolean(ma
, "auth-anonymous", &public) < 0) {
4016 pa_log("auth-anonymous= expects a boolean argument.");
4020 p
= pa_xnew(pa_protocol_native
, 1);
4025 p
->auth_ip_acl
= NULL
;
4030 if (pa_modargs_get_value_boolean(ma
, "auth-group-enabled", &a
) < 0) {
4031 pa_log("auth-group-enabled= expects a boolean argument.");
4034 p
->auth_group
= a
? pa_xstrdup(pa_modargs_get_value(ma
, "auth-group", pa_in_system_mode() ? PA_ACCESS_GROUP
: NULL
)) : NULL
;
4037 pa_log_info("Allowing access to group '%s'.", p
->auth_group
);
4042 if ((acl
= pa_modargs_get_value(ma
, "auth-ip-acl", NULL
))) {
4044 if (!(p
->auth_ip_acl
= pa_ip_acl_new(acl
))) {
4045 pa_log("Failed to parse IP ACL '%s'", acl
);
4050 if (load_key(p
, pa_modargs_get_value(ma
, "cookie", NULL
)) < 0)
4053 p
->connections
= pa_idxset_new(NULL
, NULL
);
4059 pa_xfree(p
->auth_group
);
4062 pa_ip_acl_free(p
->auth_ip_acl
);
4067 pa_protocol_native
* pa_protocol_native_new(pa_core
*core
, pa_socket_server
*server
, pa_module
*m
, pa_modargs
*ma
) {
4069 pa_protocol_native
*p
;
4071 if (!(p
= protocol_new_internal(core
, m
, ma
)))
4074 p
->server
= pa_socket_server_ref(server
);
4075 pa_socket_server_set_callback(p
->server
, on_connection
, p
);
4077 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
4079 l
= pa_property_get(core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4080 l
= pa_strlist_prepend(l
, t
);
4081 pa_property_replace(core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
4087 void pa_protocol_native_free(pa_protocol_native
*p
) {
4091 while ((c
= pa_idxset_first(p
->connections
, NULL
)))
4092 connection_unlink(c
);
4093 pa_idxset_free(p
->connections
, NULL
, NULL
);
4098 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
4100 l
= pa_property_get(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4101 l
= pa_strlist_remove(l
, t
);
4104 pa_property_replace(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
4106 pa_property_remove(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4109 pa_socket_server_unref(p
->server
);
4112 if (p
->auth_cookie_in_property
)
4113 pa_authkey_prop_unref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
4116 pa_ip_acl_free(p
->auth_ip_acl
);
4119 pa_xfree(p
->auth_group
);
4124 pa_protocol_native
* pa_protocol_native_new_iochannel(
4130 pa_protocol_native
*p
;
4132 if (!(p
= protocol_new_internal(core
, m
, ma
)))
4135 on_connection(NULL
, io
, p
);