[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 4 commits: stream-interaction: Support for triggering ducking/cork by source-output
Georg Chini
gitlab at gitlab.freedesktop.org
Tue Mar 26 15:19:58 UTC 2019
Georg Chini pushed to branch master at PulseAudio / pulseaudio
Commits:
0f4f109a by Sangchul Lee at 2019-03-26T14:54:15Z
stream-interaction: Support for triggering ducking/cork by source-output
Previously, media.role property of only sink-input is used to
determine to trigger and apply ducking or cork to sink-inputs.
On the other hand, some use cases require that source-output
also need to trigger the effect to sink-inputs. Therefore this
patch adds logic to retrieve source-ouputs to find trigger role
by checking media.role property and apply ducking/cork to sink-
inputs that meet conditions.
Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>
- - - - -
5540f728 by Sangchul Lee at 2019-03-26T14:54:15Z
stream-interaction: Use PA_IDXSET_FOREACH macro to iterate idxset
Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>
- - - - -
65cc86f6 by Sangchul Lee at 2019-03-26T14:54:15Z
role-ducking, role-cork: Add use_source_trigger argument
This is added to keep backward compatibility. The default value of
this new argument is false. Therefore, triggering by source-output
will be activated only if it is set to true explicitly.
Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>
- - - - -
a56c8a14 by Sangchul Lee at 2019-03-26T14:54:15Z
stream-interaction: Remove useless condition
Signed-off-by: Sangchul Lee
- - - - -
3 changed files:
- src/modules/module-role-cork.c
- src/modules/module-role-ducking.c
- src/modules/stream-interaction.c
Changes:
=====================================
src/modules/module-role-cork.c
=====================================
@@ -32,12 +32,15 @@ PA_MODULE_LOAD_ONCE(true);
PA_MODULE_USAGE(
"trigger_roles=<Comma separated list of roles which will trigger a cork> "
"cork_roles=<Comma separated list of roles which will be corked> "
- "global=<Should we operate globally or only inside the same device?>");
+ "global=<Should we operate globally or only inside the same device?>"
+ "use_source_trigger=<Do we trigger a cork by a role of source-output as well as sink-input's? Default: false>"
+ );
static const char* const valid_modargs[] = {
"trigger_roles",
"cork_roles",
"global",
+ "use_source_trigger",
NULL
};
=====================================
src/modules/module-role-ducking.c
=====================================
@@ -34,6 +34,7 @@ PA_MODULE_USAGE(
"ducking_roles=<Comma(and slash) separated list of roles which will be ducked. Slash can divide the roles into groups>"
"global=<Should we operate globally or only inside the same device?>"
"volume=<Volume for the attenuated streams. Default: -20dB. If trigger_roles and ducking_roles are separated by slash, use slash for dividing volume group>"
+ "use_source_trigger=<Do we trigger a ducking by a role of source-output as well as sink-input's? Default: false>"
);
static const char* const valid_modargs[] = {
@@ -41,6 +42,7 @@ static const char* const valid_modargs[] = {
"ducking_roles",
"global",
"volume",
+ "use_source_trigger",
NULL
};
=====================================
src/modules/stream-interaction.c
=====================================
@@ -48,6 +48,7 @@ struct userdata {
struct group **groups;
bool global:1;
bool duck:1;
+ bool source_trigger:1;
pa_hook_slot
*sink_input_put_slot,
*sink_input_unlink_slot,
@@ -55,14 +56,29 @@ struct userdata {
*sink_input_move_finish_slot,
*sink_input_state_changed_slot,
*sink_input_mute_changed_slot,
- *sink_input_proplist_changed_slot;
+ *sink_input_proplist_changed_slot,
+ *source_output_put_slot,
+ *source_output_unlink_slot,
+ *source_output_move_start_slot,
+ *source_output_move_finish_slot,
+ *source_output_state_changed_slot,
+ *source_output_mute_changed_slot,
+ *source_output_proplist_changed_slot;
};
-static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct group *g) {
+static inline pa_object* GET_DEVICE_FROM_STREAM(pa_object *stream) {
+ return pa_sink_input_isinstance(stream) ? PA_OBJECT(PA_SINK_INPUT(stream)->sink) : PA_OBJECT(PA_SOURCE_OUTPUT(stream)->source);
+}
+
+static inline pa_proplist* GET_PROPLIST_FROM_STREAM(pa_object *stream) {
+ return pa_sink_input_isinstance(stream) ? PA_SINK_INPUT(stream)->proplist : PA_SOURCE_OUTPUT(stream)->proplist;
+}
+
+static const char *get_trigger_role(struct userdata *u, pa_object *stream, struct group *g) {
const char *role, *trigger_role;
uint32_t role_idx;
- if (!(role = pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
+ if (!(role = pa_proplist_gets(GET_PROPLIST_FROM_STREAM(stream), PA_PROP_MEDIA_ROLE)))
role = "no_role";
if (g == NULL) {
@@ -84,39 +100,54 @@ static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct
return NULL;
}
-static const char *find_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, struct group *g) {
- pa_sink_input *j;
+static const char *find_trigger_stream(struct userdata *u, pa_object *device, pa_object *ignore_stream, struct group *g) {
+ pa_object *j;
uint32_t idx;
const char *trigger_role;
pa_assert(u);
- pa_sink_assert_ref(s);
+ pa_object_assert_ref(device);
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
+ PA_IDXSET_FOREACH(j, pa_sink_isinstance(device) ? PA_SINK(device)->inputs : PA_SOURCE(device)->outputs, idx) {
+ if (j == ignore_stream)
+ continue;
- if (j == ignore)
+ if (!(trigger_role = get_trigger_role(u, PA_OBJECT(j), g)))
continue;
- trigger_role = get_trigger_role(u, j, g);
- if (trigger_role && !j->muted && j->state != PA_SINK_INPUT_CORKED)
- return trigger_role;
+ if (pa_sink_isinstance(device)) {
+ if (!PA_SINK_INPUT(j)->muted &&
+ PA_SINK_INPUT(j)->state != PA_SINK_INPUT_CORKED)
+ return trigger_role;
+ } else {
+ if (!PA_SOURCE_OUTPUT(j)->muted &&
+ PA_SOURCE_OUTPUT(j)->state != PA_SOURCE_OUTPUT_CORKED)
+ return trigger_role;
+ }
}
return NULL;
}
-static const char *find_global_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, struct group *g) {
+static const char *find_global_trigger_stream(struct userdata *u, pa_object *ignore_stream, struct group *g) {
const char *trigger_role = NULL;
+ pa_sink *sink;
+ pa_source *source;
+ uint32_t idx;
pa_assert(u);
- if (u->global) {
- uint32_t idx;
- PA_IDXSET_FOREACH(s, u->core->sinks, idx)
- if ((trigger_role = find_trigger_stream(u, s, ignore, g)))
- break;
- } else
- trigger_role = find_trigger_stream(u, s, ignore, g);
+ /* Find any trigger role among the sink-inputs and source-outputs. */
+ PA_IDXSET_FOREACH(sink, u->core->sinks, idx)
+ if ((trigger_role = find_trigger_stream(u, PA_OBJECT(sink), ignore_stream, g)))
+ break;
+
+ if (!u->source_trigger || trigger_role)
+ return trigger_role;
+
+ PA_IDXSET_FOREACH(source, u->core->sources, idx)
+ if ((trigger_role = find_trigger_stream(u, PA_OBJECT(source), ignore_stream, g)))
+ break;
return trigger_role;
}
@@ -153,7 +184,7 @@ static void uncork_or_unduck(struct userdata *u, pa_sink_input *i, const char *i
}
}
-static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, const char *new_trigger, pa_sink_input *ignore, bool new_stream, struct group *g) {
+static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, const char *new_trigger, pa_sink_input *ignore_stream, bool new_stream, struct group *g) {
pa_sink_input *j;
uint32_t idx, role_idx;
const char *interaction_role;
@@ -162,11 +193,11 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
pa_assert(u);
pa_sink_assert_ref(s);
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
+ PA_IDXSET_FOREACH(j, s->inputs, idx) {
bool corked, interaction_applied;
const char *role;
- if (j == ignore)
+ if (j == ignore_stream)
continue;
if (!(role = pa_proplist_gets(j->proplist, PA_PROP_MEDIA_ROLE)))
@@ -175,8 +206,8 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
PA_IDXSET_FOREACH(interaction_role, g->interaction_roles, role_idx) {
if ((trigger = pa_streq(role, interaction_role)))
break;
- if ((trigger = (pa_streq(interaction_role, "any_role") && !get_trigger_role(u, j, g))))
- break;
+ if ((trigger = (pa_streq(interaction_role, "any_role") && !get_trigger_role(u, PA_OBJECT(j), g))))
+ break;
}
if (!trigger)
continue;
@@ -204,15 +235,14 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
}
}
-static void apply_interaction(struct userdata *u, pa_sink *s, const char *trigger_role, pa_sink_input *ignore, bool new_stream, struct group *g) {
+static void apply_interaction_global(struct userdata *u, const char *trigger_role, pa_sink_input *ignore_stream, bool new_stream, struct group *g) {
+ uint32_t idx;
+ pa_sink *s;
+
pa_assert(u);
- if (u->global) {
- uint32_t idx;
- PA_IDXSET_FOREACH(s, u->core->sinks, idx)
- apply_interaction_to_sink(u, s, trigger_role, ignore, new_stream, g);
- } else
- apply_interaction_to_sink(u, s, trigger_role, ignore, new_stream, g);
+ PA_IDXSET_FOREACH(s, u->core->sinks, idx)
+ apply_interaction_to_sink(u, s, trigger_role, ignore_stream, new_stream, g);
}
static void remove_interactions(struct userdata *u, struct group *g) {
@@ -223,9 +253,7 @@ static void remove_interactions(struct userdata *u, struct group *g) {
const char *role;
PA_IDXSET_FOREACH(s, u->core->sinks, idx) {
-
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx_input)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx_input))) {
-
+ PA_IDXSET_FOREACH(j, s->inputs, idx_input) {
if(!!pa_hashmap_get(g->interaction_state, j)) {
corked = (j->state == PA_SINK_INPUT_CORKED);
if (!(role = pa_proplist_gets(j->proplist, PA_PROP_MEDIA_ROLE)))
@@ -236,23 +264,38 @@ static void remove_interactions(struct userdata *u, struct group *g) {
}
}
-static pa_hook_result_t process(struct userdata *u, pa_sink_input *i, bool create, bool new_stream) {
+static pa_hook_result_t process(struct userdata *u, pa_object *stream, bool create, bool new_stream) {
const char *trigger_role;
uint32_t j;
pa_assert(u);
- pa_sink_input_assert_ref(i);
+ pa_object_assert_ref(stream);
if (!create)
for (j = 0; j < u->n_groups; j++)
- pa_hashmap_remove(u->groups[j]->interaction_state, i);
+ pa_hashmap_remove(u->groups[j]->interaction_state, stream);
- if (!i->sink)
+ if ((pa_sink_input_isinstance(stream) && !PA_SINK_INPUT(stream)->sink) ||
+ (pa_source_output_isinstance(stream) && !PA_SOURCE_OUTPUT(stream)->source))
return PA_HOOK_OK;
+ if (pa_source_output_isinstance(stream)) {
+ if (!u->source_trigger)
+ return PA_HOOK_OK;
+ /* If it is triggered from source-output with false of global option, no need to apply interaction. */
+ if (!u->global)
+ return PA_HOOK_OK;
+ }
+
for (j = 0; j < u->n_groups; j++) {
- trigger_role = find_global_trigger_stream(u, i->sink, create ? NULL : i, u->groups[j]);
- apply_interaction(u, i->sink, trigger_role, create ? NULL : i, new_stream, u->groups[j]);
+ if (u->global) {
+ trigger_role = find_global_trigger_stream(u, create ? NULL : stream, u->groups[j]);
+ apply_interaction_global(u, trigger_role, create ? NULL : (pa_sink_input_isinstance(stream) ? PA_SINK_INPUT(stream) : NULL), new_stream, u->groups[j]);
+ } else {
+ trigger_role = find_trigger_stream(u, GET_DEVICE_FROM_STREAM(stream), create ? NULL : stream, u->groups[j]);
+ if (pa_sink_input_isinstance(stream))
+ apply_interaction_to_sink(u, PA_SINK_INPUT(stream)->sink, trigger_role, create ? NULL : PA_SINK_INPUT(stream), new_stream, u->groups[j]);
+ }
}
return PA_HOOK_OK;
@@ -262,35 +305,35 @@ static pa_hook_result_t sink_input_put_cb(pa_core *core, pa_sink_input *i, struc
pa_core_assert_ref(core);
pa_sink_input_assert_ref(i);
- return process(u, i, true, true);
+ return process(u, PA_OBJECT(i), true, true);
}
static pa_hook_result_t sink_input_unlink_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
pa_sink_input_assert_ref(i);
- return process(u, i, false, false);
+ return process(u, PA_OBJECT(i), false, false);
}
static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
pa_core_assert_ref(core);
pa_sink_input_assert_ref(i);
- return process(u, i, false, false);
+ return process(u, PA_OBJECT(i), false, false);
}
static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
pa_core_assert_ref(core);
pa_sink_input_assert_ref(i);
- return process(u, i, true, false);
+ return process(u, PA_OBJECT(i), true, false);
}
static pa_hook_result_t sink_input_state_changed_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
pa_core_assert_ref(core);
pa_sink_input_assert_ref(i);
- if (PA_SINK_INPUT_IS_LINKED(i->state) && get_trigger_role(u, i, NULL))
- return process(u, i, true, false);
+ if (PA_SINK_INPUT_IS_LINKED(i->state) && get_trigger_role(u, PA_OBJECT(i), NULL))
+ return process(u, PA_OBJECT(i), true, false);
return PA_HOOK_OK;
}
@@ -299,8 +342,8 @@ static pa_hook_result_t sink_input_mute_changed_cb(pa_core *core, pa_sink_input
pa_core_assert_ref(core);
pa_sink_input_assert_ref(i);
- if (PA_SINK_INPUT_IS_LINKED(i->state) && get_trigger_role(u, i, NULL))
- return process(u, i, true, false);
+ if (PA_SINK_INPUT_IS_LINKED(i->state) && get_trigger_role(u, PA_OBJECT(i), NULL))
+ return process(u, PA_OBJECT(i), true, false);
return PA_HOOK_OK;
}
@@ -310,7 +353,64 @@ static pa_hook_result_t sink_input_proplist_changed_cb(pa_core *core, pa_sink_in
pa_sink_input_assert_ref(i);
if (PA_SINK_INPUT_IS_LINKED(i->state))
- return process(u, i, true, false);
+ return process(u, PA_OBJECT(i), true, false);
+
+ return PA_HOOK_OK;
+}
+
+static pa_hook_result_t source_output_put_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ return process(u, PA_OBJECT(o), true, true);
+}
+
+static pa_hook_result_t source_output_unlink_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_source_output_assert_ref(o);
+
+ return process(u, PA_OBJECT(o), false, false);
+}
+
+static pa_hook_result_t source_output_move_start_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ return process(u, PA_OBJECT(o), false, false);
+}
+
+static pa_hook_result_t source_output_move_finish_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ return process(u, PA_OBJECT(o), true, false);
+}
+
+static pa_hook_result_t source_output_state_changed_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && get_trigger_role(u, PA_OBJECT(o), NULL))
+ return process(u, PA_OBJECT(o), true, false);
+
+ return PA_HOOK_OK;
+}
+
+static pa_hook_result_t source_output_mute_changed_cb(pa_core *core, pa_source_output*o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && get_trigger_role(u, PA_OBJECT(o), NULL))
+ return process(u, PA_OBJECT(o), true, false);
+
+ return PA_HOOK_OK;
+}
+
+static pa_hook_result_t source_output_proplist_changed_cb(pa_core *core, pa_source_output *o, struct userdata *u) {
+ pa_core_assert_ref(core);
+ pa_source_output_assert_ref(o);
+
+ if (PA_SOURCE_OUTPUT_IS_LINKED(o->state))
+ return process(u, PA_OBJECT(o), true, false);
return PA_HOOK_OK;
}
@@ -321,6 +421,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
const char *roles;
char *roles_in_group = NULL;
bool global = false;
+ bool source_trigger = false;
uint32_t i = 0;
pa_assert(m);
@@ -489,6 +590,12 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
}
u->global = global;
+ if (pa_modargs_get_value_boolean(ma, "use_source_trigger", &source_trigger) < 0) {
+ pa_log("Invalid boolean parameter: use_source_trigger");
+ goto fail;
+ }
+ u->source_trigger = source_trigger;
+
u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u);
u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u);
u->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_start_cb, u);
@@ -496,6 +603,13 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
u->sink_input_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_state_changed_cb, u);
u->sink_input_mute_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MUTE_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_mute_changed_cb, u);
u->sink_input_proplist_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_proplist_changed_cb, u);
+ u->source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_output_put_cb, u);
+ u->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_output_unlink_cb, u);
+ u->source_output_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_LATE, (pa_hook_cb_t) source_output_move_start_cb, u);
+ u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) source_output_move_finish_cb, u);
+ u->source_output_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) source_output_state_changed_cb, u);
+ u->source_output_mute_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MUTE_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) source_output_mute_changed_cb, u);
+ u->source_output_proplist_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) source_output_proplist_changed_cb, u);
pa_modargs_free(ma);
@@ -549,6 +663,20 @@ void pa_stream_interaction_done(pa_module *m) {
pa_hook_slot_free(u->sink_input_mute_changed_slot);
if (u->sink_input_proplist_changed_slot)
pa_hook_slot_free(u->sink_input_proplist_changed_slot);
+ if (u->source_output_put_slot)
+ pa_hook_slot_free(u->source_output_put_slot);
+ if (u->source_output_unlink_slot)
+ pa_hook_slot_free(u->source_output_unlink_slot);
+ if (u->source_output_move_start_slot)
+ pa_hook_slot_free(u->source_output_move_start_slot);
+ if (u->source_output_move_finish_slot)
+ pa_hook_slot_free(u->source_output_move_finish_slot);
+ if (u->source_output_state_changed_slot)
+ pa_hook_slot_free(u->source_output_state_changed_slot);
+ if (u->source_output_mute_changed_slot)
+ pa_hook_slot_free(u->source_output_mute_changed_slot);
+ if (u->source_output_proplist_changed_slot)
+ pa_hook_slot_free(u->source_output_proplist_changed_slot);
pa_xfree(u);
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/899b176f393e475df253e84b520ea0def454946e...a56c8a14d66d54bad9d119cc19071bb59eb183e8
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/899b176f393e475df253e84b520ea0def454946e...a56c8a14d66d54bad9d119cc19071bb59eb183e8
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20190326/2b252a83/attachment-0001.html>
More information about the pulseaudio-commits
mailing list