stream-interaction: Support for triggering ducking/cork by source-output 02/196302/4 accepted/tizen/unified/20190128.061524 submit/tizen/20190123.011037
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 21 Dec 2018 05:59:31 +0000 (14:59 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 21 Jan 2019 06:41:58 +0000 (15:41 +0900)
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.

TIZEN_VOLUME_RAMP is replaced by __TIZEN__ in this file because
it is hard to consider to branch all #define directives.

[Version] 11.1-56
[Issue Type] Enhancement

Change-Id: I44aaff0db4ff7bbbf2041228ca9e5b897f50a71a
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio.spec
src/modules/stream-interaction.c

index f73a689..4602492 100644 (file)
@@ -3,7 +3,7 @@
 Name:             pulseaudio
 Summary:          Improved Linux sound server
 Version:          11.1
-Release:          55
+Release:          56
 Group:            Multimedia/Audio
 License:          LGPL-2.1
 URL:              http://pulseaudio.org
index 795bdda..51d7f04 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "stream-interaction.h"
 
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
 struct fade_durations {
     long out;
     long in;
@@ -50,8 +50,8 @@ struct group {
     pa_hashmap *interaction_state;
 #endif
     pa_volume_t volume;
-#ifdef TIZEN_VOLUME_RAMP
-    pa_idxset *triggered_inputs;
+#ifdef __TIZEN__
+    pa_idxset *triggered_streams;
     struct fade_durations fade_durs;
     bool fade_needed:1;
 #endif
@@ -70,30 +70,51 @@ struct userdata {
         *sink_input_move_finish_slot,
         *sink_input_state_changed_slot,
         *sink_input_mute_changed_slot,
+#ifndef __TIZEN__
         *sink_input_proplist_changed_slot;
+#else
+        *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;
+#endif
 };
 
-#ifdef TIZEN_VOLUME_RAMP
-static const char *get_trigger_role_with_update_fade(struct userdata *u, pa_sink_input *i, bool new_stream, struct group *g) {
+#ifdef __TIZEN__
+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;
+}
+#endif
+
+#ifdef __TIZEN__
+static const char *get_trigger_role_with_update_fade(struct userdata *u, pa_object *stream, bool new_stream, struct group *g) {
 #else
 static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct group *g) {
 #endif
     const char *role, *trigger_role;
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
     uint32_t role_idx, trigger_idx;
     void *si;
 
     pa_assert(u);
-    pa_assert(i);
+    pa_assert(stream);
     pa_assert(g);
 #else
     uint32_t role_idx;
 #endif
 
-    if (!(role = pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
+#ifdef __TIZEN__
+    if (!(role = pa_proplist_gets(GET_PROPLIST_FROM_STREAM(stream), PA_PROP_MEDIA_ROLE)))
         role = "no_role";
 
-#ifdef TIZEN_VOLUME_RAMP
     if (u->duck && new_stream)
         g->fade_needed = true;
 
@@ -103,19 +124,22 @@ static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct
                 if (new_stream) {
                     /* Update fade state for this group which is for determining that
                      * the incoming stream should be ducked with fade in or just be ducked */
-                    PA_IDXSET_FOREACH(si, g->triggered_inputs, trigger_idx) {
-                        if (i == si) {
+                    PA_IDXSET_FOREACH(si, g->triggered_streams, trigger_idx) {
+                        if (stream == si) {
                             g->fade_needed = false;
                             break;
                         }
                     }
                 }
-                pa_idxset_put(g->triggered_inputs, i, NULL);
+                pa_idxset_put(g->triggered_streams, stream, NULL);
             }
             return trigger_role;
         }
     }
 #else
+    if (!(role = pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
+        role = "no_role";
+
     if (g == NULL) {
         /* get it from all groups */
         uint32_t j;
@@ -136,16 +160,16 @@ static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct
     return NULL;
 }
 
-#ifdef TIZEN_VOLUME_RAMP
-static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct group *g) {
+#ifdef __TIZEN__
+static const char *get_trigger_role(struct userdata *u, pa_object *stream, struct group *g) {
     const char *role, *trigger_role;
     uint32_t role_idx;
 
     pa_assert(u);
-    pa_assert(i);
+    pa_assert(stream);
     pa_assert(g);
 
-    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";
 
     PA_IDXSET_FOREACH(trigger_role, g->trigger_roles, role_idx)
@@ -155,57 +179,78 @@ static const char *get_trigger_role(struct userdata *u, pa_sink_input *i, struct
     return NULL;
 }
 
-static const char *get_trigger_role_all_groups(struct userdata *u, pa_sink_input *i) {
+static const char *get_trigger_role_all_groups(struct userdata *u, pa_object *stream) {
     const char *found = NULL;
     uint32_t j;
 
     pa_assert(u);
-    pa_assert(i);
+    pa_assert(stream);
 
     for (j = 0; j < u->n_groups; j++)
-        if ((found = get_trigger_role(u, i, u->groups[j])))
+        if ((found = get_trigger_role(u, stream, u->groups[j])))
             return found;
 
     return found;
 }
+#endif
 
-static const char *find_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, bool new_stream, struct group *g) {
+#ifdef __TIZEN__
+static const char *find_trigger_stream(struct userdata *u, pa_object *device, pa_object *ignore_stream, bool new_stream, struct group *g) {
+    pa_object *j;
 #else
 static const char *find_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, struct group *g) {
-#endif
     pa_sink_input *j;
+#endif
     uint32_t idx;
     const char *trigger_role;
 
     pa_assert(u);
+#ifdef __TIZEN__
+    pa_object_assert_ref(device);
+#else
     pa_sink_assert_ref(s);
+#endif
 
 #ifdef __TIZEN__
-    PA_IDXSET_FOREACH(j, 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;
 #else
     for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
-#endif
 
         if (j == ignore)
             continue;
+#endif
 
-#ifdef TIZEN_VOLUME_RAMP
-        if (u->duck && (g->fade_durs.in > 0 || g->fade_durs.out > 0))
-            trigger_role = get_trigger_role_with_update_fade(u, j, new_stream, g);
-        else
-            trigger_role = get_trigger_role(u, j, g);
+#ifdef __TIZEN__
+        if (u->duck && (g->fade_durs.in > 0 || g->fade_durs.out > 0)) {
+            if (!(trigger_role = get_trigger_role_with_update_fade(u, PA_OBJECT(j), new_stream, g)))
+                continue;
+        } else {
+            if (!(trigger_role = get_trigger_role(u, PA_OBJECT(j), g)))
+                continue;
+        }
+
+        if (pa_sink_isinstance(device)? !PA_SINK_INPUT(j)->muted && PA_SINK_INPUT(j)->state != PA_SINK_INPUT_CORKED :
+                            !PA_SOURCE_OUTPUT(j)->muted && PA_SOURCE_OUTPUT(j)->state != PA_SOURCE_OUTPUT_CORKED) {
+            return trigger_role;
+        }
+    }
 #else
         trigger_role = get_trigger_role(u, j, g);
-#endif
         if (trigger_role && !j->muted && pa_sink_input_get_state(j) != PA_SINK_INPUT_CORKED)
             return trigger_role;
     }
+#endif
 
     return NULL;
 }
 
-#ifdef TIZEN_VOLUME_RAMP
-static const char *find_global_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, bool new_stream, struct group *g) {
+#ifdef __TIZEN__
+static const char *find_global_trigger_stream(struct userdata *u, pa_object *ignore_stream, bool new_stream, struct group *g) {
+    pa_sink *sink;
+    pa_source *source;
+    uint32_t idx;
 #else
 static const char *find_global_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_input *ignore, struct group *g) {
 #endif
@@ -213,19 +258,25 @@ static const char *find_global_trigger_stream(struct userdata *u, pa_sink *s, pa
 
     pa_assert(u);
 
+#ifdef __TIZEN__
+    /* 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, new_stream, g)))
+            break;
+
+    if (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, new_stream, g)))
+            break;
+#else
     if (u->global) {
         uint32_t idx;
         PA_IDXSET_FOREACH(s, u->core->sinks, idx)
-#ifdef TIZEN_VOLUME_RAMP
-            if ((trigger_role = find_trigger_stream(u, s, ignore, new_stream, g)))
-#else
             if ((trigger_role = find_trigger_stream(u, s, ignore, g)))
-#endif
                 break;
     } else
-#ifdef TIZEN_VOLUME_RAMP
-        trigger_role = find_trigger_stream(u, s, ignore, new_stream, g);
-#else
         trigger_role = find_trigger_stream(u, s, ignore, g);
 #endif
 
@@ -235,7 +286,7 @@ static const char *find_global_trigger_stream(struct userdata *u, pa_sink *s, pa
 static void cork_or_duck(struct userdata *u, pa_sink_input *i, const char *interaction_role,  const char *trigger_role, bool interaction_applied, struct group *g) {
 
     if (u->duck && !interaction_applied) {
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         if (g->fade_durs.in || g->fade_durs.out) {
             pa_cvolume_ramp vol_ramp;
 
@@ -271,7 +322,7 @@ static void cork_or_duck(struct userdata *u, pa_sink_input *i, const char *inter
 #endif
 
     } else if (!u->duck) {
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         pa_log_debug("Found a '%s' stream that corks/mutes a '%s' stream(%u).", trigger_role, interaction_role, i->index);
 #else
         pa_log_debug("Found a '%s' stream that corks/mutes a '%s' stream.", trigger_role, interaction_role);
@@ -284,7 +335,7 @@ static void cork_or_duck(struct userdata *u, pa_sink_input *i, const char *inter
 static void uncork_or_unduck(struct userdata *u, pa_sink_input *i, const char *interaction_role, bool corked, struct group *g) {
 
     if (u->duck) {
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         if (g->fade_durs.in || g->fade_durs.out) {
             pa_log_debug("In '%s', found a '%s' stream(%u) that should be unducked with fade-in(%lums)",
                          g->name, interaction_role, i->index, g->fade_durs.in);
@@ -300,7 +351,7 @@ static void uncork_or_unduck(struct userdata *u, pa_sink_input *i, const char *i
 #endif
     }
     else if (corked || i->muted) {
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
        pa_log_debug("Found a '%s' stream(%u) that should be uncorked/unmuted.", interaction_role, i->index);
 #else
        pa_log_debug("Found a '%s' stream that should be uncorked/unmuted.", interaction_role);
@@ -312,7 +363,11 @@ static void uncork_or_unduck(struct userdata *u, pa_sink_input *i, const char *i
     }
 }
 
+#ifdef __TIZEN__
+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) {
+#else
 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) {
+#endif
     pa_sink_input *j;
     uint32_t idx, role_idx;
     const char *interaction_role;
@@ -329,7 +384,11 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
         bool corked, interaction_applied;
         const char *role;
 
+#ifdef __TIZEN__
+        if (j == ignore_stream)
+#else
         if (j == ignore)
+#endif
             continue;
 
         if (!(role = pa_proplist_gets(j->proplist, PA_PROP_MEDIA_ROLE)))
@@ -338,7 +397,11 @@ 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;
+#ifdef __TIZEN__
+            if ((trigger = (pa_streq(interaction_role, "any_role") && !get_trigger_role(u, PA_OBJECT(j), g))))
+#else
             if ((trigger = (pa_streq(interaction_role, "any_role") && !get_trigger_role(u, j, g))))
+#endif
                break;
         }
         if (!trigger)
@@ -382,6 +445,17 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
     }
 }
 
+#ifdef __TIZEN__
+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);
+
+    PA_IDXSET_FOREACH(s, u->core->sinks, idx)
+        apply_interaction_to_sink(u, s, trigger_role, ignore_stream, new_stream, g);
+}
+#else
 static void apply_interaction(struct userdata *u, pa_sink *s, const char *trigger_role, pa_sink_input *ignore, bool new_stream, struct group *g) {
     pa_assert(u);
 
@@ -392,6 +466,7 @@ static void apply_interaction(struct userdata *u, pa_sink *s, const char *trigge
     } else
         apply_interaction_to_sink(u, s, trigger_role, ignore, new_stream, g);
 }
+#endif
 
 static void remove_interactions(struct userdata *u, struct group *g) {
     uint32_t idx, idx_input;
@@ -419,85 +494,123 @@ 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) {
+#ifdef __TIZEN__
+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);
 
-#ifdef __TIZEN__
-#ifdef TIZEN_VOLUME_RAMP
     if (!create) {
         for (j = 0; j < u->n_groups; j++) {
-            pa_idxset_remove_by_data(u->groups[j]->interacted_inputs, i, NULL);
+            if (pa_sink_input_isinstance(stream))
+                pa_idxset_remove_by_data(u->groups[j]->interacted_inputs, stream, NULL);
+
             if (u->duck)
-                pa_idxset_remove_by_data(u->groups[j]->triggered_inputs, i, NULL);
+                pa_idxset_remove_by_data(u->groups[j]->triggered_streams, stream, NULL);
         }
     }
+
+    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 it is triggered from source-output with false of global option, no need to apply interaction. */
+    if (!u->global && pa_source_output_isinstance(stream))
+        return PA_HOOK_OK;
+
+    for (j = 0; j < u->n_groups; j++) {
+        if (u->global) {
+            trigger_role = find_global_trigger_stream(u, create ? NULL : stream, new_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, new_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;
+}
 #else
-    if (!create)
-        for (j = 0; j < u->n_groups; j++)
-            pa_idxset_remove_by_data(u->groups[j]->interacted_inputs, i, NULL);
-#endif /* TIZEN_VOLUME_RAMP */
-#else
+static pa_hook_result_t process(struct userdata *u, pa_sink_input *i, bool create, bool new_stream) {
+    const char *trigger_role;
+    uint32_t j;
+
+    pa_assert(u);
+    pa_sink_input_assert_ref(i);
+
     if (!create)
         for (j = 0; j < u->n_groups; j++)
             pa_hashmap_remove(u->groups[j]->interaction_state, i);
-#endif
 
     if (!i->sink)
         return PA_HOOK_OK;
 
     for (j = 0; j < u->n_groups; j++) {
-#ifdef TIZEN_VOLUME_RAMP
-        trigger_role = find_global_trigger_stream(u, i->sink, create ? NULL : i, new_stream, u->groups[j]);
-#else
         trigger_role = find_global_trigger_stream(u, i->sink, create ? NULL : i, u->groups[j]);
-#endif
         apply_interaction(u, i->sink, trigger_role, create ? NULL : i, new_stream, u->groups[j]);
     }
 
     return PA_HOOK_OK;
 }
+#endif
 
 static pa_hook_result_t sink_input_put_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
     pa_core_assert_ref(core);
     pa_sink_input_assert_ref(i);
 
+#ifdef __TIZEN__
+    return process(u, PA_OBJECT(i), true, true);
+#else
     return process(u, i, true, true);
+#endif
 }
 
 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);
 
+#ifdef __TIZEN__
+    return process(u, PA_OBJECT(i), false, false);
+#else
     return process(u, i, false, false);
+#endif
 }
 
 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);
 
+#ifdef __TIZEN__
+    return process(u, PA_OBJECT(i), false, false);
+#else
     return process(u, i, false, false);
+#endif
 }
 
 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);
 
+#ifdef __TIZEN__
+    return process(u, PA_OBJECT(i), true, false);
+#else
     return process(u, i, true, false);
+#endif
 }
 
 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);
 
-#ifdef TIZEN_VOLUME_RAMP
-    if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role_all_groups(u, i))
+#ifdef __TIZEN__
+    if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role_all_groups(u, PA_OBJECT(i)))
+        return process(u, PA_OBJECT(i), true, false);
 #else
     if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role(u, i, NULL))
-#endif
         return process(u, i, true, false);
+#endif
 
     return PA_HOOK_OK;
 }
