2004-06-08 23:54:24 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "source.h"
|
|
|
|
|
#include "outputstream.h"
|
|
|
|
|
|
|
|
|
|
struct source* source_new(struct core *core, const char *name, const struct sample_spec *spec) {
|
|
|
|
|
struct source *s;
|
|
|
|
|
int r;
|
|
|
|
|
assert(core && spec);
|
|
|
|
|
|
|
|
|
|
s = malloc(sizeof(struct source));
|
|
|
|
|
assert(s);
|
|
|
|
|
|
|
|
|
|
s->name = name ? strdup(name) : NULL;
|
|
|
|
|
r = idxset_put(core->sources, s, &s->index);
|
|
|
|
|
assert(s->index != IDXSET_INVALID && r >= 0);
|
|
|
|
|
|
|
|
|
|
s->core = core;
|
|
|
|
|
s->sample_spec = *spec;
|
|
|
|
|
s->output_streams = idxset_new(NULL, NULL);
|
|
|
|
|
|
|
|
|
|
s->link_change_callback = NULL;
|
|
|
|
|
s->userdata = NULL;
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void source_free(struct source *s) {
|
2004-06-11 21:30:16 +00:00
|
|
|
struct output_stream *o;
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(s);
|
|
|
|
|
|
2004-06-11 21:30:16 +00:00
|
|
|
while ((o = idxset_rrobin(s->output_streams, NULL)))
|
|
|
|
|
output_stream_free(o);
|
|
|
|
|
idxset_free(s->output_streams, NULL, NULL);
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
idxset_remove_by_data(s->core->sources, s, NULL);
|
2004-06-11 21:30:16 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
free(s->name);
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int do_post(void *p, uint32_t index, int *del, void*userdata) {
|
|
|
|
|
struct memchunk *chunk = userdata;
|
|
|
|
|
struct output_stream *o = p;
|
|
|
|
|
assert(o && o->memblockq && index && del && chunk);
|
|
|
|
|
|
|
|
|
|
memblockq_push(o->memblockq, chunk, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void source_post(struct source*s, struct memchunk *chunk) {
|
|
|
|
|
assert(s && chunk);
|
|
|
|
|
|
|
|
|
|
idxset_foreach(s->output_streams, do_post, chunk);
|
|
|
|
|
}
|