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 "sinkinput.h"
|
2004-06-18 17:12:50 +00:00
|
|
|
#include "strbuf.h"
|
2004-06-29 20:37:24 +00:00
|
|
|
#include "sample-util.h"
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-23 23:17:30 +00:00
|
|
|
struct sink_input* sink_input_new(struct sink *s, struct pa_sample_spec *spec, const char *name) {
|
2004-06-15 17:05:03 +00:00
|
|
|
struct sink_input *i;
|
2004-06-08 23:54:24 +00:00
|
|
|
int r;
|
|
|
|
|
assert(s && spec);
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
i = malloc(sizeof(struct sink_input));
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(i);
|
|
|
|
|
i->name = name ? strdup(name) : NULL;
|
|
|
|
|
i->sink = s;
|
2004-06-23 23:17:30 +00:00
|
|
|
i->sample_spec = *spec;
|
2004-06-15 00:29:01 +00:00
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
i->peek = NULL;
|
|
|
|
|
i->drop = NULL;
|
2004-06-14 20:30:50 +00:00
|
|
|
i->kill = NULL;
|
2004-06-18 17:12:50 +00:00
|
|
|
i->get_latency = NULL;
|
2004-06-15 17:05:03 +00:00
|
|
|
i->userdata = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-29 20:37:24 +00:00
|
|
|
i->volume = VOLUME_NORM;
|
2004-06-19 01:01:09 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(s->core);
|
2004-06-15 17:05:03 +00:00
|
|
|
r = idxset_put(s->core->sink_inputs, i, &i->index);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(r == 0 && i->index != IDXSET_INVALID);
|
2004-06-15 17:05:03 +00:00
|
|
|
r = idxset_put(s->inputs, i, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(r == 0);
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
void sink_input_free(struct sink_input* i) {
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(i);
|
|
|
|
|
|
|
|
|
|
assert(i->sink && i->sink->core);
|
2004-06-15 17:05:03 +00:00
|
|
|
idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL);
|
|
|
|
|
idxset_remove_by_data(i->sink->inputs, i, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
free(i->name);
|
|
|
|
|
free(i);
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
void sink_input_kill(struct sink_input*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-15 00:29:01 +00:00
|
|
|
}
|
2004-06-18 17:12:50 +00:00
|
|
|
|
|
|
|
|
char *sink_input_list_to_string(struct core *c) {
|
|
|
|
|
struct strbuf *s;
|
|
|
|
|
struct sink_input *i;
|
|
|
|
|
uint32_t index = IDXSET_INVALID;
|
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
|
|
s = strbuf_new();
|
|
|
|
|
assert(s);
|
|
|
|
|
|
|
|
|
|
strbuf_printf(s, "%u sink input(s) available.\n", idxset_ncontents(c->sink_inputs));
|
|
|
|
|
|
|
|
|
|
for (i = idxset_first(c->sink_inputs, &index); i; i = idxset_next(c->sink_inputs, &index)) {
|
|
|
|
|
assert(i->sink);
|
2004-06-29 20:37:24 +00:00
|
|
|
strbuf_printf(s, " index: %u, name: <%s>, sink: <%u>; volume: <0x%04x>, latency: <%u usec>\n",
|
2004-06-18 17:12:50 +00:00
|
|
|
i->index,
|
|
|
|
|
i->name,
|
|
|
|
|
i->sink->index,
|
|
|
|
|
(unsigned) i->volume,
|
|
|
|
|
sink_input_get_latency(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strbuf_tostring_free(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t sink_input_get_latency(struct sink_input *i) {
|
|
|
|
|
uint32_t l = 0;
|
|
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
|
if (i->get_latency)
|
|
|
|
|
l += i->get_latency(i);
|
|
|
|
|
|
|
|
|
|
assert(i->sink);
|
|
|
|
|
l += sink_get_latency(i->sink);
|
|
|
|
|
|
|
|
|
|
return l;
|
|
|
|
|
}
|
2004-07-02 18:47:03 +00:00
|
|
|
|