1 #include <pulsecore/pulsecore-config.h>
4 #include <pulsecore/card.h>
13 static pa_hook_result_t card_put(void *, void *, void *);
14 static pa_hook_result_t card_unlink(void *, void *, void *);
15 static pa_hook_result_t card_profile_changed(void *, void *, void *);
17 static pa_hook_result_t sink_put(void *, void *, void *);
18 static pa_hook_result_t sink_unlink(void *, void *, void *);
19 static pa_hook_result_t sink_port_changed(void *, void *, void *);
20 static pa_hook_result_t sink_port_available_changed(void *, void *, void *);
22 static pa_hook_result_t source_put(void *, void *, void *);
23 static pa_hook_result_t source_unlink(void *, void *, void *);
24 static pa_hook_result_t source_port_changed(void *, void *, void *);
25 static pa_hook_result_t source_port_available_changed(void *, void *, void *);
27 static pa_hook_result_t sink_input_new(void *, void *, void *);
28 static pa_hook_result_t sink_input_put(void *, void *, void *);
29 static pa_hook_result_t sink_input_unlink(void *, void *, void *);
32 pa_tracker *pa_tracker_init(struct userdata *u)
39 pa_source_hooks *source;
40 pa_sink_input_hooks *sinp;
43 pa_assert_se((core = u->core));
44 pa_assert_se((hooks = core->hooks));
46 tracker = pa_xnew0(pa_tracker, 1);
47 card = &tracker->card;
48 sink = &tracker->sink;
49 source = &tracker->source;
50 sinp = &tracker->sink_input;
53 card->put = pa_hook_connect(
54 hooks + PA_CORE_HOOK_CARD_PUT,
55 PA_HOOK_LATE, card_put, u
57 card->unlink = pa_hook_connect(
58 hooks + PA_CORE_HOOK_CARD_UNLINK,
59 PA_HOOK_LATE, card_unlink, u
61 card->profchg = pa_hook_connect(
62 hooks + PA_CORE_HOOK_CARD_PROFILE_CHANGED,
63 PA_HOOK_LATE, card_profile_changed, u
66 sink->put = pa_hook_connect(
67 hooks + PA_CORE_HOOK_SINK_PUT,
68 PA_HOOK_LATE, sink_put, u
70 sink->unlink = pa_hook_connect(
71 hooks + PA_CORE_HOOK_SINK_UNLINK,
72 PA_HOOK_LATE, sink_unlink, u
74 sink->portchg = pa_hook_connect(
75 hooks + PA_CORE_HOOK_SINK_PORT_CHANGED,
76 PA_HOOK_LATE, sink_port_changed, u
78 sink->portavail = pa_hook_connect(
79 hooks + PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
80 PA_HOOK_LATE, sink_port_available_changed, u
83 source->put = pa_hook_connect(
84 hooks + PA_CORE_HOOK_SOURCE_PUT,
85 PA_HOOK_LATE, source_put, u
87 source->unlink = pa_hook_connect(
88 hooks + PA_CORE_HOOK_SOURCE_UNLINK,
89 PA_HOOK_LATE, source_unlink, u
91 source->portchg = pa_hook_connect(
92 hooks + PA_CORE_HOOK_SOURCE_PORT_CHANGED,
93 PA_HOOK_LATE, source_port_changed, u
95 source->portavail = pa_hook_connect(
96 hooks + PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
97 PA_HOOK_LATE, source_port_available_changed, u
100 sinp->neew = pa_hook_connect(
101 hooks + PA_CORE_HOOK_SINK_INPUT_NEW,
102 PA_HOOK_EARLY, sink_input_new, u
104 sinp->put = pa_hook_connect(
105 hooks + PA_CORE_HOOK_SINK_INPUT_PUT,
106 PA_HOOK_LATE, sink_input_put, u
108 sinp->unlink = pa_hook_connect(
109 hooks + PA_CORE_HOOK_SINK_INPUT_UNLINK,
110 PA_HOOK_LATE, sink_input_unlink, u
116 void pa_tracker_done(struct userdata *u)
121 pa_source_hooks *source;
122 pa_sink_input_hooks *sinp;
124 if (u && (tracker = u->tracker)) {
126 card = &tracker->card;
127 pa_hook_slot_free(card->put);
128 pa_hook_slot_free(card->unlink);
129 pa_hook_slot_free(card->profchg);
131 sink = &tracker->sink;
132 pa_hook_slot_free(sink->put);
133 pa_hook_slot_free(sink->unlink);
134 pa_hook_slot_free(sink->portchg);
135 pa_hook_slot_free(sink->portavail);
137 source = &tracker->source;
138 pa_hook_slot_free(source->put);
139 pa_hook_slot_free(source->unlink);
140 pa_hook_slot_free(source->portchg);
141 pa_hook_slot_free(source->portavail);
143 sinp = &tracker->sink_input;
144 pa_hook_slot_free(sinp->neew);
145 pa_hook_slot_free(sinp->put);
146 pa_hook_slot_free(sinp->unlink);
154 void pa_tracker_synchronize(struct userdata *u)
164 pa_assert_se((core = u->core));
166 pa_utils_new_stamp();
168 PA_IDXSET_FOREACH(card, core->cards, index) {
169 pa_discover_add_card(u, card);
172 PA_IDXSET_FOREACH(sink, core->sinks, index) {
173 pa_discover_add_sink(u, sink, FALSE);
176 PA_IDXSET_FOREACH(source, core->sources, index) {
177 pa_discover_add_source(u, source);
180 /* Hmm... we should first collect all sink-inputs, assign
181 priority to them, sort them, and call pa_discover_register_sink_input()
182 in reverse priority order. Until than we may experience sound leaks
183 unnecessary profile changes etc ... */
185 PA_IDXSET_FOREACH(sinp, core->sink_inputs, index) {
186 pa_discover_register_sink_input(u, sinp);
189 mir_router_make_routing(u);
193 static pa_hook_result_t card_put(void *hook_data,
197 pa_card *card = (pa_card *)call_data;
198 struct userdata *u = (struct userdata *)slot_data;
203 pa_utils_new_stamp();
204 pa_discover_add_card(u, card);
209 static pa_hook_result_t card_unlink(void *hook_data,
213 pa_card *card = (pa_card *)call_data;
214 struct userdata *u = (struct userdata *)slot_data;
220 pa_discover_remove_card(u, card);
222 mir_router_print_rtgroups(u, buf, sizeof(buf));
223 pa_log_debug("%s", buf);
225 mir_router_make_routing(u);
231 static pa_hook_result_t card_profile_changed(void *hook_data,
235 pa_card *card = (pa_card *)call_data;
236 struct userdata *u = (struct userdata *)slot_data;
241 pa_utils_new_stamp();
242 pa_discover_profile_changed(u, card);
248 static pa_hook_result_t sink_put(void *hook_data,
252 pa_sink *sink = (pa_sink *)call_data;
253 struct userdata *u = (struct userdata *)slot_data;
258 pa_utils_new_stamp();
259 pa_discover_add_sink(u, sink, TRUE);
265 static pa_hook_result_t sink_unlink(void *hook_data,
269 pa_sink *sink = (pa_sink *)call_data;
270 struct userdata *u = (struct userdata *)slot_data;
275 pa_discover_remove_sink(u, sink);
281 static pa_hook_result_t sink_port_changed(void *hook_data,
285 pa_sink *sink = (pa_sink *)call_data;
286 struct userdata *u = (struct userdata *)slot_data;
294 static pa_hook_result_t sink_port_available_changed(void *hook_data,
298 pa_sink *sink = (pa_sink *)call_data;
299 struct userdata *u = (struct userdata *)slot_data;
308 static pa_hook_result_t source_put(void *hook_data,
312 pa_source *source = (pa_source *)call_data;
313 struct userdata *u = (struct userdata *)slot_data;
318 pa_utils_new_stamp();
319 pa_discover_add_source(u, source);
325 static pa_hook_result_t source_unlink(void *hook_data,
329 pa_source *source = (pa_source *)call_data;
330 struct userdata *u = (struct userdata *)slot_data;
335 pa_discover_remove_source(u, source);
341 static pa_hook_result_t source_port_changed(void *hook_data,
345 pa_source *source = (pa_source *)call_data;
346 struct userdata *u = (struct userdata *)slot_data;
354 static pa_hook_result_t source_port_available_changed(void *hook_data,
358 pa_source *source = (pa_source *)call_data;
359 struct userdata *u = (struct userdata *)slot_data;
369 static pa_hook_result_t sink_input_new(void *hook_data,
373 pa_sink_input_new_data *data = (pa_sink_input_new_data *)call_data;
374 struct userdata *u = (struct userdata *)slot_data;
379 pa_utils_new_stamp();
380 pa_discover_preroute_sink_input(u, data);
385 static pa_hook_result_t sink_input_put(void *hook_data,
389 pa_sink_input *sinp = (pa_sink_input *)call_data;
390 struct userdata *u = (struct userdata *)slot_data;
395 pa_utils_new_stamp();
396 pa_discover_add_sink_input(u, sinp);
402 static pa_hook_result_t sink_input_unlink(void *hook_data,
406 struct pa_sink_input *sinp = (pa_sink_input *)call_data;
407 struct userdata *u = (struct userdata *)slot_data;
412 pa_discover_remove_sink_input(u, sinp);
421 * indent-tabs-mode: nil