]> code.delx.au - pulseaudio/blob - src/sinkinput.c
main part of the native protocol
[pulseaudio] / src / sinkinput.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "sinkinput.h"
6 #include "strbuf.h"
7
8 struct sink_input* sink_input_new(struct sink *s, struct pa_sample_spec *spec, const char *name) {
9 struct sink_input *i;
10 int r;
11 assert(s && spec);
12
13 i = malloc(sizeof(struct sink_input));
14 assert(i);
15 i->name = name ? strdup(name) : NULL;
16 i->sink = s;
17 i->sample_spec = *spec;
18
19 i->peek = NULL;
20 i->drop = NULL;
21 i->kill = NULL;
22 i->get_latency = NULL;
23 i->userdata = NULL;
24
25 i->volume = 0xFF;
26
27 assert(s->core);
28 r = idxset_put(s->core->sink_inputs, i, &i->index);
29 assert(r == 0 && i->index != IDXSET_INVALID);
30 r = idxset_put(s->inputs, i, NULL);
31 assert(r == 0);
32
33 return i;
34 }
35
36 void sink_input_free(struct sink_input* i) {
37 assert(i);
38
39 assert(i->sink && i->sink->core);
40 idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL);
41 idxset_remove_by_data(i->sink->inputs, i, NULL);
42
43 free(i->name);
44 free(i);
45 }
46
47 void sink_input_kill(struct sink_input*i) {
48 assert(i);
49
50 if (i->kill)
51 i->kill(i);
52 }
53
54 char *sink_input_list_to_string(struct core *c) {
55 struct strbuf *s;
56 struct sink_input *i;
57 uint32_t index = IDXSET_INVALID;
58 assert(c);
59
60 s = strbuf_new();
61 assert(s);
62
63 strbuf_printf(s, "%u sink input(s) available.\n", idxset_ncontents(c->sink_inputs));
64
65 for (i = idxset_first(c->sink_inputs, &index); i; i = idxset_next(c->sink_inputs, &index)) {
66 assert(i->sink);
67 strbuf_printf(s, " index: %u, name: <%s>, sink: <%u>; volume: <0x%02x>, latency: <%u usec>\n",
68 i->index,
69 i->name,
70 i->sink->index,
71 (unsigned) i->volume,
72 sink_input_get_latency(i));
73 }
74
75 return strbuf_tostring_free(s);
76 }
77
78 uint32_t sink_input_get_latency(struct sink_input *i) {
79 uint32_t l = 0;
80
81 assert(i);
82 if (i->get_latency)
83 l += i->get_latency(i);
84
85 assert(i->sink);
86 l += sink_get_latency(i->sink);
87
88 return l;
89 }