[Adapt Audio OAL] Add A2DP Source role codes in OAL 84/88084/1
authorAnupam Roy <anupam.r@samsung.com>
Tue, 13 Sep 2016 08:37:36 +0000 (14:07 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 13 Sep 2016 08:37:36 +0000 (14:07 +0530)
Change-Id: I061798d8f2e6a87444438a853377627f711cac81
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/CMakeLists.txt
bt-oal/include/oal-audio-src.h [new file with mode: 0644]
bt-oal/include/oal-event.h
bt-oal/oal-audio-src.c [new file with mode: 0644]

index 8aec2fd..13e7f2b 100755 (executable)
@@ -16,6 +16,7 @@ oal-adapter-mgr.c
 oal-device-mgr.c
 oal-hid-host.c
 oal-socket.c
+oal-audio-src.c
 common/oal-utils.c
 common/oal-common.c
 common/oal-event-dispatcher.c
diff --git a/bt-oal/include/oal-audio-src.h b/bt-oal/include/oal-audio-src.h
new file mode 100644 (file)
index 0000000..309398c
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *              http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef _OAL_AUDIO_SOURCE_H_
+#define _OAL_AUDIO_SOURCE_H_
+
+
+#include <glib.h>
+#include <sys/types.h>
+#include <oal-manager.h>
+#include "oal-event.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enable Audio Host(A2DP Source) Feature
+ *
+ * @remarks  BT Sound Share/BT speaker will be able to connect.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre OAL API must be initialized with oal_bt_init().
+ *
+ * @see  audio_disable()
+ */
+oal_status_t audio_enable(char *service_name , char *provider_name);
+
+/**
+ * @brief Disable Audio Host(A2DP Source) Feature
+ *
+ * @remarks  BT Sound Share/BT speaker will be able to connect.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre Audio host should be enabled with audio_enable().
+ *
+ * @see  audio_enable()
+ */
+oal_status_t audio_disable(void);
+
+/**
+ * @brief Initiate a connection with a BT Sound device
+ *
+ * @details  Result will be notified through an OAL event
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre BT Audio should be enabled with audio_enable().
+ *
+ * @see  OAL_EVENT_AUDIO_CONNECTED
+ */
+
+oal_status_t audio_connect(bt_address_t *device_address);
+
+/**
+ * @brief Remove a connection with a BT Sound device
+ *
+ * @details  Result will be notified through an OAL event
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre BT Audio should be connected with a BT Sound device.
+ *
+ * @see  OAL_EVENT_AUDIO_DISCONNECTED
+ */
+
+oal_status_t audio_disconnect(bt_address_t *device_address);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_AUDIO_SOURCE_H_*/
index c6fa496..9c97043 100755 (executable)
@@ -43,22 +43,22 @@ extern "C" {
        EVENT(OAL_EVENT_ADAPTER_MODE_CONNECTABLE)       \
        EVENT(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE)      \
        EVENT(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT)      /* uint32_t */\
-       EVENT(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST)             /* event_device_list_t */\
+       EVENT(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST)             /* event_device_list_t */\
        EVENT(OAL_EVENT_ADAPTER_INQUIRY_STARTED)        \
        EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY)      /* event_dev_found_t */\
-       EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE)             /* event_ble_dev_found_t */\
+       EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE)             /* event_ble_dev_found_t */\
        EVENT(OAL_EVENT_ADAPTER_INQUIRY_FINISHED)       \
        EVENT(OAL_EVENT_DEVICE_PROPERTIES)                                      /* remote_device_t */\
        EVENT(OAL_EVENT_DEVICE_NAME)                                            /* remote_device_t */\
        EVENT(OAL_EVENT_DEVICE_VIDPID)                                          /* remote_device_t */\
        EVENT(OAL_EVENT_DEVICE_SERVICES)                                        /* event_dev_services_t */\
-       EVENT(OAL_EVENT_DEVICE_PIN_REQUEST)                             /* remote_device_t */\
+       EVENT(OAL_EVENT_DEVICE_PIN_REQUEST)                             /* remote_device_t */\
        EVENT(OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST)           /* remote_device_t */\
        EVENT(OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST)/* event_dev_passkey_t */\
