]> code.delx.au - pulseaudio/blob - src/pulsecore/protocol-simple.c
Remove unnecessary #includes
[pulseaudio] / src / pulsecore / protocol-simple.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <errno.h>
29
30 #include <pulse/xmalloc.h>
31 #include <pulse/timeval.h>
32
33 #include <pulsecore/sink-input.h>
34 #include <pulsecore/source-output.h>
35 #include <pulsecore/client.h>
36 #include <pulsecore/sample-util.h>
37 #include <pulsecore/namereg.h>
38 #include <pulsecore/log.h>
39 #include <pulsecore/core-error.h>
40 #include <pulsecore/atomic.h>
41 #include <pulsecore/thread-mq.h>
42 #include <pulsecore/core-util.h>
43 #include <pulsecore/shared.h>
44
45 #include "protocol-simple.h"
46
47 /* Don't allow more than this many concurrent connections */
48 #define MAX_CONNECTIONS 10
49
50 typedef struct connection {
51 pa_msgobject parent;
52 pa_simple_protocol *protocol;
53 pa_simple_options *options;
54 pa_iochannel *io;
55 pa_sink_input *sink_input;
56 pa_source_output *source_output;
57 pa_client *client;
58 pa_memblockq *input_memblockq, *output_memblockq;
59
60 pa_bool_t dead;
61
62 struct {
63 pa_memblock *current_memblock;
64 size_t memblock_index;
65 pa_atomic_t missing;
66 pa_bool_t underrun;
67 } playback;
68 } connection;
69
70 PA_DEFINE_PRIVATE_CLASS(connection, pa_msgobject);
71 #define CONNECTION(o) (connection_cast(o))
72
73 struct pa_simple_protocol {
74 PA_REFCNT_DECLARE;
75
76 pa_core *core;
77 pa_idxset *connections;
78 };
79
80 enum {
81 SINK_INPUT_MESSAGE_POST_DATA = PA_SINK_INPUT_MESSAGE_MAX, /* data from main loop to sink input */
82 SINK_INPUT_MESSAGE_DISABLE_PREBUF /* disabled prebuf, get playback started. */
83 };
84
85 enum {
86 CONNECTION_MESSAGE_REQUEST_DATA, /* data requested from sink input from the main loop */
87 CONNECTION_MESSAGE_POST_DATA, /* data from source output to main loop */
88 CONNECTION_MESSAGE_UNLINK_CONNECTION /* Please drop a aconnection now */
89 };
90
91 #define PLAYBACK_BUFFER_SECONDS (.5)
92 #define PLAYBACK_BUFFER_FRAGMENTS (10)
93 #define RECORD_BUFFER_SECONDS (5)
94 #define DEFAULT_SINK_LATENCY (300*PA_USEC_PER_MSEC)
95 #define DEFAULT_SOURCE_LATENCY (300*PA_USEC_PER_MSEC)
96
97 static void connection_unlink(connection *c) {
98 pa_assert(c);
99
100 if (!c->protocol)
101 return;
102
103 if (c->options) {
104 pa_simple_options_unref(c->options);
105 c->options = NULL;
106 }
107
108 if (c->sink_input) {
109 pa_sink_input_unlink(c->sink_input);
110 pa_sink_input_unref(c->sink_input);
111 c->sink_input = NULL;
112 }
113
114 if (c->source_output) {
115 pa_source_output_unlink(c->source_output);
116 pa_source_output_unref(c->source_output);
117 c->source_output = NULL;
118 }
119
120 if (c->client) {
121 pa_client_free(c->client);
122 c->client = NULL;
123 }
124
125 if (c->io) {
126 pa_iochannel_free(c->io);
127 c->io = NULL;
128 }
129
130 pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
131 c->protocol = NULL;
132 connection_unref(c);
133 }
134
135 static void connection_free(pa_object *o) {
136 connection *c = CONNECTION(o);
137 pa_assert(c);
138
139 if (c->playback.current_memblock)
140 pa_memblock_unref(c->playback.current_memblock);
141
142 if (c->input_memblockq)
143 pa_memblockq_free(c->input_memblockq);
144 if (c->output_memblockq)
145 pa_memblockq_free(c->output_memblockq);
146
147 pa_xfree(c);
148 }
149
150 static int do_read(connection *c) {
151 pa_memchunk chunk;
152 ssize_t r;
153 size_t l;
154 void *p;
155 size_t space = 0;
156
157 connection_assert_ref(c);
158
159 if (!c->sink_input || (l = (size_t) pa_atomic_load(&c->playback.missing)) <= 0)
160 return 0;
161
162 if (c->playback.current_memblock) {
163
164 space = pa_memblock_get_length(c->playback.current_memblock) - c->playback.memblock_index;
165
166 if (space <= 0) {
167 pa_memblock_unref(c->playback.current_memblock);
168 c->playback.current_memblock = NULL;
169 }
170 }
171
172 if (!c->playback.current_memblock) {
173 pa_assert_se(c->playback.current_memblock = pa_memblock_new(c->protocol->core->mempool, (size_t) -1));
174 c->playback.memblock_index = 0;
175
176 space = pa_memblock_get_length(c->playback.current_memblock);
177 }
178
179 if (l > space)
180 l = space;
181
182 p = pa_memblock_acquire(c->playback.current_memblock);
183 r = pa_iochannel_read(c->io, (uint8_t*) p + c->playback.memblock_index, l);
184 pa_memblock_release(c->playback.current_memblock);
185
186 if (r <= 0) {
187
188 if (r < 0 && (errno == EINTR || errno == EAGAIN))
189 return 0;
190
191 pa_log_debug("read(): %s", r == 0 ? "EOF" : pa_cstrerror(errno));
192 return -1;
193 }
194
195 chunk.memblock = c->playback.current_memblock;
196 chunk.index = c->playback.memblock_index;
197 chunk.length = (size_t) r;
198
199 c->playback.memblock_index += (size_t) r;
200
201 pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, &chunk, NULL);
202 pa_atomic_sub(&c->playback.missing, (int) r);
203
204 return 0;
205 }
206
207 static int do_write(connection *c) {
208 pa_memchunk chunk;
209 ssize_t r;
210 void *p;
211
212 connection_assert_ref(c);
213
214 if (!c->source_output)
215 return 0;
216
217 if (pa_memblockq_peek(c->output_memblockq, &chunk) < 0) {
218 /* pa_log("peek failed"); */
219 return 0;
220 }
221
222 pa_assert(chunk.memblock);
223 pa_assert(chunk.length);
224
225 p = pa_memblock_acquire(chunk.memblock);
226 r = pa_iochannel_write(c->io, (uint8_t*) p+chunk.index, chunk.length);
227 pa_memblock_release(chunk.memblock);
228
229 pa_memblock_unref(chunk.memblock);
230
231 if (r < 0) {
232
233 if (errno == EINTR || errno == EAGAIN)
234 return 0;
235
236 pa_log("write(): %s", pa_cstrerror(errno));
237 return -1;
238 }
239
240 pa_memblockq_drop(c->output_memblockq, (size_t) r);
241
242 return 0;
243 }
244
245 static void do_work(connection *c) {
246 connection_assert_ref(c);
247
248 if (c->dead)
249 return;
250
251 if (pa_iochannel_is_readable(c->io))
252 if (do_read(c) < 0)
253 goto fail;
254
255 if (!c->sink_input && pa_iochannel_is_hungup(c->io))
256 goto fail;
257
258 if (pa_iochannel_is_writable(c->io))
259 if (do_write(c) < 0)
260 goto fail;
261
262 return;
263
264 fail:
265
266 if (c->sink_input) {
267
268 /* If there is a sink input, we first drain what we already have read before shutting down the connection */
269 c->dead = TRUE;
270
271 pa_iochannel_free(c->io);
272 c->io = NULL;
273
274 pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_DISABLE_PREBUF, NULL, 0, NULL, NULL);
275 } else
276 connection_unlink(c);
277 }
278
279 static int connection_process_msg(pa_msgobject *o, int code, void*userdata, int64_t offset, pa_memchunk *chunk) {
280 connection *c = CONNECTION(o);
281 connection_assert_ref(c);
282
283 if (!c->protocol)
284 return -1;
285
286 switch (code) {
287 case CONNECTION_MESSAGE_REQUEST_DATA:
288 do_work(c);
289 break;
290
291 case CONNECTION_MESSAGE_POST_DATA:
292 /* pa_log("got data %u", chunk->length); */
293 pa_memblockq_push_align(c->output_memblockq, chunk);
294 do_work(c);
295 break;
296
297 case CONNECTION_MESSAGE_UNLINK_CONNECTION:
298 connection_unlink(c);
299 break;
300 }
301
302 return 0;
303 }
304
305 /*** sink_input callbacks ***/
306
307 /* Called from thread context */
308 static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk) {
309 pa_sink_input *i = PA_SINK_INPUT(o);
310 connection*c;
311
312 pa_sink_input_assert_ref(i);
313 c = CONNECTION(i->userdata);
314 connection_assert_ref(c);
315
316 switch (code) {
317
318 case SINK_INPUT_MESSAGE_POST_DATA: {
319 pa_assert(chunk);
320
321 /* New data from the main loop */
322 pa_memblockq_push_align(c->input_memblockq, chunk);
323
324 if (pa_memblockq_is_readable(c->input_memblockq) && c->playback.underrun) {
325 pa_log_debug("Requesting rewind due to end of underrun.");
326 pa_sink_input_request_rewind(c->sink_input, 0, FALSE, TRUE, FALSE);
327 }
328
329 /* pa_log("got data, %u", pa_memblockq_get_length(c->input_memblockq)); */
330
331 return 0;
332 }
333
334 case SINK_INPUT_MESSAGE_DISABLE_PREBUF:
335 pa_memblockq_prebuf_disable(c->input_memblockq);
336 return 0;
337
338 case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
339 pa_usec_t *r = userdata;
340
341 *r = pa_bytes_to_usec(pa_memblockq_get_length(c->input_memblockq), &c->sink_input->sample_spec);
342
343 /* Fall through, the default handler will add in the extra
344 * latency added by the resampler */
345 }
346
347 default:
348 return pa_sink_input_process_msg(o, code, userdata, offset, chunk);
349 }
350 }
351
352 /* Called from thread context */
353 static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
354 connection *c;
355
356 pa_sink_input_assert_ref(i);
357 c = CONNECTION(i->userdata);
358 connection_assert_ref(c);
359 pa_assert(chunk);
360
361 if (pa_memblockq_peek(c->input_memblockq, chunk) < 0) {
362
363 c->playback.underrun = TRUE;
364
365 if (c->dead && pa_sink_input_safe_to_remove(i))
366 pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(c), CONNECTION_MESSAGE_UNLINK_CONNECTION, NULL, 0, NULL, NULL);
367
368 return -1;
369 } else {
370 size_t m;
371
372 chunk->length = PA_MIN(length, chunk->length);
373
374 c->playback.underrun = FALSE;
375
376 pa_memblockq_drop(c->input_memblockq, chunk->length);
377 m = pa_memblockq_pop_missing(c->input_memblockq);
378
379 if (m > 0)
380 if (pa_atomic_add(&c->playback.missing, (int) m) <= 0)
381 pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(c), CONNECTION_MESSAGE_REQUEST_DATA, NULL, 0, NULL, NULL);
382
383 return 0;
384 }
385 }
386
387 /* Called from thread context */
388 static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
389 connection *c;
390
391 pa_sink_input_assert_ref(i);
392 c = CONNECTION(i->userdata);
393 connection_assert_ref(c);
394
395 /* If we are in an underrun, then we don't rewind */
396 if (i->thread_info.underrun_for > 0)
397 return;
398
399 pa_memblockq_rewind(c->input_memblockq, nbytes);
400 }
401
402 /* Called from thread context */
403 static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes) {
404 connection *c;
405
406 pa_sink_input_assert_ref(i);
407 c = CONNECTION(i->userdata);
408 connection_assert_ref(c);
409
410 pa_memblockq_set_maxrewind(c->input_memblockq, nbytes);
411 }
412
413 /* Called from main context */
414 static void sink_input_kill_cb(pa_sink_input *i) {
415 pa_sink_input_assert_ref(i);
416
417 connection_unlink(CONNECTION(i->userdata));
418 }
419
420 /*** source_output callbacks ***/
421
422 /* Called from thread context */
423 static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) {
424 connection *c;
425
426 pa_source_output_assert_ref(o);
427 c = CONNECTION(o->userdata);
428 pa_assert(c);
429 pa_assert(chunk);
430
431 pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(c), CONNECTION_MESSAGE_POST_DATA, NULL, 0, chunk, NULL);
432 }
433
434 /* Called from main context */
435 static void source_output_kill_cb(pa_source_output *o) {
436 pa_source_output_assert_ref(o);
437
438 connection_unlink(CONNECTION(o->userdata));
439 }
440
441 /* Called from main context */
442 static pa_usec_t source_output_get_latency_cb(pa_source_output *o) {
443 connection*c;
444
445 pa_source_output_assert_ref(o);
446 c = CONNECTION(o->userdata);
447 pa_assert(c);
448
449 return pa_bytes_to_usec(pa_memblockq_get_length(c->output_memblockq), &c->source_output->sample_spec);
450 }
451
452 /*** client callbacks ***/
453
454 static void client_kill_cb(pa_client *client) {
455 connection*c;
456
457 pa_assert(client);
458 c = CONNECTION(client->userdata);
459 pa_assert(c);
460
461 connection_unlink(c);
462 }
463
464 /*** pa_iochannel callbacks ***/
465
466 static void io_callback(pa_iochannel*io, void *userdata) {
467 connection *c = CONNECTION(userdata);
468
469 connection_assert_ref(c);
470 pa_assert(io);
471
472 do_work(c);
473 }
474
475 /*** socket_server callbacks ***/
476
477 void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simple_options *o) {
478 connection *c = NULL;
479 char pname[128];
480 pa_client_new_data client_data;
481
482 pa_assert(p);
483 pa_assert(io);
484 pa_assert(o);
485
486 if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
487 pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
488 pa_iochannel_free(io);
489 return;
490 }
491
492 c = pa_msgobject_new(connection);
493 c->parent.parent.free = connection_free;
494 c->parent.process_msg = connection_process_msg;
495 c->io = io;
496 pa_iochannel_set_callback(c->io, io_callback, c);
497
498 c->sink_input = NULL;
499 c->source_output = NULL;
500 c->input_memblockq = c->output_memblockq = NULL;
501 c->protocol = p;
502 c->options = pa_simple_options_ref(o);
503 c->playback.current_memblock = NULL;
504 c->playback.memblock_index = 0;
505 c->dead = FALSE;
506 c->playback.underrun = TRUE;
507 pa_atomic_store(&c->playback.missing, 0);
508
509 pa_client_new_data_init(&client_data);
510 client_data.module = o->module;
511 client_data.driver = __FILE__;
512 pa_iochannel_socket_peer_to_string(io, pname, sizeof(pname));
513 pa_proplist_setf(client_data.proplist, PA_PROP_APPLICATION_NAME, "Simple client (%s)", pname);
514 pa_proplist_sets(client_data.proplist, "simple-protocol.peer", pname);
515 c->client = pa_client_new(p->core, &client_data);
516 pa_client_new_data_done(&client_data);
517
518 if (!c->client)
519 goto fail;
520
521 c->client->kill = client_kill_cb;
522 c->client->userdata = c;
523
524 if (o->playback) {
525 pa_sink_input_new_data data;
526 pa_memchunk silence;
527 size_t l;
528 pa_sink *sink;
529
530 if (!(sink = pa_namereg_get(c->protocol->core, o->default_sink, PA_NAMEREG_SINK))) {
531 pa_log("Failed to get sink.");
532 goto fail;
533 }
534
535 pa_sink_input_new_data_init(&data);
536 data.driver = __FILE__;
537 data.module = o->module;
538 data.client = c->client;
539 pa_sink_input_new_data_set_sink(&data, sink, FALSE);
540 pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
541 pa_sink_input_new_data_set_sample_spec(&data, &o->sample_spec);
542
543 pa_sink_input_new(&c->sink_input, p->core, &data);
544 pa_sink_input_new_data_done(&data);
545
546 if (!c->sink_input) {
547 pa_log("Failed to create sink input.");
548 goto fail;
549 }
550
551 c->sink_input->parent.process_msg = sink_input_process_msg;
552 c->sink_input->pop = sink_input_pop_cb;
553 c->sink_input->process_rewind = sink_input_process_rewind_cb;
554 c->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
555 c->sink_input->kill = sink_input_kill_cb;
556 c->sink_input->userdata = c;
557
558 pa_sink_input_set_requested_latency(c->sink_input, DEFAULT_SINK_LATENCY);
559
560 l = (size_t) ((double) pa_bytes_per_second(&o->sample_spec)*PLAYBACK_BUFFER_SECONDS);
561 pa_sink_input_get_silence(c->sink_input, &silence);
562 c->input_memblockq = pa_memblockq_new(
563 0,
564 l,
565 l,
566 pa_frame_size(&o->sample_spec),
567 (size_t) -1,
568 l/PLAYBACK_BUFFER_FRAGMENTS,
569 0,
570 &silence);
571 pa_memblock_unref(silence.memblock);
572
573 pa_iochannel_socket_set_rcvbuf(io, l);
574
575 pa_atomic_store(&c->playback.missing, (int) pa_memblockq_pop_missing(c->input_memblockq));
576
577 pa_sink_input_put(c->sink_input);
578 }
579
580 if (o->record) {
581 pa_source_output_new_data data;
582 size_t l;
583 pa_source *source;
584
585 if (!(source = pa_namereg_get(c->protocol->core, o->default_source, PA_NAMEREG_SOURCE))) {
586 pa_log("Failed to get source.");
587 goto fail;
588 }
589
590 pa_source_output_new_data_init(&data);
591 data.driver = __FILE__;
592 data.module = o->module;
593 data.client = c->client;
594 pa_source_output_new_data_set_source(&data, source, FALSE);
595 pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
596 pa_source_output_new_data_set_sample_spec(&data, &o->sample_spec);
597
598 pa_source_output_new(&c->source_output, p->core, &data);
599 pa_source_output_new_data_done(&data);
600
601 if (!c->source_output) {
602 pa_log("Failed to create source output.");
603 goto fail;
604 }
605 c->source_output->push = source_output_push_cb;
606 c->source_output->kill = source_output_kill_cb;
607 c->source_output->get_latency = source_output_get_latency_cb;
608 c->source_output->userdata = c;
609
610 pa_source_output_set_requested_latency(c->source_output, DEFAULT_SOURCE_LATENCY);
611
612 l = (size_t) (pa_bytes_per_second(&o->sample_spec)*RECORD_BUFFER_SECONDS);
613 c->output_memblockq = pa_memblockq_new(
614 0,
615 l,
616 0,
617 pa_frame_size(&o->sample_spec),
618 1,
619 0,
620 0,
621 NULL);
622 pa_iochannel_socket_set_sndbuf(io, l);
623
624 pa_source_output_put(c->source_output);
625 }
626
627 pa_idxset_put(p->connections, c, NULL);
628
629 return;
630
631 fail:
632 connection_unlink(c);
633 }
634
635 void pa_simple_protocol_disconnect(pa_simple_protocol *p, pa_module *m) {
636 connection *c;
637 void *state = NULL;
638
639 pa_assert(p);
640 pa_assert(m);
641
642 while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
643 if (c->options->module == m)
644 connection_unlink(c);
645 }
646
647 static pa_simple_protocol* simple_protocol_new(pa_core *c) {
648 pa_simple_protocol *p;
649
650 pa_assert(c);
651
652 p = pa_xnew(pa_simple_protocol, 1);
653 PA_REFCNT_INIT(p);
654 p->core = c;
655 p->connections = pa_idxset_new(NULL, NULL);
656
657 pa_assert_se(pa_shared_set(c, "simple-protocol", p) >= 0);
658
659 return p;
660 }
661
662 pa_simple_protocol* pa_simple_protocol_get(pa_core *c) {
663 pa_simple_protocol *p;
664
665 if ((p = pa_shared_get(c, "simple-protocol")))
666 return pa_simple_protocol_ref(p);
667
668 return simple_protocol_new(c);
669 }
670
671 pa_simple_protocol* pa_simple_protocol_ref(pa_simple_protocol *p) {
672 pa_assert(p);
673 pa_assert(PA_REFCNT_VALUE(p) >= 1);
674
675 PA_REFCNT_INC(p);
676
677 return p;
678 }
679
680 void pa_simple_protocol_unref(pa_simple_protocol *p) {
681 connection *c;
682 pa_assert(p);
683 pa_assert(PA_REFCNT_VALUE(p) >= 1);
684
685 if (PA_REFCNT_DEC(p) > 0)
686 return;
687
688 while ((c = pa_idxset_first(p->connections, NULL)))
689 connection_unlink(c);
690
691 pa_idxset_free(p->connections, NULL, NULL);
692
693 pa_assert_se(pa_shared_remove(p->core, "simple-protocol") >= 0);
694
695 pa_xfree(p);
696 }
697
698 pa_simple_options* pa_simple_options_new(void) {
699 pa_simple_options *o;
700
701 o = pa_xnew0(pa_simple_options, 1);
702 PA_REFCNT_INIT(o);
703
704 o->record = FALSE;
705 o->playback = TRUE;
706
707 return o;
708 }
709
710 pa_simple_options* pa_simple_options_ref(pa_simple_options *o) {
711 pa_assert(o);
712 pa_assert(PA_REFCNT_VALUE(o) >= 1);
713
714 PA_REFCNT_INC(o);
715
716 return o;
717 }
718
719 void pa_simple_options_unref(pa_simple_options *o) {
720 pa_assert(o);
721 pa_assert(PA_REFCNT_VALUE(o) >= 1);
722
723 if (PA_REFCNT_DEC(o) > 0)
724 return;
725
726 pa_xfree(o->default_sink);
727 pa_xfree(o->default_source);
728
729 pa_xfree(o);
730 }
731
732 int pa_simple_options_parse(pa_simple_options *o, pa_core *c, pa_modargs *ma) {
733 pa_bool_t enabled;
734
735 pa_assert(o);
736 pa_assert(PA_REFCNT_VALUE(o) >= 1);
737 pa_assert(ma);
738
739 o->sample_spec = c->default_sample_spec;
740 if (pa_modargs_get_sample_spec_and_channel_map(ma, &o->sample_spec, &o->channel_map, PA_CHANNEL_MAP_DEFAULT) < 0) {
741 pa_log("Failed to parse sample type specification.");
742 return -1;
743 }
744
745 pa_xfree(o->default_source);
746 o->default_source = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
747
748 pa_xfree(o->default_sink);
749 o->default_sink = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
750
751 enabled = o->record;
752 if (pa_modargs_get_value_boolean(ma, "record", &enabled) < 0) {
753 pa_log("record= expects a boolean argument.");
754 return -1;
755 }
756 o->record = enabled;
757
758 enabled = o->playback;
759 if (pa_modargs_get_value_boolean(ma, "playback", &enabled) < 0) {
760 pa_log("playback= expects a boolean argument.");
761 return -1;
762 }
763 o->playback = enabled;
764
765 if (!o->playback && !o->record) {
766 pa_log("neither playback nor recording enabled for protocol.");
767 return -1;
768 }
769
770 return 0;
771 }