stream-manager: Add device_profile_changed_hook_cb to update proper sink in case... 55/91355/2
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 7 Oct 2016 06:30:55 +0000 (15:30 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 7 Oct 2016 06:39:20 +0000 (15:39 +0900)
It is related to the previous commit regarding device-manage: avail-mode for bt.
The previous logic about device connected callback for BT was changed from that commit, so some issues happened.
Now, this commit supports the device-manager changes and works well with the scenario of BT profile change.

[Version] 5.0.84
[Profile] Common
[Issue Type] Fix bug

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

index d662d86..a06cef8 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.83
+Version:          5.0.84
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 8cfeca9..ce6ea54 100644 (file)
@@ -706,6 +706,8 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                             /* if the device type is forwarding, keep going to next device for proper UCM setting */
                             if (pa_streq(dm_device_type, DEVICE_TYPE_FORWARDING))
                                 continue;
+                            if (pa_streq(dm_device_type, DEVICE_TYPE_BT))
+                                continue;
                             hal_direction = CONVERT_TO_HAL_DIRECTION(data->stream_type);
                             route_info.num_of_devices++;
                             route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices);
@@ -1219,7 +1221,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi
     return PA_HOOK_OK;
 }
 
-/* Update connected device list when a device's information has been changed */
+/* Update connected device list when a device profile has been changed */
 static pa_hook_result_t device_profile_changed_hook_cb(pa_core *c, pa_tz_device_hook_data_for_profile_changed *conn, struct userdata *u) {
     dm_device_direction_t device_direction = DM_DEVICE_DIRECTION_OUT;
     int* ptr_in = NULL;
index ec71b6e..c47152e 100644 (file)
@@ -141,6 +141,7 @@ struct _stream_manager {
     struct {
         pa_communicator *comm;
         pa_hook_slot *comm_hook_device_connection_changed_slot;
+        pa_hook_slot *comm_hook_device_profile_changed_slot;
         pa_hook_slot *comm_hook_event_fully_handled_slot;
     } comm;
 };
index 8652fbf..30e3238 100644 (file)
@@ -3179,7 +3179,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
                     }
                 } else if (!is_connected) {
                     /* DISCONNECTED: find a connected device that has the next priority */
-                    if (sink && (sink == ((pa_sink_input*)s)->sink)) {
+                    if (sink) {
                         find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
                         if (next_device) {
                             if ((next_sink = pa_tz_device_get_sink(next_device, DEVICE_ROLE_NORMAL))) {
@@ -3204,7 +3204,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
                                 s, ((pa_sink_input*)s)->index, null_sink, null_sink->name);
                         }
 
-                    } else if (source && (source == ((pa_source_output*)s)->source)) {
+                    } else if (source) {
                         find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device);
                         if (next_device) {
                             if ((next_source = pa_tz_device_get_source(next_device, DEVICE_ROLE_NORMAL))) {
@@ -3450,6 +3450,41 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi
     return PA_HOOK_OK;
 }
 
+/* Update connected device list when a device profile has been changed */
+static pa_hook_result_t device_profile_changed_hook_cb(pa_core *c, pa_tz_device_hook_data_for_profile_changed *conn, pa_stream_manager *m) {
+    dm_device_direction_t device_direction = DM_DEVICE_DIRECTION_OUT;
+    bool use_internal_codec = false;
+    bool bt_sink_available = false;
+
+    pa_assert(c);
+    pa_assert(conn);
+    pa_assert(m);
+
+    device_direction = pa_tz_device_get_direction(conn->device);
+    use_internal_codec = pa_tz_device_is_use_internal_codec(conn->device);
+
+    pa_log_info("[SM][CONN] device_profile_changed_hook_cb is called. conn(%p), changed(%d), device(%p), direction(0x%x), use_internal_codec(%d)",
+                conn, conn->changed, conn->device, device_direction, use_internal_codec);
+
+    if (conn->changed == PA_TZ_DEVICE_ACTIVE_PROFILE_CHANGED) {
+        if (pa_streq(pa_tz_device_get_type(conn->device), DEVICE_TYPE_BT)) {
+            pa_log_info("[SM][CONN] BT: active profile changed to [%s]", pa_tz_device_get_profile(conn->device));
+            if (use_internal_codec)
+                bt_sink_available = false; /* already bt device is connected and A2DP is newly deactivated, now SCO is only activated */
+            else
+                bt_sink_available = true;  /* already bt device is connected and A2DP is newly activated */
+        }
+        if (device_direction & DM_DEVICE_DIRECTION_OUT) {
+            update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs,
+                                                   STREAM_SINK_INPUT, conn->device, bt_sink_available, m);
+            update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs,
+                                                   STREAM_SINK_INPUT, conn->device, bt_sink_available, m);
+        }
+    }
+
+    return PA_HOOK_OK;
+}
+
 static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t idx, pa_stream_manager *m) {
     pa_client *client = NULL;
     stream_parent *sp = NULL;
@@ -3649,6 +3684,8 @@ pa_stream_manager* pa_stream_manager_init(pa_core *c) {
     m->comm.comm = pa_communicator_get(c);
     m->comm.comm_hook_device_connection_changed_slot = pa_hook_connect(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED),
             PA_HOOK_EARLY + 10, (pa_hook_cb_t)device_connection_changed_hook_cb, m);
+    m->comm.comm_hook_device_profile_changed_slot = pa_hook_connect(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_DEVICE_PROFILE_CHANGED),
+            PA_HOOK_EARLY + 10, (pa_hook_cb_t)device_profile_changed_hook_cb, m);
     m->comm.comm_hook_event_fully_handled_slot = pa_hook_connect(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_EVENT_FULLY_HANDLED),
             PA_HOOK_EARLY + 10, (pa_hook_cb_t)event_fully_handled_hook_cb, m);