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) {
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);
27 s->sample_spec = *spec;
28 s->outputs = pa_idxset_new(NULL, NULL);
34 r = pa_idxset_put(core->sources, s, &s->index);
35 assert(s->index != PA_IDXSET_INVALID && r >= 0);
37 pa_sample_snprint(st, sizeof(st), spec);
38 fprintf(stderr, "source: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
43 void pa_source_free(struct pa_source *s) {
44 struct pa_source_output *o, *j = NULL;
47 pa_namereg_unregister(s->core, s->name);
49 while ((o = pa_idxset_first(s->outputs, NULL))) {
51 pa_source_output_kill(o);
54 pa_idxset_free(s->outputs, NULL, NULL);
56 pa_idxset_remove_by_data(s->core->sources, s, NULL);
58 fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name);
64 void pa_source_notify(struct pa_source*s) {
71 static int do_post(void *p, uint32_t index, int *del, void*userdata) {
72 struct pa_memchunk *chunk = userdata;
73 struct pa_source_output *o = p;
74 assert(o && o->push && del && chunk);
76 pa_source_output_push(o, chunk);
80 void pa_source_post(struct pa_source*s, struct pa_memchunk *chunk) {
83 pa_idxset_foreach(s->outputs, do_post, chunk);
86 struct pa_source* pa_source_get_default(struct pa_core *c) {
87 struct pa_source *source;
90 if ((source = pa_idxset_get_by_index(c->sources, c->default_source_index)))
93 if (!(source = pa_idxset_first(c->sources, &c->default_source_index)))
96 fprintf(stderr, "core: default source vanished, setting to %u.\n", source->index);
100 char *pa_source_list_to_string(struct pa_core *c) {
102 struct pa_source *source, *default_source;
103 uint32_t index = PA_IDXSET_INVALID;
109 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
111 default_source = pa_source_get_default(c);
113 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
114 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
116 if (source->monitor_of)
117 snprintf(mo, sizeof(mo), "\n\tmonitor_of: <%u>", source->monitor_of->index);
118 pa_sample_snprint(ss, sizeof(ss), &source->sample_spec);
119 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>%s\n", source == default_source ? '*' : ' ', source->index, source->name, ss, mo);
122 return pa_strbuf_tostring_free(s);