2 This file is part of PulseAudio.
4 Copyright 2011 Colin Guthrie
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulse/xmalloc.h>
28 #include <pulsecore/macro.h>
29 #include <pulsecore/hook-list.h>
30 #include <pulsecore/core.h>
31 #include <pulsecore/core-util.h>
32 #include <pulsecore/sink-input.h>
33 #include <pulsecore/modargs.h>
35 #include "module-filter-heuristics-symdef.h"
37 #define PA_PROP_FILTER_APPLY_MOVING "filter.apply.moving"
38 #define PA_PROP_FILTER_HEURISTICS "filter.heuristics"
40 PA_MODULE_AUTHOR("Colin Guthrie");
41 PA_MODULE_DESCRIPTION("Detect when various filters are desirable");
42 PA_MODULE_VERSION(PACKAGE_VERSION);
43 PA_MODULE_LOAD_ONCE(TRUE);
45 static const char* const valid_modargs[] = {
53 *sink_input_move_finish_slot,
54 *source_output_put_slot,
55 *source_output_move_finish_slot;
58 static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_sink_input) {
60 pa_proplist *pl, *parent_pl;
63 pl = PA_SINK_INPUT(o)->proplist;
64 parent_pl = PA_SINK_INPUT(o)->sink->proplist;
66 pl = PA_SOURCE_OUTPUT(o)->proplist;
67 parent_pl = PA_SOURCE_OUTPUT(o)->source->proplist;
70 /* If the stream already specifies what it must have, then let it be. */
71 if (!pa_proplist_gets(pl, PA_PROP_FILTER_HEURISTICS) && pa_proplist_gets(pl, PA_PROP_FILTER_APPLY))
74 /* On phone sinks, make sure we're not applying echo cancellation */
75 if (pa_str_in_list_spaces(pa_proplist_gets(parent_pl, PA_PROP_DEVICE_INTENDED_ROLES), "phone")) {
76 const char *apply = pa_proplist_gets(pl, PA_PROP_FILTER_APPLY);
78 if (apply && pa_streq(apply, "echo-cancel")) {
79 pa_proplist_unset(pl, PA_PROP_FILTER_APPLY);
80 pa_proplist_unset(pl, PA_PROP_FILTER_HEURISTICS);
86 want = pa_proplist_gets(pl, PA_PROP_FILTER_WANT);
89 /* There's a filter that we want, ask module-filter-apply to apply it, and remember that we're managing filter.apply */
90 pa_proplist_sets(pl, PA_PROP_FILTER_APPLY, want);
91 pa_proplist_sets(pl, PA_PROP_FILTER_HEURISTICS, "1");
97 static pa_hook_result_t sink_input_put_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
98 pa_core_assert_ref(core);
99 pa_sink_input_assert_ref(i);
102 return process(u, PA_OBJECT(i), TRUE);
105 static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
106 pa_core_assert_ref(core);
107 pa_sink_input_assert_ref(i);
110 /* module-filter-apply triggered this move, ignore */
111 if (pa_proplist_gets(i->proplist, PA_PROP_FILTER_APPLY_MOVING))
114 return process(u, PA_OBJECT(i), TRUE);
117 static pa_hook_result_t source_output_put_cb(pa_core *core, pa_source_output *i, struct userdata *u) {
118 pa_core_assert_ref(core);
119 pa_source_output_assert_ref(i);
122 return process(u, PA_OBJECT(i), FALSE);
125 static pa_hook_result_t source_output_move_finish_cb(pa_core *core, pa_source_output *i, struct userdata *u) {
126 pa_core_assert_ref(core);
127 pa_source_output_assert_ref(i);
130 /* module-filter-apply triggered this move, ignore */
131 if (pa_proplist_gets(i->proplist, PA_PROP_FILTER_APPLY_MOVING))
134 return process(u, PA_OBJECT(i), FALSE);
137 int pa__init(pa_module *m) {
138 pa_modargs *ma = NULL;
143 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
144 pa_log("Failed to parse module arguments");
148 m->userdata = u = pa_xnew(struct userdata, 1);
152 u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_put_cb, u);
153 u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_move_finish_cb, u);
154 u->source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_put_cb, u);
155 u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_move_finish_cb, u);
172 void pa__done(pa_module *m) {
177 if (!(u = m->userdata))
180 if (u->sink_input_put_slot)
181 pa_hook_slot_free(u->sink_input_put_slot);
182 if (u->sink_input_move_finish_slot)
183 pa_hook_slot_free(u->sink_input_move_finish_slot);
184 if (u->source_output_put_slot)
185 pa_hook_slot_free(u->source_output_put_slot);
186 if (u->source_output_move_finish_slot)
187 pa_hook_slot_free(u->source_output_move_finish_slot);