]> code.delx.au - pulseaudio/blob - src/outputstream.c
make the whole stuff run and clean it self up again
[pulseaudio] / src / outputstream.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "outputstream.h"
6
7 struct output_stream* output_stream_new(struct source *s, struct sample_spec *spec, const char *name) {
8 struct output_stream *o;
9 int r;
10 assert(s && spec);
11
12 o = malloc(sizeof(struct output_stream));
13 assert(o);
14 o->name = name ? strdup(name) : NULL;
15 o->source = s;
16 o->spec = *spec;
17
18 o->memblockq = memblockq_new(bytes_per_second(spec)*5, sample_size(spec));
19 assert(o->memblockq);
20
21 assert(s->core);
22 r = idxset_put(s->core->output_streams, o, &o->index);
23 assert(r == 0 && o->index != IDXSET_INVALID);
24 r = idxset_put(s->output_streams, o, NULL);
25 assert(r == 0);
26
27 return o;
28 }
29
30 void output_stream_free(struct output_stream* o) {
31 assert(o);
32
33 memblockq_free(o->memblockq);
34
35 assert(o->source && o->source->core);
36 idxset_remove_by_data(o->source->core->output_streams, o, NULL);
37 idxset_remove_by_data(o->source->output_streams, o, NULL);
38
39 free(o->name);
40 free(o);
41 }