7 #include "sourceoutput.h"
11 struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
15 assert(core && spec && name);
17 s = malloc(sizeof(struct pa_source));
20 if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) {
25 s->name = strdup(name);
26 s->description = NULL;
30 s->sample_spec = *spec;
31 s->outputs = pa_idxset_new(NULL, NULL);
37 r = pa_idxset_put(core->sources, s, &s->index);
38 assert(s->index != PA_IDXSET_INVALID && r >= 0);
40 pa_sample_snprint(st, sizeof(st), spec);
41 fprintf(stderr, "source: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
46 void pa_source_free(struct pa_source *s) {
47 struct pa_source_output *o, *j = NULL;
50 pa_namereg_unregister(s->core, s->name);
52 while ((o = pa_idxset_first(s->outputs, NULL))) {
54 pa_source_output_kill(o);
57 pa_idxset_free(s->outputs, NULL, NULL);
59 pa_idxset_remove_by_data(s->core->sources, s, NULL);
61 fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name);
68 void pa_source_notify(struct pa_source*s) {
75 static int do_post(void *p, uint32_t index, int *del, void*userdata) {
76 struct pa_memchunk *chunk = userdata;
77 struct pa_source_output *o = p;
78 assert(o && o->push && del && chunk);
80 pa_source_output_push(o, chunk);
84 void pa_source_post(struct pa_source*s, struct pa_memchunk *chunk) {
87 pa_idxset_foreach(s->outputs, do_post, chunk);
90 struct pa_source* pa_source_get_default(struct pa_core *c) {
91 struct pa_source *source;
94 if ((source = pa_idxset_get_by_index(c->sources, c->default_source_index)))
97 if (!(source = pa_idxset_first(c->sources, &c->default_source_index)))
100 fprintf(stderr, "core: default source vanished, setting to %u.\n", source->index);
104 char *pa_source_list_to_string(struct pa_core *c) {
106 struct pa_source *source, *default_source;
107 uint32_t index = PA_IDXSET_INVALID;
113 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
115 default_source = pa_source_get_default(c);
117 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
118 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
119 pa_sample_snprint(ss, sizeof(ss), &source->sample_spec);
120 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name, ss);
122 if (source->monitor_of)
123 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
125 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
126 if (source->description)
127 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
130 return pa_strbuf_tostring_free(s);
133 void pa_source_set_owner(struct pa_source *s, struct pa_module *m) {