Merge "Mesh: Fix issues in Mesh Model Subscrition" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-avrcp-tg.c
index 58af0aa..31e0795 100644 (file)
@@ -53,6 +53,7 @@ static void cb_avrcp_set_player_app_value(btrc_player_settings_t *p_vals, bt_bda
 static void cb_avrcp_get_element_attr(uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
 static void cb_avrcp_register_notification(btrc_event_id_t event_id, uint32_t param, bt_bdaddr_t *bd_addr);
 static void cb_avrcp_volume_change(uint8_t volume, uint8_t ctype, bt_bdaddr_t *bd_addr);
+static void cb_avrcp_delay_change(uint16_t delay, bt_bdaddr_t *bd_addr);
 static void cb_avrcp_passthrough_command(int id, int pressed, bt_bdaddr_t *bd_addr);
 
 typedef struct {
@@ -104,31 +105,32 @@ static notif_t registered_notifications;
 static const btrc_interface_t *avrcp_api;
 
 static btrc_callbacks_t sBluetoothAvrcpCallbacks = {
-       sizeof(sBluetoothAvrcpCallbacks),
+       .size = sizeof(sBluetoothAvrcpCallbacks),
 #ifdef TIZEN_BT_HAL
-       cb_connection_state,
+       .connection_state_cb = cb_connection_state,
 #endif
-       cb_avrcp_remote_features,
-       cb_avrcp_get_play_status,
-       NULL, /* cb_avrcp_list_player_app_attr, */
-       NULL, /* cb_avrcp_list_player_app_values, */
-       NULL, /* cb_avrcp_get_player_app_value, */
-       NULL, /* cb_avrcp_get_player_app_attrs_text, */
-       NULL, /* cb_avrcp_get_player_app_values_text, */
-       cb_avrcp_set_player_app_value,
-       cb_avrcp_get_element_attr,
-       cb_avrcp_register_notification,
-       cb_avrcp_volume_change,
-       cb_avrcp_passthrough_command,
-       NULL, /* cb_avrcp_set_addressed_player, */
-       NULL, /* cb_avrcp_set_browsed_player, */
-       NULL, /* cb_avrcp_get_folder_items, */
-       NULL, /* cb_avrcp_change_path, */
-       NULL, /* cb_avrcp_get_item_attr, */
-       NULL, /* cb_avrcp_play_item, */
-       NULL, /* cb_avrcp_get_total_num_of_items, */
-       NULL, /* cb_avrcp_search, */
-       NULL, /* cb_avrcp_add_to_now_playing, */
+       .remote_features_cb = cb_avrcp_remote_features,
+       .get_play_status_cb = cb_avrcp_get_play_status,
+       .list_player_app_attr_cb = NULL,
+       .list_player_app_values_cb = NULL,
+       .get_player_app_value_cb = NULL,
+       .get_player_app_attrs_text_cb = NULL,
+       .get_player_app_values_text_cb = NULL,
+       .set_player_app_value_cb = cb_avrcp_set_player_app_value,
+       .get_element_attr_cb = cb_avrcp_get_element_attr,
+       .register_notification_cb = cb_avrcp_register_notification,
+       .volume_change_cb = cb_avrcp_volume_change,
+       .delay_change_cb = cb_avrcp_delay_change,
+       .passthrough_cmd_cb = cb_avrcp_passthrough_command,
+       .set_addressed_player_cb = NULL,
+       .set_browsed_player_cb = NULL,
+       .get_folder_items_cb = NULL,
+       .change_path_cb = NULL,
+       .get_item_attr_cb = NULL,
+       .play_item_cb = NULL,
+       .get_total_num_of_items_cb = NULL,
+       .search_cb = NULL,
+       .add_to_now_playing_cb = NULL,
 };
 
 static void send_pos_changed(void)
@@ -358,10 +360,12 @@ oal_status_t avrcp_set_track_info(oal_media_metadata_attributes_t *meta_data)
                int ret;
                btrc_register_notification_t response;
 
+               memset(&response, 0x00, sizeof(btrc_register_notification_t));
+
                track_info.cur_track = meta_data->number;
 
                /* Send Track Change notification */
-               memcpy(&response.track, &track_info.cur_track, BTRC_UID_SIZE);
+               memcpy(&response.track, &track_info.cur_track, sizeof(uint32_t));
                ret = avrcp_api->register_notification_rsp(
                        BTRC_EVT_TRACK_CHANGE, BTRC_NOTIFICATION_TYPE_CHANGED, &response);
                if (ret != BT_STATUS_SUCCESS)
@@ -449,41 +453,14 @@ oal_status_t avrcp_set_property(int type, unsigned int value)
        }
        case AVRCP_STATUS:
                if (value != player_setting.status) {
-                       btrc_play_status_t play_status = player_setting.status;
-
                        player_setting.status = (value == STATUS_ERROR) ? BTRC_PLAYSTATE_ERROR : value;
 
                        if (registered_notifications.play_status) {
-                               gboolean is_timer = FALSE;
-
                                response.play_status = player_setting.status;
                                ret = avrcp_api->register_notification_rsp(BTRC_EVT_PLAY_STATUS_CHANGED,
                                                BTRC_NOTIFICATION_TYPE_CHANGED, &response);
                                if (ret != BT_STATUS_SUCCESS)
                                        BT_ERR("Notif send failed: %s", status2string(ret));
-
-                               /* Check if old and new status value are changed from NOT PLAYING to PLAYING */
-                               switch (play_status) {
-                               case BTRC_PLAYSTATE_ERROR:      /* Intentional fall-through */
-                               case BTRC_PLAYSTATE_STOPPED:    /* Intentional fall-through */
-                               case BTRC_PLAYSTATE_PAUSED:     /* Intentional fall-through */
-                                       if (STATUS_PLAYING == value ||
-                                                       STATUS_REVERSE_SEEK == value ||
-                                                       STATUS_FORWARD_SEEK == value) {
-                                               BT_INFO("Play status changed from stopped to playing");
-                                               is_timer = TRUE;
-                                       }
-                                       break;
-                               default:
-                                       is_timer = FALSE;
-                               }
-
-                               if (is_timer) {
-                                       BT_DBG("Player is playing mode, start sending pos change notifications");
-                                       remove_pos_timer();
-                                       send_pos_timer = g_timeout_add(registered_notifications.interval * 1000,
-                                                       send_pos_timeout, NULL);
-                               }
                        }
                }
                break;
@@ -502,6 +479,61 @@ oal_status_t avrcp_set_property(int type, unsigned int value)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t avrcp_tg_set_volume(bt_address_t *rem_addr, unsigned int volume)
+{
+       int result = OAL_STATUS_SUCCESS;
+       bt_status_t status;
+       bdstr_t bdstr;
+
+       API_TRACE();
+
+       CHECK_OAL_AVRCP_ENABLED();
+       OAL_CHECK_PARAMETER(rem_addr, return);
+
+       BT_INFO("BT Audio Address: %s", bdt_bd2str(rem_addr, &bdstr));
+
+#ifdef TIZEN_BT_HAL
+       status = avrcp_api->set_volume((bt_bdaddr_t *)rem_addr, volume);
+       if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
+               BT_ERR("set volume failed, err: %s", status2string(status));;
+               result = convert_to_oal_status(status);
+       }
+#else
+       BT_INFO("Not Supported");
+       result = OAL_STATUS_NOT_SUPPORT;
+#endif
+
+       return result;
+}
+
+oal_status_t avrcp_tg_get_volume(bt_address_t *rem_addr, unsigned int *volume)
+{
+       int result = OAL_STATUS_SUCCESS;
+       bt_status_t status;
+       bdstr_t bdstr;
+
+       API_TRACE();
+
+       CHECK_OAL_AVRCP_ENABLED();
+       OAL_CHECK_PARAMETER(rem_addr, return);
+
+       BT_INFO("BT Audio Address: %s", bdt_bd2str(rem_addr, &bdstr));
+
+#ifdef TIZEN_BT_HAL
+       status = avrcp_api->get_volume((bt_bdaddr_t *)rem_addr, volume);
+       if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
+               BT_ERR("set volume failed, err: %s", status2string(status));;
+               result = convert_to_oal_status(status);
+       }
+#else
+       BT_INFO("Not Supported");
+       result = OAL_STATUS_NOT_SUPPORT;
+#endif
+
+       return result;
+}
+
+
 #ifdef TIZEN_BT_HAL
 static void cb_connection_state(bt_bdaddr_t* bd_addr, btrc_connection_state_t state)
 {
@@ -674,6 +706,7 @@ static void cb_avrcp_register_notification(btrc_event_id_t event_id, uint32_t pa
                BT_ERR("AVRCP Not Enabled");
                return ;
        }
+       memset(&response, 0x00, sizeof(btrc_register_notification_t));
 
        switch (event_id) {
        case BTRC_EVT_PLAY_STATUS_CHANGED:
@@ -684,7 +717,7 @@ static void cb_avrcp_register_notification(btrc_event_id_t event_id, uint32_t pa
                break;
        case BTRC_EVT_TRACK_CHANGE:
                registered_notifications.track_change = 1;
-               memcpy(response.track, &track_info.cur_track, BTRC_UID_SIZE);
+               memcpy(response.track, &track_info.cur_track, sizeof(uint32_t));
                ret = avrcp_api->register_notification_rsp(
                        BTRC_EVT_TRACK_CHANGE, BTRC_NOTIFICATION_TYPE_INTERIM, &response);
                break;
@@ -747,6 +780,16 @@ static void cb_avrcp_volume_change(uint8_t volume, uint8_t ctype, bt_bdaddr_t *b
                        avrcp_volume_mute, sizeof(oal_avrcp_volume_mute_t));
 }
 
+static void cb_avrcp_delay_change(uint16_t delay, bt_bdaddr_t *bd_addr)
+{
+       BT_INFO("Delay : %d", delay);
+       oal_avrcp_delay_t *avrcp_delay = g_new0(oal_avrcp_delay_t, 1);
+       avrcp_delay->delay = delay;
+
+       send_event(OAL_EVENT_AVRCP_DELAY_CHANGED,
+                       avrcp_delay, sizeof(oal_avrcp_delay_t));
+}
+
 static void cb_avrcp_passthrough_command(int id, int key_state, bt_bdaddr_t *bd_addr)
 {
        BT_DBG("id: %d, key_state: %d", id, key_state);