stream-manager: Revise implemenation of handle_get_current_volume_type() 35/115635/4
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 17 Feb 2017 09:48:33 +0000 (18:48 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 22 Feb 2017 05:36:17 +0000 (14:36 +0900)
[Version] 5.0.135
[Profile] Common
[Issue Type] Bug fix

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

index 69e4734e03621d50d2eb952b2efcfda647f169ce..c1fe629dea7684b8faed78bc47d24aeee3cc06db 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.134
+Version:          5.0.135
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 621f9a22e88a4a4557bef38c9176e72c91d72883..6712b1810644069661f0325ec00cda1ac402db56 100644 (file)
@@ -63,6 +63,9 @@ typedef enum _stream_direction {
 #define GET_FOCUS_STATUS(focus, type) \
       (type == STREAM_SINK_INPUT ? (focus & STREAM_FOCUS_ACQUIRED_PLAYBACK) : (focus & STREAM_FOCUS_ACQUIRED_CAPTURE))
 
+#define CHECK_STREAM_RUNNING(stream, type) \
+      (type == STREAM_SINK_INPUT ? ((pa_sink_input*)stream)->state == PA_SINK_INPUT_RUNNING : ((pa_source_output*)stream)->state == PA_SOURCE_OUTPUT_RUNNING)
+
 typedef struct _volume_info {
     bool is_hal_volume_type;
     struct _values {
index fe1b68db98ef8b423406573bdc0918c67853b6f5..f667b79a1fe03e42a326c719b51b2117273fb107 100644 (file)
@@ -1416,6 +1416,7 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms
     DBusMessage *reply = NULL;
     pa_stream_manager *m = (pa_stream_manager*)userdata;
     uint32_t idx = 0;
+    pa_idxset *streams = NULL;
 
     pa_assert(conn);
     pa_assert(msg);
@@ -1428,25 +1429,42 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms
 
     pa_assert_se((reply = dbus_message_new_method_return(msg)));
 
-    if (pa_streq(direction, "in"))
+    if (pa_streq(direction, "in")) {
         stream_type = STREAM_SOURCE_OUTPUT;
-    else if (pa_streq(direction, "out"))
+        streams = m->core->source_outputs;
+    } else if (pa_streq(direction, "out")) {
         stream_type = STREAM_SINK_INPUT;
-    else {
+        streams = m->core->sink_inputs;
+    } else {
         pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &dbus_str_none, DBUS_TYPE_INVALID));
         pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID));
         goto fail;
     }
 
-    if ((s = (stream_type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) : (void*)(m->cur_highest_priority.source_output)))
-        type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE);
-    else {
-        if (pa_idxset_size(m->core->sink_inputs)) {
-            PA_IDXSET_FOREACH(s, m->core->sink_inputs, idx) {
-                if ((type = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE)))
-                    break;
+    /* Get a volume type of a stream that has the max priority role among all the running streams regardless of devices.
+       Note that it does not represent any focus status of a stream rather only checking the priority of it */
+    if (pa_idxset_size(streams)) {
+        int cur_max_priority = 0;
+        const char *cur_max_type = NULL;
+        const char *role = NULL;
+        stream_info *s_info;
+
+        PA_IDXSET_FOREACH(s, streams, idx) {
+            if (!CHECK_STREAM_RUNNING(s, stream_type))
+                continue;
+            if (!(type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE)))
+                continue;
+            if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROLE)))
+                continue;
+            if ((s_info = pa_hashmap_get(m->stream_infos, role))) {
+                if (s_info->priority >= cur_max_priority) {
+                    cur_max_priority = s_info->priority;
+                    cur_max_type = type;
+                    pa_log_info("updated, volume type of the max priority stream(%u): %s", GET_STREAM_INDEX(s, stream_type), cur_max_type);
+                }
             }
         }
+        type = cur_max_type;
     }
 
     if (type) {