2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <pulse/timeval.h>
33 #include <pulse/version.h>
34 #include <pulse/utf8.h>
35 #include <pulse/util.h>
36 #include <pulse/xmalloc.h>
38 #include <pulsecore/native-common.h>
39 #include <pulsecore/packet.h>
40 #include <pulsecore/client.h>
41 #include <pulsecore/source-output.h>
42 #include <pulsecore/sink-input.h>
43 #include <pulsecore/pstream.h>
44 #include <pulsecore/tagstruct.h>
45 #include <pulsecore/pdispatch.h>
46 #include <pulsecore/pstream-util.h>
47 #include <pulsecore/authkey.h>
48 #include <pulsecore/namereg.h>
49 #include <pulsecore/core-scache.h>
50 #include <pulsecore/core-subscribe.h>
51 #include <pulsecore/log.h>
52 #include <pulsecore/autoload.h>
53 #include <pulsecore/authkey-prop.h>
54 #include <pulsecore/strlist.h>
55 #include <pulsecore/props.h>
56 #include <pulsecore/sample-util.h>
57 #include <pulsecore/llist.h>
58 #include <pulsecore/creds.h>
59 #include <pulsecore/core-util.h>
60 #include <pulsecore/ipacl.h>
61 #include <pulsecore/thread-mq.h>
63 #include "protocol-native.h"
65 /* Kick a client if it doesn't authenticate within this time */
66 #define AUTH_TIMEOUT 60
68 /* Don't accept more connection than this */
69 #define MAX_CONNECTIONS 64
71 #define MAX_MEMBLOCKQ_LENGTH (4*1024*1024) /* 4MB */
72 #define DEFAULT_TLENGTH_MSEC 2000 /* 2s */
73 #define DEFAULT_PROCESS_MSEC 20 /* 20ms */
74 #define DEFAULT_FRAGSIZE_MSEC DEFAULT_TLENGTH_MSEC
76 typedef struct connection connection
;
77 struct pa_protocol_native
;
79 typedef struct record_stream
{
82 connection
*connection
;
85 pa_source_output
*source_output
;
86 pa_memblockq
*memblockq
;
88 pa_usec_t source_latency
;
91 typedef struct output_stream
{
95 typedef struct playback_stream
{
98 connection
*connection
;
101 pa_sink_input
*sink_input
;
102 pa_memblockq
*memblockq
;
103 pa_bool_t drain_request
;
109 pa_usec_t sink_latency
;
111 /* Only updated after SINK_INPUT_MESSAGE_UPDATE_LATENCY */
112 int64_t read_index
, write_index
;
113 size_t render_memblockq_length
;
116 typedef struct upload_stream
{
117 output_stream parent
;
119 connection
*connection
;
122 pa_memchunk memchunk
;
125 pa_sample_spec sample_spec
;
126 pa_channel_map channel_map
;
127 pa_proplist
*proplist
;
133 pa_bool_t authorized
:1;
134 pa_bool_t is_local
:1;
136 pa_protocol_native
*protocol
;
139 pa_pdispatch
*pdispatch
;
140 pa_idxset
*record_streams
, *output_streams
;
141 uint32_t rrobin_index
;
142 pa_subscription
*subscription
;
143 pa_time_event
*auth_timeout_event
;
146 PA_DECLARE_CLASS(record_stream
);
147 #define RECORD_STREAM(o) (record_stream_cast(o))
148 static PA_DEFINE_CHECK_TYPE(record_stream
, pa_msgobject
);
150 PA_DECLARE_CLASS(output_stream
);
151 #define OUTPUT_STREAM(o) (output_stream_cast(o))
152 static PA_DEFINE_CHECK_TYPE(output_stream
, pa_msgobject
);
154 PA_DECLARE_CLASS(playback_stream
);
155 #define PLAYBACK_STREAM(o) (playback_stream_cast(o))
156 static PA_DEFINE_CHECK_TYPE(playback_stream
, output_stream
);
158 PA_DECLARE_CLASS(upload_stream
);
159 #define UPLOAD_STREAM(o) (upload_stream_cast(o))
160 static PA_DEFINE_CHECK_TYPE(upload_stream
, output_stream
);
162 PA_DECLARE_CLASS(connection
);
163 #define CONNECTION(o) (connection_cast(o))
164 static PA_DEFINE_CHECK_TYPE(connection
, pa_msgobject
);
166 struct pa_protocol_native
{
170 pa_socket_server
*server
;
171 pa_idxset
*connections
;
172 uint8_t auth_cookie
[PA_NATIVE_COOKIE_LENGTH
];
173 pa_bool_t auth_cookie_in_property
;
177 pa_ip_acl
*auth_ip_acl
;
181 SINK_INPUT_MESSAGE_POST_DATA
= PA_SINK_INPUT_MESSAGE_MAX
, /* data from main loop to sink input */
182 SINK_INPUT_MESSAGE_DRAIN
, /* disabled prebuf, get playback started. */
183 SINK_INPUT_MESSAGE_FLUSH
,
184 SINK_INPUT_MESSAGE_TRIGGER
,
185 SINK_INPUT_MESSAGE_SEEK
,
186 SINK_INPUT_MESSAGE_PREBUF_FORCE
,
187 SINK_INPUT_MESSAGE_UPDATE_LATENCY
191 PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, /* data requested from sink input from the main loop */
192 PLAYBACK_STREAM_MESSAGE_UNDERFLOW
,
193 PLAYBACK_STREAM_MESSAGE_OVERFLOW
,
194 PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
,
195 PLAYBACK_STREAM_MESSAGE_STARTED
199 RECORD_STREAM_MESSAGE_POST_DATA
/* data from source output to main loop */
203 CONNECTION_MESSAGE_RELEASE
,
204 CONNECTION_MESSAGE_REVOKE
207 static int sink_input_pop_cb(pa_sink_input
*i
, size_t length
, pa_memchunk
*chunk
);
208 static void sink_input_kill_cb(pa_sink_input
*i
);
209 static void sink_input_suspend_cb(pa_sink_input
*i
, pa_bool_t suspend
);
210 static void sink_input_moved_cb(pa_sink_input
*i
);
211 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
);
212 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
);
215 static void send_memblock(connection
*c
);
216 static void request_bytes(struct playback_stream
*s
);
218 static void source_output_kill_cb(pa_source_output
*o
);
219 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
);
220 static void source_output_suspend_cb(pa_source_output
*o
, pa_bool_t suspend
);
221 static void source_output_moved_cb(pa_source_output
*o
);
222 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
);
224 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
);
226 static void command_exit(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
227 static void command_create_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
228 static void command_drain_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
229 static void command_create_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
230 static void command_delete_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
231 static void command_auth(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
232 static void command_set_client_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
233 static void command_lookup(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
234 static void command_stat(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
235 static void command_get_playback_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
236 static void command_get_record_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
237 static void command_create_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
238 static void command_finish_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
239 static void command_play_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
240 static void command_remove_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
241 static void command_get_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
242 static void command_get_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
243 static void command_get_server_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
244 static void command_subscribe(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
245 static void command_set_volume(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
246 static void command_set_mute(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
247 static void command_cork_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
248 static void command_trigger_or_flush_or_prebuf_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
249 static void command_set_default_sink_or_source(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
250 static void command_set_stream_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
251 static void command_kill(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
252 static void command_load_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
253 static void command_unload_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
254 static void command_add_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
255 static void command_remove_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
256 static void command_get_autoload_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
257 static void command_get_autoload_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
258 static void command_cork_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
259 static void command_flush_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
260 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
261 static void command_suspend(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
262 static void command_set_stream_buffer_attr(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
263 static void command_update_stream_sample_rate(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
264 static void command_update_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
265 static void command_remove_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
267 static const pa_pdispatch_cb_t command_table
[PA_COMMAND_MAX
] = {
268 [PA_COMMAND_ERROR
] = NULL
,
269 [PA_COMMAND_TIMEOUT
] = NULL
,
270 [PA_COMMAND_REPLY
] = NULL
,
271 [PA_COMMAND_CREATE_PLAYBACK_STREAM
] = command_create_playback_stream
,
272 [PA_COMMAND_DELETE_PLAYBACK_STREAM
] = command_delete_stream
,
273 [PA_COMMAND_DRAIN_PLAYBACK_STREAM
] = command_drain_playback_stream
,
274 [PA_COMMAND_CREATE_RECORD_STREAM
] = command_create_record_stream
,
275 [PA_COMMAND_DELETE_RECORD_STREAM
] = command_delete_stream
,
276 [PA_COMMAND_AUTH
] = command_auth
,
277 [PA_COMMAND_REQUEST
] = NULL
,
278 [PA_COMMAND_EXIT
] = command_exit
,
279 [PA_COMMAND_SET_CLIENT_NAME
] = command_set_client_name
,
280 [PA_COMMAND_LOOKUP_SINK
] = command_lookup
,
281 [PA_COMMAND_LOOKUP_SOURCE
] = command_lookup
,
282 [PA_COMMAND_STAT
] = command_stat
,
283 [PA_COMMAND_GET_PLAYBACK_LATENCY
] = command_get_playback_latency
,
284 [PA_COMMAND_GET_RECORD_LATENCY
] = command_get_record_latency
,
285 [PA_COMMAND_CREATE_UPLOAD_STREAM
] = command_create_upload_stream
,
286 [PA_COMMAND_DELETE_UPLOAD_STREAM
] = command_delete_stream
,
287 [PA_COMMAND_FINISH_UPLOAD_STREAM
] = command_finish_upload_stream
,
288 [PA_COMMAND_PLAY_SAMPLE
] = command_play_sample
,
289 [PA_COMMAND_REMOVE_SAMPLE
] = command_remove_sample
,
290 [PA_COMMAND_GET_SINK_INFO
] = command_get_info
,
291 [PA_COMMAND_GET_SOURCE_INFO
] = command_get_info
,
292 [PA_COMMAND_GET_CLIENT_INFO
] = command_get_info
,
293 [PA_COMMAND_GET_MODULE_INFO
] = command_get_info
,
294 [PA_COMMAND_GET_SINK_INPUT_INFO
] = command_get_info
,
295 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO
] = command_get_info
,
296 [PA_COMMAND_GET_SAMPLE_INFO
] = command_get_info
,
297 [PA_COMMAND_GET_SINK_INFO_LIST
] = command_get_info_list
,
298 [PA_COMMAND_GET_SOURCE_INFO_LIST
] = command_get_info_list
,
299 [PA_COMMAND_GET_MODULE_INFO_LIST
] = command_get_info_list
,
300 [PA_COMMAND_GET_CLIENT_INFO_LIST
] = command_get_info_list
,
301 [PA_COMMAND_GET_SINK_INPUT_INFO_LIST
] = command_get_info_list
,
302 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
] = command_get_info_list
,
303 [PA_COMMAND_GET_SAMPLE_INFO_LIST
] = command_get_info_list
,
304 [PA_COMMAND_GET_SERVER_INFO
] = command_get_server_info
,
305 [PA_COMMAND_SUBSCRIBE
] = command_subscribe
,
307 [PA_COMMAND_SET_SINK_VOLUME
] = command_set_volume
,
308 [PA_COMMAND_SET_SINK_INPUT_VOLUME
] = command_set_volume
,
309 [PA_COMMAND_SET_SOURCE_VOLUME
] = command_set_volume
,
311 [PA_COMMAND_SET_SINK_MUTE
] = command_set_mute
,
312 [PA_COMMAND_SET_SINK_INPUT_MUTE
] = command_set_mute
,
313 [PA_COMMAND_SET_SOURCE_MUTE
] = command_set_mute
,
315 [PA_COMMAND_SUSPEND_SINK
] = command_suspend
,
316 [PA_COMMAND_SUSPEND_SOURCE
] = command_suspend
,
318 [PA_COMMAND_CORK_PLAYBACK_STREAM
] = command_cork_playback_stream
,
319 [PA_COMMAND_FLUSH_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
320 [PA_COMMAND_TRIGGER_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
321 [PA_COMMAND_PREBUF_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
323 [PA_COMMAND_CORK_RECORD_STREAM
] = command_cork_record_stream
,
324 [PA_COMMAND_FLUSH_RECORD_STREAM
] = command_flush_record_stream
,
326 [PA_COMMAND_SET_DEFAULT_SINK
] = command_set_default_sink_or_source
,
327 [PA_COMMAND_SET_DEFAULT_SOURCE
] = command_set_default_sink_or_source
,
328 [PA_COMMAND_SET_PLAYBACK_STREAM_NAME
] = command_set_stream_name
,
329 [PA_COMMAND_SET_RECORD_STREAM_NAME
] = command_set_stream_name
,
330 [PA_COMMAND_KILL_CLIENT
] = command_kill
,
331 [PA_COMMAND_KILL_SINK_INPUT
] = command_kill
,
332 [PA_COMMAND_KILL_SOURCE_OUTPUT
] = command_kill
,
333 [PA_COMMAND_LOAD_MODULE
] = command_load_module
,
334 [PA_COMMAND_UNLOAD_MODULE
] = command_unload_module
,
335 [PA_COMMAND_GET_AUTOLOAD_INFO
] = command_get_autoload_info
,
336 [PA_COMMAND_GET_AUTOLOAD_INFO_LIST
] = command_get_autoload_info_list
,
337 [PA_COMMAND_ADD_AUTOLOAD
] = command_add_autoload
,
338 [PA_COMMAND_REMOVE_AUTOLOAD
] = command_remove_autoload
,
340 [PA_COMMAND_MOVE_SINK_INPUT
] = command_move_stream
,
341 [PA_COMMAND_MOVE_SOURCE_OUTPUT
] = command_move_stream
,
343 [PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR
] = command_set_stream_buffer_attr
,
344 [PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR
] = command_set_stream_buffer_attr
,
346 [PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE
] = command_update_stream_sample_rate
,
347 [PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE
] = command_update_stream_sample_rate
,
349 [PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST
] = command_update_proplist
,
350 [PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST
] = command_update_proplist
,
351 [PA_COMMAND_UPDATE_CLIENT_PROPLIST
] = command_update_proplist
,
353 [PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
] = command_remove_proplist
,
354 [PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
] = command_remove_proplist
,
355 [PA_COMMAND_REMOVE_CLIENT_PROPLIST
] = command_remove_proplist
,
358 /* structure management */
360 static void upload_stream_unlink(upload_stream
*s
) {
366 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
367 s
->connection
= NULL
;
368 upload_stream_unref(s
);
371 static void upload_stream_free(pa_object
*o
) {
372 upload_stream
*s
= UPLOAD_STREAM(o
);
375 upload_stream_unlink(s
);
380 pa_proplist_free(s
->proplist
);
382 if (s
->memchunk
.memblock
)
383 pa_memblock_unref(s
->memchunk
.memblock
);
388 static upload_stream
* upload_stream_new(
390 const pa_sample_spec
*ss
,
391 const pa_channel_map
*map
,
401 pa_assert(length
> 0);
404 s
= pa_msgobject_new(upload_stream
);
405 s
->parent
.parent
.parent
.free
= upload_stream_free
;
407 s
->sample_spec
= *ss
;
408 s
->channel_map
= *map
;
409 s
->name
= pa_xstrdup(name
);
410 pa_memchunk_reset(&s
->memchunk
);
412 s
->proplist
= pa_proplist_copy(p
);
413 pa_proplist_update(s
->proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
415 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
420 static void record_stream_unlink(record_stream
*s
) {
426 if (s
->source_output
) {
427 pa_source_output_unlink(s
->source_output
);
428 pa_source_output_unref(s
->source_output
);
429 s
->source_output
= NULL
;
432 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->record_streams
, s
, NULL
) == s
);
433 s
->connection
= NULL
;
434 record_stream_unref(s
);
437 static void record_stream_free(pa_object
*o
) {
438 record_stream
*s
= RECORD_STREAM(o
);
441 record_stream_unlink(s
);
443 pa_memblockq_free(s
->memblockq
);
447 static int record_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
448 record_stream
*s
= RECORD_STREAM(o
);
449 record_stream_assert_ref(s
);
456 case RECORD_STREAM_MESSAGE_POST_DATA
:
458 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
459 /* pa_log_warn("Failed to push data into output queue."); */
463 if (!pa_pstream_is_pending(s
->connection
->pstream
))
464 send_memblock(s
->connection
);
472 static void fix_record_buffer_attr_pre(record_stream
*s
, pa_bool_t adjust_latency
, uint32_t *maxlength
, uint32_t *fragsize
) {
474 pa_assert(maxlength
);
477 if (*maxlength
<= 0 || *maxlength
> MAX_MEMBLOCKQ_LENGTH
)
478 *maxlength
= MAX_MEMBLOCKQ_LENGTH
;
481 *fragsize
= pa_usec_to_bytes(DEFAULT_FRAGSIZE_MSEC
*PA_USEC_PER_MSEC
, &s
->source_output
->sample_spec
);
483 if (adjust_latency
) {
484 pa_usec_t fragsize_usec
;
486 /* So, the user asked us to adjust the latency according to
487 * what the source can provide. Half the latency will be
488 * spent on the hw buffer, half of it in the async buffer
489 * queue we maintain for each client. */
491 fragsize_usec
= pa_bytes_to_usec(*fragsize
, &s
->source_output
->sample_spec
);
493 s
->source_latency
= pa_source_output_set_requested_latency(s
->source_output
, fragsize_usec
/2);
495 if (fragsize_usec
>= s
->source_latency
*2)
496 fragsize_usec
-= s
->source_latency
;
498 fragsize_usec
= s
->source_latency
;
500 *fragsize
= pa_usec_to_bytes(fragsize_usec
, &s
->source_output
->sample_spec
);
502 s
->source_latency
= 0;
505 static void fix_record_buffer_attr_post(record_stream
*s
, uint32_t *maxlength
, uint32_t *fragsize
) {
509 pa_assert(maxlength
);
512 *maxlength
= pa_memblockq_get_maxlength(s
->memblockq
);
514 base
= pa_frame_size(&s
->source_output
->sample_spec
);
516 s
->fragment_size
= (*fragsize
/base
)*base
;
517 if (s
->fragment_size
<= 0)
518 s
->fragment_size
= base
;
520 if (s
->fragment_size
> *maxlength
)
521 s
->fragment_size
= *maxlength
;
523 *fragsize
= s
->fragment_size
;
526 static record_stream
* record_stream_new(
531 pa_bool_t peak_detect
,
534 pa_source_output_flags_t flags
,
536 pa_bool_t adjust_latency
,
537 pa_sink_input
*direct_on_input
) {
540 pa_source_output
*source_output
;
542 pa_source_output_new_data data
;
546 pa_assert(maxlength
);
549 pa_source_output_new_data_init(&data
);
551 pa_proplist_update(data
.proplist
, PA_UPDATE_REPLACE
, p
);
552 pa_proplist_update(data
.proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
553 data
.driver
= __FILE__
;
554 data
.module
= c
->protocol
->module
;
555 data
.client
= c
->client
;
556 data
.source
= source
;
557 data
.direct_on_input
= direct_on_input
;
558 pa_source_output_new_data_set_sample_spec(&data
, ss
);
559 pa_source_output_new_data_set_channel_map(&data
, map
);
561 data
.resample_method
= PA_RESAMPLER_PEAKS
;
563 source_output
= pa_source_output_new(c
->protocol
->core
, &data
, flags
);
565 pa_source_output_new_data_done(&data
);
570 s
= pa_msgobject_new(record_stream
);
571 s
->parent
.parent
.free
= record_stream_free
;
572 s
->parent
.process_msg
= record_stream_process_msg
;
574 s
->source_output
= source_output
;
576 s
->source_output
->push
= source_output_push_cb
;
577 s
->source_output
->kill
= source_output_kill_cb
;
578 s
->source_output
->get_latency
= source_output_get_latency_cb
;
579 s
->source_output
->moved
= source_output_moved_cb
;
580 s
->source_output
->suspend
= source_output_suspend_cb
;
581 s
->source_output
->userdata
= s
;
583 fix_record_buffer_attr_pre(s
, adjust_latency
, maxlength
, fragsize
);
585 s
->memblockq
= pa_memblockq_new(
589 base
= pa_frame_size(&source_output
->sample_spec
),
595 fix_record_buffer_attr_post(s
, maxlength
, fragsize
);
597 *ss
= s
->source_output
->sample_spec
;
598 *map
= s
->source_output
->channel_map
;
600 pa_idxset_put(c
->record_streams
, s
, &s
->index
);
602 pa_log_info("Final latency %0.2f ms = %0.2f ms + %0.2f ms",
603 ((double) pa_bytes_to_usec(s
->fragment_size
, &source_output
->sample_spec
) + (double) s
->source_latency
) / PA_USEC_PER_MSEC
,
604 (double) pa_bytes_to_usec(s
->fragment_size
, &source_output
->sample_spec
) / PA_USEC_PER_MSEC
,
605 (double) s
->source_latency
/ PA_USEC_PER_MSEC
);
607 pa_source_output_put(s
->source_output
);
611 static void playback_stream_unlink(playback_stream
*s
) {
618 pa_sink_input_unlink(s
->sink_input
);
619 pa_sink_input_unref(s
->sink_input
);
620 s
->sink_input
= NULL
;
623 if (s
->drain_request
)
624 pa_pstream_send_error(s
->connection
->pstream
, s
->drain_tag
, PA_ERR_NOENTITY
);
626 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
627 s
->connection
= NULL
;
628 playback_stream_unref(s
);
631 static void playback_stream_free(pa_object
* o
) {
632 playback_stream
*s
= PLAYBACK_STREAM(o
);
635 playback_stream_unlink(s
);
637 pa_memblockq_free(s
->memblockq
);
641 static int playback_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
642 playback_stream
*s
= PLAYBACK_STREAM(o
);
643 playback_stream_assert_ref(s
);
649 case PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
: {
654 if ((l
= pa_atomic_load(&s
->missing
)) <= 0)
657 if (pa_atomic_cmpxchg(&s
->missing
, l
, 0))
664 t
= pa_tagstruct_new(NULL
, 0);
665 pa_tagstruct_putu32(t
, PA_COMMAND_REQUEST
);
666 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
667 pa_tagstruct_putu32(t
, s
->index
);
668 pa_tagstruct_putu32(t
, l
);
669 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
671 /* pa_log("Requesting %lu bytes", (unsigned long) l); */
675 case PLAYBACK_STREAM_MESSAGE_UNDERFLOW
: {
678 /* Report that we're empty */
679 t
= pa_tagstruct_new(NULL
, 0);
680 pa_tagstruct_putu32(t
, PA_COMMAND_UNDERFLOW
);
681 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
682 pa_tagstruct_putu32(t
, s
->index
);
683 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
687 case PLAYBACK_STREAM_MESSAGE_OVERFLOW
: {
690 /* Notify the user we're overflowed*/
691 t
= pa_tagstruct_new(NULL
, 0);
692 pa_tagstruct_putu32(t
, PA_COMMAND_OVERFLOW
);
693 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
694 pa_tagstruct_putu32(t
, s
->index
);
695 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
699 case PLAYBACK_STREAM_MESSAGE_STARTED
:
701 if (s
->connection
->version
>= 13) {
704 /* Notify the user we're overflowed*/
705 t
= pa_tagstruct_new(NULL
, 0);
706 pa_tagstruct_putu32(t
, PA_COMMAND_STARTED
);
707 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
708 pa_tagstruct_putu32(t
, s
->index
);
709 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
714 case PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
:
715 pa_pstream_send_simple_ack(s
->connection
->pstream
, PA_PTR_TO_UINT(userdata
));
722 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
) {
724 pa_usec_t tlength_usec
, minreq_usec
, sink_usec
;
727 pa_assert(maxlength
);
732 if (*maxlength
<= 0 || *maxlength
> MAX_MEMBLOCKQ_LENGTH
)
733 *maxlength
= MAX_MEMBLOCKQ_LENGTH
;
735 *tlength
= pa_usec_to_bytes(DEFAULT_TLENGTH_MSEC
*PA_USEC_PER_MSEC
, &s
->sink_input
->sample_spec
);
737 *minreq
= pa_usec_to_bytes(DEFAULT_PROCESS_MSEC
*PA_USEC_PER_MSEC
, &s
->sink_input
->sample_spec
);
739 frame_size
= pa_frame_size(&s
->sink_input
->sample_spec
);
741 *minreq
= frame_size
;
742 if (*tlength
< *minreq
+frame_size
)
743 *tlength
= *minreq
+frame_size
;
745 tlength_usec
= pa_bytes_to_usec(*tlength
, &s
->sink_input
->sample_spec
);
746 minreq_usec
= pa_bytes_to_usec(*minreq
, &s
->sink_input
->sample_spec
);
748 pa_log_info("Requested tlength=%0.2f ms, minreq=%0.2f ms",
749 (double) tlength_usec
/ PA_USEC_PER_MSEC
,
750 (double) minreq_usec
/ PA_USEC_PER_MSEC
);
752 if (adjust_latency
) {
754 /* So, the user asked us to adjust the latency of the stream
755 * buffer according to the what the sink can provide. The
756 * tlength passed in shall be the overall latency. Roughly
757 * half the latency will be spent on the hw buffer, the other
758 * half of it in the async buffer queue we maintain for each
759 * client. In between we'll have a safety space of size
760 * 2*minreq. Why the 2*minreq? When the hw buffer is completey
761 * empty and needs to be filled, then our buffer must have
762 * enough data to fulfill this request immediatly and thus
763 * have at least the same tlength as the size of the hw
764 * buffer. It additionally needs space for 2 times minreq
765 * because if the buffer ran empty and a partial fillup
766 * happens immediately on the next iteration we need to be
767 * able to fulfill it and give the application also minreq
768 * time to fill it up again for the next request Makes 2 times
769 * minreq in plus.. */
771 if (tlength_usec
> minreq_usec
*2)
772 sink_usec
= (tlength_usec
- minreq_usec
*2)/2;
778 /* Ok, the user didn't ask us to adjust the latency, but we
779 * still need to make sure that the parameters from the user
782 if (tlength_usec
> minreq_usec
*2)
783 sink_usec
= (tlength_usec
- minreq_usec
*2);
788 s
->sink_latency
= pa_sink_input_set_requested_latency(s
->sink_input
, sink_usec
);
790 if (adjust_latency
) {
791 /* Ok, we didn't necessarily get what we were asking for, so
792 * let's subtract from what we asked for for the remaining
795 if (tlength_usec
>= s
->sink_latency
)
796 tlength_usec
-= s
->sink_latency
;
799 if (tlength_usec
< s
->sink_latency
+ 2*minreq_usec
)
800 tlength_usec
= s
->sink_latency
+ 2*minreq_usec
;
802 *tlength
= pa_usec_to_bytes(tlength_usec
, &s
->sink_input
->sample_spec
);
803 *minreq
= pa_usec_to_bytes(minreq_usec
, &s
->sink_input
->sample_spec
);
806 *minreq
+= frame_size
;
807 *tlength
+= frame_size
*2;
810 if (*tlength
<= *minreq
)
811 *tlength
= *minreq
*2 + frame_size
;
813 if (*prebuf
<= 0 || *prebuf
> *tlength
)
817 static void fix_playback_buffer_attr_post(playback_stream
*s
, uint32_t *maxlength
, uint32_t *tlength
, uint32_t* prebuf
, uint32_t* minreq
) {
819 pa_assert(maxlength
);
824 *maxlength
= (uint32_t) pa_memblockq_get_maxlength(s
->memblockq
);
825 *tlength
= (uint32_t) pa_memblockq_get_tlength(s
->memblockq
);
826 *prebuf
= (uint32_t) pa_memblockq_get_prebuf(s
->memblockq
);
827 *minreq
= (uint32_t) pa_memblockq_get_minreq(s
->memblockq
);
832 static playback_stream
* playback_stream_new(
845 pa_sink_input_flags_t flags
,
847 pa_bool_t adjust_latency
) {
849 playback_stream
*s
, *ssync
;
850 pa_sink_input
*sink_input
;
854 pa_sink_input_new_data data
;
858 pa_assert(maxlength
);
866 /* Find syncid group */
867 for (ssync
= pa_idxset_first(c
->output_streams
, &idx
); ssync
; ssync
= pa_idxset_next(c
->output_streams
, &idx
)) {
869 if (!playback_stream_isinstance(ssync
))
872 if (ssync
->syncid
== syncid
)
876 /* Synced streams must connect to the same sink */
880 sink
= ssync
->sink_input
->sink
;
881 else if (sink
!= ssync
->sink_input
->sink
)
885 pa_sink_input_new_data_init(&data
);
887 pa_proplist_update(data
.proplist
, PA_UPDATE_REPLACE
, p
);
888 pa_proplist_update(data
.proplist
, PA_UPDATE_MERGE
, c
->client
->proplist
);
889 data
.driver
= __FILE__
;
890 data
.module
= c
->protocol
->module
;
891 data
.client
= c
->client
;
893 pa_sink_input_new_data_set_sample_spec(&data
, ss
);
894 pa_sink_input_new_data_set_channel_map(&data
, map
);
895 pa_sink_input_new_data_set_volume(&data
, volume
);
896 pa_sink_input_new_data_set_muted(&data
, muted
);
897 data
.sync_base
= ssync
? ssync
->sink_input
: NULL
;
899 sink_input
= pa_sink_input_new(c
->protocol
->core
, &data
, flags
);
901 pa_sink_input_new_data_done(&data
);
906 s
= pa_msgobject_new(playback_stream
);
907 s
->parent
.parent
.parent
.free
= playback_stream_free
;
908 s
->parent
.parent
.process_msg
= playback_stream_process_msg
;
911 s
->sink_input
= sink_input
;
913 s
->sink_input
->parent
.process_msg
= sink_input_process_msg
;
914 s
->sink_input
->pop
= sink_input_pop_cb
;
915 s
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
916 s
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
917 s
->sink_input
->kill
= sink_input_kill_cb
;
918 s
->sink_input
->moved
= sink_input_moved_cb
;
919 s
->sink_input
->suspend
= sink_input_suspend_cb
;
920 s
->sink_input
->userdata
= s
;
922 start_index
= ssync
? pa_memblockq_get_read_index(ssync
->memblockq
) : 0;
924 fix_playback_buffer_attr_pre(s
, adjust_latency
, maxlength
, tlength
, prebuf
, minreq
);
925 pa_sink_input_get_silence(sink_input
, &silence
);
927 s
->memblockq
= pa_memblockq_new(
931 pa_frame_size(&sink_input
->sample_spec
),
937 pa_memblock_unref(silence
.memblock
);
938 fix_playback_buffer_attr_post(s
, maxlength
, tlength
, prebuf
, minreq
);
940 *missing
= (uint32_t) pa_memblockq_pop_missing(s
->memblockq
);
942 *ss
= s
->sink_input
->sample_spec
;
943 *map
= s
->sink_input
->channel_map
;
945 pa_atomic_store(&s
->missing
, 0);
946 s
->drain_request
= FALSE
;
948 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
950 pa_log_info("Final latency %0.2f ms = %0.2f ms + 2*%0.2f ms + %0.2f ms",
951 ((double) pa_bytes_to_usec(*tlength
, &sink_input
->sample_spec
) + (double) s
->sink_latency
) / PA_USEC_PER_MSEC
,
952 (double) pa_bytes_to_usec(*tlength
-*minreq
*2, &sink_input
->sample_spec
) / PA_USEC_PER_MSEC
,
953 (double) pa_bytes_to_usec(*minreq
, &sink_input
->sample_spec
) / PA_USEC_PER_MSEC
,
954 (double) s
->sink_latency
/ PA_USEC_PER_MSEC
);
956 pa_sink_input_put(s
->sink_input
);
960 static int connection_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
961 connection
*c
= CONNECTION(o
);
962 connection_assert_ref(c
);
969 case CONNECTION_MESSAGE_REVOKE
:
970 pa_pstream_send_revoke(c
->pstream
, PA_PTR_TO_UINT(userdata
));
973 case CONNECTION_MESSAGE_RELEASE
:
974 pa_pstream_send_release(c
->pstream
, PA_PTR_TO_UINT(userdata
));
981 static void connection_unlink(connection
*c
) {
990 while ((r
= pa_idxset_first(c
->record_streams
, NULL
)))
991 record_stream_unlink(r
);
993 while ((o
= pa_idxset_first(c
->output_streams
, NULL
)))
994 if (playback_stream_isinstance(o
))
995 playback_stream_unlink(PLAYBACK_STREAM(o
));
997 upload_stream_unlink(UPLOAD_STREAM(o
));
1000 pa_subscription_free(c
->subscription
);
1003 pa_pstream_unlink(c
->pstream
);
1005 if (c
->auth_timeout_event
) {
1006 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
1007 c
->auth_timeout_event
= NULL
;
1010 pa_assert_se(pa_idxset_remove_by_data(c
->protocol
->connections
, c
, NULL
) == c
);
1012 connection_unref(c
);
1015 static void connection_free(pa_object
*o
) {
1016 connection
*c
= CONNECTION(o
);
1020 connection_unlink(c
);
1022 pa_idxset_free(c
->record_streams
, NULL
, NULL
);
1023 pa_idxset_free(c
->output_streams
, NULL
, NULL
);
1025 pa_pdispatch_unref(c
->pdispatch
);
1026 pa_pstream_unref(c
->pstream
);
1027 pa_client_free(c
->client
);
1032 /* Called from thread context */
1033 static void request_bytes(playback_stream
*s
) {
1034 size_t m
, previous_missing
;
1036 playback_stream_assert_ref(s
);
1038 m
= pa_memblockq_pop_missing(s
->memblockq
);
1043 /* pa_log("request_bytes(%lu)", (unsigned long) m); */
1045 previous_missing
= pa_atomic_add(&s
->missing
, m
);
1047 if (pa_memblockq_prebuf_active(s
->memblockq
) ||
1048 (previous_missing
< s
->minreq
&& previous_missing
+m
>= s
->minreq
))
1049 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, NULL
, 0, NULL
, NULL
);
1052 static void send_memblock(connection
*c
) {
1056 start
= PA_IDXSET_INVALID
;
1060 if (!(r
= RECORD_STREAM(pa_idxset_rrobin(c
->record_streams
, &c
->rrobin_index
))))
1063 if (start
== PA_IDXSET_INVALID
)
1064 start
= c
->rrobin_index
;
1065 else if (start
== c
->rrobin_index
)
1068 if (pa_memblockq_peek(r
->memblockq
, &chunk
) >= 0) {
1069 pa_memchunk schunk
= chunk
;
1071 if (schunk
.length
> r
->fragment_size
)
1072 schunk
.length
= r
->fragment_size
;
1074 pa_pstream_send_memblock(c
->pstream
, r
->index
, 0, PA_SEEK_RELATIVE
, &schunk
);
1076 pa_memblockq_drop(r
->memblockq
, schunk
.length
);
1077 pa_memblock_unref(schunk
.memblock
);
1084 static void send_playback_stream_killed(playback_stream
*p
) {
1086 playback_stream_assert_ref(p
);
1088 t
= pa_tagstruct_new(NULL
, 0);
1089 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_KILLED
);
1090 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1091 pa_tagstruct_putu32(t
, p
->index
);
1092 pa_pstream_send_tagstruct(p
->connection
->pstream
, t
);
1095 static void send_record_stream_killed(record_stream
*r
) {
1097 record_stream_assert_ref(r
);
1099 t
= pa_tagstruct_new(NULL
, 0);
1100 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_KILLED
);
1101 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1102 pa_tagstruct_putu32(t
, r
->index
);
1103 pa_pstream_send_tagstruct(r
->connection
->pstream
, t
);
1106 /*** sink input callbacks ***/
1108 static void handle_seek(playback_stream
*s
, int64_t indexw
) {
1109 playback_stream_assert_ref(s
);
1111 /* pa_log("handle_seek: %llu -- %i", (unsigned long long) s->sink_input->thread_info.underrun_for, pa_memblockq_is_readable(s->memblockq)); */
1113 if (s
->sink_input
->thread_info
.underrun_for
> 0) {
1115 /* pa_log("%lu vs. %lu", (unsigned long) pa_memblockq_get_length(s->memblockq), (unsigned long) pa_memblockq_get_prebuf(s->memblockq)); */
1117 if (pa_memblockq_is_readable(s
->memblockq
)) {
1119 /* We just ended an underrun, let's ask the sink
1120 * for a complete rewind rewrite */
1122 pa_log_debug("Requesting rewind due to end of underrun.");
1123 pa_sink_input_request_rewind(s
->sink_input
,
1124 s
->sink_input
->thread_info
.underrun_for
== (size_t) -1 ? 0 : s
->sink_input
->thread_info
.underrun_for
,
1131 indexr
= pa_memblockq_get_read_index(s
->memblockq
);
1133 if (indexw
< indexr
) {
1134 /* OK, the sink already asked for this data, so
1135 * let's have it usk us again */
1137 pa_log_debug("Requesting rewind due to rewrite.");
1138 pa_sink_input_request_rewind(s
->sink_input
, indexr
- indexw
, TRUE
, FALSE
);
1145 /* Called from thread context */
1146 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
) {
1147 pa_sink_input
*i
= PA_SINK_INPUT(o
);
1150 pa_sink_input_assert_ref(i
);
1151 s
= PLAYBACK_STREAM(i
->userdata
);
1152 playback_stream_assert_ref(s
);
1156 case SINK_INPUT_MESSAGE_SEEK
: {
1159 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1160 pa_memblockq_seek(s
->memblockq
, offset
, PA_PTR_TO_UINT(userdata
));
1162 handle_seek(s
, windex
);
1166 case SINK_INPUT_MESSAGE_POST_DATA
: {
1171 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1173 /* pa_log("sink input post: %lu %lli", (unsigned long) chunk->length, (long long) windex); */
1175 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
1176 pa_log_warn("Failed to push data into queue");
1177 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_OVERFLOW
, NULL
, 0, NULL
, NULL
);
1178 pa_memblockq_seek(s
->memblockq
, chunk
->length
, PA_SEEK_RELATIVE
);
1181 handle_seek(s
, windex
);
1183 /* pa_log("sink input post2: %lu", (unsigned long) pa_memblockq_get_length(s->memblockq)); */
1188 case SINK_INPUT_MESSAGE_DRAIN
:
1189 case SINK_INPUT_MESSAGE_FLUSH
:
1190 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
1191 case SINK_INPUT_MESSAGE_TRIGGER
: {
1194 pa_sink_input
*isync
;
1195 void (*func
)(pa_memblockq
*bq
);
1198 case SINK_INPUT_MESSAGE_FLUSH
:
1199 func
= pa_memblockq_flush_write
;
1202 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
1203 func
= pa_memblockq_prebuf_force
;
1206 case SINK_INPUT_MESSAGE_DRAIN
:
1207 case SINK_INPUT_MESSAGE_TRIGGER
:
1208 func
= pa_memblockq_prebuf_disable
;
1212 pa_assert_not_reached();
1215 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1217 handle_seek(s
, windex
);
1219 /* Do the same for all other members in the sync group */
1220 for (isync
= i
->sync_prev
; isync
; isync
= isync
->sync_prev
) {
1221 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
1222 windex
= pa_memblockq_get_write_index(ssync
->memblockq
);
1223 func(ssync
->memblockq
);
1224 handle_seek(ssync
, windex
);
1227 for (isync
= i
->sync_next
; isync
; isync
= isync
->sync_next
) {
1228 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
1229 windex
= pa_memblockq_get_write_index(ssync
->memblockq
);
1230 func(ssync
->memblockq
);
1231 handle_seek(ssync
, windex
);
1234 if (code
== SINK_INPUT_MESSAGE_DRAIN
) {
1235 if (!pa_memblockq_is_readable(s
->memblockq
))
1236 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
, userdata
, 0, NULL
, NULL
);
1238 s
->drain_tag
= PA_PTR_TO_UINT(userdata
);
1239 s
->drain_request
= TRUE
;
1246 case SINK_INPUT_MESSAGE_UPDATE_LATENCY
:
1248 s
->read_index
= pa_memblockq_get_read_index(s
->memblockq
);
1249 s
->write_index
= pa_memblockq_get_write_index(s
->memblockq
);
1250 s
->render_memblockq_length
= pa_memblockq_get_length(s
->sink_input
->thread_info
.render_memblockq
);
1253 case PA_SINK_INPUT_MESSAGE_SET_STATE
: {
1256 windex
= pa_memblockq_get_write_index(s
->memblockq
);
1258 pa_memblockq_prebuf_force(s
->memblockq
);
1260 handle_seek(s
, windex
);
1262 /* Fall through to the default handler */
1266 case PA_SINK_INPUT_MESSAGE_GET_LATENCY
: {
1267 pa_usec_t
*r
= userdata
;
1269 *r
= pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &i
->sample_spec
);
1271 /* Fall through, the default handler will add in the extra
1272 * latency added by the resampler */
1277 return pa_sink_input_process_msg(o
, code
, userdata
, offset
, chunk
);
1280 /* Called from thread context */
1281 static int sink_input_pop_cb(pa_sink_input
*i
, size_t nbytes
, pa_memchunk
*chunk
) {
1284 pa_sink_input_assert_ref(i
);
1285 s
= PLAYBACK_STREAM(i
->userdata
);
1286 playback_stream_assert_ref(s
);
1289 if (pa_memblockq_peek(s
->memblockq
, chunk
) < 0) {
1291 /* pa_log("UNDERRUN: %lu", (unsigned long) pa_memblockq_get_length(s->memblockq)); */
1293 if (s
->drain_request
&& pa_sink_input_safe_to_remove(i
)) {
1294 s
->drain_request
= FALSE
;
1295 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
);
1296 } else if (i
->thread_info
.playing_for
> 0)
1297 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_UNDERFLOW
, NULL
, 0, NULL
, NULL
);
1299 /* pa_log("adding %llu bytes", (unsigned long long) nbytes); */
1306 /* pa_log("NOTUNDERRUN %lu", (unsigned long) chunk->length); */
1308 chunk
->length
= PA_MIN(nbytes
, chunk
->length
);
1310 if (i
->thread_info
.underrun_for
> 0)
1311 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_STARTED
, NULL
, 0, NULL
, NULL
);
1313 pa_memblockq_drop(s
->memblockq
, chunk
->length
);
1319 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
1322 pa_sink_input_assert_ref(i
);
1323 s
= PLAYBACK_STREAM(i
->userdata
);
1324 playback_stream_assert_ref(s
);
1326 /* If we are in an underrun, then we don't rewind */
1327 if (i
->thread_info
.underrun_for
> 0)
1330 pa_memblockq_rewind(s
->memblockq
, nbytes
);
1333 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
1336 pa_sink_input_assert_ref(i
);
1337 s
= PLAYBACK_STREAM(i
->userdata
);
1338 playback_stream_assert_ref(s
);
1340 pa_memblockq_set_maxrewind(s
->memblockq
, nbytes
);
1343 /* Called from main context */
1344 static void sink_input_kill_cb(pa_sink_input
*i
) {
1347 pa_sink_input_assert_ref(i
);
1348 s
= PLAYBACK_STREAM(i
->userdata
);
1349 playback_stream_assert_ref(s
);
1351 send_playback_stream_killed(s
);
1352 playback_stream_unlink(s
);
1355 /* Called from main context */
1356 static void sink_input_suspend_cb(pa_sink_input
*i
, pa_bool_t suspend
) {
1360 pa_sink_input_assert_ref(i
);
1361 s
= PLAYBACK_STREAM(i
->userdata
);
1362 playback_stream_assert_ref(s
);
1364 if (s
->connection
->version
< 12)
1367 t
= pa_tagstruct_new(NULL
, 0);
1368 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_SUSPENDED
);
1369 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1370 pa_tagstruct_putu32(t
, s
->index
);
1371 pa_tagstruct_put_boolean(t
, suspend
);
1372 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1375 /* Called from main context */
1376 static void sink_input_moved_cb(pa_sink_input
*i
) {
1379 uint32_t maxlength
, tlength
, prebuf
, minreq
;
1381 pa_sink_input_assert_ref(i
);
1382 s
= PLAYBACK_STREAM(i
->userdata
);
1383 playback_stream_assert_ref(s
);
1385 maxlength
= (uint32_t) pa_memblockq_get_maxlength(s
->memblockq
);
1386 tlength
= (uint32_t) pa_memblockq_get_tlength(s
->memblockq
);
1387 prebuf
= (uint32_t) pa_memblockq_get_prebuf(s
->memblockq
);
1388 minreq
= (uint32_t) pa_memblockq_get_minreq(s
->memblockq
);
1390 fix_playback_buffer_attr_pre(s
, TRUE
, &maxlength
, &tlength
, &prebuf
, &minreq
);
1391 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
1392 pa_memblockq_set_tlength(s
->memblockq
, tlength
);
1393 pa_memblockq_set_prebuf(s
->memblockq
, prebuf
);
1394 pa_memblockq_set_minreq(s
->memblockq
, minreq
);
1395 fix_playback_buffer_attr_post(s
, &maxlength
, &tlength
, &prebuf
, &minreq
);
1397 if (s
->connection
->version
< 12)
1400 t
= pa_tagstruct_new(NULL
, 0);
1401 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_MOVED
);
1402 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1403 pa_tagstruct_putu32(t
, s
->index
);
1404 pa_tagstruct_putu32(t
, i
->sink
->index
);
1405 pa_tagstruct_puts(t
, i
->sink
->name
);
1406 pa_tagstruct_put_boolean(t
, pa_sink_get_state(i
->sink
) == PA_SINK_SUSPENDED
);
1408 if (s
->connection
->version
>= 13) {
1409 pa_tagstruct_putu32(t
, maxlength
);
1410 pa_tagstruct_putu32(t
, tlength
);
1411 pa_tagstruct_putu32(t
, prebuf
);
1412 pa_tagstruct_putu32(t
, minreq
);
1413 pa_tagstruct_put_usec(t
, s
->sink_latency
);
1416 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1419 /*** source_output callbacks ***/
1421 /* Called from thread context */
1422 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
) {
1425 pa_source_output_assert_ref(o
);
1426 s
= RECORD_STREAM(o
->userdata
);
1427 record_stream_assert_ref(s
);
1430 pa_asyncmsgq_post(pa_thread_mq_get()->outq
, PA_MSGOBJECT(s
), RECORD_STREAM_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
1433 static void source_output_kill_cb(pa_source_output
*o
) {
1436 pa_source_output_assert_ref(o
);
1437 s
= RECORD_STREAM(o
->userdata
);
1438 record_stream_assert_ref(s
);
1440 send_record_stream_killed(s
);
1441 record_stream_unlink(s
);
1444 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
) {
1447 pa_source_output_assert_ref(o
);
1448 s
= RECORD_STREAM(o
->userdata
);
1449 record_stream_assert_ref(s
);
1451 /*pa_log("get_latency: %u", pa_memblockq_get_length(s->memblockq));*/
1453 return pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &o
->sample_spec
);
1456 /* Called from main context */
1457 static void source_output_suspend_cb(pa_source_output
*o
, pa_bool_t suspend
) {
1461 pa_source_output_assert_ref(o
);
1462 s
= RECORD_STREAM(o
->userdata
);
1463 record_stream_assert_ref(s
);
1465 if (s
->connection
->version
< 12)
1468 t
= pa_tagstruct_new(NULL
, 0);
1469 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_SUSPENDED
);
1470 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1471 pa_tagstruct_putu32(t
, s
->index
);
1472 pa_tagstruct_put_boolean(t
, suspend
);
1473 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1476 /* Called from main context */
1477 static void source_output_moved_cb(pa_source_output
*o
) {
1480 uint32_t maxlength
, fragsize
;
1482 pa_source_output_assert_ref(o
);
1483 s
= RECORD_STREAM(o
->userdata
);
1484 record_stream_assert_ref(s
);
1486 fragsize
= (uint32_t) s
->fragment_size
;
1487 maxlength
= (uint32_t) pa_memblockq_get_length(s
->memblockq
);
1489 fix_record_buffer_attr_pre(s
, TRUE
, &maxlength
, &fragsize
);
1490 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
1491 fix_record_buffer_attr_post(s
, &maxlength
, &fragsize
);
1493 if (s
->connection
->version
< 12)
1496 t
= pa_tagstruct_new(NULL
, 0);
1497 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_MOVED
);
1498 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
1499 pa_tagstruct_putu32(t
, s
->index
);
1500 pa_tagstruct_putu32(t
, o
->source
->index
);
1501 pa_tagstruct_puts(t
, o
->source
->name
);
1502 pa_tagstruct_put_boolean(t
, pa_source_get_state(o
->source
) == PA_SOURCE_SUSPENDED
);
1504 if (s
->connection
->version
>= 13) {
1505 pa_tagstruct_putu32(t
, maxlength
);
1506 pa_tagstruct_putu32(t
, fragsize
);
1507 pa_tagstruct_put_usec(t
, s
->source_latency
);
1510 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
1513 /*** pdispatch callbacks ***/
1515 static void protocol_error(connection
*c
) {
1516 pa_log("protocol error, kicking client");
1517 connection_unlink(c
);
1520 #define CHECK_VALIDITY(pstream, expression, tag, error) do { \
1521 if (!(expression)) { \
1522 pa_pstream_send_error((pstream), (tag), (error)); \
1527 static pa_tagstruct
*reply_new(uint32_t tag
) {
1528 pa_tagstruct
*reply
;
1530 reply
= pa_tagstruct_new(NULL
, 0);
1531 pa_tagstruct_putu32(reply
, PA_COMMAND_REPLY
);
1532 pa_tagstruct_putu32(reply
, tag
);
1536 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
) {
1537 connection
*c
= CONNECTION(userdata
);
1539 uint32_t maxlength
, tlength
, prebuf
, minreq
, sink_index
, syncid
, missing
;
1540 const char *name
= NULL
, *sink_name
;
1543 pa_tagstruct
*reply
;
1544 pa_sink
*sink
= NULL
;
1552 fix_channels
= FALSE
,
1554 variable_rate
= FALSE
,
1556 adjust_latency
= FALSE
;
1558 pa_sink_input_flags_t flags
= 0;
1561 connection_assert_ref(c
);
1564 if ((c
->version
< 13 && (pa_tagstruct_gets(t
, &name
) < 0 || !name
)) ||
1567 PA_TAG_SAMPLE_SPEC
, &ss
,
1568 PA_TAG_CHANNEL_MAP
, &map
,
1569 PA_TAG_U32
, &sink_index
,
1570 PA_TAG_STRING
, &sink_name
,
1571 PA_TAG_U32
, &maxlength
,
1572 PA_TAG_BOOLEAN
, &corked
,
1573 PA_TAG_U32
, &tlength
,
1574 PA_TAG_U32
, &prebuf
,
1575 PA_TAG_U32
, &minreq
,
1576 PA_TAG_U32
, &syncid
,
1577 PA_TAG_CVOLUME
, &volume
,
1578 PA_TAG_INVALID
) < 0) {
1584 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1585 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(sink_name
)), tag
, PA_ERR_INVALID
);
1586 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1587 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1588 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
1589 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
&& volume
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1591 p
= pa_proplist_new();
1594 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
1596 if (c
->version
>= 12) {
1597 /* Since 0.9.8 the user can ask for a couple of additional flags */
1599 if (pa_tagstruct_get_boolean(t
, &no_remap
) < 0 ||
1600 pa_tagstruct_get_boolean(t
, &no_remix
) < 0 ||
1601 pa_tagstruct_get_boolean(t
, &fix_format
) < 0 ||
1602 pa_tagstruct_get_boolean(t
, &fix_rate
) < 0 ||
1603 pa_tagstruct_get_boolean(t
, &fix_channels
) < 0 ||
1604 pa_tagstruct_get_boolean(t
, &no_move
) < 0 ||
1605 pa_tagstruct_get_boolean(t
, &variable_rate
) < 0) {
1608 pa_proplist_free(p
);
1613 if (c
->version
>= 13) {
1615 if (pa_tagstruct_get_boolean(t
, &muted
) < 0 ||
1616 pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0 ||
1617 pa_tagstruct_get_proplist(t
, p
) < 0) {
1619 pa_proplist_free(p
);
1624 if (!pa_tagstruct_eof(t
)) {
1626 pa_proplist_free(p
);
1630 if (sink_index
!= PA_INVALID_INDEX
) {
1632 if (!(sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
))) {
1633 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1634 pa_proplist_free(p
);
1638 } else if (sink_name
) {
1640 if (!(sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1))) {
1641 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1642 pa_proplist_free(p
);
1648 (corked
? PA_SINK_INPUT_START_CORKED
: 0) |
1649 (no_remap
? PA_SINK_INPUT_NO_REMAP
: 0) |
1650 (no_remix
? PA_SINK_INPUT_NO_REMIX
: 0) |
1651 (fix_format
? PA_SINK_INPUT_FIX_FORMAT
: 0) |
1652 (fix_rate
? PA_SINK_INPUT_FIX_RATE
: 0) |
1653 (fix_channels
? PA_SINK_INPUT_FIX_CHANNELS
: 0) |
1654 (no_move
? PA_SINK_INPUT_DONT_MOVE
: 0) |
1655 (variable_rate
? PA_SINK_INPUT_VARIABLE_RATE
: 0);
1657 s
= playback_stream_new(c
, sink
, &ss
, &map
, &maxlength
, &tlength
, &prebuf
, &minreq
, &volume
, muted
, syncid
, &missing
, flags
, p
, adjust_latency
);
1658 pa_proplist_free(p
);
1660 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1662 reply
= reply_new(tag
);
1663 pa_tagstruct_putu32(reply
, s
->index
);
1664 pa_assert(s
->sink_input
);
1665 pa_tagstruct_putu32(reply
, s
->sink_input
->index
);
1666 pa_tagstruct_putu32(reply
, missing
);
1668 /* pa_log("initial request is %u", missing); */
1670 if (c
->version
>= 9) {
1671 /* Since 0.9.0 we support sending the buffer metrics back to the client */
1673 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1674 pa_tagstruct_putu32(reply
, (uint32_t) tlength
);
1675 pa_tagstruct_putu32(reply
, (uint32_t) prebuf
);
1676 pa_tagstruct_putu32(reply
, (uint32_t) minreq
);
1679 if (c
->version
>= 12) {
1680 /* Since 0.9.8 we support sending the chosen sample
1681 * spec/channel map/device/suspend status back to the
1684 pa_tagstruct_put_sample_spec(reply
, &ss
);
1685 pa_tagstruct_put_channel_map(reply
, &map
);
1687 pa_tagstruct_putu32(reply
, s
->sink_input
->sink
->index
);
1688 pa_tagstruct_puts(reply
, s
->sink_input
->sink
->name
);
1690 pa_tagstruct_put_boolean(reply
, pa_sink_get_state(s
->sink_input
->sink
) == PA_SINK_SUSPENDED
);
1693 if (c
->version
>= 13)
1694 pa_tagstruct_put_usec(reply
, s
->sink_latency
);
1696 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1699 static void command_delete_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1700 connection
*c
= CONNECTION(userdata
);
1703 connection_assert_ref(c
);
1706 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
1707 !pa_tagstruct_eof(t
)) {
1712 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1716 case PA_COMMAND_DELETE_PLAYBACK_STREAM
: {
1718 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !playback_stream_isinstance(s
)) {
1719 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1723 playback_stream_unlink(s
);
1727 case PA_COMMAND_DELETE_RECORD_STREAM
: {
1729 if (!(s
= pa_idxset_get_by_index(c
->record_streams
, channel
))) {
1730 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1734 record_stream_unlink(s
);
1738 case PA_COMMAND_DELETE_UPLOAD_STREAM
: {
1741 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !upload_stream_isinstance(s
)) {
1742 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1746 upload_stream_unlink(s
);
1751 pa_assert_not_reached();
1754 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1757 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
) {
1758 connection
*c
= CONNECTION(userdata
);
1760 uint32_t maxlength
, fragment_size
;
1761 uint32_t source_index
;
1762 const char *name
= NULL
, *source_name
;
1765 pa_tagstruct
*reply
;
1766 pa_source
*source
= NULL
;
1773 fix_channels
= FALSE
,
1775 variable_rate
= FALSE
,
1776 adjust_latency
= FALSE
,
1777 peak_detect
= FALSE
;
1778 pa_source_output_flags_t flags
= 0;
1780 uint32_t direct_on_input_idx
= PA_INVALID_INDEX
;
1781 pa_sink_input
*direct_on_input
= NULL
;
1783 connection_assert_ref(c
);
1786 if ((c
->version
< 13 && (pa_tagstruct_gets(t
, &name
) < 0 || !name
)) ||
1787 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
1788 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
1789 pa_tagstruct_getu32(t
, &source_index
) < 0 ||
1790 pa_tagstruct_gets(t
, &source_name
) < 0 ||
1791 pa_tagstruct_getu32(t
, &maxlength
) < 0 ||
1792 pa_tagstruct_get_boolean(t
, &corked
) < 0 ||
1793 pa_tagstruct_getu32(t
, &fragment_size
) < 0) {
1798 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1799 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1800 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1801 CHECK_VALIDITY(c
->pstream
, source_index
!= PA_INVALID_INDEX
|| !source_name
|| (*source_name
&& pa_utf8_valid(source_name
)), tag
, PA_ERR_INVALID
);
1802 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1804 p
= pa_proplist_new();
1807 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
1809 if (c
->version
>= 12) {
1810 /* Since 0.9.8 the user can ask for a couple of additional flags */
1812 if (pa_tagstruct_get_boolean(t
, &no_remap
) < 0 ||
1813 pa_tagstruct_get_boolean(t
, &no_remix
) < 0 ||
1814 pa_tagstruct_get_boolean(t
, &fix_format
) < 0 ||
1815 pa_tagstruct_get_boolean(t
, &fix_rate
) < 0 ||
1816 pa_tagstruct_get_boolean(t
, &fix_channels
) < 0 ||
1817 pa_tagstruct_get_boolean(t
, &no_move
) < 0 ||
1818 pa_tagstruct_get_boolean(t
, &variable_rate
) < 0) {
1821 pa_proplist_free(p
);
1826 if (c
->version
>= 13) {
1828 if (pa_tagstruct_get_boolean(t
, &peak_detect
) < 0 ||
1829 pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0 ||
1830 pa_tagstruct_get_proplist(t
, p
) < 0 ||
1831 pa_tagstruct_getu32(t
, &direct_on_input_idx
) < 0) {
1833 pa_proplist_free(p
);
1838 if (!pa_tagstruct_eof(t
)) {
1840 pa_proplist_free(p
);
1844 if (source_index
!= PA_INVALID_INDEX
) {
1846 if (!(source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, source_index
))) {
1847 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1848 pa_proplist_free(p
);
1852 } else if (source_name
) {
1854 if (!(source
= pa_namereg_get(c
->protocol
->core
, source_name
, PA_NAMEREG_SOURCE
, 1))) {
1855 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1856 pa_proplist_free(p
);
1861 if (direct_on_input_idx
!= PA_INVALID_INDEX
) {
1863 if (!(direct_on_input
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, direct_on_input_idx
))) {
1864 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1865 pa_proplist_free(p
);
1871 (corked
? PA_SOURCE_OUTPUT_START_CORKED
: 0) |
1872 (no_remap
? PA_SOURCE_OUTPUT_NO_REMAP
: 0) |
1873 (no_remix
? PA_SOURCE_OUTPUT_NO_REMIX
: 0) |
1874 (fix_format
? PA_SOURCE_OUTPUT_FIX_FORMAT
: 0) |
1875 (fix_rate
? PA_SOURCE_OUTPUT_FIX_RATE
: 0) |
1876 (fix_channels
? PA_SOURCE_OUTPUT_FIX_CHANNELS
: 0) |
1877 (no_move
? PA_SOURCE_OUTPUT_DONT_MOVE
: 0) |
1878 (variable_rate
? PA_SOURCE_OUTPUT_VARIABLE_RATE
: 0);
1880 s
= record_stream_new(c
, source
, &ss
, &map
, peak_detect
, &maxlength
, &fragment_size
, flags
, p
, adjust_latency
, direct_on_input
);
1881 pa_proplist_free(p
);
1883 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1885 reply
= reply_new(tag
);
1886 pa_tagstruct_putu32(reply
, s
->index
);
1887 pa_assert(s
->source_output
);
1888 pa_tagstruct_putu32(reply
, s
->source_output
->index
);
1890 if (c
->version
>= 9) {
1891 /* Since 0.9 we support sending the buffer metrics back to the client */
1893 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1894 pa_tagstruct_putu32(reply
, (uint32_t) fragment_size
);
1897 if (c
->version
>= 12) {
1898 /* Since 0.9.8 we support sending the chosen sample
1899 * spec/channel map/device/suspend status back to the
1902 pa_tagstruct_put_sample_spec(reply
, &ss
);
1903 pa_tagstruct_put_channel_map(reply
, &map
);
1905 pa_tagstruct_putu32(reply
, s
->source_output
->source
->index
);
1906 pa_tagstruct_puts(reply
, s
->source_output
->source
->name
);
1908 pa_tagstruct_put_boolean(reply
, pa_source_get_state(s
->source_output
->source
) == PA_SOURCE_SUSPENDED
);
1911 if (c
->version
>= 13)
1912 pa_tagstruct_put_usec(reply
, s
->source_latency
);
1914 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1917 static void command_exit(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1918 connection
*c
= CONNECTION(userdata
);
1920 connection_assert_ref(c
);
1923 if (!pa_tagstruct_eof(t
)) {
1928 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1930 c
->protocol
->core
->mainloop
->quit(c
->protocol
->core
->mainloop
, 0);
1931 pa_pstream_send_simple_ack(c
->pstream
, tag
); /* nonsense */
1934 static void command_auth(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1935 connection
*c
= CONNECTION(userdata
);
1937 pa_tagstruct
*reply
;
1938 pa_bool_t shm_on_remote
, do_shm
;
1940 connection_assert_ref(c
);
1943 if (pa_tagstruct_getu32(t
, &c
->version
) < 0 ||
1944 pa_tagstruct_get_arbitrary(t
, &cookie
, PA_NATIVE_COOKIE_LENGTH
) < 0 ||
1945 !pa_tagstruct_eof(t
)) {
1950 /* Minimum supported version */
1951 if (c
->version
< 8) {
1952 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_VERSION
);
1956 /* Starting with protocol version 13 the MSB of the version tag
1957 reflects if shm is available for this connection or
1959 if (c
->version
>= 13) {
1960 shm_on_remote
= !!(c
->version
& 0x80000000U
);
1961 c
->version
&= 0x7FFFFFFFU
;
1964 pa_log_debug("Protocol version: remote %u, local %u", c
->version
, PA_PROTOCOL_VERSION
);
1966 pa_proplist_setf(c
->client
->proplist
, "native-protocol.version", "%u", c
->version
);
1968 if (!c
->authorized
) {
1969 pa_bool_t success
= FALSE
;
1972 const pa_creds
*creds
;
1974 if ((creds
= pa_pdispatch_creds(pd
))) {
1975 if (creds
->uid
== getuid())
1977 else if (c
->protocol
->auth_group
) {
1981 if ((gid
= pa_get_gid_of_group(c
->protocol
->auth_group
)) == (gid_t
) -1)
1982 pa_log_warn("Failed to get GID of group '%s'", c
->protocol
->auth_group
);
1983 else if (gid
== creds
->gid
)
1987 if ((r
= pa_uid_in_group(creds
->uid
, c
->protocol
->auth_group
)) < 0)
1988 pa_log_warn("Failed to check group membership.");
1994 pa_log_info("Got credentials: uid=%lu gid=%lu success=%i",
1995 (unsigned long) creds
->uid
,
1996 (unsigned long) creds
->gid
,
2001 if (!success
&& memcmp(c
->protocol
->auth_cookie
, cookie
, PA_NATIVE_COOKIE_LENGTH
) == 0)
2005 pa_log_warn("Denied access to client with invalid authorization data.");
2006 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_ACCESS
);
2010 c
->authorized
= TRUE
;
2011 if (c
->auth_timeout_event
) {
2012 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
2013 c
->auth_timeout_event
= NULL
;
2017 /* Enable shared memory support if possible */
2019 pa_mempool_is_shared(c
->protocol
->core
->mempool
) &&
2022 pa_log_debug("SHM possible: %s", pa_yes_no(do_shm
));
2025 if (c
->version
< 10 || (c
->version
>= 13 && !shm_on_remote
))
2029 /* Only enable SHM if both sides are owned by the same
2030 * user. This is a security measure because otherwise data
2031 * private to the user might leak. */
2033 const pa_creds
*creds
;
2034 if (!(creds
= pa_pdispatch_creds(pd
)) || getuid() != creds
->uid
)
2038 pa_log_debug("Negotiated SHM: %s", pa_yes_no(do_shm
));
2039 pa_pstream_enable_shm(c
->pstream
, do_shm
);
2041 reply
= reply_new(tag
);
2042 pa_tagstruct_putu32(reply
, PA_PROTOCOL_VERSION
| (do_shm
? 0x80000000 : 0));
2046 /* SHM support is only enabled after both sides made sure they are the same user. */
2050 ucred
.uid
= getuid();
2051 ucred
.gid
= getgid();
2053 pa_pstream_send_tagstruct_with_creds(c
->pstream
, reply
, &ucred
);
2056 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2060 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
) {
2061 connection
*c
= CONNECTION(userdata
);
2062 const char *name
= NULL
;
2064 pa_tagstruct
*reply
;
2066 connection_assert_ref(c
);
2069 p
= pa_proplist_new();
2071 if ((c
->version
< 13 && pa_tagstruct_gets(t
, &name
) < 0) ||
2072 (c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) ||
2073 !pa_tagstruct_eof(t
)) {
2076 pa_proplist_free(p
);
2081 if (pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, name
) < 0) {
2082 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
2083 pa_proplist_free(p
);
2087 pa_proplist_update(c
->client
->proplist
, PA_UPDATE_REPLACE
, p
);
2088 pa_proplist_free(p
);
2090 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
2092 reply
= reply_new(tag
);
2094 if (c
->version
>= 13)
2095 pa_tagstruct_putu32(reply
, c
->client
->index
);
2097 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2100 static void command_lookup(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2101 connection
*c
= CONNECTION(userdata
);
2103 uint32_t idx
= PA_IDXSET_INVALID
;
2105 connection_assert_ref(c
);
2108 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2109 !pa_tagstruct_eof(t
)) {
2114 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2115 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2117 if (command
== PA_COMMAND_LOOKUP_SINK
) {
2119 if ((sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1)))
2123 pa_assert(command
== PA_COMMAND_LOOKUP_SOURCE
);
2124 if ((source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1)))
2125 idx
= source
->index
;
2128 if (idx
== PA_IDXSET_INVALID
)
2129 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2131 pa_tagstruct
*reply
;
2132 reply
= reply_new(tag
);
2133 pa_tagstruct_putu32(reply
, idx
);
2134 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2138 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
) {
2139 connection
*c
= CONNECTION(userdata
);
2143 connection_assert_ref(c
);
2146 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2147 !pa_tagstruct_eof(t
)) {
2152 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2153 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2154 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2155 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2157 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
);
2160 static void command_stat(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2161 connection
*c
= CONNECTION(userdata
);
2162 pa_tagstruct
*reply
;
2163 const pa_mempool_stat
*stat
;
2165 connection_assert_ref(c
);
2168 if (!pa_tagstruct_eof(t
)) {
2173 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2175 stat
= pa_mempool_get_stat(c
->protocol
->core
->mempool
);
2177 reply
= reply_new(tag
);
2178 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_allocated
));
2179 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->allocated_size
));
2180 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_accumulated
));
2181 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->accumulated_size
));
2182 pa_tagstruct_putu32(reply
, pa_scache_total_size(c
->protocol
->core
));
2183 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2186 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
) {
2187 connection
*c
= CONNECTION(userdata
);
2188 pa_tagstruct
*reply
;
2190 struct timeval tv
, now
;
2194 connection_assert_ref(c
);
2197 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2198 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
2199 !pa_tagstruct_eof(t
)) {
2204 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2205 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2206 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2207 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2208 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
)
2210 reply
= reply_new(tag
);
2212 latency
= pa_sink_get_latency(s
->sink_input
->sink
);
2213 latency
+= pa_bytes_to_usec(s
->render_memblockq_length
, &s
->sink_input
->sample_spec
);
2215 pa_tagstruct_put_usec(reply
, latency
);
2217 pa_tagstruct_put_usec(reply
, 0);
2218 pa_tagstruct_put_boolean(reply
, s
->sink_input
->thread_info
.playing_for
> 0);
2219 pa_tagstruct_put_timeval(reply
, &tv
);
2220 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
2221 pa_tagstruct_puts64(reply
, s
->write_index
);
2222 pa_tagstruct_puts64(reply
, s
->read_index
);
2224 if (c
->version
>= 13) {
2225 pa_tagstruct_putu64(reply
, s
->sink_input
->thread_info
.underrun_for
);
2226 pa_tagstruct_putu64(reply
, s
->sink_input
->thread_info
.playing_for
);
2229 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2232 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
) {
2233 connection
*c
= CONNECTION(userdata
);
2234 pa_tagstruct
*reply
;
2236 struct timeval tv
, now
;
2239 connection_assert_ref(c
);
2242 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2243 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
2244 !pa_tagstruct_eof(t
)) {
2249 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2250 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
2251 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2253 reply
= reply_new(tag
);
2254 pa_tagstruct_put_usec(reply
, s
->source_output
->source
->monitor_of
? pa_sink_get_latency(s
->source_output
->source
->monitor_of
) : 0);
2255 pa_tagstruct_put_usec(reply
, pa_source_get_latency(s
->source_output
->source
));
2256 pa_tagstruct_put_boolean(reply
, pa_source_get_state(s
->source_output
->source
) == PA_SOURCE_RUNNING
);
2257 pa_tagstruct_put_timeval(reply
, &tv
);
2258 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
2259 pa_tagstruct_puts64(reply
, pa_memblockq_get_write_index(s
->memblockq
));
2260 pa_tagstruct_puts64(reply
, pa_memblockq_get_read_index(s
->memblockq
));
2261 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2264 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
) {
2265 connection
*c
= CONNECTION(userdata
);
2268 const char *name
= NULL
;
2271 pa_tagstruct
*reply
;
2274 connection_assert_ref(c
);
2277 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2278 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
2279 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
2280 pa_tagstruct_getu32(t
, &length
) < 0) {
2285 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2286 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
2287 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
2288 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
2289 CHECK_VALIDITY(c
->pstream
, (length
% pa_frame_size(&ss
)) == 0 && length
> 0, tag
, PA_ERR_INVALID
);
2290 CHECK_VALIDITY(c
->pstream
, length
<= PA_SCACHE_ENTRY_SIZE_MAX
, tag
, PA_ERR_TOOLARGE
);
2292 p
= pa_proplist_new();
2294 if (c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) {
2296 pa_proplist_free(p
);
2300 if (c
->version
< 13)
2301 pa_proplist_sets(p
, PA_PROP_MEDIA_NAME
, name
);
2303 if (!(name
= pa_proplist_gets(p
, PA_PROP_EVENT_ID
)))
2304 name
= pa_proplist_gets(p
, PA_PROP_MEDIA_NAME
);
2306 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2308 s
= upload_stream_new(c
, &ss
, &map
, name
, length
, p
);
2309 pa_proplist_free(p
);
2311 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
2313 reply
= reply_new(tag
);
2314 pa_tagstruct_putu32(reply
, s
->index
);
2315 pa_tagstruct_putu32(reply
, length
);
2316 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2319 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
) {
2320 connection
*c
= CONNECTION(userdata
);
2325 connection_assert_ref(c
);
2328 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
2329 !pa_tagstruct_eof(t
)) {
2334 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2336 s
= pa_idxset_get_by_index(c
->output_streams
, channel
);
2337 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2338 CHECK_VALIDITY(c
->pstream
, upload_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2340 if (pa_scache_add_item(c
->protocol
->core
, s
->name
, &s
->sample_spec
, &s
->channel_map
, &s
->memchunk
, s
->proplist
, &idx
) < 0)
2341 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INTERNAL
);
2343 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2345 upload_stream_unlink(s
);
2348 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
) {
2349 connection
*c
= CONNECTION(userdata
);
2350 uint32_t sink_index
;
2353 const char *name
, *sink_name
;
2356 pa_tagstruct
*reply
;
2358 connection_assert_ref(c
);
2361 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2363 if (pa_tagstruct_getu32(t
, &sink_index
) < 0 ||
2364 pa_tagstruct_gets(t
, &sink_name
) < 0 ||
2365 pa_tagstruct_getu32(t
, &volume
) < 0 ||
2366 pa_tagstruct_gets(t
, &name
) < 0) {
2371 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2372 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2374 if (sink_index
!= PA_INVALID_INDEX
)
2375 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
);
2377 sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1);
2379 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
2381 p
= pa_proplist_new();
2383 if ((c
->version
>= 13 && pa_tagstruct_get_proplist(t
, p
) < 0) ||
2384 !pa_tagstruct_eof(t
)) {
2386 pa_proplist_free(p
);
2390 if (pa_scache_play_item(c
->protocol
->core
, name
, sink
, volume
, p
, &idx
) < 0) {
2391 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2392 pa_proplist_free(p
);
2396 pa_proplist_free(p
);
2398 reply
= reply_new(tag
);
2400 if (c
->version
>= 13)
2401 pa_tagstruct_putu32(reply
, idx
);
2403 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2406 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
) {
2407 connection
*c
= CONNECTION(userdata
);
2410 connection_assert_ref(c
);
2413 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2414 !pa_tagstruct_eof(t
)) {
2419 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2420 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2422 if (pa_scache_remove_item(c
->protocol
->core
, name
) < 0) {
2423 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2427 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2430 static void fixup_sample_spec(connection
*c
, pa_sample_spec
*fixed
, const pa_sample_spec
*original
) {
2433 pa_assert(original
);
2437 if (c
->version
< 12) {
2438 /* Before protocol version 12 we didn't support S32 samples,
2439 * so we need to lie about this to the client */
2441 if (fixed
->format
== PA_SAMPLE_S32LE
)
2442 fixed
->format
= PA_SAMPLE_FLOAT32LE
;
2443 if (fixed
->format
== PA_SAMPLE_S32BE
)
2444 fixed
->format
= PA_SAMPLE_FLOAT32BE
;
2448 static void sink_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_sink
*sink
) {
2449 pa_sample_spec fixed_ss
;
2452 pa_sink_assert_ref(sink
);
2454 fixup_sample_spec(c
, &fixed_ss
, &sink
->sample_spec
);
2458 PA_TAG_U32
, sink
->index
,
2459 PA_TAG_STRING
, sink
->name
,
2460 PA_TAG_STRING
, pa_strnull(pa_proplist_gets(sink
->proplist
, PA_PROP_DEVICE_DESCRIPTION
)),
2461 PA_TAG_SAMPLE_SPEC
, &fixed_ss
,
2462 PA_TAG_CHANNEL_MAP
, &sink
->channel_map
,
2463 PA_TAG_U32
, sink
->module
? sink
->module
->index
: PA_INVALID_INDEX
,
2464 PA_TAG_CVOLUME
, pa_sink_get_volume(sink
),
2465 PA_TAG_BOOLEAN
, pa_sink_get_mute(sink
),
2466 PA_TAG_U32
, sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
2467 PA_TAG_STRING
, sink
->monitor_source
? sink
->monitor_source
->name
: NULL
,
2468 PA_TAG_USEC
, pa_sink_get_latency(sink
),
2469 PA_TAG_STRING
, sink
->driver
,
2470 PA_TAG_U32
, sink
->flags
,
2473 if (c
->version
>= 13) {
2474 pa_tagstruct_put_proplist(t
, sink
->proplist
);
2475 pa_tagstruct_put_usec(t
, pa_sink_get_requested_latency(sink
));
2479 static void source_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_source
*source
) {
2480 pa_sample_spec fixed_ss
;
2483 pa_source_assert_ref(source
);
2485 fixup_sample_spec(c
, &fixed_ss
, &source
->sample_spec
);
2489 PA_TAG_U32
, source
->index
,
2490 PA_TAG_STRING
, source
->name
,
2491 PA_TAG_STRING
, pa_strnull(pa_proplist_gets(source
->proplist
, PA_PROP_DEVICE_DESCRIPTION
)),
2492 PA_TAG_SAMPLE_SPEC
, &fixed_ss
,
2493 PA_TAG_CHANNEL_MAP
, &source
->channel_map
,
2494 PA_TAG_U32
, source
->module
? source
->module
->index
: PA_INVALID_INDEX
,
2495 PA_TAG_CVOLUME
, pa_source_get_volume(source
),
2496 PA_TAG_BOOLEAN
, pa_source_get_mute(source
),
2497 PA_TAG_U32
, source
->monitor_of
? source
->monitor_of
->index
: PA_INVALID_INDEX
,
2498 PA_TAG_STRING
, source
->monitor_of
? source
->monitor_of
->name
: NULL
,
2499 PA_TAG_USEC
, pa_source_get_latency(source
),
2500 PA_TAG_STRING
, source
->driver
,
2501 PA_TAG_U32
, source
->flags
,
2504 if (c
->version
>= 13) {
2505 pa_tagstruct_put_proplist(t
, source
->proplist
);
2506 pa_tagstruct_put_usec(t
, pa_source_get_requested_latency(source
));
2511 static void client_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_client
*client
) {
2515 pa_tagstruct_putu32(t
, client
->index
);
2516 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(client
->proplist
, PA_PROP_APPLICATION_NAME
)));
2517 pa_tagstruct_putu32(t
, client
->module
? client
->module
->index
: PA_INVALID_INDEX
);
2518 pa_tagstruct_puts(t
, client
->driver
);
2520 if (c
->version
>= 13)
2521 pa_tagstruct_put_proplist(t
, client
->proplist
);
2525 static void module_fill_tagstruct(pa_tagstruct
*t
, pa_module
*module
) {
2529 pa_tagstruct_putu32(t
, module
->index
);
2530 pa_tagstruct_puts(t
, module
->name
);
2531 pa_tagstruct_puts(t
, module
->argument
);
2532 pa_tagstruct_putu32(t
, module
->n_used
);
2533 pa_tagstruct_put_boolean(t
, module
->auto_unload
);
2536 static void sink_input_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_sink_input
*s
) {
2537 pa_sample_spec fixed_ss
;
2538 pa_usec_t sink_latency
;
2541 pa_sink_input_assert_ref(s
);
2543 fixup_sample_spec(c
, &fixed_ss
, &s
->sample_spec
);
2545 pa_tagstruct_putu32(t
, s
->index
);
2546 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(s
->proplist
, PA_PROP_MEDIA_NAME
)));
2547 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
2548 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
2549 pa_tagstruct_putu32(t
, s
->sink
->index
);
2550 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2551 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
2552 pa_tagstruct_put_cvolume(t
, &s
->volume
);
2553 pa_tagstruct_put_usec(t
, pa_sink_input_get_latency(s
, &sink_latency
));
2554 pa_tagstruct_put_usec(t
, sink_latency
);
2555 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_sink_input_get_resample_method(s
)));
2556 pa_tagstruct_puts(t
, s
->driver
);
2557 if (c
->version
>= 11)
2558 pa_tagstruct_put_boolean(t
, pa_sink_input_get_mute(s
));
2559 if (c
->version
>= 13)
2560 pa_tagstruct_put_proplist(t
, s
->proplist
);
2563 static void source_output_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_source_output
*s
) {
2564 pa_sample_spec fixed_ss
;
2565 pa_usec_t source_latency
;
2568 pa_source_output_assert_ref(s
);
2570 fixup_sample_spec(c
, &fixed_ss
, &s
->sample_spec
);
2572 pa_tagstruct_putu32(t
, s
->index
);
2573 pa_tagstruct_puts(t
, pa_strnull(pa_proplist_gets(s
->proplist
, PA_PROP_MEDIA_NAME
)));
2574 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
2575 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
2576 pa_tagstruct_putu32(t
, s
->source
->index
);
2577 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2578 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
2579 pa_tagstruct_put_usec(t
, pa_source_output_get_latency(s
, &source_latency
));
2580 pa_tagstruct_put_usec(t
, source_latency
);
2581 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_source_output_get_resample_method(s
)));
2582 pa_tagstruct_puts(t
, s
->driver
);
2584 if (c
->version
>= 13)
2585 pa_tagstruct_put_proplist(t
, s
->proplist
);
2588 static void scache_fill_tagstruct(connection
*c
, pa_tagstruct
*t
, pa_scache_entry
*e
) {
2589 pa_sample_spec fixed_ss
;
2594 if (e
->memchunk
.memblock
)
2595 fixup_sample_spec(c
, &fixed_ss
, &e
->sample_spec
);
2597 memset(&fixed_ss
, 0, sizeof(fixed_ss
));
2599 pa_tagstruct_putu32(t
, e
->index
);
2600 pa_tagstruct_puts(t
, e
->name
);
2601 pa_tagstruct_put_cvolume(t
, &e
->volume
);
2602 pa_tagstruct_put_usec(t
, e
->memchunk
.memblock
? pa_bytes_to_usec(e
->memchunk
.length
, &e
->sample_spec
) : 0);
2603 pa_tagstruct_put_sample_spec(t
, &fixed_ss
);
2604 pa_tagstruct_put_channel_map(t
, &e
->channel_map
);
2605 pa_tagstruct_putu32(t
, e
->memchunk
.length
);
2606 pa_tagstruct_put_boolean(t
, e
->lazy
);
2607 pa_tagstruct_puts(t
, e
->filename
);
2609 if (c
->version
>= 13)
2610 pa_tagstruct_put_proplist(t
, e
->proplist
);
2613 static void command_get_info(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2614 connection
*c
= CONNECTION(userdata
);
2616 pa_sink
*sink
= NULL
;
2617 pa_source
*source
= NULL
;
2618 pa_client
*client
= NULL
;
2619 pa_module
*module
= NULL
;
2620 pa_sink_input
*si
= NULL
;
2621 pa_source_output
*so
= NULL
;
2622 pa_scache_entry
*sce
= NULL
;
2624 pa_tagstruct
*reply
;
2626 connection_assert_ref(c
);
2629 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2630 (command
!= PA_COMMAND_GET_CLIENT_INFO
&&
2631 command
!= PA_COMMAND_GET_MODULE_INFO
&&
2632 command
!= PA_COMMAND_GET_SINK_INPUT_INFO
&&
2633 command
!= PA_COMMAND_GET_SOURCE_OUTPUT_INFO
&&
2634 pa_tagstruct_gets(t
, &name
) < 0) ||
2635 !pa_tagstruct_eof(t
)) {
2640 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2641 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2643 if (command
== PA_COMMAND_GET_SINK_INFO
) {
2644 if (idx
!= PA_INVALID_INDEX
)
2645 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2647 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2648 } else if (command
== PA_COMMAND_GET_SOURCE_INFO
) {
2649 if (idx
!= PA_INVALID_INDEX
)
2650 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2652 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2653 } else if (command
== PA_COMMAND_GET_CLIENT_INFO
)
2654 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
2655 else if (command
== PA_COMMAND_GET_MODULE_INFO
)
2656 module
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
2657 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO
)
2658 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2659 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO
)
2660 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
2662 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO
);
2663 if (idx
!= PA_INVALID_INDEX
)
2664 sce
= pa_idxset_get_by_index(c
->protocol
->core
->scache
, idx
);
2666 sce
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SAMPLE
, 0);
2669 if (!sink
&& !source
&& !client
&& !module
&& !si
&& !so
&& !sce
) {
2670 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
2674 reply
= reply_new(tag
);
2676 sink_fill_tagstruct(c
, reply
, sink
);
2678 source_fill_tagstruct(c
, reply
, source
);
2680 client_fill_tagstruct(c
, reply
, client
);
2682 module_fill_tagstruct(reply
, module
);
2684 sink_input_fill_tagstruct(c
, reply
, si
);
2686 source_output_fill_tagstruct(c
, reply
, so
);
2688 scache_fill_tagstruct(c
, reply
, sce
);
2689 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2692 static void command_get_info_list(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2693 connection
*c
= CONNECTION(userdata
);
2697 pa_tagstruct
*reply
;
2699 connection_assert_ref(c
);
2702 if (!pa_tagstruct_eof(t
)) {
2707 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2709 reply
= reply_new(tag
);
2711 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
2712 i
= c
->protocol
->core
->sinks
;
2713 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
2714 i
= c
->protocol
->core
->sources
;
2715 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
2716 i
= c
->protocol
->core
->clients
;
2717 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
2718 i
= c
->protocol
->core
->modules
;
2719 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
2720 i
= c
->protocol
->core
->sink_inputs
;
2721 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
2722 i
= c
->protocol
->core
->source_outputs
;
2724 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
2725 i
= c
->protocol
->core
->scache
;
2729 for (p
= pa_idxset_first(i
, &idx
); p
; p
= pa_idxset_next(i
, &idx
)) {
2730 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
2731 sink_fill_tagstruct(c
, reply
, p
);
2732 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
2733 source_fill_tagstruct(c
, reply
, p
);
2734 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
2735 client_fill_tagstruct(c
, reply
, p
);
2736 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
2737 module_fill_tagstruct(reply
, p
);
2738 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
2739 sink_input_fill_tagstruct(c
, reply
, p
);
2740 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
2741 source_output_fill_tagstruct(c
, reply
, p
);
2743 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
2744 scache_fill_tagstruct(c
, reply
, p
);
2749 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2752 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
) {
2753 connection
*c
= CONNECTION(userdata
);
2754 pa_tagstruct
*reply
;
2757 pa_sample_spec fixed_ss
;
2759 connection_assert_ref(c
);
2762 if (!pa_tagstruct_eof(t
)) {
2767 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2769 reply
= reply_new(tag
);
2770 pa_tagstruct_puts(reply
, PACKAGE_NAME
);
2771 pa_tagstruct_puts(reply
, PACKAGE_VERSION
);
2772 pa_tagstruct_puts(reply
, pa_get_user_name(txt
, sizeof(txt
)));
2773 pa_tagstruct_puts(reply
, pa_get_host_name(txt
, sizeof(txt
)));
2775 fixup_sample_spec(c
, &fixed_ss
, &c
->protocol
->core
->default_sample_spec
);
2776 pa_tagstruct_put_sample_spec(reply
, &fixed_ss
);
2778 n
= pa_namereg_get_default_sink_name(c
->protocol
->core
);
2779 pa_tagstruct_puts(reply
, n
);
2780 n
= pa_namereg_get_default_source_name(c
->protocol
->core
);
2781 pa_tagstruct_puts(reply
, n
);
2783 pa_tagstruct_putu32(reply
, c
->protocol
->core
->cookie
);
2785 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2788 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t e
, uint32_t idx
, void *userdata
) {
2790 connection
*c
= CONNECTION(userdata
);
2792 connection_assert_ref(c
);
2794 t
= pa_tagstruct_new(NULL
, 0);
2795 pa_tagstruct_putu32(t
, PA_COMMAND_SUBSCRIBE_EVENT
);
2796 pa_tagstruct_putu32(t
, (uint32_t) -1);
2797 pa_tagstruct_putu32(t
, e
);
2798 pa_tagstruct_putu32(t
, idx
);
2799 pa_pstream_send_tagstruct(c
->pstream
, t
);
2802 static void command_subscribe(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2803 connection
*c
= CONNECTION(userdata
);
2804 pa_subscription_mask_t m
;
2806 connection_assert_ref(c
);
2809 if (pa_tagstruct_getu32(t
, &m
) < 0 ||
2810 !pa_tagstruct_eof(t
)) {
2815 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2816 CHECK_VALIDITY(c
->pstream
, (m
& ~PA_SUBSCRIPTION_MASK_ALL
) == 0, tag
, PA_ERR_INVALID
);
2818 if (c
->subscription
)
2819 pa_subscription_free(c
->subscription
);
2822 c
->subscription
= pa_subscription_new(c
->protocol
->core
, m
, subscription_cb
, c
);
2823 pa_assert(c
->subscription
);
2825 c
->subscription
= NULL
;
2827 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2830 static void command_set_volume(
2831 PA_GCC_UNUSED pa_pdispatch
*pd
,
2837 connection
*c
= CONNECTION(userdata
);
2840 pa_sink
*sink
= NULL
;
2841 pa_source
*source
= NULL
;
2842 pa_sink_input
*si
= NULL
;
2843 const char *name
= NULL
;
2845 connection_assert_ref(c
);
2848 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2849 (command
== PA_COMMAND_SET_SINK_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2850 (command
== PA_COMMAND_SET_SOURCE_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2851 pa_tagstruct_get_cvolume(t
, &volume
) ||
2852 !pa_tagstruct_eof(t
)) {
2857 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2858 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2859 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
2863 case PA_COMMAND_SET_SINK_VOLUME
:
2864 if (idx
!= PA_INVALID_INDEX
)
2865 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2867 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2870 case PA_COMMAND_SET_SOURCE_VOLUME
:
2871 if (idx
!= PA_INVALID_INDEX
)
2872 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2874 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2877 case PA_COMMAND_SET_SINK_INPUT_VOLUME
:
2878 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2882 pa_assert_not_reached();
2885 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2888 pa_sink_set_volume(sink
, &volume
);
2890 pa_source_set_volume(source
, &volume
);
2892 pa_sink_input_set_volume(si
, &volume
);
2894 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2897 static void command_set_mute(
2898 PA_GCC_UNUSED pa_pdispatch
*pd
,
2904 connection
*c
= CONNECTION(userdata
);
2907 pa_sink
*sink
= NULL
;
2908 pa_source
*source
= NULL
;
2909 pa_sink_input
*si
= NULL
;
2910 const char *name
= NULL
;
2912 connection_assert_ref(c
);
2915 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2916 (command
== PA_COMMAND_SET_SINK_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2917 (command
== PA_COMMAND_SET_SOURCE_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2918 pa_tagstruct_get_boolean(t
, &mute
) ||
2919 !pa_tagstruct_eof(t
)) {
2924 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2925 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2929 case PA_COMMAND_SET_SINK_MUTE
:
2931 if (idx
!= PA_INVALID_INDEX
)
2932 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2934 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2938 case PA_COMMAND_SET_SOURCE_MUTE
:
2939 if (idx
!= PA_INVALID_INDEX
)
2940 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2942 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2946 case PA_COMMAND_SET_SINK_INPUT_MUTE
:
2947 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2951 pa_assert_not_reached();
2954 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2957 pa_sink_set_mute(sink
, mute
);
2959 pa_source_set_mute(source
, mute
);
2961 pa_sink_input_set_mute(si
, mute
);
2963 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2966 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
) {
2967 connection
*c
= CONNECTION(userdata
);
2972 connection_assert_ref(c
);
2975 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2976 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
2977 !pa_tagstruct_eof(t
)) {
2982 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2983 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2984 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2985 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2986 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2988 pa_sink_input_cork(s
->sink_input
, b
);
2989 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2992 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
) {
2993 connection
*c
= CONNECTION(userdata
);
2997 connection_assert_ref(c
);
3000 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3001 !pa_tagstruct_eof(t
)) {
3006 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3007 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
3008 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3009 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3010 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3013 case PA_COMMAND_FLUSH_PLAYBACK_STREAM
:
3014 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_FLUSH
, NULL
, 0, NULL
);
3017 case PA_COMMAND_PREBUF_PLAYBACK_STREAM
:
3018 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_PREBUF_FORCE
, NULL
, 0, NULL
);
3021 case PA_COMMAND_TRIGGER_PLAYBACK_STREAM
:
3022 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_TRIGGER
, NULL
, 0, NULL
);
3026 pa_assert_not_reached();
3029 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3032 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
) {
3033 connection
*c
= CONNECTION(userdata
);
3038 connection_assert_ref(c
);
3041 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3042 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
3043 !pa_tagstruct_eof(t
)) {
3048 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3049 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3050 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3052 pa_source_output_cork(s
->source_output
, b
);
3053 pa_memblockq_prebuf_force(s
->memblockq
);
3054 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3057 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
) {
3058 connection
*c
= CONNECTION(userdata
);
3062 connection_assert_ref(c
);
3065 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3066 !pa_tagstruct_eof(t
)) {
3071 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3072 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3073 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3075 pa_memblockq_flush_read(s
->memblockq
);
3076 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3079 static void command_set_stream_buffer_attr(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3080 connection
*c
= CONNECTION(userdata
);
3082 uint32_t maxlength
, tlength
, prebuf
, minreq
, fragsize
;
3083 pa_tagstruct
*reply
;
3085 connection_assert_ref(c
);
3088 if (pa_tagstruct_getu32(t
, &idx
) < 0) {
3093 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3095 if (command
== PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR
) {
3097 pa_bool_t adjust_latency
= FALSE
;
3099 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3100 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3101 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3103 if (pa_tagstruct_get(
3105 PA_TAG_U32
, &maxlength
,
3106 PA_TAG_U32
, &tlength
,
3107 PA_TAG_U32
, &prebuf
,
3108 PA_TAG_U32
, &minreq
,
3109 PA_TAG_INVALID
) < 0 ||
3110 (c
->version
>= 13 && pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0) ||
3111 !pa_tagstruct_eof(t
)) {
3116 fix_playback_buffer_attr_pre(s
, adjust_latency
, &maxlength
, &tlength
, &prebuf
, &minreq
);
3117 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
3118 pa_memblockq_set_tlength(s
->memblockq
, tlength
);
3119 pa_memblockq_set_prebuf(s
->memblockq
, prebuf
);
3120 pa_memblockq_set_minreq(s
->memblockq
, minreq
);
3121 fix_playback_buffer_attr_post(s
, &maxlength
, &tlength
, &prebuf
, &minreq
);
3123 reply
= reply_new(tag
);
3124 pa_tagstruct_putu32(reply
, maxlength
);
3125 pa_tagstruct_putu32(reply
, tlength
);
3126 pa_tagstruct_putu32(reply
, prebuf
);
3127 pa_tagstruct_putu32(reply
, minreq
);
3129 if (c
->version
>= 13)
3130 pa_tagstruct_put_usec(reply
, s
->sink_latency
);
3134 pa_bool_t adjust_latency
= FALSE
;
3135 pa_assert(command
== PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR
);
3137 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3138 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3140 if (pa_tagstruct_get(
3142 PA_TAG_U32
, &maxlength
,
3143 PA_TAG_U32
, &fragsize
,
3144 PA_TAG_INVALID
) < 0 ||
3145 (c
->version
>= 13 && pa_tagstruct_get_boolean(t
, &adjust_latency
) < 0) ||
3146 !pa_tagstruct_eof(t
)) {
3151 fix_record_buffer_attr_pre(s
, adjust_latency
, &maxlength
, &fragsize
);
3152 pa_memblockq_set_maxlength(s
->memblockq
, maxlength
);
3153 fix_record_buffer_attr_post(s
, &maxlength
, &fragsize
);
3155 reply
= reply_new(tag
);
3156 pa_tagstruct_putu32(reply
, maxlength
);
3157 pa_tagstruct_putu32(reply
, fragsize
);
3159 if (c
->version
>= 13)
3160 pa_tagstruct_put_usec(reply
, s
->source_latency
);
3163 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3166 static void command_update_stream_sample_rate(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3167 connection
*c
= CONNECTION(userdata
);
3171 connection_assert_ref(c
);
3174 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3175 pa_tagstruct_getu32(t
, &rate
) < 0 ||
3176 !pa_tagstruct_eof(t
)) {
3181 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3182 CHECK_VALIDITY(c
->pstream
, rate
> 0 && rate
<= PA_RATE_MAX
, tag
, PA_ERR_INVALID
);
3184 if (command
== PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE
) {
3187 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3188 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3189 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3191 pa_sink_input_set_rate(s
->sink_input
, rate
);
3195 pa_assert(command
== PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE
);
3197 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3198 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3200 pa_source_output_set_rate(s
->source_output
, rate
);
3203 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3206 static void command_update_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3207 connection
*c
= CONNECTION(userdata
);
3212 connection_assert_ref(c
);
3215 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3217 p
= pa_proplist_new();
3219 if (command
== PA_COMMAND_UPDATE_CLIENT_PROPLIST
) {
3221 if (pa_tagstruct_getu32(t
, &mode
) < 0 ||
3222 pa_tagstruct_get_proplist(t
, p
) < 0 ||
3223 !pa_tagstruct_eof(t
)) {
3225 pa_proplist_free(p
);
3231 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3232 pa_tagstruct_getu32(t
, &mode
) < 0 ||
3233 pa_tagstruct_get_proplist(t
, p
) < 0 ||
3234 !pa_tagstruct_eof(t
)) {
3236 pa_proplist_free(p
);
3241 CHECK_VALIDITY(c
->pstream
, mode
== PA_UPDATE_SET
|| mode
== PA_UPDATE_MERGE
|| mode
== PA_UPDATE_REPLACE
, tag
, PA_ERR_INVALID
);
3243 if (command
== PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST
) {
3246 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3247 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3248 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3250 pa_proplist_update(s
->sink_input
->proplist
, mode
, p
);
3251 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->sink_input
->index
);
3253 } else if (command
== PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST
) {
3256 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3257 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3259 pa_proplist_update(s
->source_output
->proplist
, mode
, p
);
3260 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->source_output
->index
);
3262 pa_assert(command
== PA_COMMAND_UPDATE_CLIENT_PROPLIST
);
3264 pa_proplist_update(c
->client
->proplist
, mode
, p
);
3265 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
3268 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3271 static void command_remove_proplist(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3272 connection
*c
= CONNECTION(userdata
);
3274 unsigned changed
= 0;
3276 pa_strlist
*l
= NULL
;
3278 connection_assert_ref(c
);
3281 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3283 if (command
!= PA_COMMAND_REMOVE_CLIENT_PROPLIST
) {
3285 if (pa_tagstruct_getu32(t
, &idx
) < 0) {
3291 if (command
== PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
) {
3294 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3295 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3296 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3298 p
= s
->sink_input
->proplist
;
3300 } else if (command
== PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
) {
3303 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3304 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3306 p
= s
->source_output
->proplist
;
3308 pa_assert(command
== PA_COMMAND_REMOVE_CLIENT_PROPLIST
);
3310 p
= c
->client
->proplist
;
3316 if (pa_tagstruct_gets(t
, &k
) < 0) {
3325 l
= pa_strlist_prepend(l
, k
);
3328 if (!pa_tagstruct_eof(t
)) {
3337 l
= pa_strlist_pop(l
, &z
);
3342 changed
+= pa_proplist_unset(p
, z
) >= 0;
3346 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3349 if (command
== PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST
) {
3352 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3353 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->sink_input
->index
);
3355 } else if (command
== PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST
) {
3358 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3359 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->source_output
->index
);
3362 pa_assert(command
== PA_COMMAND_REMOVE_CLIENT_PROPLIST
);
3363 pa_subscription_post(c
->protocol
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->client
->index
);
3368 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
) {
3369 connection
*c
= CONNECTION(userdata
);
3372 connection_assert_ref(c
);
3375 if (pa_tagstruct_gets(t
, &s
) < 0 ||
3376 !pa_tagstruct_eof(t
)) {
3381 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3382 CHECK_VALIDITY(c
->pstream
, !s
|| (*s
&& pa_utf8_valid(s
)), tag
, PA_ERR_INVALID
);
3384 pa_namereg_set_default(c
->protocol
->core
, s
, command
== PA_COMMAND_SET_DEFAULT_SOURCE
? PA_NAMEREG_SOURCE
: PA_NAMEREG_SINK
);
3385 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3388 static void command_set_stream_name(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3389 connection
*c
= CONNECTION(userdata
);
3393 connection_assert_ref(c
);
3396 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3397 pa_tagstruct_gets(t
, &name
) < 0 ||
3398 !pa_tagstruct_eof(t
)) {
3403 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3404 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3406 if (command
== PA_COMMAND_SET_PLAYBACK_STREAM_NAME
) {
3409 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
3410 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3411 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
3413 pa_sink_input_set_name(s
->sink_input
, name
);
3417 pa_assert(command
== PA_COMMAND_SET_RECORD_STREAM_NAME
);
3419 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
3420 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3422 pa_source_output_set_name(s
->source_output
, name
);
3425 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3428 static void command_kill(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3429 connection
*c
= CONNECTION(userdata
);
3432 connection_assert_ref(c
);
3435 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3436 !pa_tagstruct_eof(t
)) {
3441 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3443 if (command
== PA_COMMAND_KILL_CLIENT
) {
3446 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
3447 CHECK_VALIDITY(c
->pstream
, client
, tag
, PA_ERR_NOENTITY
);
3450 pa_client_kill(client
);
3452 } else if (command
== PA_COMMAND_KILL_SINK_INPUT
) {
3455 s
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
3456 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3459 pa_sink_input_kill(s
);
3461 pa_source_output
*s
;
3463 pa_assert(command
== PA_COMMAND_KILL_SOURCE_OUTPUT
);
3465 s
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
3466 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
3469 pa_source_output_kill(s
);
3472 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3473 connection_unref(c
);
3476 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
) {
3477 connection
*c
= CONNECTION(userdata
);
3479 const char *name
, *argument
;
3480 pa_tagstruct
*reply
;
3482 connection_assert_ref(c
);
3485 if (pa_tagstruct_gets(t
, &name
) < 0 ||
3486 pa_tagstruct_gets(t
, &argument
) < 0 ||
3487 !pa_tagstruct_eof(t
)) {
3492 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3493 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
) && !strchr(name
, '/'), tag
, PA_ERR_INVALID
);
3494 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
3496 if (!(m
= pa_module_load(c
->protocol
->core
, name
, argument
))) {
3497 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_MODINITFAILED
);
3501 reply
= reply_new(tag
);
3502 pa_tagstruct_putu32(reply
, m
->index
);
3503 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3506 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
) {
3507 connection
*c
= CONNECTION(userdata
);
3511 connection_assert_ref(c
);
3514 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3515 !pa_tagstruct_eof(t
)) {
3520 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3521 m
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
3522 CHECK_VALIDITY(c
->pstream
, m
, tag
, PA_ERR_NOENTITY
);
3524 pa_module_unload_request(m
);
3525 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3528 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
) {
3529 connection
*c
= CONNECTION(userdata
);
3530 const char *name
, *module
, *argument
;
3533 pa_tagstruct
*reply
;
3535 connection_assert_ref(c
);
3538 if (pa_tagstruct_gets(t
, &name
) < 0 ||
3539 pa_tagstruct_getu32(t
, &type
) < 0 ||
3540 pa_tagstruct_gets(t
, &module
) < 0 ||
3541 pa_tagstruct_gets(t
, &argument
) < 0 ||
3542 !pa_tagstruct_eof(t
)) {
3547 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3548 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3549 CHECK_VALIDITY(c
->pstream
, type
== 0 || type
== 1, tag
, PA_ERR_INVALID
);
3550 CHECK_VALIDITY(c
->pstream
, module
&& *module
&& pa_utf8_valid(module
), tag
, PA_ERR_INVALID
);
3551 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
3553 if (pa_autoload_add(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
, module
, argument
, &idx
) < 0) {
3554 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
3558 reply
= reply_new(tag
);
3559 pa_tagstruct_putu32(reply
, idx
);
3560 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3563 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
) {
3564 connection
*c
= CONNECTION(userdata
);
3565 const char *name
= NULL
;
3566 uint32_t type
, idx
= PA_IDXSET_INVALID
;
3569 connection_assert_ref(c
);
3572 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
3573 (pa_tagstruct_gets(t
, &name
) < 0 ||
3574 pa_tagstruct_getu32(t
, &type
) < 0)) ||
3575 !pa_tagstruct_eof(t
)) {
3580 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3581 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
3582 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& pa_utf8_valid(name
) && (type
== 0 || type
== 1)), tag
, PA_ERR_INVALID
);
3585 r
= pa_autoload_remove_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
3587 r
= pa_autoload_remove_by_index(c
->protocol
->core
, idx
);
3589 CHECK_VALIDITY(c
->pstream
, r
>= 0, tag
, PA_ERR_NOENTITY
);
3591 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3594 static void autoload_fill_tagstruct(pa_tagstruct
*t
, const pa_autoload_entry
*e
) {
3597 pa_tagstruct_putu32(t
, e
->index
);
3598 pa_tagstruct_puts(t
, e
->name
);
3599 pa_tagstruct_putu32(t
, e
->type
== PA_NAMEREG_SINK
? 0 : 1);
3600 pa_tagstruct_puts(t
, e
->module
);
3601 pa_tagstruct_puts(t
, e
->argument
);
3604 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
) {
3605 connection
*c
= CONNECTION(userdata
);
3606 const pa_autoload_entry
*a
= NULL
;
3609 pa_tagstruct
*reply
;
3611 connection_assert_ref(c
);
3614 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
3615 (pa_tagstruct_gets(t
, &name
) < 0 ||
3616 pa_tagstruct_getu32(t
, &type
) < 0)) ||
3617 !pa_tagstruct_eof(t
)) {
3622 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3623 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
3624 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& (type
== 0 || type
== 1) && pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
3627 a
= pa_autoload_get_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
3629 a
= pa_autoload_get_by_index(c
->protocol
->core
, idx
);
3631 CHECK_VALIDITY(c
->pstream
, a
, tag
, PA_ERR_NOENTITY
);
3633 reply
= reply_new(tag
);
3634 autoload_fill_tagstruct(reply
, a
);
3635 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3638 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
) {
3639 connection
*c
= CONNECTION(userdata
);
3640 pa_tagstruct
*reply
;
3642 connection_assert_ref(c
);
3645 if (!pa_tagstruct_eof(t
)) {
3650 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3652 reply
= reply_new(tag
);
3654 if (c
->protocol
->core
->autoload_hashmap
) {
3655 pa_autoload_entry
*a
;
3658 while ((a
= pa_hashmap_iterate(c
->protocol
->core
->autoload_hashmap
, &state
, NULL
)))
3659 autoload_fill_tagstruct(reply
, a
);
3662 pa_pstream_send_tagstruct(c
->pstream
, reply
);
3665 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3666 connection
*c
= CONNECTION(userdata
);
3667 uint32_t idx
= PA_INVALID_INDEX
, idx_device
= PA_INVALID_INDEX
;
3668 const char *name
= NULL
;
3670 connection_assert_ref(c
);
3673 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3674 pa_tagstruct_getu32(t
, &idx_device
) < 0 ||
3675 pa_tagstruct_gets(t
, &name
) < 0 ||
3676 !pa_tagstruct_eof(t
)) {
3681 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3682 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
3683 CHECK_VALIDITY(c
->pstream
, idx_device
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
3685 if (command
== PA_COMMAND_MOVE_SINK_INPUT
) {
3686 pa_sink_input
*si
= NULL
;
3687 pa_sink
*sink
= NULL
;
3689 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
3691 if (idx_device
!= PA_INVALID_INDEX
)
3692 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx_device
);
3694 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
3696 CHECK_VALIDITY(c
->pstream
, si
&& sink
, tag
, PA_ERR_NOENTITY
);
3698 if (pa_sink_input_move_to(si
, sink
) < 0) {
3699 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3703 pa_source_output
*so
= NULL
;
3706 pa_assert(command
== PA_COMMAND_MOVE_SOURCE_OUTPUT
);
3708 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
3710 if (idx_device
!= PA_INVALID_INDEX
)
3711 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx_device
);
3713 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
3715 CHECK_VALIDITY(c
->pstream
, so
&& source
, tag
, PA_ERR_NOENTITY
);
3717 if (pa_source_output_move_to(so
, source
) < 0) {
3718 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3723 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3726 static void command_suspend(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
3727 connection
*c
= CONNECTION(userdata
);
3728 uint32_t idx
= PA_INVALID_INDEX
;
3729 const char *name
= NULL
;
3732 connection_assert_ref(c
);
3735 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
3736 pa_tagstruct_gets(t
, &name
) < 0 ||
3737 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
3738 !pa_tagstruct_eof(t
)) {
3743 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
3744 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| !*name
|| pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
3746 if (command
== PA_COMMAND_SUSPEND_SINK
) {
3748 if (idx
== PA_INVALID_INDEX
&& name
&& !*name
) {
3750 if (pa_sink_suspend_all(c
->protocol
->core
, b
) < 0) {
3751 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3755 pa_sink
*sink
= NULL
;
3757 if (idx
!= PA_INVALID_INDEX
)
3758 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
3760 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
3762 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
3764 if (pa_sink_suspend(sink
, b
) < 0) {
3765 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3771 pa_assert(command
== PA_COMMAND_SUSPEND_SOURCE
);
3773 if (idx
== PA_INVALID_INDEX
&& name
&& !*name
) {
3775 if (pa_source_suspend_all(c
->protocol
->core
, b
) < 0) {
3776 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3783 if (idx
!= PA_INVALID_INDEX
)
3784 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
3786 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
3788 CHECK_VALIDITY(c
->pstream
, source
, tag
, PA_ERR_NOENTITY
);
3790 if (pa_source_suspend(source
, b
) < 0) {
3791 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
3797 pa_pstream_send_simple_ack(c
->pstream
, tag
);
3800 /*** pstream callbacks ***/
3802 static void pstream_packet_callback(pa_pstream
*p
, pa_packet
*packet
, const pa_creds
*creds
, void *userdata
) {
3803 connection
*c
= CONNECTION(userdata
);
3807 connection_assert_ref(c
);
3809 if (pa_pdispatch_run(c
->pdispatch
, packet
, creds
, c
) < 0) {
3810 pa_log("invalid packet.");
3811 connection_unlink(c
);
3815 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
) {
3816 connection
*c
= CONNECTION(userdata
);
3817 output_stream
*stream
;
3821 connection_assert_ref(c
);
3823 if (!(stream
= OUTPUT_STREAM(pa_idxset_get_by_index(c
->output_streams
, channel
)))) {
3824 pa_log("client sent block for invalid stream.");
3829 if (playback_stream_isinstance(stream
)) {
3830 playback_stream
*ps
= PLAYBACK_STREAM(stream
);
3832 if (seek
!= PA_SEEK_RELATIVE
|| offset
!= 0)
3833 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
);
3835 pa_asyncmsgq_post(ps
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(ps
->sink_input
), SINK_INPUT_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
3838 upload_stream
*u
= UPLOAD_STREAM(stream
);
3841 if (!u
->memchunk
.memblock
) {
3842 if (u
->length
== chunk
->length
) {
3843 u
->memchunk
= *chunk
;
3844 pa_memblock_ref(u
->memchunk
.memblock
);
3847 u
->memchunk
.memblock
= pa_memblock_new(c
->protocol
->core
->mempool
, u
->length
);
3848 u
->memchunk
.index
= u
->memchunk
.length
= 0;
3852 pa_assert(u
->memchunk
.memblock
);
3855 if (l
> chunk
->length
)
3861 dst
= pa_memblock_acquire(u
->memchunk
.memblock
);
3862 src
= pa_memblock_acquire(chunk
->memblock
);
3864 memcpy((uint8_t*) dst
+ u
->memchunk
.index
+ u
->memchunk
.length
,
3865 (uint8_t*) src
+chunk
->index
, l
);
3867 pa_memblock_release(u
->memchunk
.memblock
);
3868 pa_memblock_release(chunk
->memblock
);
3870 u
->memchunk
.length
+= l
;
3876 static void pstream_die_callback(pa_pstream
*p
, void *userdata
) {
3877 connection
*c
= CONNECTION(userdata
);
3880 connection_assert_ref(c
);
3882 connection_unlink(c
);
3883 pa_log_info("connection died.");
3886 static void pstream_drain_callback(pa_pstream
*p
, void *userdata
) {
3887 connection
*c
= CONNECTION(userdata
);
3890 connection_assert_ref(c
);
3895 static void pstream_revoke_callback(pa_pstream
*p
, uint32_t block_id
, void *userdata
) {
3898 if (!(q
= pa_thread_mq_get()))
3899 pa_pstream_send_revoke(p
, block_id
);
3901 pa_asyncmsgq_post(q
->outq
, PA_MSGOBJECT(userdata
), CONNECTION_MESSAGE_REVOKE
, PA_UINT_TO_PTR(block_id
), 0, NULL
, NULL
);
3904 static void pstream_release_callback(pa_pstream
*p
, uint32_t block_id
, void *userdata
) {
3907 if (!(q
= pa_thread_mq_get()))
3908 pa_pstream_send_release(p
, block_id
);
3910 pa_asyncmsgq_post(q
->outq
, PA_MSGOBJECT(userdata
), CONNECTION_MESSAGE_RELEASE
, PA_UINT_TO_PTR(block_id
), 0, NULL
, NULL
);
3913 /*** client callbacks ***/
3915 static void client_kill_cb(pa_client
*c
) {
3918 connection_unlink(CONNECTION(c
->userdata
));
3921 /*** socket server callbacks ***/
3923 static void auth_timeout(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
3924 connection
*c
= CONNECTION(userdata
);
3928 connection_assert_ref(c
);
3929 pa_assert(c
->auth_timeout_event
== e
);
3932 connection_unlink(c
);
3935 static void on_connection(PA_GCC_UNUSED pa_socket_server
*s
, pa_iochannel
*io
, void *userdata
) {
3936 pa_protocol_native
*p
= userdata
;
3938 char cname
[256], pname
[128];
3943 if (pa_idxset_size(p
->connections
)+1 > MAX_CONNECTIONS
) {
3944 pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS
);
3945 pa_iochannel_free(io
);
3949 c
= pa_msgobject_new(connection
);
3950 c
->parent
.parent
.free
= connection_free
;
3951 c
->parent
.process_msg
= connection_process_msg
;
3953 c
->authorized
= p
->public;
3955 if (!c
->authorized
&& p
->auth_ip_acl
&& pa_ip_acl_check(p
->auth_ip_acl
, pa_iochannel_get_recv_fd(io
)) > 0) {
3956 pa_log_info("Client authenticated by IP ACL.");
3957 c
->authorized
= TRUE
;
3960 if (!c
->authorized
) {
3962 pa_gettimeofday(&tv
);
3963 tv
.tv_sec
+= AUTH_TIMEOUT
;
3964 c
->auth_timeout_event
= p
->core
->mainloop
->time_new(p
->core
->mainloop
, &tv
, auth_timeout
, c
);
3966 c
->auth_timeout_event
= NULL
;
3968 c
->is_local
= pa_iochannel_socket_is_local(io
);
3971 pa_iochannel_socket_peer_to_string(io
, pname
, sizeof(pname
));
3972 pa_snprintf(cname
, sizeof(cname
), "Native client (%s)", pname
);
3973 c
->client
= pa_client_new(p
->core
, __FILE__
, cname
);
3974 pa_proplist_sets(c
->client
->proplist
, "native-protocol.peer", pname
);
3975 c
->client
->kill
= client_kill_cb
;
3976 c
->client
->userdata
= c
;
3977 c
->client
->module
= p
->module
;
3979 c
->pstream
= pa_pstream_new(p
->core
->mainloop
, io
, p
->core
->mempool
);
3981 pa_pstream_set_recieve_packet_callback(c
->pstream
, pstream_packet_callback
, c
);
3982 pa_pstream_set_recieve_memblock_callback(c
->pstream
, pstream_memblock_callback
, c
);
3983 pa_pstream_set_die_callback(c
->pstream
, pstream_die_callback
, c
);
3984 pa_pstream_set_drain_callback(c
->pstream
, pstream_drain_callback
, c
);
3985 pa_pstream_set_revoke_callback(c
->pstream
, pstream_revoke_callback
, c
);
3986 pa_pstream_set_release_callback(c
->pstream
, pstream_release_callback
, c
);
3988 c
->pdispatch
= pa_pdispatch_new(p
->core
->mainloop
, command_table
, PA_COMMAND_MAX
);
3990 c
->record_streams
= pa_idxset_new(NULL
, NULL
);
3991 c
->output_streams
= pa_idxset_new(NULL
, NULL
);
3993 c
->rrobin_index
= PA_IDXSET_INVALID
;
3994 c
->subscription
= NULL
;
3996 pa_idxset_put(p
->connections
, c
, NULL
);
3999 if (pa_iochannel_creds_supported(io
))
4000 pa_iochannel_creds_enable(io
);
4004 /*** module entry points ***/
4006 static int load_key(pa_protocol_native
*p
, const char*fn
) {
4009 p
->auth_cookie_in_property
= FALSE
;
4011 if (!fn
&& pa_authkey_prop_get(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0) {
4012 pa_log_info("using already loaded auth cookie.");
4013 pa_authkey_prop_ref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
4014 p
->auth_cookie_in_property
= TRUE
;
4019 fn
= PA_NATIVE_COOKIE_FILE
;
4021 if (pa_authkey_load_auto(fn
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) < 0)
4024 pa_log_info("loading cookie from disk.");
4026 if (pa_authkey_prop_put(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0)
4027 p
->auth_cookie_in_property
= TRUE
;
4032 static pa_protocol_native
* protocol_new_internal(pa_core
*c
, pa_module
*m
, pa_modargs
*ma
) {
4033 pa_protocol_native
*p
;
4034 pa_bool_t
public = FALSE
;
4040 if (pa_modargs_get_value_boolean(ma
, "auth-anonymous", &public) < 0) {
4041 pa_log("auth-anonymous= expects a boolean argument.");
4045 p
= pa_xnew(pa_protocol_native
, 1);
4050 p
->auth_ip_acl
= NULL
;
4055 if (pa_modargs_get_value_boolean(ma
, "auth-group-enabled", &a
) < 0) {
4056 pa_log("auth-group-enabled= expects a boolean argument.");
4059 p
->auth_group
= a
? pa_xstrdup(pa_modargs_get_value(ma
, "auth-group", pa_in_system_mode() ? PA_ACCESS_GROUP
: NULL
)) : NULL
;
4062 pa_log_info("Allowing access to group '%s'.", p
->auth_group
);
4067 if ((acl
= pa_modargs_get_value(ma
, "auth-ip-acl", NULL
))) {
4069 if (!(p
->auth_ip_acl
= pa_ip_acl_new(acl
))) {
4070 pa_log("Failed to parse IP ACL '%s'", acl
);
4075 if (load_key(p
, pa_modargs_get_value(ma
, "cookie", NULL
)) < 0)
4078 p
->connections
= pa_idxset_new(NULL
, NULL
);
4084 pa_xfree(p
->auth_group
);
4087 pa_ip_acl_free(p
->auth_ip_acl
);
4092 pa_protocol_native
* pa_protocol_native_new(pa_core
*core
, pa_socket_server
*server
, pa_module
*m
, pa_modargs
*ma
) {
4094 pa_protocol_native
*p
;
4096 if (!(p
= protocol_new_internal(core
, m
, ma
)))
4099 p
->server
= pa_socket_server_ref(server
);
4100 pa_socket_server_set_callback(p
->server
, on_connection
, p
);
4102 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
4104 l
= pa_property_get(core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4105 l
= pa_strlist_prepend(l
, t
);
4106 pa_property_replace(core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
4112 void pa_protocol_native_free(pa_protocol_native
*p
) {
4116 while ((c
= pa_idxset_first(p
->connections
, NULL
)))
4117 connection_unlink(c
);
4118 pa_idxset_free(p
->connections
, NULL
, NULL
);
4123 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
4125 l
= pa_property_get(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4126 l
= pa_strlist_remove(l
, t
);
4129 pa_property_replace(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
4131 pa_property_remove(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
4134 pa_socket_server_unref(p
->server
);
4137 if (p
->auth_cookie_in_property
)
4138 pa_authkey_prop_unref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
4141 pa_ip_acl_free(p
->auth_ip_acl
);
4144 pa_xfree(p
->auth_group
);
4149 pa_protocol_native
* pa_protocol_native_new_iochannel(
4155 pa_protocol_native
*p
;
4157 if (!(p
= protocol_new_internal(core
, m
, ma
)))
4160 on_connection(NULL
, io
, p
);