7 #include "sourceoutput.h"
9 struct source* source_new(struct core *core, const char *name, const struct sample_spec *spec) {
14 s = malloc(sizeof(struct source));
17 s->name = name ? strdup(name) : NULL;
19 s->sample_spec = *spec;
20 s->outputs = idxset_new(NULL, NULL);
25 r = idxset_put(core->sources, s, &s->index);
26 assert(s->index != IDXSET_INVALID && r >= 0);
28 fprintf(stderr, "source: created %u \"%s\"\n", s->index, s->name);
33 void source_free(struct source *s) {
34 struct source_output *o, *j = NULL;
37 while ((o = idxset_first(s->outputs, NULL))) {
39 source_output_kill(o);
42 idxset_free(s->outputs, NULL, NULL);
44 idxset_remove_by_data(s->core->sources, s, NULL);
46 fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name);
52 void source_notify(struct source*s) {
59 static int do_post(void *p, uint32_t index, int *del, void*userdata) {
60 struct memchunk *chunk = userdata;
61 struct source_output *o = p;
62 assert(o && o->push && del && chunk);
68 void source_post(struct source*s, struct memchunk *chunk) {
71 idxset_foreach(s->outputs, do_post, chunk);