-       EVENT(OAL_EVENT_DEVICE_PASSKEY_DISPLAY)                         /* event_dev_passkey_t */\
-       EVENT(OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST)             /* remote_device_t */\
-       EVENT(OAL_EVENT_DEVICE_BONDING_SUCCESS)                         /* bt_address_t */\
-       EVENT(OAL_EVENT_DEVICE_BONDING_REMOVED)                         /* bt_address_t */\
+       EVENT(OAL_EVENT_DEVICE_PASSKEY_DISPLAY)                 /* event_dev_passkey_t */\
+       EVENT(OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST)             /* remote_device_t */\
+       EVENT(OAL_EVENT_DEVICE_BONDING_SUCCESS)                 /* bt_address_t */\
+       EVENT(OAL_EVENT_DEVICE_BONDING_REMOVED)                 /* bt_address_t */\
        EVENT(OAL_EVENT_DEVICE_BONDING_FAILED)                          /* event_dev_bond_failed_t */\
        EVENT(OAL_EVENT_DEVICE_AUTHORIZE_REQUEST)                       /* event_dev_authorize_req_t */\
        EVENT(OAL_EVENT_SOCKET_AUTHORIZE_REQUEST)                       /* event_socket_authorize_req_t */\
@@ -72,6 +72,12 @@ extern "C" {
        EVENT(OAL_EVENT_HID_DISCONNECTED)                                       /* event_hid_conn_t */\
        EVENT(OAL_EVENT_SOCKET_OUTGOING_CONNECTED)                 /* RFCOMM */  \
        EVENT(OAL_EVENT_SOCKET_DISCONNECTED)            /* RFCOMM */  \
+       EVENT(OAL_EVENT_AUDIO_CONNECTING)                   /* bt_address_t */ \
+       EVENT(OAL_EVENT_AUDIO_DISCONNECTING)                /* bt_address_t*/ \
+       EVENT(OAL_EVENT_AUDIO_CONNECTED)                                        /* bt_address_t*/ \
+       EVENT(OAL_EVENT_AUDIO_DISCONNECTED)                             /* bt_address_t*/  \
+       EVENT(OAL_EVENT_AUDIO_STOPPED)                                          /* bt_address_t*/  \
+       EVENT(OAL_EVENT_AUDIO_STARTED)                                          /* bt_address_t*/  \
        EVENT(OAL_EVENT_END)                                /* End of event*/\
 
 
@@ -172,4 +178,3 @@ typedef struct {
 }
 #endif /* __cplusplus */
 #endif /*_OAL_EVENT_H_*/
-
diff --git a/bt-oal/oal-audio-src.c b/bt-oal/oal-audio-src.c
new file mode 100644 (file)
index 0000000..bdc8bb5
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *              http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dlog.h>
+
+#include <bluetooth.h>
+#include <bt_av.h>
+
+#include "oal-internal.h"
+#include "oal-audio-src.h"
+#include "oal-utils.h"
+#include "oal-common.h"
+
+#define CHECK_OAL_AUDIO_ENABLED() \
+       do { \
+               if (blued_a2dp_interface == NULL) { \
+                       BT_ERR("OAL, Audio Not Enabled"); \
+                       return OAL_STATUS_NOT_READY; \
+               } \
+       } while (0)
+
+
+static void cb_audio_connection_state(btav_connection_state_t event, bt_bdaddr_t* bd_addr);
+static void cb_audio_state(btav_audio_state_t state, bt_bdaddr_t* bd_addr);
+
+const bt_interface_t * _bt_get_stack_interface(void);
+static const btav_interface_t *blued_a2dp_interface = NULL;
+
+static btav_callbacks_t blued_a2dp_cb = {
+       sizeof(blued_a2dp_cb),
+       cb_audio_connection_state,
+       cb_audio_state,
+       NULL /* Audio Config Callback */
+};
+
+oal_status_t audio_enable(char *service_name , char *provider_name)
+{
+       const bt_interface_t* blued_inf;
+       int ret;
+
+       API_TRACE("Audio Enable");
+
+       if ((blued_inf = adapter_get_stack_interface()) == NULL) {
+               BT_ERR("Bluetooth module is not loaded");
+               return OAL_STATUS_NOT_READY;
+       }
+
+       if (blued_a2dp_interface != NULL) {
+               BT_WARN("A2DP Interface is already initialized...");
+               return OAL_STATUS_ALREADY_DONE;
+       }
+
+       if ((blued_a2dp_interface = (const btav_interface_t *)blued_inf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID)) == NULL) {
+               BT_ERR("OAL, Failed to get Bluetooth A2DP Interface");
+               return OAL_STATUS_INTERNAL_ERROR;
+       }
+
+       BT_DBG("Got profile interface");
+       if ((ret = blued_a2dp_interface->init(&blued_a2dp_cb)) != BT_STATUS_SUCCESS) {
+               BT_ERR("Failed to initialize Bluetooth A2DP, status: %s", status2string(ret));
+               blued_a2dp_interface = NULL;
+               return convert_to_oal_status(ret);
+       }
+       BT_DBG("OAL, Bluetooth audio interface initialised");
+
+       return OAL_STATUS_SUCCESS;
+}
+
+/* Audio deinit: Resets all the audio information
+ * Note: Adapter should be disabled before calling deinit
+ * */
+oal_status_t audio_disable(void)
+{
+       API_TRACE("audio disable");
+
+       CHECK_OAL_AUDIO_ENABLED();
+
+       blued_a2dp_interface->cleanup();
+       blued_a2dp_interface = NULL;
+
+       return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t audio_connect(bt_address_t *device_address)
+{
+       int result = OAL_STATUS_SUCCESS;
+       bt_status_t status;
+       bdstr_t bdstr;
+
+       API_TRACE();
+
+       CHECK_OAL_AUDIO_ENABLED();
+       OAL_CHECK_PARAMETER(device_address, return);
+
+       BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
+
+       /* Call connect function of Bluedroid*/
+       status = blued_a2dp_interface->connect((bt_bdaddr_t *)device_address);
+       if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
+               BT_ERR("Connection could not be established, err: %s", status2string(status));;
+               result =  convert_to_oal_status(status);
+       }
+       return result;
+}
+
+
+oal_status_t audio_disconnect( bt_address_t *device_address )
+{
+       int result = OAL_STATUS_SUCCESS;
+       bdstr_t bdstr;
+       bt_status_t status;
+
+       API_TRACE();
+
+       CHECK_OAL_AUDIO_ENABLED();
+       OAL_CHECK_PARAMETER(device_address, return);
+
+       BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
+
+       /* call Disconnect function of Bluedroid */
+       status = blued_a2dp_interface->disconnect((bt_bdaddr_t *)device_address);
+       if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
+               BT_ERR("OAL, Disconnection failed err: %s", status2string(status));
+               result =  convert_to_oal_status(status);
+       }
+       return result;
+}
+
+static void cb_audio_connection_state(btav_connection_state_t state, bt_bdaddr_t* bd_addr)
+{
+       bt_address_t * event_data = NULL;
+       bdstr_t bdstr;
+       oal_event_t event;
+
+       ret_if(bd_addr == NULL);
+       BT_INFO("state = %d,  BT Address = %s", state, bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
+
+       event_data = g_new0(bt_address_t, 1);
+       memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
+
+       switch(state){
+               case BTAV_CONNECTION_STATE_CONNECTING: {
+                       event = OAL_EVENT_AUDIO_CONNECTING;
+                       break;
+               }
+               case BTAV_CONNECTION_STATE_CONNECTED: {
+                       event = OAL_EVENT_AUDIO_CONNECTED;
+                       break;
+               }
+               case BTAV_CONNECTION_STATE_DISCONNECTING: {
+                       event = OAL_EVENT_AUDIO_DISCONNECTING;
+                       break;
+               }
+               case BTAV_CONNECTION_STATE_DISCONNECTED: {
+                       event = OAL_EVENT_AUDIO_DISCONNECTED;
+                       break;
+               }
+               default: {
+                       BT_INFO("Invalid state");
+                       g_free(event_data);
+                       event_data = NULL;
+                       return;
+               }
+       }
+       send_event_bda_trace(event, event_data, sizeof(bt_address_t), (bt_address_t*)bd_addr);
+}
+
+static void cb_audio_state(btav_audio_state_t state, bt_bdaddr_t* bd_addr)
+{
+       bdstr_t bdstr;
+
+       ret_if(bd_addr == NULL);
+       BT_INFO("A2DP state = %d,  BT Address = %s", state, bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
+
+       if (state == BTAV_AUDIO_STATE_REMOTE_SUSPEND) {
+               BT_INFO("Audio Streaming Suspended");
+       } else if ( state == BTAV_AUDIO_STATE_STOPPED) {
+               BT_INFO("###Audio Streaming Stopped");
+               bt_address_t * event_data = g_new0(bt_address_t, 1);
+
+               memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
+               send_event_bda_trace(OAL_EVENT_AUDIO_STOPPED, event_data, sizeof(bt_address_t), (bt_address_t*)bd_addr);
+       } else if( state == BTAV_AUDIO_STATE_STARTED) {
+               BT_INFO("###Audio Streaming Startted");
+               bt_address_t * event_data = g_new0(bt_address_t, 1);
+
+               memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
+               send_event_bda_trace(OAL_EVENT_AUDIO_STARTED, event_data, sizeof(bt_address_t), (bt_address_t*)bd_addr);
+       } else{
+               BT_ERR("Unknown state received:%d", (int)state);
+       }
+}