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-07-03 23:35:12 +00:00
|
|
|
struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
|
|
|
|
|
struct pa_source_output *o;
|
|
|
|
|
struct pa_resampler *resampler = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
int r;
|
|
|
|
|
assert(s && spec);
|
|
|
|
|
|
2004-07-03 00:19:17 +00:00
|
|
|
if (!pa_sample_spec_equal(&s->sample_spec, spec))
|
2004-07-03 23:35:12 +00:00
|
|
|
if (!(resampler = pa_resampler_new(&s->sample_spec, spec)))
|
2004-07-03 00:19:17 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
o = malloc(sizeof(struct pa_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-07-03 00:19:17 +00:00
|
|
|
o->resampler = resampler;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
assert(s->core);
|
2004-07-03 23:35:12 +00:00
|
|
|
r = pa_idxset_put(s->core->source_outputs, o, &o->index);
|
|
|
|
|
assert(r == 0 && o->index != PA_IDXSET_INVALID);
|
|
|
|
|
r = pa_idxset_put(s->outputs, o, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(r == 0);
|
|
|
|
|
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_source_output_free(struct pa_source_output* o) {
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(o);
|
|
|
|
|
|
|
|
|
|
assert(o->source && o->source->core);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
|
|
|
|
|
pa_idxset_remove_by_data(o->source->outputs, o, NULL);
|
2004-07-03 00:19:17 +00:00
|
|
|
|
|
|
|
|
if (o->resampler)
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_resampler_free(o->resampler);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
free(o->name);
|
|
|
|
|
free(o);
|
|
|
|
|
}
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_source_output_kill(struct pa_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
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
char *pa_source_output_list_to_string(struct pa_core *c) {
|
|
|
|
|
struct pa_strbuf *s;
|
|
|
|
|
struct pa_source_output *o;
|
|
|
|
|
uint32_t index = PA_IDXSET_INVALID;
|
2004-06-18 17:12:50 +00:00
|
|
|
assert(c);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
s = pa_strbuf_new();
|
2004-06-18 17:12:50 +00:00
|
|
|
assert(s);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
|
2004-06-18 17:12:50 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
|
2004-07-07 00:22:46 +00:00
|
|
|
char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
|
|
|
|
|
pa_sample_snprint(ss, sizeof(ss), &o->sample_spec);
|
2004-06-18 17:12:50 +00:00
|
|
|
assert(o->source);
|
2004-07-07 00:22:46 +00:00
|
|
|
pa_strbuf_printf(
|
|
|
|
|
s, " %c index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%u>\n",
|
|
|
|
|
o->index,
|
|
|
|
|
o->name,
|
|
|
|
|
o->source->index,
|
|
|
|
|
ss,
|
|
|
|
|
ss);
|
2004-06-18 17:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
return pa_strbuf_tostring_free(s);
|
2004-06-18 17:12:50 +00:00
|
|
|
}
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk) {
|
|
|
|
|
struct pa_memchunk rchunk;
|
2004-07-03 00:19:17 +00:00
|
|
|
assert(o && chunk && chunk->length && o->push);
|
|
|
|
|
|
|
|
|
|
if (!o->resampler) {
|
|
|
|
|
o->push(o, chunk);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_resampler_run(o->resampler, chunk, &rchunk);
|
2004-07-03 00:19:17 +00:00
|
|
|
if (!rchunk.length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(rchunk.memblock);
|
|
|
|
|
o->push(o, &rchunk);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_memblock_unref(rchunk.memblock);
|
2004-07-03 00:19:17 +00:00
|
|
|
}
|