stream-manager-dbus: Improve ducking API regarding a stream not running 89/212889/2
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 28 Aug 2019 02:17:13 +0000 (11:17 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 29 Aug 2019 02:42:36 +0000 (11:42 +0900)
If there's only one stream that belongs to the target stream of ducking
effect and is not running, PA_CORE_HOOK_SINK_INPUT_RAMP_FINISH is not
invoked because it is not a stream to be rendered in this state.

This patch adds condition to use pa_sink_input_add_volume_factor() to
make the effect properly and to send the signal immediately in this case.

[Version] 11.1.70
[Issue Type] Bug fix

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

index 54a3670..9ca471b 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.69
+Version:          11.1.70
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 0c9a098..48ce7b4 100644 (file)
@@ -1782,7 +1782,7 @@ static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void
     dbus_bool_t enable = 0;
     const char *target_stream = NULL;
     uint32_t idx = 0;
-    pa_sink_input *stream = NULL;
+    pa_sink_input *i = NULL;
     dbus_uint32_t duration = 0;
     double ratio = 0.0;
     DBusMessage *reply = NULL;
@@ -1821,31 +1821,41 @@ static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void
     }
 
     /* set volume ramp factor to target stream */
-    PA_IDXSET_FOREACH(stream, m->core->sink_inputs, idx) {
-        if (!pa_safe_streq(target_stream, pa_proplist_gets(stream->proplist, PA_PROP_MEDIA_ROLE)))
+    PA_IDXSET_FOREACH(i, m->core->sink_inputs, idx) {
+        if (!pa_safe_streq(target_stream, pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
             continue;
 
-        target_matched = true;
-        sd->ducking_stream_count++;
+        if (i->state == PA_SINK_INPUT_RUNNING) {
+            target_matched = true;
+            sd->ducking_stream_count++;
+        }
 
         if (enable) {
             pa_cvolume_ramp vol_ramp;
 
-            pa_idxset_put(sd->idx_ducking_streams, (void *)stream, NULL);
+            pa_idxset_put(sd->idx_ducking_streams, (void *)i, NULL);
 
             pa_log_info("ducking: add volume_ramp factor, key[%s], set_vol[%u] to stream[idx:%u]",
-                sd->vol_key, sd->set_vol, stream->index);
+                sd->vol_key, sd->set_vol, i->index);
 
-            pa_cvolume_ramp_set(&vol_ramp, stream->volume.channels,
+            pa_cvolume_ramp_set(&vol_ramp, i->volume.channels,
                 PA_VOLUME_RAMP_TYPE_LINEAR, (long)duration, sd->set_vol);
 
-            pa_sink_input_add_volume_ramp_factor(stream, sd->vol_key, &vol_ramp, true);
+            if (i->state != PA_SINK_INPUT_RUNNING) {
+                pa_cvolume vol;
+                pa_cvolume_set(&vol, i->volume.channels, sd->set_vol);
+                pa_sink_input_add_volume_factor(i, sd->vol_key, &vol);
+                pa_sink_input_add_volume_ramp_factor(i, sd->vol_key, &vol_ramp, false);
+            } else {
+                pa_sink_input_add_volume_ramp_factor(i, sd->vol_key, &vol_ramp, true);
+            }
+
         } else {
             pa_log_info("unducking: remove volume(ramp) factor, key[%s] from stream[idx:%u]",
-                sd->vol_key, stream->index);
+                sd->vol_key, i->index);
 
-            pa_sink_input_remove_volume_factor(stream, sd->vol_key);
-            pa_sink_input_remove_volume_ramp_factor(stream, sd->vol_key, true);
+            pa_sink_input_remove_volume_factor(i, sd->vol_key);
+            pa_sink_input_remove_volume_ramp_factor(i, sd->vol_key, true);
         }
     }
 
index 6a900b4..4b8bafc 100644 (file)
@@ -2259,7 +2259,8 @@ static void remove_sink_input_from_ducking_streams(pa_stream_manager *m, pa_sink
 
             pa_log_info("remove stream(idx:%u,%p) from idx_ducking_streams, trigger_index(%u)",
                 i->index, i, sd->trigger_index);
-            pa_idxset_remove_by_data(sd->idx_ducking_streams, stream, NULL);
+            pa_idxset_remove_by_data(sd->idx_ducking_streams, i, NULL);
+
             return;
         }
     }
@@ -2442,12 +2443,14 @@ static pa_hook_result_t sink_input_ramp_finish_cb(pa_core *core, pa_sink_input *
 
     is_ducked = i->thread_info.ramp.ramps[0].start > i->thread_info.ramp.ramps[0].end;
 
-    /* remove trigger when unducked */
+    /* Remove trigger when unducked */
     if (is_ducked == false)
         pa_idxset_remove_by_data(sd->idx_ducking_streams, (void *)i, NULL);
 
-    /* send signal when all streams are ducked */
-    if (--sd->ducking_stream_count == 0) {
+    /* Send signal when all streams are ducked.
+     * Note that the condition of increasing count value below is located in
+     * handle_activate_ducking() of DBus handler. */
+    if (sd->ducking_stream_count > 0 && --sd->ducking_stream_count == 0) {
         pa_log_info("send signal for ramp finished - is_ducked(%d)", is_ducked);
         sd->is_ducked = is_ducked;
         send_ducking_state_changed_signal(pa_dbus_connection_get(m->dbus_conn), sd->trigger_index, sd->is_ducked);