@@ -506,12 +619,13 @@ 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);
 
-#ifdef TIZEN_VOLUME_RAMP
-    if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role_all_groups(u, i))
+#ifdef __TIZEN__
+    if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role_all_groups(u, PA_OBJECT(i)))
+        return process(u, PA_OBJECT(i), true, false);
 #else
     if (PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(i)) && get_trigger_role(u, i, NULL))
-#endif
         return process(u, i, true, false);
+#endif
 
     return PA_HOOK_OK;
 }
@@ -521,11 +635,74 @@ 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(pa_sink_input_get_state(i)))
+#ifdef __TIZEN__
+        return process(u, PA_OBJECT(i), true, false);
+#else
         return process(u, i, true, false);
+#endif
 
     return PA_HOOK_OK;
 }
 
+#ifdef __TIZEN__
+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(pa_source_output_get_state(o)) && get_trigger_role_all_groups(u, PA_OBJECT(o)))
+        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(pa_source_output_get_state(o)) && get_trigger_role_all_groups(u, PA_OBJECT(o)))
+        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(pa_source_output_get_state(o)))
+        return process(u, PA_OBJECT(o), true, false);
+
+    return PA_HOOK_OK;
+}
+#endif
+
 int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
     pa_modargs *ma = NULL;
     struct userdata *u;
