Add support for A2DP source and sink both role 92/301492/1 accepted/tizen/7.0/unified/20231208.173554
authorWootak Jung <wootak.jung@samsung.com>
Wed, 15 Nov 2023 02:28:51 +0000 (11:28 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 17 Nov 2023 00:15:13 +0000 (09:15 +0900)
Change-Id: I8638a5ae3728d3f4fceac03b1403b0c38d8f351a
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-a2dp-sink-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-av-dbus-handler.c
bt-service/services/adapter/bt-service-core-adapter.c
bt-service/services/audio/bt-service-audio.c
bt-service/services/include/bt-service-audio-common.h

index 383a336..f6014af 100644 (file)
@@ -268,7 +268,7 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_sink(void)
                        /* Add the exception case for Already Exists */
                        if (g_strrstr(error->message, "Already Exists")) {
                                g_clear_error(&error);
-                               return BT_STATUS_DONE;
+                               return BT_STATUS_SUCCESS;
                        }
 
                        g_clear_error(&error);
index 598dc25..b0a9999 100644 (file)
@@ -268,7 +268,7 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_source(void)
                        /* Add the exception case for Already Exists */
                        if (g_strrstr(error->message, "Already Exists")) {
                                g_clear_error(&error);
-                               return BT_STATUS_DONE;
+                               return BT_STATUS_SUCCESS;
                        }
 
                        g_clear_error(&error);
index 57c9773..a282696 100644 (file)
@@ -90,9 +90,10 @@ static gboolean a2dp_init_pending = TRUE;
 static bt_status_t adapter_state = BT_DEACTIVATED;
 static bt_adapter_discovery_state_t adapter_discovery_state = ADAPTER_DISCOVERY_STOPPED;
 
+/* Below masking value will be delivered from bluez */
 typedef enum {
-       BT_ADAPTER_A2DP_ROLE_SOURCE = 0,
-       BT_ADAPTER_A2DP_ROLE_SINK,
+       BT_ADAPTER_A2DP_ROLE_SOURCE = 0x01,
+       BT_ADAPTER_A2DP_ROLE_SINK = 0x02,
 } bt_adapter_a2dp_role_e;
 
 static bt_adapter_a2dp_role_e a2dp_role_state = BT_ADAPTER_A2DP_ROLE_SOURCE;
@@ -1004,7 +1005,7 @@ static void __bt_handle_pending_a2dp_init(unsigned int a2dp_role)
        BT_DBG("+");
        a2dp_init_pending = FALSE;
 
-       if (a2dp_role == BT_A2DP_SINK_ROLE) {
+       if (a2dp_role & BT_ADAPTER_A2DP_ROLE_SINK) {
                BT_INFO("Enable A2DP Sink role");
                /* Initialize A2DP Sink */
                ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
@@ -1017,21 +1018,23 @@ static void __bt_handle_pending_a2dp_init(unsigned int a2dp_role)
                        BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
 
                _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
-               return;
        }
 
-       BT_INFO("Enable A2DP Source role");
-       /* Initialize A2DP Source */
-       ret = _bt_audio_initialize(BT_A2DP_SOURCE_MODULE);
-       if (ret != BLUETOOTH_ERROR_NONE)
-               BT_ERR("_bt_audio_initialize(BT_A2DP_SOURCE_MODULE) Failed");
+       if (a2dp_role & BT_ADAPTER_A2DP_ROLE_SOURCE) {
+               BT_INFO("Enable A2DP Source role");
+               /* Initialize A2DP Source */
+               ret = _bt_audio_initialize(BT_A2DP_SOURCE_MODULE);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("_bt_audio_initialize(BT_A2DP_SOURCE_MODULE) Failed");
 
-       /* Initialize AVRCP Target */
-       ret = _bt_audio_initialize(BT_AVRCP_MODULE);
-       if (ret != BLUETOOTH_ERROR_NONE)
-               BT_ERR("_bt_audio_initialize(BT_AVRCP_MODULE) Failed");
+               /* Initialize AVRCP Target */
+               ret = _bt_audio_initialize(BT_AVRCP_MODULE);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("_bt_audio_initialize(BT_AVRCP_MODULE) Failed");
+
+               _bt_audio_set_current_role(BLUETOOTH_A2DP_SOURCE);
+       }
 
-       _bt_audio_set_current_role(BLUETOOTH_A2DP_SOURCE);
        BT_DBG("-");
 }
 
@@ -1237,6 +1240,7 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
 
                BT_INFO("a2dp role: [%u]", *a2dp_role);
 
+               /* In Fhub case, both role(Source|Sink, 0x03) can be delivered */
                __bt_handle_pending_a2dp_init(*a2dp_role);
 
                if (TIZEN_FEATURE_FHUB_REFERENCE) {
@@ -1506,7 +1510,7 @@ static gboolean __bt_adapter_post_set_enabled(gpointer user_data)
        if (TIZEN_FEATURE_DA_REFERENCE) {
                /* If non-Fhub, visible off even if headless device.
                 * If Fhub, visible on when a2dp role sink(speaker). otherwise, visible off */
-               if (TIZEN_FEATURE_FHUB_REFERENCE && a2dp_role_state == BT_ADAPTER_A2DP_ROLE_SINK) {
+               if (TIZEN_FEATURE_FHUB_REFERENCE && a2dp_role_state & BT_ADAPTER_A2DP_ROLE_SINK) {
                        BT_DBG("It is initial state.. Set General Discoverable Mode");
                        if (BLUETOOTH_ERROR_NONE != _bt_set_discoverable_mode(
                                        BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0))
@@ -1882,7 +1886,7 @@ static void __bt_set_visible_mode(void)
 
        if (TIZEN_FEATURE_FHUB_REFERENCE) {
                BT_DBG("timeout : %d, a2dp_role : %d", timeout, a2dp_role_state);
-               if (timeout == 0 && a2dp_role_state == BT_ADAPTER_A2DP_ROLE_SINK) {
+               if (timeout == 0 && a2dp_role_state & BT_ADAPTER_A2DP_ROLE_SINK) {
                        BT_DBG("It is initial state.. Set General Discoverable Mode");
                        if (_bt_set_discoverable_mode(
                                                        BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
index a03227e..05006a3 100644 (file)
@@ -1289,6 +1289,11 @@ int _bt_audio_select_role(bluetooth_audio_role_t role)
 
        BT_DBG("+");
 
+       if (TIZEN_FEATURE_FHUB_REFERENCE) {
+               BT_INFO("Both role(Source/Sink) already enabled in Fhub. No need to select role");
+               return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+       }
+
        if (curr_audio_role == role) {
                BT_ERR("Desired audio role already enabled, return");
                return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
index 86da48c..9a5be06 100644 (file)
@@ -48,11 +48,6 @@ typedef enum {
 } bt_audio_type_t;
 
 typedef enum {
-       BT_A2DP_SOURCE_ROLE = 0,
-       BT_A2DP_SINK_ROLE,
-} bt_a2dp_role_t;
-
-typedef enum {
        SERVICE_SEARCH_NOT_STARTED,
        SERVICE_SEARCH_STARTED,
        SERVICE_SEARCH_DONE,