sound-player: stop all other existence sound playbacks if requested 89/282189/16
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 28 Sep 2022 04:35:46 +0000 (13:35 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 14 Oct 2022 02:22:57 +0000 (11:22 +0900)
[Version] 15.0.29
[Issue Type] Feature

Change-Id: Ife2480f0afc993165186e6f7b1cd04dbe16539fe

packaging/pulseaudio-modules-tizen.spec
src/module-sound-player.c

index b8c2e8a..e29fb34 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.28
+Version:          15.0.29
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index cf55d04..229501d 100644 (file)
@@ -103,9 +103,10 @@ static pa_dbus_arg_info sound_play_args[] = { { "filename", "s", "in" },
                                                { "repeat", "i", "in" },
                                                { "client_pid", "i", "in" },
                                                { "role", "s", "in" },
-                                               { "parent_id", "i", "in" } };
+                                               { "parent_id", "i", "in" },
+                                               { "stop_others", "b", "in" } };
 static pa_dbus_arg_info sound_stop_args[] = { { "stream_idx", "i", "in" } };
-static const char* signature_args_for_in[] = { "sss", "s", NULL, "sss", "siisi", "i" };
+static const char* signature_args_for_in[] = { "sss", "s", NULL, "sss", "siisib", "i" };
 
 static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
     [METHOD_HANDLER_SIMPLE_PLAY] = {
@@ -179,6 +180,7 @@ static pa_dbus_interface_info sound_player_interface_info = {
     "   <arg name=\"client_pid\" direction=\"in\" type=\"i\"/>"         \
     "   <arg name=\"role\" direction=\"in\" type=\"s\"/>"               \
     "   <arg name=\"parent_id\" direction=\"in\" type=\"i\"/>"          \
+    "   <arg name=\"stop_others\" direction=\"in\" type=\"b\"/>"        \
     "  </method>"                                                       \
     "  <method name=\"SOUND_PLAYER_METHOD_NAME_SOUND_STOP\">"           \
     "   <arg name=\"stream_idx\" direction=\"in\" type=\"i\"/>"         \
@@ -316,6 +318,27 @@ static void _simple_stop_all(struct userdata *u) {
     }
 }
 
+static void _sound_stop_all(struct userdata *u) {
+    pa_sink_input *si;
+    uint32_t idx;
+    int32_t *stream_idx;
+
+    pa_assert(u);
+
+    PA_IDXSET_FOREACH(stream_idx, u->stream_idxs, idx) {
+        pa_assert(stream_idx);
+
+        si = pa_idxset_get_by_index(u->module->core->sink_inputs, *stream_idx);
+        if (!si) {
+            pa_log_warn("null sink input for stream idx(%d)", *stream_idx);
+            continue;
+        }
+
+        pa_log_info("killing sink-input(%d), stream_idx(%d)", si->index, *stream_idx);
+        pa_sink_input_kill(si);
+    }
+}
+
 static int _sample_play(struct userdata *u, const char *sample_name, const char *role, const char *vol_gain_type) {
     int ret = 0;
     pa_sink *sink = NULL;
@@ -474,6 +497,7 @@ static void handle_sound_play(DBusConnection *conn, DBusMessage *msg, void *user
     const char *role;
     uint32_t parent_id;
     uint32_t stream_idx;
+    dbus_bool_t stop_others = false;
     pa_proplist *p;
 
     pa_assert_se(dbus_message_get_args(msg, NULL,
@@ -482,8 +506,15 @@ static void handle_sound_play(DBusConnection *conn, DBusMessage *msg, void *user
                                        DBUS_TYPE_INT32, &client_pid,
                                        DBUS_TYPE_STRING, &role,
                                        DBUS_TYPE_INT32, &parent_id,
+                                       DBUS_TYPE_BOOLEAN, &stop_others,
                                        DBUS_TYPE_INVALID));
 
+    if (stop_others) {
+        pa_log_info("stop_others enabled, stop all other sounds");
+        _sound_stop_all(u);
+        pa_log_info("stop done, ready to play the requested one");
+    }
+
     p = pa_proplist_new();
     pa_proplist_sets(p, PA_PROP_MEDIA_ROLE, role);
     pa_proplist_setf(p, PA_PROP_APPLICATION_PROCESS_ID_ORIGIN, "%d", client_pid);