@@ -553,7 +730,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
 
     if (u->duck) {
         const char *volumes;
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         const char *durations;
         uint32_t group_count_fd_out = 0;
         uint32_t group_count_fd_in = 0;
@@ -589,7 +766,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
                 pa_xfree(n);
             }
         }
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         durations = pa_modargs_get_value(ma, "fade_out", NULL);
         if (durations) {
             const char *split_state = NULL;
@@ -611,7 +788,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
 #endif
 
         if ((group_count_tr > 1 || group_count_du > 1 || group_count_vol > 1) &&
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
             ((group_count_tr != group_count_du) || (group_count_tr != group_count_vol) ||
             (group_count_fd_out > group_count_tr) || (group_count_fd_in > group_count_tr))) {
 #else
@@ -635,9 +812,9 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
 #else
         u->groups[i]->interaction_state = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
 #endif
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         if (u->duck) {
-            u->groups[i]->triggered_inputs = pa_idxset_new(NULL, NULL);
+            u->groups[i]->triggered_streams = pa_idxset_new(NULL, NULL);
             u->groups[i]->name = pa_sprintf_malloc("ducking_group_%u", i);
         }
 #else
@@ -713,7 +890,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
 
     if (u->duck) {
         const char *volumes;
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
         const char *durations;
 #endif
         u->groups[0]->volume = pa_sw_volume_from_dB(-20);
@@ -736,7 +913,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
                 pa_xfree(n);
             }
         }
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
 
         u->groups[0]->fade_durs.out = 0L;
         durations = pa_modargs_get_value(ma, "fade_out", NULL);
@@ -797,6 +974,15 @@ 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);
+#ifdef __TIZEN__
+    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);
+#endif
 
     pa_modargs_free(ma);
 
@@ -833,9 +1019,9 @@ void pa_stream_interaction_done(pa_module *m) {
 #else
             pa_hashmap_free(u->groups[j]->interaction_state);
 #endif
-#ifdef TIZEN_VOLUME_RAMP
+#ifdef __TIZEN__
             if (u->duck) {
-                pa_idxset_free(u->groups[j]->triggered_inputs, pa_xfree);
+                pa_idxset_free(u->groups[j]->triggered_streams, pa_xfree);
                 pa_xfree(u->groups[j]->name);
             }
 #else
@@ -861,6 +1047,22 @@ 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);
+#ifdef __TIZEN__
+    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);
+#endif
 
     pa_xfree(u);