2004-06-08 23:54:24 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
#include "sourceoutput.h"
|
2004-06-18 17:12:50 +00:00
|
|
|
#include "strbuf.h"
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-23 23:17:30 +00:00
|
|
|
struct source_output* source_output_new(struct source *s, struct pa_sample_spec *spec, const char *name) {
|
2004-06-15 17:05:03 +00:00
|
|
|
struct source_output *o;
|
2004-06-08 23:54:24 +00:00
|
|
|
int r;
|
|
|
|
|
assert(s && spec);
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
o = malloc(sizeof(struct source_output));
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(o);
|
|
|
|
|
o->name = name ? strdup(name) : NULL;
|
|
|
|
|
o->source = s;
|
2004-06-23 23:17:30 +00:00
|
|
|
o->sample_spec = *spec;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
o->push = NULL;
|
|
|
|
|
o->kill = NULL;
|
|
|
|
|
o->userdata = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
assert(s->core);
|
2004-06-15 17:05:03 +00:00
|
|
|
r = idxset_put(s->core->source_outputs, o, &o->index);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(r == 0 && o->index != IDXSET_INVALID);
|
2004-06-15 17:05:03 +00:00
|
|
|
r = idxset_put(s->outputs, o, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(r == 0);
|
|
|
|
|
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
void source_output_free(struct source_output* o) {
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(o);
|
|
|
|
|
|
|
|
|
|
assert(o->source && o->source->core);
|
2004-06-15 17:05:03 +00:00
|
|
|
idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
|
|
|
|
|
idxset_remove_by_data(o->source->outputs, o, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
free(o->name);
|
|
|
|
|
free(o);
|
|
|
|
|
}
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
void source_output_kill(struct source_output*i) {
|
2004-06-14 20:30:50 +00:00
|
|
|
assert(i);
|
|
|
|
|
|
|
|
|
|
if (i->kill)
|
2004-06-15 17:05:03 +00:00
|
|
|
i->kill(i);
|
2004-06-14 20:30:50 +00:00
|
|
|
}
|
2004-06-18 17:12:50 +00:00
|
|
|
|
|
|
|
|
char *source_output_list_to_string(struct core *c) {
|
|
|
|
|
struct strbuf *s;
|
|
|
|
|
struct source_output *o;
|
|
|
|
|
uint32_t index = IDXSET_INVALID;
|
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
|
|
s = strbuf_new();
|
|
|
|
|
assert(s);
|
|
|
|
|
|
|
|
|
|
strbuf_printf(s, "%u source outputs(s) available.\n", idxset_ncontents(c->source_outputs));
|
|
|
|
|
|
|
|
|
|
for (o = idxset_first(c->source_outputs, &index); o; o = idxset_next(c->source_outputs, &index)) {
|
|
|
|
|
assert(o->source);
|
|
|
|
|
strbuf_printf(s, " %c index: %u, name: <%s>, source: <%u>\n",
|
|
|
|
|
o->index,
|
|
|
|
|
o->name,
|
|
|
|
|
o->source->index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strbuf_tostring_free(s);
|
|
|
|
|
}
|