]> code.delx.au - pulseaudio/blob - src/source.c
make the whole stuff run and clean it self up again
[pulseaudio] / src / source.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "source.h"
6 #include "outputstream.h"
7
8 struct source* source_new(struct core *core, const char *name, const struct sample_spec *spec) {
9 struct source *s;
10 int r;
11 assert(core && spec);
12
13 s = malloc(sizeof(struct source));
14 assert(s);
15
16 s->name = name ? strdup(name) : NULL;
17 r = idxset_put(core->sources, s, &s->index);
18 assert(s->index != IDXSET_INVALID && r >= 0);
19
20 s->core = core;
21 s->sample_spec = *spec;
22 s->output_streams = idxset_new(NULL, NULL);
23
24 s->link_change_callback = NULL;
25 s->userdata = NULL;
26
27 return s;
28 }
29
30 static void do_free(void *p, void *userdata) {
31 struct output_stream *o = p;
32 assert(o);
33 output_stream_free(o);
34 };
35
36 void source_free(struct source *s) {
37 struct output_stream *o;
38 assert(s);
39
40 while ((o = idxset_rrobin(s->output_streams, NULL)))
41 output_stream_free(o);
42 idxset_free(s->output_streams, NULL, NULL);
43
44 idxset_remove_by_data(s->core->sources, s, NULL);
45 idxset_free(s->output_streams, do_free, NULL);
46
47 free(s->name);
48 free(s);
49 }
50
51 static int do_post(void *p, uint32_t index, int *del, void*userdata) {
52 struct memchunk *chunk = userdata;
53 struct output_stream *o = p;
54 assert(o && o->memblockq && index && del && chunk);
55
56 memblockq_push(o->memblockq, chunk, 0);
57 return 0;
58 }
59
60 void source_post(struct source*s, struct memchunk *chunk) {
61 assert(s && chunk);
62
63 idxset_foreach(s->output_streams, do_post, chunk);
64 }