4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 #include <pulse/timeval.h>
35 #include <pulse/version.h>
36 #include <pulse/utf8.h>
37 #include <pulse/util.h>
38 #include <pulse/xmalloc.h>
40 #include <pulsecore/native-common.h>
41 #include <pulsecore/packet.h>
42 #include <pulsecore/client.h>
43 #include <pulsecore/source-output.h>
44 #include <pulsecore/sink-input.h>
45 #include <pulsecore/pstream.h>
46 #include <pulsecore/tagstruct.h>
47 #include <pulsecore/pdispatch.h>
48 #include <pulsecore/pstream-util.h>
49 #include <pulsecore/authkey.h>
50 #include <pulsecore/namereg.h>
51 #include <pulsecore/core-scache.h>
52 #include <pulsecore/core-subscribe.h>
53 #include <pulsecore/log.h>
54 #include <pulsecore/autoload.h>
55 #include <pulsecore/authkey-prop.h>
56 #include <pulsecore/strlist.h>
57 #include <pulsecore/props.h>
58 #include <pulsecore/sample-util.h>
59 #include <pulsecore/llist.h>
60 #include <pulsecore/creds.h>
61 #include <pulsecore/core-util.h>
62 #include <pulsecore/ipacl.h>
64 #include "protocol-native.h"
66 /* Kick a client if it doesn't authenticate within this time */
67 #define AUTH_TIMEOUT 60
69 /* Don't accept more connection than this */
70 #define MAX_CONNECTIONS 64
72 #define MAX_MEMBLOCKQ_LENGTH (4*1024*1024) /* 4MB */
74 typedef struct connection connection
;
75 struct pa_protocol_native
;
77 typedef struct record_stream
{
80 connection
*connection
;
83 pa_source_output
*source_output
;
84 pa_memblockq
*memblockq
;
88 typedef struct output_stream
{
92 typedef struct playback_stream
{
95 connection
*connection
;
98 pa_sink_input
*sink_input
;
99 pa_memblockq
*memblockq
;
108 /* Only updated after SINK_INPUT_MESSAGE_UPDATE_LATENCY */
109 int64_t read_index
, write_index
;
110 size_t resampled_chunk_length
;
113 typedef struct upload_stream
{
114 output_stream parent
;
116 connection
*connection
;
119 pa_memchunk memchunk
;
122 pa_sample_spec sample_spec
;
123 pa_channel_map channel_map
;
131 pa_protocol_native
*protocol
;
134 pa_pdispatch
*pdispatch
;
135 pa_idxset
*record_streams
, *output_streams
;
136 uint32_t rrobin_index
;
137 pa_subscription
*subscription
;
138 pa_time_event
*auth_timeout_event
;
142 PA_DECLARE_CLASS(record_stream
);
143 #define RECORD_STREAM(o) (record_stream_cast(o))
144 static PA_DEFINE_CHECK_TYPE(record_stream
, pa_msgobject
);
146 PA_DECLARE_CLASS(output_stream
);
147 #define OUTPUT_STREAM(o) (output_stream_cast(o))
148 static PA_DEFINE_CHECK_TYPE(output_stream
, pa_msgobject
);
150 PA_DECLARE_CLASS(playback_stream
);
151 #define PLAYBACK_STREAM(o) (playback_stream_cast(o))
152 static PA_DEFINE_CHECK_TYPE(playback_stream
, output_stream
);
154 PA_DECLARE_CLASS(upload_stream
);
155 #define UPLOAD_STREAM(o) (upload_stream_cast(o))
156 static PA_DEFINE_CHECK_TYPE(upload_stream
, output_stream
);
158 PA_DECLARE_CLASS(connection
);
159 #define CONNECTION(o) (connection_cast(o))
160 static PA_DEFINE_CHECK_TYPE(connection
, pa_msgobject
);
162 struct pa_protocol_native
{
166 pa_socket_server
*server
;
167 pa_idxset
*connections
;
168 uint8_t auth_cookie
[PA_NATIVE_COOKIE_LENGTH
];
169 int auth_cookie_in_property
;
173 pa_ip_acl
*auth_ip_acl
;
177 SINK_INPUT_MESSAGE_POST_DATA
= PA_SINK_INPUT_MESSAGE_MAX
, /* data from main loop to sink input */
178 SINK_INPUT_MESSAGE_DRAIN
, /* disabled prebuf, get playback started. */
179 SINK_INPUT_MESSAGE_FLUSH
,
180 SINK_INPUT_MESSAGE_TRIGGER
,
181 SINK_INPUT_MESSAGE_SEEK
,
182 SINK_INPUT_MESSAGE_PREBUF_FORCE
,
183 SINK_INPUT_MESSAGE_UPDATE_LATENCY
187 PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, /* data requested from sink input from the main loop */
188 PLAYBACK_STREAM_MESSAGE_UNDERFLOW
,
189 PLAYBACK_STREAM_MESSAGE_OVERFLOW
,
190 PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
194 RECORD_STREAM_MESSAGE_POST_DATA
/* data from source output to main loop */
197 static int sink_input_peek_cb(pa_sink_input
*i
, pa_memchunk
*chunk
);
198 static void sink_input_drop_cb(pa_sink_input
*i
, size_t length
);
199 static void sink_input_kill_cb(pa_sink_input
*i
);
201 static void send_memblock(connection
*c
);
202 static void request_bytes(struct playback_stream
*s
);
204 static void source_output_kill_cb(pa_source_output
*o
);
205 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
);
206 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
);
208 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
);
210 static void command_exit(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
211 static void command_create_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
212 static void command_drain_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
213 static void command_create_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
214 static void command_delete_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
215 static void command_auth(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
216 static void command_set_client_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
217 static void command_lookup(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
218 static void command_stat(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
219 static void command_get_playback_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
220 static void command_get_record_latency(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
221 static void command_create_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
222 static void command_finish_upload_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
223 static void command_play_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
224 static void command_remove_sample(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
225 static void command_get_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
226 static void command_get_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
227 static void command_get_server_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
228 static void command_subscribe(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
229 static void command_set_volume(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
230 static void command_set_mute(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
231 static void command_cork_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
232 static void command_trigger_or_flush_or_prebuf_playback_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
233 static void command_set_default_sink_or_source(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
234 static void command_set_stream_name(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
235 static void command_kill(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
236 static void command_load_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
237 static void command_unload_module(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
238 static void command_add_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
239 static void command_remove_autoload(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
240 static void command_get_autoload_info(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
241 static void command_get_autoload_info_list(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
242 static void command_cork_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
243 static void command_flush_record_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
244 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
246 static const pa_pdispatch_cb_t command_table
[PA_COMMAND_MAX
] = {
247 [PA_COMMAND_ERROR
] = NULL
,
248 [PA_COMMAND_TIMEOUT
] = NULL
,
249 [PA_COMMAND_REPLY
] = NULL
,
250 [PA_COMMAND_CREATE_PLAYBACK_STREAM
] = command_create_playback_stream
,
251 [PA_COMMAND_DELETE_PLAYBACK_STREAM
] = command_delete_stream
,
252 [PA_COMMAND_DRAIN_PLAYBACK_STREAM
] = command_drain_playback_stream
,
253 [PA_COMMAND_CREATE_RECORD_STREAM
] = command_create_record_stream
,
254 [PA_COMMAND_DELETE_RECORD_STREAM
] = command_delete_stream
,
255 [PA_COMMAND_AUTH
] = command_auth
,
256 [PA_COMMAND_REQUEST
] = NULL
,
257 [PA_COMMAND_EXIT
] = command_exit
,
258 [PA_COMMAND_SET_CLIENT_NAME
] = command_set_client_name
,
259 [PA_COMMAND_LOOKUP_SINK
] = command_lookup
,
260 [PA_COMMAND_LOOKUP_SOURCE
] = command_lookup
,
261 [PA_COMMAND_STAT
] = command_stat
,
262 [PA_COMMAND_GET_PLAYBACK_LATENCY
] = command_get_playback_latency
,
263 [PA_COMMAND_GET_RECORD_LATENCY
] = command_get_record_latency
,
264 [PA_COMMAND_CREATE_UPLOAD_STREAM
] = command_create_upload_stream
,
265 [PA_COMMAND_DELETE_UPLOAD_STREAM
] = command_delete_stream
,
266 [PA_COMMAND_FINISH_UPLOAD_STREAM
] = command_finish_upload_stream
,
267 [PA_COMMAND_PLAY_SAMPLE
] = command_play_sample
,
268 [PA_COMMAND_REMOVE_SAMPLE
] = command_remove_sample
,
269 [PA_COMMAND_GET_SINK_INFO
] = command_get_info
,
270 [PA_COMMAND_GET_SOURCE_INFO
] = command_get_info
,
271 [PA_COMMAND_GET_CLIENT_INFO
] = command_get_info
,
272 [PA_COMMAND_GET_MODULE_INFO
] = command_get_info
,
273 [PA_COMMAND_GET_SINK_INPUT_INFO
] = command_get_info
,
274 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO
] = command_get_info
,
275 [PA_COMMAND_GET_SAMPLE_INFO
] = command_get_info
,
276 [PA_COMMAND_GET_SINK_INFO_LIST
] = command_get_info_list
,
277 [PA_COMMAND_GET_SOURCE_INFO_LIST
] = command_get_info_list
,
278 [PA_COMMAND_GET_MODULE_INFO_LIST
] = command_get_info_list
,
279 [PA_COMMAND_GET_CLIENT_INFO_LIST
] = command_get_info_list
,
280 [PA_COMMAND_GET_SINK_INPUT_INFO_LIST
] = command_get_info_list
,
281 [PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
] = command_get_info_list
,
282 [PA_COMMAND_GET_SAMPLE_INFO_LIST
] = command_get_info_list
,
283 [PA_COMMAND_GET_SERVER_INFO
] = command_get_server_info
,
284 [PA_COMMAND_SUBSCRIBE
] = command_subscribe
,
286 [PA_COMMAND_SET_SINK_VOLUME
] = command_set_volume
,
287 [PA_COMMAND_SET_SINK_INPUT_VOLUME
] = command_set_volume
,
288 [PA_COMMAND_SET_SOURCE_VOLUME
] = command_set_volume
,
290 [PA_COMMAND_SET_SINK_MUTE
] = command_set_mute
,
291 [PA_COMMAND_SET_SINK_INPUT_MUTE
] = command_set_mute
,
292 [PA_COMMAND_SET_SOURCE_MUTE
] = command_set_mute
,
294 [PA_COMMAND_CORK_PLAYBACK_STREAM
] = command_cork_playback_stream
,
295 [PA_COMMAND_FLUSH_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
296 [PA_COMMAND_TRIGGER_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
297 [PA_COMMAND_PREBUF_PLAYBACK_STREAM
] = command_trigger_or_flush_or_prebuf_playback_stream
,
299 [PA_COMMAND_CORK_RECORD_STREAM
] = command_cork_record_stream
,
300 [PA_COMMAND_FLUSH_RECORD_STREAM
] = command_flush_record_stream
,
302 [PA_COMMAND_SET_DEFAULT_SINK
] = command_set_default_sink_or_source
,
303 [PA_COMMAND_SET_DEFAULT_SOURCE
] = command_set_default_sink_or_source
,
304 [PA_COMMAND_SET_PLAYBACK_STREAM_NAME
] = command_set_stream_name
,
305 [PA_COMMAND_SET_RECORD_STREAM_NAME
] = command_set_stream_name
,
306 [PA_COMMAND_KILL_CLIENT
] = command_kill
,
307 [PA_COMMAND_KILL_SINK_INPUT
] = command_kill
,
308 [PA_COMMAND_KILL_SOURCE_OUTPUT
] = command_kill
,
309 [PA_COMMAND_LOAD_MODULE
] = command_load_module
,
310 [PA_COMMAND_UNLOAD_MODULE
] = command_unload_module
,
311 [PA_COMMAND_GET_AUTOLOAD_INFO
] = command_get_autoload_info
,
312 [PA_COMMAND_GET_AUTOLOAD_INFO_LIST
] = command_get_autoload_info_list
,
313 [PA_COMMAND_ADD_AUTOLOAD
] = command_add_autoload
,
314 [PA_COMMAND_REMOVE_AUTOLOAD
] = command_remove_autoload
,
316 [PA_COMMAND_MOVE_SINK_INPUT
] = command_move_stream
,
317 [PA_COMMAND_MOVE_SOURCE_OUTPUT
] = command_move_stream
320 /* structure management */
322 static void upload_stream_unlink(upload_stream
*s
) {
328 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
329 s
->connection
= NULL
;
330 upload_stream_unref(s
);
333 static void upload_stream_free(pa_object
*o
) {
334 upload_stream
*s
= UPLOAD_STREAM(o
);
337 upload_stream_unlink(s
);
341 if (s
->memchunk
.memblock
)
342 pa_memblock_unref(s
->memchunk
.memblock
);
347 static upload_stream
* upload_stream_new(
349 const pa_sample_spec
*ss
,
350 const pa_channel_map
*map
,
351 const char *name
, size_t length
) {
358 pa_assert(length
> 0);
360 s
= pa_msgobject_new(upload_stream
);
361 s
->parent
.parent
.parent
.free
= upload_stream_free
;
363 s
->sample_spec
= *ss
;
364 s
->channel_map
= *map
;
365 s
->name
= pa_xstrdup(name
);
366 pa_memchunk_reset(&s
->memchunk
);
369 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
374 static void record_stream_unlink(record_stream
*s
) {
380 if (s
->source_output
) {
381 pa_source_output_disconnect(s
->source_output
);
382 pa_source_output_unref(s
->source_output
);
383 s
->source_output
= NULL
;
386 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->record_streams
, s
, NULL
) == s
);
387 s
->connection
= NULL
;
388 record_stream_unref(s
);
391 static void record_stream_free(pa_object
*o
) {
392 record_stream
*s
= RECORD_STREAM(o
);
395 record_stream_unlink(s
);
397 pa_memblockq_free(s
->memblockq
);
401 static int record_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
402 record_stream
*s
= RECORD_STREAM(o
);
403 record_stream_assert_ref(s
);
407 case RECORD_STREAM_MESSAGE_POST_DATA
:
409 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
410 /* pa_log_warn("Failed to push data into output queue."); */
414 if (!pa_pstream_is_pending(s
->connection
->pstream
))
415 send_memblock(s
->connection
);
417 pa_pstream_send_memblock(s
->connection
->pstream
, s
->index
, 0, PA_SEEK_RELATIVE
, chunk
);
424 static record_stream
* record_stream_new(
427 const pa_sample_spec
*ss
,
428 const pa_channel_map
*map
,
431 size_t fragment_size
,
435 pa_source_output
*source_output
;
437 pa_source_output_new_data data
;
442 pa_assert(maxlength
);
443 pa_assert(*maxlength
> 0);
445 pa_source_output_new_data_init(&data
);
446 data
.module
= c
->protocol
->module
;
447 data
.client
= c
->client
;
448 data
.source
= source
;
449 data
.driver
= __FILE__
;
451 data
.start_corked
= corked
;
452 pa_source_output_new_data_set_sample_spec(&data
, ss
);
453 pa_source_output_new_data_set_channel_map(&data
, map
);
455 if (!(source_output
= pa_source_output_new(c
->protocol
->core
, &data
, 0)))
458 s
= pa_msgobject_new(record_stream
);
459 s
->parent
.parent
.free
= record_stream_free
;
460 s
->parent
.process_msg
= record_stream_process_msg
;
462 s
->source_output
= source_output
;
463 s
->source_output
->push
= source_output_push_cb
;
464 s
->source_output
->kill
= source_output_kill_cb
;
465 s
->source_output
->get_latency
= source_output_get_latency_cb
;
466 s
->source_output
->userdata
= s
;
468 s
->memblockq
= pa_memblockq_new(
472 base
= pa_frame_size(ss
),
477 s
->fragment_size
= (fragment_size
/base
)*base
;
478 if (s
->fragment_size
<= 0)
479 s
->fragment_size
= base
;
480 *maxlength
= pa_memblockq_get_maxlength(s
->memblockq
);
482 pa_idxset_put(c
->record_streams
, s
, &s
->index
);
484 pa_source_output_put(s
->source_output
);
488 static void playback_stream_unlink(playback_stream
*s
) {
495 pa_sink_input_disconnect(s
->sink_input
);
496 pa_sink_input_unref(s
->sink_input
);
497 s
->sink_input
= NULL
;
500 if (s
->drain_request
)
501 pa_pstream_send_error(s
->connection
->pstream
, s
->drain_tag
, PA_ERR_NOENTITY
);
503 pa_assert_se(pa_idxset_remove_by_data(s
->connection
->output_streams
, s
, NULL
) == s
);
504 s
->connection
= NULL
;
505 playback_stream_unref(s
);
508 static void playback_stream_free(pa_object
* o
) {
509 playback_stream
*s
= PLAYBACK_STREAM(o
);
512 playback_stream_unlink(s
);
514 pa_memblockq_free(s
->memblockq
);
518 static int playback_stream_process_msg(pa_msgobject
*o
, int code
, void*userdata
, int64_t offset
, pa_memchunk
*chunk
) {
519 playback_stream
*s
= PLAYBACK_STREAM(o
);
520 playback_stream_assert_ref(s
);
523 case PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
: {
527 if ((l
= pa_atomic_load(&s
->missing
)) <= 0)
530 pa_assert_se(pa_atomic_sub(&s
->missing
, l
) >= l
);
532 t
= pa_tagstruct_new(NULL
, 0);
533 pa_tagstruct_putu32(t
, PA_COMMAND_REQUEST
);
534 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
535 pa_tagstruct_putu32(t
, s
->index
);
536 pa_tagstruct_putu32(t
, l
);
537 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
539 /* pa_log("Requesting %u bytes", l); */
543 case PLAYBACK_STREAM_MESSAGE_UNDERFLOW
: {
546 /* Report that we're empty */
547 t
= pa_tagstruct_new(NULL
, 0);
548 pa_tagstruct_putu32(t
, PA_COMMAND_UNDERFLOW
);
549 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
550 pa_tagstruct_putu32(t
, s
->index
);
551 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
555 case PLAYBACK_STREAM_MESSAGE_OVERFLOW
: {
558 /* Notify the user we're overflowed*/
559 t
= pa_tagstruct_new(NULL
, 0);
560 pa_tagstruct_putu32(t
, PA_COMMAND_OVERFLOW
);
561 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
562 pa_tagstruct_putu32(t
, s
->index
);
563 pa_pstream_send_tagstruct(s
->connection
->pstream
, t
);
567 case PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
:
568 pa_pstream_send_simple_ack(s
->connection
->pstream
, PA_PTR_TO_UINT(userdata
));
576 static playback_stream
* playback_stream_new(
579 const pa_sample_spec
*ss
,
580 const pa_channel_map
*map
,
591 playback_stream
*s
, *ssync
;
592 pa_sink_input
*sink_input
;
593 pa_memblock
*silence
;
596 pa_sink_input_new_data data
;
601 pa_assert(maxlength
);
603 /* Find syncid group */
604 for (ssync
= pa_idxset_first(c
->output_streams
, &idx
); ssync
; ssync
= pa_idxset_next(c
->output_streams
, &idx
)) {
606 if (!playback_stream_isinstance(ssync
))
609 if (ssync
->syncid
== syncid
)
613 /* Synced streams must connect to the same sink */
617 sink
= ssync
->sink_input
->sink
;
618 else if (sink
!= ssync
->sink_input
->sink
)
622 pa_sink_input_new_data_init(&data
);
624 data
.driver
= __FILE__
;
626 pa_sink_input_new_data_set_sample_spec(&data
, ss
);
627 pa_sink_input_new_data_set_channel_map(&data
, map
);
628 pa_sink_input_new_data_set_volume(&data
, volume
);
629 data
.module
= c
->protocol
->module
;
630 data
.client
= c
->client
;
631 data
.start_corked
= corked
;
632 data
.sync_base
= ssync
? ssync
->sink_input
: NULL
;
634 if (!(sink_input
= pa_sink_input_new(c
->protocol
->core
, &data
, 0)))
637 s
= pa_msgobject_new(playback_stream
);
638 s
->parent
.parent
.parent
.free
= playback_stream_free
;
639 s
->parent
.parent
.process_msg
= playback_stream_process_msg
;
642 s
->sink_input
= sink_input
;
645 s
->sink_input
->parent
.process_msg
= sink_input_process_msg
;
646 s
->sink_input
->peek
= sink_input_peek_cb
;
647 s
->sink_input
->drop
= sink_input_drop_cb
;
648 s
->sink_input
->kill
= sink_input_kill_cb
;
649 s
->sink_input
->userdata
= s
;
651 start_index
= ssync
? pa_memblockq_get_read_index(ssync
->memblockq
) : 0;
653 silence
= pa_silence_memblock_new(c
->protocol
->core
->mempool
, ss
, 0);
655 s
->memblockq
= pa_memblockq_new(
664 pa_memblock_unref(silence
);
666 *maxlength
= pa_memblockq_get_maxlength(s
->memblockq
);
667 *tlength
= pa_memblockq_get_tlength(s
->memblockq
);
668 *prebuf
= pa_memblockq_get_prebuf(s
->memblockq
);
669 *minreq
= pa_memblockq_get_minreq(s
->memblockq
);
670 *missing
= pa_memblockq_missing(s
->memblockq
);
672 pa_atomic_store(&s
->missing
, 0);
673 s
->last_missing
= *missing
;
674 s
->drain_request
= 0;
676 pa_idxset_put(c
->output_streams
, s
, &s
->index
);
678 pa_sink_input_put(s
->sink_input
);
683 static void connection_unlink(connection
*c
) {
692 while ((r
= pa_idxset_first(c
->record_streams
, NULL
)))
693 record_stream_unlink(r
);
695 while ((o
= pa_idxset_first(c
->output_streams
, NULL
)))
696 if (playback_stream_isinstance(o
))
697 playback_stream_unlink(PLAYBACK_STREAM(o
));
699 upload_stream_unlink(UPLOAD_STREAM(o
));
702 pa_subscription_free(c
->subscription
);
705 pa_pstream_unlink(c
->pstream
);
707 if (c
->auth_timeout_event
) {
708 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
709 c
->auth_timeout_event
= NULL
;
712 pa_assert_se(pa_idxset_remove_by_data(c
->protocol
->connections
, c
, NULL
) == c
);
717 static void connection_free(pa_object
*o
) {
718 connection
*c
= CONNECTION(o
);
722 connection_unlink(c
);
724 pa_idxset_free(c
->record_streams
, NULL
, NULL
);
725 pa_idxset_free(c
->output_streams
, NULL
, NULL
);
727 pa_pdispatch_unref(c
->pdispatch
);
728 pa_pstream_unref(c
->pstream
);
729 pa_client_free(c
->client
);
734 /* Called from thread context */
735 static void request_bytes(playback_stream
*s
) {
736 size_t new_missing
, delta
, previous_missing
;
738 /* pa_log("request_bytes()"); */
739 playback_stream_assert_ref(s
);
741 new_missing
= pa_memblockq_missing(s
->memblockq
);
743 if (new_missing
<= s
->last_missing
) {
744 s
->last_missing
= new_missing
;
748 delta
= new_missing
- s
->last_missing
;
749 s
->last_missing
= new_missing
;
751 /* pa_log("request_bytes(%u)", delta); */
753 previous_missing
= pa_atomic_add(&s
->missing
, delta
);
754 if (previous_missing
< pa_memblockq_get_minreq(s
->memblockq
) && previous_missing
+delta
>= pa_memblockq_get_minreq(s
->memblockq
))
755 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_REQUEST_DATA
, NULL
, 0, NULL
, NULL
);
758 static void send_memblock(connection
*c
) {
762 start
= PA_IDXSET_INVALID
;
766 if (!(r
= RECORD_STREAM(pa_idxset_rrobin(c
->record_streams
, &c
->rrobin_index
))))
769 if (start
== PA_IDXSET_INVALID
)
770 start
= c
->rrobin_index
;
771 else if (start
== c
->rrobin_index
)
774 if (pa_memblockq_peek(r
->memblockq
, &chunk
) >= 0) {
775 pa_memchunk schunk
= chunk
;
777 if (schunk
.length
> r
->fragment_size
)
778 schunk
.length
= r
->fragment_size
;
780 pa_pstream_send_memblock(c
->pstream
, r
->index
, 0, PA_SEEK_RELATIVE
, &schunk
);
782 pa_memblockq_drop(r
->memblockq
, schunk
.length
);
783 pa_memblock_unref(schunk
.memblock
);
790 static void send_playback_stream_killed(playback_stream
*p
) {
792 playback_stream_assert_ref(p
);
794 t
= pa_tagstruct_new(NULL
, 0);
795 pa_tagstruct_putu32(t
, PA_COMMAND_PLAYBACK_STREAM_KILLED
);
796 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
797 pa_tagstruct_putu32(t
, p
->index
);
798 pa_pstream_send_tagstruct(p
->connection
->pstream
, t
);
801 static void send_record_stream_killed(record_stream
*r
) {
803 record_stream_assert_ref(r
);
805 t
= pa_tagstruct_new(NULL
, 0);
806 pa_tagstruct_putu32(t
, PA_COMMAND_RECORD_STREAM_KILLED
);
807 pa_tagstruct_putu32(t
, (uint32_t) -1); /* tag */
808 pa_tagstruct_putu32(t
, r
->index
);
809 pa_pstream_send_tagstruct(r
->connection
->pstream
, t
);
812 /*** sink input callbacks ***/
814 /* Called from thread context */
815 static int sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
) {
816 pa_sink_input
*i
= PA_SINK_INPUT(o
);
819 pa_sink_input_assert_ref(i
);
820 s
= PLAYBACK_STREAM(i
->userdata
);
821 playback_stream_assert_ref(s
);
825 case SINK_INPUT_MESSAGE_SEEK
:
826 pa_memblockq_seek(s
->memblockq
, offset
, PA_PTR_TO_UINT(userdata
));
830 case SINK_INPUT_MESSAGE_POST_DATA
: {
833 if (pa_memblockq_push_align(s
->memblockq
, chunk
) < 0) {
835 pa_log_warn("Failed to push data into queue");
836 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_OVERFLOW
, NULL
, 0, NULL
, NULL
);
837 pa_memblockq_seek(s
->memblockq
, chunk
->length
, PA_SEEK_RELATIVE
);
846 case SINK_INPUT_MESSAGE_DRAIN
: {
848 pa_memblockq_prebuf_disable(s
->memblockq
);
850 if (!pa_memblockq_is_readable(s
->memblockq
))
851 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
, userdata
, 0, NULL
, NULL
);
853 s
->drain_tag
= PA_PTR_TO_UINT(userdata
);
854 s
->drain_request
= 1;
861 case SINK_INPUT_MESSAGE_FLUSH
:
862 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
863 case SINK_INPUT_MESSAGE_TRIGGER
: {
865 pa_sink_input
*isync
;
866 void (*func
)(pa_memblockq
*bq
);
869 case SINK_INPUT_MESSAGE_FLUSH
:
870 func
= pa_memblockq_flush
;
873 case SINK_INPUT_MESSAGE_PREBUF_FORCE
:
874 func
= pa_memblockq_prebuf_force
;
877 case SINK_INPUT_MESSAGE_TRIGGER
:
878 func
= pa_memblockq_prebuf_disable
;
882 pa_assert_not_reached();
889 /* Do the same for all other members in the sync group */
890 for (isync
= i
->sync_prev
; isync
; isync
= isync
->sync_prev
) {
891 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
892 func(ssync
->memblockq
);
894 request_bytes(ssync
);
897 for (isync
= i
->sync_next
; isync
; isync
= isync
->sync_next
) {
898 playback_stream
*ssync
= PLAYBACK_STREAM(isync
->userdata
);
899 func(ssync
->memblockq
);
901 request_bytes(ssync
);
907 case SINK_INPUT_MESSAGE_UPDATE_LATENCY
:
909 s
->read_index
= pa_memblockq_get_read_index(s
->memblockq
);
910 s
->write_index
= pa_memblockq_get_write_index(s
->memblockq
);
911 s
->resampled_chunk_length
= s
->sink_input
->thread_info
.resampled_chunk
.memblock
? s
->sink_input
->thread_info
.resampled_chunk
.length
: 0;
914 case PA_SINK_INPUT_MESSAGE_SET_STATE
:
916 pa_memblockq_prebuf_force(s
->memblockq
);
920 case PA_SINK_INPUT_MESSAGE_GET_LATENCY
: {
921 pa_usec_t
*r
= userdata
;
923 *r
= pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &i
->sample_spec
);
925 /* Fall through, the default handler will add in the extra
926 * latency added by the resampler */
931 return pa_sink_input_process_msg(o
, code
, userdata
, offset
, chunk
);
934 /* Called from thread context */
935 static int sink_input_peek_cb(pa_sink_input
*i
, pa_memchunk
*chunk
) {
938 pa_sink_input_assert_ref(i
);
939 s
= PLAYBACK_STREAM(i
->userdata
);
940 playback_stream_assert_ref(s
);
943 if (pa_memblockq_get_length(s
->memblockq
) <= 0 && !s
->underrun
) {
944 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_UNDERFLOW
, NULL
, 0, NULL
, NULL
);
948 if (pa_memblockq_peek(s
->memblockq
, chunk
) < 0) {
949 /* pa_log("peek: failure"); */
953 /* pa_log("peek: %u", chunk->length); */
960 /* Called from thread context */
961 static void sink_input_drop_cb(pa_sink_input
*i
, size_t length
) {
964 pa_sink_input_assert_ref(i
);
965 s
= PLAYBACK_STREAM(i
->userdata
);
966 playback_stream_assert_ref(s
);
967 pa_assert(length
> 0);
969 pa_memblockq_drop(s
->memblockq
, length
);
971 if (s
->drain_request
&& !pa_memblockq_is_readable(s
->memblockq
)) {
972 s
->drain_request
= 0;
973 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), PLAYBACK_STREAM_MESSAGE_DRAIN_ACK
, PA_UINT_TO_PTR(s
->drain_tag
), 0, NULL
, NULL
);
978 /* pa_log("after_drop: %u %u", pa_memblockq_get_length(s->memblockq), pa_memblockq_is_readable(s->memblockq)); */
981 static void sink_input_kill_cb(pa_sink_input
*i
) {
984 pa_sink_input_assert_ref(i
);
985 s
= PLAYBACK_STREAM(i
->userdata
);
986 playback_stream_assert_ref(s
);
988 send_playback_stream_killed(s
);
989 playback_stream_unlink(s
);
992 /*** source_output callbacks ***/
994 /* Called from thread context */
995 static void source_output_push_cb(pa_source_output
*o
, const pa_memchunk
*chunk
) {
998 pa_source_output_assert_ref(o
);
999 s
= RECORD_STREAM(o
->userdata
);
1000 record_stream_assert_ref(s
);
1003 pa_asyncmsgq_post(s
->connection
->protocol
->core
->asyncmsgq
, PA_MSGOBJECT(s
), RECORD_STREAM_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
1006 static void source_output_kill_cb(pa_source_output
*o
) {
1009 pa_source_output_assert_ref(o
);
1010 s
= RECORD_STREAM(o
->userdata
);
1011 record_stream_assert_ref(s
);
1013 send_record_stream_killed(s
);
1014 record_stream_unlink(s
);
1017 static pa_usec_t
source_output_get_latency_cb(pa_source_output
*o
) {
1020 pa_source_output_assert_ref(o
);
1021 s
= RECORD_STREAM(o
->userdata
);
1022 record_stream_assert_ref(s
);
1024 /*pa_log("get_latency: %u", pa_memblockq_get_length(s->memblockq));*/
1026 return pa_bytes_to_usec(pa_memblockq_get_length(s
->memblockq
), &o
->sample_spec
);
1029 /*** pdispatch callbacks ***/
1031 static void protocol_error(connection
*c
) {
1032 pa_log("protocol error, kicking client");
1033 connection_unlink(c
);
1036 #define CHECK_VALIDITY(pstream, expression, tag, error) do { \
1037 if (!(expression)) { \
1038 pa_pstream_send_error((pstream), (tag), (error)); \
1043 static pa_tagstruct
*reply_new(uint32_t tag
) {
1044 pa_tagstruct
*reply
;
1046 reply
= pa_tagstruct_new(NULL
, 0);
1047 pa_tagstruct_putu32(reply
, PA_COMMAND_REPLY
);
1048 pa_tagstruct_putu32(reply
, tag
);
1052 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
) {
1053 connection
*c
= CONNECTION(userdata
);
1055 uint32_t maxlength
, tlength
, prebuf
, minreq
, sink_index
, syncid
, missing
;
1056 const char *name
, *sink_name
;
1059 pa_tagstruct
*reply
;
1060 pa_sink
*sink
= NULL
;
1064 connection_assert_ref(c
);
1067 if (pa_tagstruct_get(
1069 PA_TAG_STRING
, &name
,
1070 PA_TAG_SAMPLE_SPEC
, &ss
,
1071 PA_TAG_CHANNEL_MAP
, &map
,
1072 PA_TAG_U32
, &sink_index
,
1073 PA_TAG_STRING
, &sink_name
,
1074 PA_TAG_U32
, &maxlength
,
1075 PA_TAG_BOOLEAN
, &corked
,
1076 PA_TAG_U32
, &tlength
,
1077 PA_TAG_U32
, &prebuf
,
1078 PA_TAG_U32
, &minreq
,
1079 PA_TAG_U32
, &syncid
,
1080 PA_TAG_CVOLUME
, &volume
,
1081 PA_TAG_INVALID
) < 0 ||
1082 !pa_tagstruct_eof(t
) ||
1088 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1089 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1090 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
1091 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1092 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1093 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
1094 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
&& volume
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1095 CHECK_VALIDITY(c
->pstream
, maxlength
> 0 && maxlength
<= MAX_MEMBLOCKQ_LENGTH
, tag
, PA_ERR_INVALID
);
1096 CHECK_VALIDITY(c
->pstream
, maxlength
>= pa_frame_size(&ss
), tag
, PA_ERR_INVALID
);
1098 if (sink_index
!= PA_INVALID_INDEX
) {
1099 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
);
1100 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
1101 } else if (sink_name
) {
1102 sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1);
1103 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
1106 s
= playback_stream_new(c
, sink
, &ss
, &map
, name
, &maxlength
, &tlength
, &prebuf
, &minreq
, &volume
, syncid
, corked
, &missing
);
1107 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1109 reply
= reply_new(tag
);
1110 pa_tagstruct_putu32(reply
, s
->index
);
1111 pa_assert(s
->sink_input
);
1112 pa_tagstruct_putu32(reply
, s
->sink_input
->index
);
1113 pa_tagstruct_putu32(reply
, missing
);
1115 /* pa_log("initial request is %u", missing); */
1117 if (c
->version
>= 9) {
1118 /* Since 0.9 we support sending the buffer metrics back to the client */
1120 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1121 pa_tagstruct_putu32(reply
, (uint32_t) tlength
);
1122 pa_tagstruct_putu32(reply
, (uint32_t) prebuf
);
1123 pa_tagstruct_putu32(reply
, (uint32_t) minreq
);
1126 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1129 static void command_delete_stream(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1130 connection
*c
= CONNECTION(userdata
);
1133 connection_assert_ref(c
);
1136 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
1137 !pa_tagstruct_eof(t
)) {
1142 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1146 case PA_COMMAND_DELETE_PLAYBACK_STREAM
: {
1148 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !playback_stream_isinstance(s
)) {
1149 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1153 playback_stream_unlink(s
);
1157 case PA_COMMAND_DELETE_RECORD_STREAM
: {
1159 if (!(s
= pa_idxset_get_by_index(c
->record_streams
, channel
))) {
1160 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1164 record_stream_unlink(s
);
1168 case PA_COMMAND_DELETE_UPLOAD_STREAM
: {
1171 if (!(s
= pa_idxset_get_by_index(c
->output_streams
, channel
)) || !upload_stream_isinstance(s
)) {
1172 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
1176 upload_stream_unlink(s
);
1181 pa_assert_not_reached();
1184 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1187 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
) {
1188 connection
*c
= CONNECTION(userdata
);
1190 uint32_t maxlength
, fragment_size
;
1191 uint32_t source_index
;
1192 const char *name
, *source_name
;
1195 pa_tagstruct
*reply
;
1196 pa_source
*source
= NULL
;
1199 connection_assert_ref(c
);
1202 if (pa_tagstruct_gets(t
, &name
) < 0 ||
1203 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
1204 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
1205 pa_tagstruct_getu32(t
, &source_index
) < 0 ||
1206 pa_tagstruct_gets(t
, &source_name
) < 0 ||
1207 pa_tagstruct_getu32(t
, &maxlength
) < 0 ||
1208 pa_tagstruct_get_boolean(t
, &corked
) < 0 ||
1209 pa_tagstruct_getu32(t
, &fragment_size
) < 0 ||
1210 !pa_tagstruct_eof(t
)) {
1215 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1216 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1217 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1218 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1219 CHECK_VALIDITY(c
->pstream
, source_index
!= PA_INVALID_INDEX
|| !source_name
|| (*source_name
&& pa_utf8_valid(source_name
)), tag
, PA_ERR_INVALID
);
1220 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1221 CHECK_VALIDITY(c
->pstream
, maxlength
<= MAX_MEMBLOCKQ_LENGTH
, tag
, PA_ERR_INVALID
);
1223 if (source_index
!= PA_INVALID_INDEX
) {
1224 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, source_index
);
1225 CHECK_VALIDITY(c
->pstream
, source
, tag
, PA_ERR_NOENTITY
);
1226 } else if (source_name
) {
1227 source
= pa_namereg_get(c
->protocol
->core
, source_name
, PA_NAMEREG_SOURCE
, 1);
1228 CHECK_VALIDITY(c
->pstream
, source
, tag
, PA_ERR_NOENTITY
);
1231 s
= record_stream_new(c
, source
, &ss
, &map
, name
, &maxlength
, fragment_size
, corked
);
1232 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1234 reply
= reply_new(tag
);
1235 pa_tagstruct_putu32(reply
, s
->index
);
1236 pa_assert(s
->source_output
);
1237 pa_tagstruct_putu32(reply
, s
->source_output
->index
);
1239 if (c
->version
>= 9) {
1240 /* Since 0.9 we support sending the buffer metrics back to the client */
1242 pa_tagstruct_putu32(reply
, (uint32_t) maxlength
);
1243 pa_tagstruct_putu32(reply
, (uint32_t) s
->fragment_size
);
1246 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1249 static void command_exit(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1250 connection
*c
= CONNECTION(userdata
);
1252 connection_assert_ref(c
);
1255 if (!pa_tagstruct_eof(t
)) {
1260 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1262 c
->protocol
->core
->mainloop
->quit(c
->protocol
->core
->mainloop
, 0);
1263 pa_pstream_send_simple_ack(c
->pstream
, tag
); /* nonsense */
1266 static void command_auth(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1267 connection
*c
= CONNECTION(userdata
);
1269 pa_tagstruct
*reply
;
1271 connection_assert_ref(c
);
1274 if (pa_tagstruct_getu32(t
, &c
->version
) < 0 ||
1275 pa_tagstruct_get_arbitrary(t
, &cookie
, PA_NATIVE_COOKIE_LENGTH
) < 0 ||
1276 !pa_tagstruct_eof(t
)) {
1281 /* Minimum supported version */
1282 if (c
->version
< 8) {
1283 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_VERSION
);
1287 if (!c
->authorized
) {
1291 const pa_creds
*creds
;
1293 if ((creds
= pa_pdispatch_creds(pd
))) {
1294 if (creds
->uid
== getuid())
1296 else if (c
->protocol
->auth_group
) {
1300 if ((gid
= pa_get_gid_of_group(c
->protocol
->auth_group
)) == (gid_t
) -1)
1301 pa_log_warn("failed to get GID of group '%s'", c
->protocol
->auth_group
);
1302 else if (gid
== creds
->gid
)
1306 if ((r
= pa_uid_in_group(creds
->uid
, c
->protocol
->auth_group
)) < 0)
1307 pa_log_warn("failed to check group membership.");
1313 pa_log_info("Got credentials: uid=%lu gid=%lu success=%i",
1314 (unsigned long) creds
->uid
,
1315 (unsigned long) creds
->gid
,
1318 if (c
->version
>= 10 &&
1319 pa_mempool_is_shared(c
->protocol
->core
->mempool
) &&
1320 creds
->uid
== getuid()) {
1322 pa_pstream_use_shm(c
->pstream
, 1);
1323 pa_log_info("Enabled SHM for new connection");
1329 if (!success
&& memcmp(c
->protocol
->auth_cookie
, cookie
, PA_NATIVE_COOKIE_LENGTH
) == 0)
1333 pa_log_warn("Denied access to client with invalid authorization data.");
1334 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_ACCESS
);
1339 if (c
->auth_timeout_event
) {
1340 c
->protocol
->core
->mainloop
->time_free(c
->auth_timeout_event
);
1341 c
->auth_timeout_event
= NULL
;
1345 reply
= reply_new(tag
);
1346 pa_tagstruct_putu32(reply
, PA_PROTOCOL_VERSION
);
1350 /* SHM support is only enabled after both sides made sure they are the same user. */
1354 ucred
.uid
= getuid();
1355 ucred
.gid
= getgid();
1357 pa_pstream_send_tagstruct_with_creds(c
->pstream
, reply
, &ucred
);
1360 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1364 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
) {
1365 connection
*c
= CONNECTION(userdata
);
1368 connection_assert_ref(c
);
1371 if (pa_tagstruct_gets(t
, &name
) < 0 ||
1372 !pa_tagstruct_eof(t
)) {
1377 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1379 pa_client_set_name(c
->client
, name
);
1380 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1383 static void command_lookup(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1384 connection
*c
= CONNECTION(userdata
);
1386 uint32_t idx
= PA_IDXSET_INVALID
;
1388 connection_assert_ref(c
);
1391 if (pa_tagstruct_gets(t
, &name
) < 0 ||
1392 !pa_tagstruct_eof(t
)) {
1397 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1398 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1400 if (command
== PA_COMMAND_LOOKUP_SINK
) {
1402 if ((sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1)))
1406 pa_assert(command
== PA_COMMAND_LOOKUP_SOURCE
);
1407 if ((source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1)))
1408 idx
= source
->index
;
1411 if (idx
== PA_IDXSET_INVALID
)
1412 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1414 pa_tagstruct
*reply
;
1415 reply
= reply_new(tag
);
1416 pa_tagstruct_putu32(reply
, idx
);
1417 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1421 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
) {
1422 connection
*c
= CONNECTION(userdata
);
1426 connection_assert_ref(c
);
1429 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
1430 !pa_tagstruct_eof(t
)) {
1435 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1436 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
1437 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
1438 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
1440 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
);
1443 static void command_stat(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1444 connection
*c
= CONNECTION(userdata
);
1445 pa_tagstruct
*reply
;
1446 const pa_mempool_stat
*stat
;
1448 connection_assert_ref(c
);
1451 if (!pa_tagstruct_eof(t
)) {
1456 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1458 stat
= pa_mempool_get_stat(c
->protocol
->core
->mempool
);
1460 reply
= reply_new(tag
);
1461 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_allocated
));
1462 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->allocated_size
));
1463 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->n_accumulated
));
1464 pa_tagstruct_putu32(reply
, (uint32_t) pa_atomic_load(&stat
->accumulated_size
));
1465 pa_tagstruct_putu32(reply
, pa_scache_total_size(c
->protocol
->core
));
1466 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1469 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
) {
1470 connection
*c
= CONNECTION(userdata
);
1471 pa_tagstruct
*reply
;
1473 struct timeval tv
, now
;
1477 connection_assert_ref(c
);
1480 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
1481 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
1482 !pa_tagstruct_eof(t
)) {
1487 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1488 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
1489 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
1490 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
1491 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
)
1493 reply
= reply_new(tag
);
1495 latency
= pa_sink_get_latency(s
->sink_input
->sink
);
1496 latency
+= pa_bytes_to_usec(s
->resampled_chunk_length
, &s
->sink_input
->sample_spec
);
1498 pa_tagstruct_put_usec(reply
, latency
);
1500 pa_tagstruct_put_usec(reply
, 0);
1501 pa_tagstruct_put_boolean(reply
, pa_sink_input_get_state(s
->sink_input
) == PA_SINK_INPUT_RUNNING
);
1502 pa_tagstruct_put_timeval(reply
, &tv
);
1503 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
1504 pa_tagstruct_puts64(reply
, s
->write_index
);
1505 pa_tagstruct_puts64(reply
, s
->read_index
);
1506 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1509 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
) {
1510 connection
*c
= CONNECTION(userdata
);
1511 pa_tagstruct
*reply
;
1513 struct timeval tv
, now
;
1516 connection_assert_ref(c
);
1519 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
1520 pa_tagstruct_get_timeval(t
, &tv
) < 0 ||
1521 !pa_tagstruct_eof(t
)) {
1526 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1527 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
1528 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
1530 reply
= reply_new(tag
);
1531 pa_tagstruct_put_usec(reply
, s
->source_output
->source
->monitor_of
? pa_sink_get_latency(s
->source_output
->source
->monitor_of
) : 0);
1532 pa_tagstruct_put_usec(reply
, pa_source_get_latency(s
->source_output
->source
));
1533 pa_tagstruct_put_boolean(reply
, 0);
1534 pa_tagstruct_put_timeval(reply
, &tv
);
1535 pa_tagstruct_put_timeval(reply
, pa_gettimeofday(&now
));
1536 pa_tagstruct_puts64(reply
, pa_memblockq_get_write_index(s
->memblockq
));
1537 pa_tagstruct_puts64(reply
, pa_memblockq_get_read_index(s
->memblockq
));
1538 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1541 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
) {
1542 connection
*c
= CONNECTION(userdata
);
1548 pa_tagstruct
*reply
;
1550 connection_assert_ref(c
);
1553 if (pa_tagstruct_gets(t
, &name
) < 0 ||
1554 pa_tagstruct_get_sample_spec(t
, &ss
) < 0 ||
1555 pa_tagstruct_get_channel_map(t
, &map
) < 0 ||
1556 pa_tagstruct_getu32(t
, &length
) < 0 ||
1557 !pa_tagstruct_eof(t
)) {
1562 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1563 CHECK_VALIDITY(c
->pstream
, pa_sample_spec_valid(&ss
), tag
, PA_ERR_INVALID
);
1564 CHECK_VALIDITY(c
->pstream
, pa_channel_map_valid(&map
), tag
, PA_ERR_INVALID
);
1565 CHECK_VALIDITY(c
->pstream
, map
.channels
== ss
.channels
, tag
, PA_ERR_INVALID
);
1566 CHECK_VALIDITY(c
->pstream
, (length
% pa_frame_size(&ss
)) == 0 && length
> 0, tag
, PA_ERR_INVALID
);
1567 CHECK_VALIDITY(c
->pstream
, length
<= PA_SCACHE_ENTRY_SIZE_MAX
, tag
, PA_ERR_TOOLARGE
);
1568 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1570 s
= upload_stream_new(c
, &ss
, &map
, name
, length
);
1571 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_INVALID
);
1573 reply
= reply_new(tag
);
1574 pa_tagstruct_putu32(reply
, s
->index
);
1575 pa_tagstruct_putu32(reply
, length
);
1576 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1579 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
) {
1580 connection
*c
= CONNECTION(userdata
);
1585 connection_assert_ref(c
);
1588 if (pa_tagstruct_getu32(t
, &channel
) < 0 ||
1589 !pa_tagstruct_eof(t
)) {
1594 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1596 s
= pa_idxset_get_by_index(c
->output_streams
, channel
);
1597 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
1598 CHECK_VALIDITY(c
->pstream
, upload_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
1600 if (pa_scache_add_item(c
->protocol
->core
, s
->name
, &s
->sample_spec
, &s
->channel_map
, &s
->memchunk
, &idx
) < 0)
1601 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INTERNAL
);
1603 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1605 upload_stream_unlink(s
);
1608 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
) {
1609 connection
*c
= CONNECTION(userdata
);
1610 uint32_t sink_index
;
1613 const char *name
, *sink_name
;
1615 connection_assert_ref(c
);
1618 if (pa_tagstruct_getu32(t
, &sink_index
) < 0 ||
1619 pa_tagstruct_gets(t
, &sink_name
) < 0 ||
1620 pa_tagstruct_getu32(t
, &volume
) < 0 ||
1621 pa_tagstruct_gets(t
, &name
) < 0 ||
1622 !pa_tagstruct_eof(t
)) {
1627 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1628 CHECK_VALIDITY(c
->pstream
, sink_index
!= PA_INVALID_INDEX
|| !sink_name
|| (*sink_name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
1629 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1631 if (sink_index
!= PA_INVALID_INDEX
)
1632 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, sink_index
);
1634 sink
= pa_namereg_get(c
->protocol
->core
, sink_name
, PA_NAMEREG_SINK
, 1);
1636 CHECK_VALIDITY(c
->pstream
, sink
, tag
, PA_ERR_NOENTITY
);
1638 if (pa_scache_play_item(c
->protocol
->core
, name
, sink
, volume
) < 0) {
1639 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1643 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1646 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
) {
1647 connection
*c
= CONNECTION(userdata
);
1650 connection_assert_ref(c
);
1653 if (pa_tagstruct_gets(t
, &name
) < 0 ||
1654 !pa_tagstruct_eof(t
)) {
1659 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1660 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
1662 if (pa_scache_remove_item(c
->protocol
->core
, name
) < 0) {
1663 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1667 pa_pstream_send_simple_ack(c
->pstream
, tag
);
1670 static void sink_fill_tagstruct(pa_tagstruct
*t
, pa_sink
*sink
) {
1672 pa_sink_assert_ref(sink
);
1676 PA_TAG_U32
, sink
->index
,
1677 PA_TAG_STRING
, sink
->name
,
1678 PA_TAG_STRING
, sink
->description
,
1679 PA_TAG_SAMPLE_SPEC
, &sink
->sample_spec
,
1680 PA_TAG_CHANNEL_MAP
, &sink
->channel_map
,
1681 PA_TAG_U32
, sink
->module
? sink
->module
->index
: PA_INVALID_INDEX
,
1682 PA_TAG_CVOLUME
, pa_sink_get_volume(sink
),
1683 PA_TAG_BOOLEAN
, pa_sink_get_mute(sink
),
1684 PA_TAG_U32
, sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
1685 PA_TAG_STRING
, sink
->monitor_source
? sink
->monitor_source
->name
: NULL
,
1686 PA_TAG_USEC
, pa_sink_get_latency(sink
),
1687 PA_TAG_STRING
, sink
->driver
,
1689 (sink
->get_volume
? PA_SINK_HW_VOLUME_CTRL
: 0) | /* FIXME */
1690 (sink
->get_latency
? PA_SINK_LATENCY
: 0) | /* FIXME */
1691 (sink
->is_hardware
? PA_SINK_HARDWARE
: 0),
1695 static void source_fill_tagstruct(pa_tagstruct
*t
, pa_source
*source
) {
1697 pa_source_assert_ref(source
);
1701 PA_TAG_U32
, source
->index
,
1702 PA_TAG_STRING
, source
->name
,
1703 PA_TAG_STRING
, source
->description
,
1704 PA_TAG_SAMPLE_SPEC
, &source
->sample_spec
,
1705 PA_TAG_CHANNEL_MAP
, &source
->channel_map
,
1706 PA_TAG_U32
, source
->module
? source
->module
->index
: PA_INVALID_INDEX
,
1707 PA_TAG_CVOLUME
, pa_source_get_volume(source
),
1708 PA_TAG_BOOLEAN
, pa_source_get_mute(source
),
1709 PA_TAG_U32
, source
->monitor_of
? source
->monitor_of
->index
: PA_INVALID_INDEX
,
1710 PA_TAG_STRING
, source
->monitor_of
? source
->monitor_of
->name
: NULL
,
1711 PA_TAG_USEC
, pa_source_get_latency(source
),
1712 PA_TAG_STRING
, source
->driver
,
1714 (source
->get_volume
? PA_SOURCE_HW_VOLUME_CTRL
: 0) | /* FIXME */
1715 (source
->get_latency
? PA_SOURCE_LATENCY
: 0) | /* FIXME */
1716 (source
->is_hardware
? PA_SOURCE_HARDWARE
: 0),
1720 static void client_fill_tagstruct(pa_tagstruct
*t
, pa_client
*client
) {
1724 pa_tagstruct_putu32(t
, client
->index
);
1725 pa_tagstruct_puts(t
, client
->name
);
1726 pa_tagstruct_putu32(t
, client
->owner
? client
->owner
->index
: PA_INVALID_INDEX
);
1727 pa_tagstruct_puts(t
, client
->driver
);
1730 static void module_fill_tagstruct(pa_tagstruct
*t
, pa_module
*module
) {
1734 pa_tagstruct_putu32(t
, module
->index
);
1735 pa_tagstruct_puts(t
, module
->name
);
1736 pa_tagstruct_puts(t
, module
->argument
);
1737 pa_tagstruct_putu32(t
, module
->n_used
);
1738 pa_tagstruct_put_boolean(t
, module
->auto_unload
);
1741 static void sink_input_fill_tagstruct(pa_tagstruct
*t
, pa_sink_input
*s
) {
1743 pa_sink_input_assert_ref(s
);
1745 pa_tagstruct_putu32(t
, s
->index
);
1746 pa_tagstruct_puts(t
, s
->name
);
1747 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
1748 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
1749 pa_tagstruct_putu32(t
, s
->sink
->index
);
1750 pa_tagstruct_put_sample_spec(t
, &s
->sample_spec
);
1751 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
1752 pa_tagstruct_put_cvolume(t
, &s
->volume
);
1753 pa_tagstruct_put_usec(t
, pa_sink_input_get_latency(s
));
1754 pa_tagstruct_put_usec(t
, pa_sink_get_latency(s
->sink
));
1755 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_sink_input_get_resample_method(s
)));
1756 pa_tagstruct_puts(t
, s
->driver
);
1759 static void source_output_fill_tagstruct(pa_tagstruct
*t
, pa_source_output
*s
) {
1761 pa_source_output_assert_ref(s
);
1763 pa_tagstruct_putu32(t
, s
->index
);
1764 pa_tagstruct_puts(t
, s
->name
);
1765 pa_tagstruct_putu32(t
, s
->module
? s
->module
->index
: PA_INVALID_INDEX
);
1766 pa_tagstruct_putu32(t
, s
->client
? s
->client
->index
: PA_INVALID_INDEX
);
1767 pa_tagstruct_putu32(t
, s
->source
->index
);
1768 pa_tagstruct_put_sample_spec(t
, &s
->sample_spec
);
1769 pa_tagstruct_put_channel_map(t
, &s
->channel_map
);
1770 pa_tagstruct_put_usec(t
, pa_source_output_get_latency(s
));
1771 pa_tagstruct_put_usec(t
, pa_source_get_latency(s
->source
));
1772 pa_tagstruct_puts(t
, pa_resample_method_to_string(pa_source_output_get_resample_method(s
)));
1773 pa_tagstruct_puts(t
, s
->driver
);
1776 static void scache_fill_tagstruct(pa_tagstruct
*t
, pa_scache_entry
*e
) {
1780 pa_tagstruct_putu32(t
, e
->index
);
1781 pa_tagstruct_puts(t
, e
->name
);
1782 pa_tagstruct_put_cvolume(t
, &e
->volume
);
1783 pa_tagstruct_put_usec(t
, pa_bytes_to_usec(e
->memchunk
.length
, &e
->sample_spec
));
1784 pa_tagstruct_put_sample_spec(t
, &e
->sample_spec
);
1785 pa_tagstruct_put_channel_map(t
, &e
->channel_map
);
1786 pa_tagstruct_putu32(t
, e
->memchunk
.length
);
1787 pa_tagstruct_put_boolean(t
, e
->lazy
);
1788 pa_tagstruct_puts(t
, e
->filename
);
1791 static void command_get_info(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1792 connection
*c
= CONNECTION(userdata
);
1794 pa_sink
*sink
= NULL
;
1795 pa_source
*source
= NULL
;
1796 pa_client
*client
= NULL
;
1797 pa_module
*module
= NULL
;
1798 pa_sink_input
*si
= NULL
;
1799 pa_source_output
*so
= NULL
;
1800 pa_scache_entry
*sce
= NULL
;
1802 pa_tagstruct
*reply
;
1804 connection_assert_ref(c
);
1807 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
1808 (command
!= PA_COMMAND_GET_CLIENT_INFO
&&
1809 command
!= PA_COMMAND_GET_MODULE_INFO
&&
1810 command
!= PA_COMMAND_GET_SINK_INPUT_INFO
&&
1811 command
!= PA_COMMAND_GET_SOURCE_OUTPUT_INFO
&&
1812 pa_tagstruct_gets(t
, &name
) < 0) ||
1813 !pa_tagstruct_eof(t
)) {
1818 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1819 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
1821 if (command
== PA_COMMAND_GET_SINK_INFO
) {
1822 if (idx
!= PA_INVALID_INDEX
)
1823 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
1825 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
1826 } else if (command
== PA_COMMAND_GET_SOURCE_INFO
) {
1827 if (idx
!= PA_INVALID_INDEX
)
1828 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
1830 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
1831 } else if (command
== PA_COMMAND_GET_CLIENT_INFO
)
1832 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
1833 else if (command
== PA_COMMAND_GET_MODULE_INFO
)
1834 module
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
1835 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO
)
1836 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
1837 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO
)
1838 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
1840 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO
);
1841 if (idx
!= PA_INVALID_INDEX
)
1842 sce
= pa_idxset_get_by_index(c
->protocol
->core
->scache
, idx
);
1844 sce
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SAMPLE
, 0);
1847 if (!sink
&& !source
&& !client
&& !module
&& !si
&& !so
&& !sce
) {
1848 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_NOENTITY
);
1852 reply
= reply_new(tag
);
1854 sink_fill_tagstruct(reply
, sink
);
1856 source_fill_tagstruct(reply
, source
);
1858 client_fill_tagstruct(reply
, client
);
1860 module_fill_tagstruct(reply
, module
);
1862 sink_input_fill_tagstruct(reply
, si
);
1864 source_output_fill_tagstruct(reply
, so
);
1866 scache_fill_tagstruct(reply
, sce
);
1867 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1870 static void command_get_info_list(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1871 connection
*c
= CONNECTION(userdata
);
1875 pa_tagstruct
*reply
;
1877 connection_assert_ref(c
);
1880 if (!pa_tagstruct_eof(t
)) {
1885 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1887 reply
= reply_new(tag
);
1889 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
1890 i
= c
->protocol
->core
->sinks
;
1891 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
1892 i
= c
->protocol
->core
->sources
;
1893 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
1894 i
= c
->protocol
->core
->clients
;
1895 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
1896 i
= c
->protocol
->core
->modules
;
1897 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
1898 i
= c
->protocol
->core
->sink_inputs
;
1899 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
1900 i
= c
->protocol
->core
->source_outputs
;
1902 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
1903 i
= c
->protocol
->core
->scache
;
1907 for (p
= pa_idxset_first(i
, &idx
); p
; p
= pa_idxset_next(i
, &idx
)) {
1908 if (command
== PA_COMMAND_GET_SINK_INFO_LIST
)
1909 sink_fill_tagstruct(reply
, p
);
1910 else if (command
== PA_COMMAND_GET_SOURCE_INFO_LIST
)
1911 source_fill_tagstruct(reply
, p
);
1912 else if (command
== PA_COMMAND_GET_CLIENT_INFO_LIST
)
1913 client_fill_tagstruct(reply
, p
);
1914 else if (command
== PA_COMMAND_GET_MODULE_INFO_LIST
)
1915 module_fill_tagstruct(reply
, p
);
1916 else if (command
== PA_COMMAND_GET_SINK_INPUT_INFO_LIST
)
1917 sink_input_fill_tagstruct(reply
, p
);
1918 else if (command
== PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
)
1919 source_output_fill_tagstruct(reply
, p
);
1921 pa_assert(command
== PA_COMMAND_GET_SAMPLE_INFO_LIST
);
1922 scache_fill_tagstruct(reply
, p
);
1927 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1930 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
) {
1931 connection
*c
= CONNECTION(userdata
);
1932 pa_tagstruct
*reply
;
1936 connection_assert_ref(c
);
1939 if (!pa_tagstruct_eof(t
)) {
1944 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1946 reply
= reply_new(tag
);
1947 pa_tagstruct_puts(reply
, PACKAGE_NAME
);
1948 pa_tagstruct_puts(reply
, PACKAGE_VERSION
);
1949 pa_tagstruct_puts(reply
, pa_get_user_name(txt
, sizeof(txt
)));
1950 pa_tagstruct_puts(reply
, pa_get_fqdn(txt
, sizeof(txt
)));
1951 pa_tagstruct_put_sample_spec(reply
, &c
->protocol
->core
->default_sample_spec
);
1953 n
= pa_namereg_get_default_sink_name(c
->protocol
->core
);
1954 pa_tagstruct_puts(reply
, n
);
1955 n
= pa_namereg_get_default_source_name(c
->protocol
->core
);
1956 pa_tagstruct_puts(reply
, n
);
1958 pa_tagstruct_putu32(reply
, c
->protocol
->core
->cookie
);
1960 pa_pstream_send_tagstruct(c
->pstream
, reply
);
1963 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t e
, uint32_t idx
, void *userdata
) {
1965 connection
*c
= CONNECTION(userdata
);
1967 connection_assert_ref(c
);
1969 t
= pa_tagstruct_new(NULL
, 0);
1970 pa_tagstruct_putu32(t
, PA_COMMAND_SUBSCRIBE_EVENT
);
1971 pa_tagstruct_putu32(t
, (uint32_t) -1);
1972 pa_tagstruct_putu32(t
, e
);
1973 pa_tagstruct_putu32(t
, idx
);
1974 pa_pstream_send_tagstruct(c
->pstream
, t
);
1977 static void command_subscribe(PA_GCC_UNUSED pa_pdispatch
*pd
, PA_GCC_UNUSED
uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
1978 connection
*c
= CONNECTION(userdata
);
1979 pa_subscription_mask_t m
;
1981 connection_assert_ref(c
);
1984 if (pa_tagstruct_getu32(t
, &m
) < 0 ||
1985 !pa_tagstruct_eof(t
)) {
1990 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
1991 CHECK_VALIDITY(c
->pstream
, (m
& ~PA_SUBSCRIPTION_MASK_ALL
) == 0, tag
, PA_ERR_INVALID
);
1993 if (c
->subscription
)
1994 pa_subscription_free(c
->subscription
);
1997 c
->subscription
= pa_subscription_new(c
->protocol
->core
, m
, subscription_cb
, c
);
1998 pa_assert(c
->subscription
);
2000 c
->subscription
= NULL
;
2002 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2005 static void command_set_volume(
2006 PA_GCC_UNUSED pa_pdispatch
*pd
,
2012 connection
*c
= CONNECTION(userdata
);
2015 pa_sink
*sink
= NULL
;
2016 pa_source
*source
= NULL
;
2017 pa_sink_input
*si
= NULL
;
2018 const char *name
= NULL
;
2020 connection_assert_ref(c
);
2023 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2024 (command
== PA_COMMAND_SET_SINK_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2025 (command
== PA_COMMAND_SET_SOURCE_VOLUME
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2026 pa_tagstruct_get_cvolume(t
, &volume
) ||
2027 !pa_tagstruct_eof(t
)) {
2032 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2033 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2034 CHECK_VALIDITY(c
->pstream
, pa_cvolume_valid(&volume
), tag
, PA_ERR_INVALID
);
2038 case PA_COMMAND_SET_SINK_VOLUME
:
2039 if (idx
!= PA_INVALID_INDEX
)
2040 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2042 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2045 case PA_COMMAND_SET_SOURCE_VOLUME
:
2046 if (idx
!= PA_INVALID_INDEX
)
2047 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2049 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2052 case PA_COMMAND_SET_SINK_INPUT_VOLUME
:
2053 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2057 pa_assert_not_reached();
2060 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2063 pa_sink_set_volume(sink
, &volume
);
2065 pa_source_set_volume(source
, &volume
);
2067 pa_sink_input_set_volume(si
, &volume
);
2069 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2072 static void command_set_mute(
2073 PA_GCC_UNUSED pa_pdispatch
*pd
,
2079 connection
*c
= CONNECTION(userdata
);
2082 pa_sink
*sink
= NULL
;
2083 pa_source
*source
= NULL
;
2084 pa_sink_input
*si
= NULL
;
2085 const char *name
= NULL
;
2087 connection_assert_ref(c
);
2090 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2091 (command
== PA_COMMAND_SET_SINK_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2092 (command
== PA_COMMAND_SET_SOURCE_MUTE
&& pa_tagstruct_gets(t
, &name
) < 0) ||
2093 pa_tagstruct_get_boolean(t
, &mute
) ||
2094 !pa_tagstruct_eof(t
)) {
2099 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2100 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2104 case PA_COMMAND_SET_SINK_MUTE
:
2106 if (idx
!= PA_INVALID_INDEX
)
2107 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx
);
2109 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2113 case PA_COMMAND_SET_SOURCE_MUTE
:
2114 if (idx
!= PA_INVALID_INDEX
)
2115 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx
);
2117 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2121 case PA_COMMAND_SET_SINK_INPUT_MUTE
:
2122 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2126 pa_assert_not_reached();
2129 CHECK_VALIDITY(c
->pstream
, si
|| sink
|| source
, tag
, PA_ERR_NOENTITY
);
2132 pa_sink_set_mute(sink
, mute
);
2134 pa_source_set_mute(source
, mute
);
2136 pa_sink_input_set_mute(si
, mute
);
2138 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2141 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
) {
2142 connection
*c
= CONNECTION(userdata
);
2147 connection_assert_ref(c
);
2150 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2151 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
2152 !pa_tagstruct_eof(t
)) {
2157 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2158 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2159 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2160 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2161 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2163 pa_sink_input_cork(s
->sink_input
, b
);
2164 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2167 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
) {
2168 connection
*c
= CONNECTION(userdata
);
2172 connection_assert_ref(c
);
2175 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2176 !pa_tagstruct_eof(t
)) {
2181 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2182 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2183 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2184 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2185 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2188 case PA_COMMAND_FLUSH_PLAYBACK_STREAM
:
2189 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_FLUSH
, NULL
, 0, NULL
);
2192 case PA_COMMAND_PREBUF_PLAYBACK_STREAM
:
2193 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_PREBUF_FORCE
, NULL
, 0, NULL
);
2196 case PA_COMMAND_TRIGGER_PLAYBACK_STREAM
:
2197 pa_asyncmsgq_send(s
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(s
->sink_input
), SINK_INPUT_MESSAGE_TRIGGER
, NULL
, 0, NULL
);
2201 pa_assert_not_reached();
2204 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2207 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
) {
2208 connection
*c
= CONNECTION(userdata
);
2213 connection_assert_ref(c
);
2216 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2217 pa_tagstruct_get_boolean(t
, &b
) < 0 ||
2218 !pa_tagstruct_eof(t
)) {
2223 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2224 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
2225 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2227 pa_source_output_cork(s
->source_output
, b
);
2228 pa_memblockq_prebuf_force(s
->memblockq
);
2229 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2232 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
) {
2233 connection
*c
= CONNECTION(userdata
);
2237 connection_assert_ref(c
);
2240 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2241 !pa_tagstruct_eof(t
)) {
2246 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2247 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
2248 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2250 pa_memblockq_flush(s
->memblockq
);
2251 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2254 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
) {
2255 connection
*c
= CONNECTION(userdata
);
2258 connection_assert_ref(c
);
2261 if (pa_tagstruct_gets(t
, &s
) < 0 ||
2262 !pa_tagstruct_eof(t
)) {
2267 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2268 CHECK_VALIDITY(c
->pstream
, !s
|| (*s
&& pa_utf8_valid(s
)), tag
, PA_ERR_INVALID
);
2270 pa_namereg_set_default(c
->protocol
->core
, s
, command
== PA_COMMAND_SET_DEFAULT_SOURCE
? PA_NAMEREG_SOURCE
: PA_NAMEREG_SINK
);
2271 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2274 static void command_set_stream_name(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2275 connection
*c
= CONNECTION(userdata
);
2279 connection_assert_ref(c
);
2282 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2283 pa_tagstruct_gets(t
, &name
) < 0 ||
2284 !pa_tagstruct_eof(t
)) {
2289 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2290 CHECK_VALIDITY(c
->pstream
, name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2292 if (command
== PA_COMMAND_SET_PLAYBACK_STREAM_NAME
) {
2295 s
= pa_idxset_get_by_index(c
->output_streams
, idx
);
2296 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2297 CHECK_VALIDITY(c
->pstream
, playback_stream_isinstance(s
), tag
, PA_ERR_NOENTITY
);
2299 pa_sink_input_set_name(s
->sink_input
, name
);
2304 s
= pa_idxset_get_by_index(c
->record_streams
, idx
);
2305 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2307 pa_source_output_set_name(s
->source_output
, name
);
2310 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2313 static void command_kill(PA_GCC_UNUSED pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2314 connection
*c
= CONNECTION(userdata
);
2317 connection_assert_ref(c
);
2320 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2321 !pa_tagstruct_eof(t
)) {
2326 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2328 if (command
== PA_COMMAND_KILL_CLIENT
) {
2331 client
= pa_idxset_get_by_index(c
->protocol
->core
->clients
, idx
);
2332 CHECK_VALIDITY(c
->pstream
, client
, tag
, PA_ERR_NOENTITY
);
2335 pa_client_kill(client
);
2337 } else if (command
== PA_COMMAND_KILL_SINK_INPUT
) {
2340 s
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2341 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2344 pa_sink_input_kill(s
);
2346 pa_source_output
*s
;
2348 pa_assert(command
== PA_COMMAND_KILL_SOURCE_OUTPUT
);
2350 s
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
2351 CHECK_VALIDITY(c
->pstream
, s
, tag
, PA_ERR_NOENTITY
);
2354 pa_source_output_kill(s
);
2357 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2358 connection_unref(c
);
2361 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
) {
2362 connection
*c
= CONNECTION(userdata
);
2364 const char *name
, *argument
;
2365 pa_tagstruct
*reply
;
2367 connection_assert_ref(c
);
2370 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2371 pa_tagstruct_gets(t
, &argument
) < 0 ||
2372 !pa_tagstruct_eof(t
)) {
2377 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2378 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
) && !strchr(name
, '/'), tag
, PA_ERR_INVALID
);
2379 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
2381 if (!(m
= pa_module_load(c
->protocol
->core
, name
, argument
))) {
2382 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_MODINITFAILED
);
2386 reply
= reply_new(tag
);
2387 pa_tagstruct_putu32(reply
, m
->index
);
2388 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2391 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
) {
2392 connection
*c
= CONNECTION(userdata
);
2396 connection_assert_ref(c
);
2399 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2400 !pa_tagstruct_eof(t
)) {
2405 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2406 m
= pa_idxset_get_by_index(c
->protocol
->core
->modules
, idx
);
2407 CHECK_VALIDITY(c
->pstream
, m
, tag
, PA_ERR_NOENTITY
);
2409 pa_module_unload_request(m
);
2410 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2413 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
) {
2414 connection
*c
= CONNECTION(userdata
);
2415 const char *name
, *module
, *argument
;
2418 pa_tagstruct
*reply
;
2420 connection_assert_ref(c
);
2423 if (pa_tagstruct_gets(t
, &name
) < 0 ||
2424 pa_tagstruct_getu32(t
, &type
) < 0 ||
2425 pa_tagstruct_gets(t
, &module
) < 0 ||
2426 pa_tagstruct_gets(t
, &argument
) < 0 ||
2427 !pa_tagstruct_eof(t
)) {
2432 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2433 CHECK_VALIDITY(c
->pstream
, name
&& *name
&& pa_utf8_valid(name
), tag
, PA_ERR_INVALID
);
2434 CHECK_VALIDITY(c
->pstream
, type
== 0 || type
== 1, tag
, PA_ERR_INVALID
);
2435 CHECK_VALIDITY(c
->pstream
, module
&& *module
&& pa_utf8_valid(module
), tag
, PA_ERR_INVALID
);
2436 CHECK_VALIDITY(c
->pstream
, !argument
|| pa_utf8_valid(argument
), tag
, PA_ERR_INVALID
);
2438 if (pa_autoload_add(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
, module
, argument
, &idx
) < 0) {
2439 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_EXIST
);
2443 reply
= reply_new(tag
);
2444 pa_tagstruct_putu32(reply
, idx
);
2445 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2448 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
) {
2449 connection
*c
= CONNECTION(userdata
);
2450 const char *name
= NULL
;
2451 uint32_t type
, idx
= PA_IDXSET_INVALID
;
2454 connection_assert_ref(c
);
2457 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
2458 (pa_tagstruct_gets(t
, &name
) < 0 ||
2459 pa_tagstruct_getu32(t
, &type
) < 0)) ||
2460 !pa_tagstruct_eof(t
)) {
2465 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2466 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
2467 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& pa_utf8_valid(name
) && (type
== 0 || type
== 1)), tag
, PA_ERR_INVALID
);
2470 r
= pa_autoload_remove_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
2472 r
= pa_autoload_remove_by_index(c
->protocol
->core
, idx
);
2474 CHECK_VALIDITY(c
->pstream
, r
>= 0, tag
, PA_ERR_NOENTITY
);
2476 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2479 static void autoload_fill_tagstruct(pa_tagstruct
*t
, const pa_autoload_entry
*e
) {
2482 pa_tagstruct_putu32(t
, e
->index
);
2483 pa_tagstruct_puts(t
, e
->name
);
2484 pa_tagstruct_putu32(t
, e
->type
== PA_NAMEREG_SINK
? 0 : 1);
2485 pa_tagstruct_puts(t
, e
->module
);
2486 pa_tagstruct_puts(t
, e
->argument
);
2489 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
) {
2490 connection
*c
= CONNECTION(userdata
);
2491 const pa_autoload_entry
*a
= NULL
;
2494 pa_tagstruct
*reply
;
2496 connection_assert_ref(c
);
2499 if ((pa_tagstruct_getu32(t
, &idx
) < 0 &&
2500 (pa_tagstruct_gets(t
, &name
) < 0 ||
2501 pa_tagstruct_getu32(t
, &type
) < 0)) ||
2502 !pa_tagstruct_eof(t
)) {
2507 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2508 CHECK_VALIDITY(c
->pstream
, name
|| idx
!= PA_IDXSET_INVALID
, tag
, PA_ERR_INVALID
);
2509 CHECK_VALIDITY(c
->pstream
, !name
|| (*name
&& (type
== 0 || type
== 1) && pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2512 a
= pa_autoload_get_by_name(c
->protocol
->core
, name
, type
== 0 ? PA_NAMEREG_SINK
: PA_NAMEREG_SOURCE
);
2514 a
= pa_autoload_get_by_index(c
->protocol
->core
, idx
);
2516 CHECK_VALIDITY(c
->pstream
, a
, tag
, PA_ERR_NOENTITY
);
2518 reply
= reply_new(tag
);
2519 autoload_fill_tagstruct(reply
, a
);
2520 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2523 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
) {
2524 connection
*c
= CONNECTION(userdata
);
2525 pa_tagstruct
*reply
;
2527 connection_assert_ref(c
);
2530 if (!pa_tagstruct_eof(t
)) {
2535 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2537 reply
= reply_new(tag
);
2539 if (c
->protocol
->core
->autoload_hashmap
) {
2540 pa_autoload_entry
*a
;
2543 while ((a
= pa_hashmap_iterate(c
->protocol
->core
->autoload_hashmap
, &state
, NULL
)))
2544 autoload_fill_tagstruct(reply
, a
);
2547 pa_pstream_send_tagstruct(c
->pstream
, reply
);
2550 static void command_move_stream(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
2551 connection
*c
= CONNECTION(userdata
);
2552 uint32_t idx
= PA_INVALID_INDEX
, idx_device
= PA_INVALID_INDEX
;
2553 const char *name
= NULL
;
2555 connection_assert_ref(c
);
2558 if (pa_tagstruct_getu32(t
, &idx
) < 0 ||
2559 pa_tagstruct_getu32(t
, &idx_device
) < 0 ||
2560 pa_tagstruct_gets(t
, &name
) < 0 ||
2561 !pa_tagstruct_eof(t
)) {
2566 CHECK_VALIDITY(c
->pstream
, c
->authorized
, tag
, PA_ERR_ACCESS
);
2567 CHECK_VALIDITY(c
->pstream
, idx
!= PA_INVALID_INDEX
, tag
, PA_ERR_INVALID
);
2568 CHECK_VALIDITY(c
->pstream
, idx_device
!= PA_INVALID_INDEX
|| !name
|| (*name
&& pa_utf8_valid(name
)), tag
, PA_ERR_INVALID
);
2570 if (command
== PA_COMMAND_MOVE_SINK_INPUT
) {
2571 pa_sink_input
*si
= NULL
;
2572 pa_sink
*sink
= NULL
;
2574 si
= pa_idxset_get_by_index(c
->protocol
->core
->sink_inputs
, idx
);
2576 if (idx_device
!= PA_INVALID_INDEX
)
2577 sink
= pa_idxset_get_by_index(c
->protocol
->core
->sinks
, idx_device
);
2579 sink
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SINK
, 1);
2581 CHECK_VALIDITY(c
->pstream
, si
&& sink
, tag
, PA_ERR_NOENTITY
);
2583 if (pa_sink_input_move_to(si
, sink
, 0) < 0) {
2584 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
2588 pa_source_output
*so
= NULL
;
2591 so
= pa_idxset_get_by_index(c
->protocol
->core
->source_outputs
, idx
);
2593 if (idx_device
!= PA_INVALID_INDEX
)
2594 source
= pa_idxset_get_by_index(c
->protocol
->core
->sources
, idx_device
);
2596 source
= pa_namereg_get(c
->protocol
->core
, name
, PA_NAMEREG_SOURCE
, 1);
2598 CHECK_VALIDITY(c
->pstream
, so
&& source
, tag
, PA_ERR_NOENTITY
);
2600 if (pa_source_output_move_to(so
, source
) < 0) {
2601 pa_pstream_send_error(c
->pstream
, tag
, PA_ERR_INVALID
);
2606 pa_pstream_send_simple_ack(c
->pstream
, tag
);
2609 /*** pstream callbacks ***/
2611 static void pstream_packet_callback(pa_pstream
*p
, pa_packet
*packet
, const pa_creds
*creds
, void *userdata
) {
2612 connection
*c
= CONNECTION(userdata
);
2616 connection_assert_ref(c
);
2618 if (pa_pdispatch_run(c
->pdispatch
, packet
, creds
, c
) < 0) {
2619 pa_log("invalid packet.");
2620 connection_unlink(c
);
2624 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
) {
2625 connection
*c
= CONNECTION(userdata
);
2626 output_stream
*stream
;
2630 connection_assert_ref(c
);
2632 if (!(stream
= OUTPUT_STREAM(pa_idxset_get_by_index(c
->output_streams
, channel
)))) {
2633 pa_log("client sent block for invalid stream.");
2638 if (playback_stream_isinstance(stream
)) {
2639 playback_stream
*ps
= PLAYBACK_STREAM(stream
);
2641 if (seek
!= PA_SEEK_RELATIVE
|| offset
!= 0)
2642 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
);
2644 pa_asyncmsgq_post(ps
->sink_input
->sink
->asyncmsgq
, PA_MSGOBJECT(ps
->sink_input
), SINK_INPUT_MESSAGE_POST_DATA
, NULL
, 0, chunk
, NULL
);
2647 upload_stream
*u
= UPLOAD_STREAM(stream
);
2650 if (!u
->memchunk
.memblock
) {
2651 if (u
->length
== chunk
->length
) {
2652 u
->memchunk
= *chunk
;
2653 pa_memblock_ref(u
->memchunk
.memblock
);
2656 u
->memchunk
.memblock
= pa_memblock_new(c
->protocol
->core
->mempool
, u
->length
);
2657 u
->memchunk
.index
= u
->memchunk
.length
= 0;
2661 pa_assert(u
->memchunk
.memblock
);
2664 if (l
> chunk
->length
)
2670 dst
= pa_memblock_acquire(u
->memchunk
.memblock
);
2671 src
= pa_memblock_acquire(chunk
->memblock
);
2673 memcpy((uint8_t*) dst
+ u
->memchunk
.index
+ u
->memchunk
.length
,
2674 (uint8_t*) src
+chunk
->index
, l
);
2676 pa_memblock_release(u
->memchunk
.memblock
);
2677 pa_memblock_release(chunk
->memblock
);
2679 u
->memchunk
.length
+= l
;
2685 static void pstream_die_callback(pa_pstream
*p
, void *userdata
) {
2686 connection
*c
= CONNECTION(userdata
);
2689 connection_assert_ref(c
);
2691 connection_unlink(c
);
2692 pa_log_info("connection died.");
2695 static void pstream_drain_callback(pa_pstream
*p
, void *userdata
) {
2696 connection
*c
= CONNECTION(userdata
);
2699 connection_assert_ref(c
);
2704 /*** client callbacks ***/
2706 static void client_kill_cb(pa_client
*c
) {
2709 connection_unlink(CONNECTION(c
->userdata
));
2712 /*** socket server callbacks ***/
2714 static void auth_timeout(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
2715 connection
*c
= CONNECTION(userdata
);
2719 connection_assert_ref(c
);
2720 pa_assert(c
->auth_timeout_event
== e
);
2723 connection_unlink(c
);
2726 static void on_connection(PA_GCC_UNUSED pa_socket_server
*s
, pa_iochannel
*io
, void *userdata
) {
2727 pa_protocol_native
*p
= userdata
;
2729 char cname
[256], pname
[128];
2735 if (pa_idxset_size(p
->connections
)+1 > MAX_CONNECTIONS
) {
2736 pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS
);
2737 pa_iochannel_free(io
);
2741 c
= pa_msgobject_new(connection
);
2742 c
->parent
.parent
.free
= connection_free
;
2744 c
->authorized
= !!p
->public;
2746 if (!c
->authorized
&& p
->auth_ip_acl
&& pa_ip_acl_check(p
->auth_ip_acl
, pa_iochannel_get_recv_fd(io
)) > 0) {
2747 pa_log_info("Client authenticated by IP ACL.");
2751 if (!c
->authorized
) {
2753 pa_gettimeofday(&tv
);
2754 tv
.tv_sec
+= AUTH_TIMEOUT
;
2755 c
->auth_timeout_event
= p
->core
->mainloop
->time_new(p
->core
->mainloop
, &tv
, auth_timeout
, c
);
2757 c
->auth_timeout_event
= NULL
;
2761 pa_iochannel_socket_peer_to_string(io
, pname
, sizeof(pname
));
2762 pa_snprintf(cname
, sizeof(cname
), "Native client (%s)", pname
);
2763 c
->client
= pa_client_new(p
->core
, __FILE__
, cname
);
2764 c
->client
->kill
= client_kill_cb
;
2765 c
->client
->userdata
= c
;
2766 c
->client
->owner
= p
->module
;
2768 c
->pstream
= pa_pstream_new(p
->core
->mainloop
, io
, p
->core
->mempool
);
2770 pa_pstream_set_recieve_packet_callback(c
->pstream
, pstream_packet_callback
, c
);
2771 pa_pstream_set_recieve_memblock_callback(c
->pstream
, pstream_memblock_callback
, c
);
2772 pa_pstream_set_die_callback(c
->pstream
, pstream_die_callback
, c
);
2773 pa_pstream_set_drain_callback(c
->pstream
, pstream_drain_callback
, c
);
2775 c
->pdispatch
= pa_pdispatch_new(p
->core
->mainloop
, command_table
, PA_COMMAND_MAX
);
2777 c
->record_streams
= pa_idxset_new(NULL
, NULL
);
2778 c
->output_streams
= pa_idxset_new(NULL
, NULL
);
2780 c
->rrobin_index
= PA_IDXSET_INVALID
;
2781 c
->subscription
= NULL
;
2783 pa_idxset_put(p
->connections
, c
, NULL
);
2786 if (pa_iochannel_creds_supported(io
))
2787 pa_iochannel_creds_enable(io
);
2792 /*** module entry points ***/
2794 static int load_key(pa_protocol_native
*p
, const char*fn
) {
2797 p
->auth_cookie_in_property
= 0;
2799 if (!fn
&& pa_authkey_prop_get(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0) {
2800 pa_log_info("using already loaded auth cookie.");
2801 pa_authkey_prop_ref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
2802 p
->auth_cookie_in_property
= 1;
2807 fn
= PA_NATIVE_COOKIE_FILE
;
2809 if (pa_authkey_load_auto(fn
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) < 0)
2812 pa_log_info("loading cookie from disk.");
2814 if (pa_authkey_prop_put(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, p
->auth_cookie
, sizeof(p
->auth_cookie
)) >= 0)
2815 p
->auth_cookie_in_property
= 1;
2820 static pa_protocol_native
* protocol_new_internal(pa_core
*c
, pa_module
*m
, pa_modargs
*ma
) {
2821 pa_protocol_native
*p
;
2828 if (pa_modargs_get_value_boolean(ma
, "auth-anonymous", &public) < 0) {
2829 pa_log("auth-anonymous= expects a boolean argument.");
2833 p
= pa_xnew(pa_protocol_native
, 1);
2838 p
->auth_ip_acl
= NULL
;
2843 if (pa_modargs_get_value_boolean(ma
, "auth-group-enabled", &a
) < 0) {
2844 pa_log("auth-group-enabled= expects a boolean argument.");
2847 p
->auth_group
= a
? pa_xstrdup(pa_modargs_get_value(ma
, "auth-group", c
->is_system_instance
? PA_ACCESS_GROUP
: NULL
)) : NULL
;
2850 pa_log_info("Allowing access to group '%s'.", p
->auth_group
);
2855 if ((acl
= pa_modargs_get_value(ma
, "auth-ip-acl", NULL
))) {
2857 if (!(p
->auth_ip_acl
= pa_ip_acl_new(acl
))) {
2858 pa_log("Failed to parse IP ACL '%s'", acl
);
2863 if (load_key(p
, pa_modargs_get_value(ma
, "cookie", NULL
)) < 0)
2866 p
->connections
= pa_idxset_new(NULL
, NULL
);
2872 pa_xfree(p
->auth_group
);
2875 pa_ip_acl_free(p
->auth_ip_acl
);
2880 pa_protocol_native
* pa_protocol_native_new(pa_core
*core
, pa_socket_server
*server
, pa_module
*m
, pa_modargs
*ma
) {
2882 pa_protocol_native
*p
;
2884 if (!(p
= protocol_new_internal(core
, m
, ma
)))
2888 pa_socket_server_set_callback(p
->server
, on_connection
, p
);
2890 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
2892 l
= pa_property_get(core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
2893 l
= pa_strlist_prepend(l
, t
);
2894 pa_property_replace(core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
2900 void pa_protocol_native_free(pa_protocol_native
*p
) {
2904 while ((c
= pa_idxset_first(p
->connections
, NULL
)))
2905 connection_unlink(c
);
2906 pa_idxset_free(p
->connections
, NULL
, NULL
);
2911 if (pa_socket_server_get_address(p
->server
, t
, sizeof(t
))) {
2913 l
= pa_property_get(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
2914 l
= pa_strlist_remove(l
, t
);
2917 pa_property_replace(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
, l
);
2919 pa_property_remove(p
->core
, PA_NATIVE_SERVER_PROPERTY_NAME
);
2922 pa_socket_server_unref(p
->server
);
2925 if (p
->auth_cookie_in_property
)
2926 pa_authkey_prop_unref(p
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
2929 pa_ip_acl_free(p
->auth_ip_acl
);
2932 pa_xfree(p
->auth_group
);
2937 pa_protocol_native
* pa_protocol_native_new_iochannel(
2943 pa_protocol_native
*p
;
2945 if (!(p
= protocol_new_internal(core
, m
, ma
)))
2948 on_connection(NULL
, io
, p
);