2 * Open Adaptation Layer (OAL)
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
6 * Contact: Nilesh Trimbake <t.shripati@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <sys/socket.h>
25 #include <sys/errno.h>
31 #include <bluetooth.h>
34 #include "oal-internal.h"
35 #include "oal-avrcp-ct.h"
36 #include "oal-utils.h"
37 #include "oal-common.h"
39 #define CHECK_OAL_AVRCP_CTRL_ENABLED() \
41 if (avrcp_ct_interface == NULL) { \
42 BT_ERR("OAL, Audio Not Enabled"); \
43 return OAL_STATUS_NOT_READY; \
47 #define NO_OF_ATTRIBUTE 1
51 long int playing_time;
52 uint8_t title_info[BTRC_MAX_ATTR_STR_LEN];
53 uint8_t artist_info[BTRC_MAX_ATTR_STR_LEN];
54 uint8_t album_info[BTRC_MAX_ATTR_STR_LEN];
55 uint8_t genre_info[BTRC_MAX_ATTR_STR_LEN];
57 uint32_t track_number;
58 } avrcp_ct_track_info_t;
63 btrc_player_repeat_val_t repeat;
64 btrc_player_shuffle_val_t shuffle;
66 btrc_play_status_t status;
68 } avrcp_ct_player_settings_t;
71 char address[BT_ADDRESS_STR_LEN];
72 avrcp_ct_player_settings_t player_setting;
73 avrcp_ct_track_info_t track_info;
74 } avrcp_ct_player_info_t;
76 static GSList *player_list = NULL;
78 const btrc_ctrl_interface_t * _bt_get_stack_interface(void);
79 static const btrc_ctrl_interface_t *avrcp_ct_interface = NULL;
81 static void cb_avrcp_ct_connection_state(bool rc_connect, bool bt_connect, bt_bdaddr_t* bd_addr);
82 static void cb_avrcp_ct_btrc_playerapplicationsetting_changed(bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals);
83 static void cb_avrcp_ct_btrc_play_position_changed(bt_bdaddr_t *bd_addr, uint32_t song_len, uint32_t song_pos);
84 static void cb_avrcp_ct_btrc_play_status_changed(bt_bdaddr_t *bd_addr, btrc_play_status_t play_status);
85 static void cb_avrcp_ct_trak_info_chnaged(bt_bdaddr_t *bd_address, uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
86 static void cb_avrcp_ct_btrc_passthrough_rsp(bt_bdaddr_t *bd_addr, int id, int key_state);
87 static void cb_avrcp_ct_btrc_setplayerapplicationsetting_rsp(bt_bdaddr_t *bd_addr, uint8_t accepted);
89 /** AVRCP Controller callback structure. */
90 static btrc_ctrl_callbacks_t avrcp_ct_cb = {
91 .size = sizeof(avrcp_ct_cb),
92 .passthrough_rsp_cb = cb_avrcp_ct_btrc_passthrough_rsp,
93 .groupnavigation_rsp_cb = NULL,
94 .connection_state_cb = cb_avrcp_ct_connection_state,
95 .getrcfeatures_cb = NULL,
96 .setplayerappsetting_rsp_cb = cb_avrcp_ct_btrc_setplayerapplicationsetting_rsp,
97 .playerapplicationsetting_cb = NULL,
98 .playerapplicationsetting_changed_cb = cb_avrcp_ct_btrc_playerapplicationsetting_changed,
99 .setabsvol_cmd_cb = NULL,
100 .registernotification_absvol_cb = NULL,
101 .track_changed_cb = cb_avrcp_ct_trak_info_chnaged,
102 .play_position_changed_cb = cb_avrcp_ct_btrc_play_position_changed,
103 .play_status_changed_cb = cb_avrcp_ct_btrc_play_status_changed,
104 .get_folder_items_cb = NULL,
105 .change_folder_path_cb = NULL,
106 .set_browsed_player_cb = NULL,
107 .set_addressed_player_cb = NULL
110 static void __add_device_to_avrcp_list(bt_address_t *address)
112 avrcp_ct_player_info_t *player_info;
113 avrcp_ct_player_settings_t *player_setting;
117 bdt_bd2str(address, &bdstr);
118 BT_INFO("Address: %s", bdstr);
119 for (l = player_list; NULL != l; l = g_slist_next(l)) {
120 player_info = (avrcp_ct_player_info_t *)l->data;
125 if (!strncmp(bdstr, player_info->address, BT_ADDRESS_STR_LEN)) {
126 BT_INFO("Already added");
131 player_info = g_new0(avrcp_ct_player_info_t, 1);
133 /* Copy address to player_info->address */
134 g_strlcpy(player_info->address, bdstr, BT_ADDRESS_STR_LEN);
136 /* Init player settings with default values */
137 player_setting = &player_info->player_setting;
138 player_setting->equalizer = 0;
139 player_setting->repeat = BTRC_PLAYER_VAL_OFF_REPEAT;
140 player_setting->shuffle = BTRC_PLAYER_VAL_OFF_SHUFFLE;
141 player_setting->scan = 0;
142 player_setting->status = BTRC_PLAYSTATE_STOPPED;
143 player_setting->volume = 0;
145 /* Nothing to do for track_info as values are already initialized to 0 */
147 /* Add player_info to player_list */
148 player_list = g_slist_append(player_list, player_info);
151 static void __remove_device_from_avrcp_list(bt_address_t *address)
153 avrcp_ct_player_info_t *player_info = NULL;
157 bdt_bd2str(address, &bdstr);
158 BT_INFO("Address: %s", bdstr);
159 for (l = player_list; NULL != l; l = g_slist_next(l)) {
160 player_info = (avrcp_ct_player_info_t *)l->data;
165 if (!strncmp(bdstr, player_info->address, BT_ADDRESS_STR_LEN)) {
176 player_list = g_slist_remove(player_list, player_info);
180 static avrcp_ct_player_info_t *__get_player_info_from_list(bt_address_t *address)
182 avrcp_ct_player_info_t *player_info;
186 bdt_bd2str(address, &bdstr);
187 BT_INFO("Address: %s", bdstr);
188 for (l = player_list; NULL != l; l = g_slist_next(l)) {
189 player_info = (avrcp_ct_player_info_t *)l->data;
194 if (!strncmp(bdstr, player_info->address, BT_ADDRESS_STR_LEN)) {
203 oal_status_t avrcp_ct_enable(void)
205 const bt_interface_t* blued_inf;
208 API_TRACE("AVRCP Controller Enable");
210 if ((blued_inf = adapter_get_stack_interface()) == NULL) {
211 BT_ERR("Bluetooth module is not loaded");
212 return OAL_STATUS_NOT_READY;
215 if (avrcp_ct_interface != NULL) {
216 BT_WARN("AVRCP Controller Interface is already initialized...");
217 return OAL_STATUS_ALREADY_DONE;
220 if ((avrcp_ct_interface = (const btrc_ctrl_interface_t *)blued_inf->get_profile_interface(BT_PROFILE_AV_RC_CTRL_ID)) == NULL) {
221 BT_ERR("OAL, Failed to get Bluetooth AVRCP Controller Interface");
222 return OAL_STATUS_INTERNAL_ERROR;
225 BT_DBG("Got profile interface");
226 if ((ret = avrcp_ct_interface->init(&avrcp_ct_cb)) != BT_STATUS_SUCCESS) {
227 BT_ERR("Failed to initialize Bluetooth AVRCP Controller, status: %s", status2string(ret));
228 avrcp_ct_interface = NULL;
229 return convert_to_oal_status(ret);
231 BT_DBG("OAL, Bluetooth avrcp controller interface initialised");
233 return OAL_STATUS_SUCCESS;
236 /* Audio deinit: Resets all the audio information
237 * Note: Adapter should be disabled before calling deinit
239 oal_status_t avrcp_ct_disable(void)
241 API_TRACE("AVRCP Controller Disable");
243 CHECK_OAL_AVRCP_CTRL_ENABLED();
245 avrcp_ct_interface->cleanup();
246 avrcp_ct_interface = NULL;
248 return OAL_STATUS_SUCCESS;
251 void avrcp_ct_cleanup(void)
254 avrcp_ct_interface = NULL;
258 oal_status_t avrcp_ct_connect(bt_address_t *device_address)
260 int result = OAL_STATUS_SUCCESS;
266 CHECK_OAL_AVRCP_CTRL_ENABLED();
267 OAL_CHECK_PARAMETER(device_address, return);
269 BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
272 status = avrcp_ct_interface->connect((bt_bdaddr_t *)device_address);
273 if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
274 BT_ERR("Connection could not be established, err: %s", status2string(status));;
275 result = convert_to_oal_status(status);
278 BT_INFO("Not Supported");
279 result = OAL_STATUS_NOT_SUPPORT;
284 oal_status_t avrcp_ct_disconnect(bt_address_t *device_address)
286 int result = OAL_STATUS_SUCCESS;
292 CHECK_OAL_AVRCP_CTRL_ENABLED();
293 OAL_CHECK_PARAMETER(device_address, return);
295 BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
298 status = avrcp_ct_interface->disconnect((bt_bdaddr_t *)device_address);
299 if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
300 BT_ERR("OAL, Disconnection failed err: %s", status2string(status));
301 result = convert_to_oal_status(status);
304 BT_INFO("Not Supported");
305 result = OAL_STATUS_NOT_SUPPORT;
310 static void cb_avrcp_ct_connection_state(bool rc_connect, bool bt_connect, bt_bdaddr_t* bd_addr)
312 bt_address_t *event_data = NULL;
316 ret_if(bd_addr == NULL);
317 BT_INFO("rc_connect = %d, bt_connect = %d, BT Address = %s",
318 rc_connect, bt_connect, bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
320 event_data = g_new0(bt_address_t, 1);
321 memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
324 event = OAL_EVENT_AVRCP_CT_CONNECTED;
325 __add_device_to_avrcp_list(event_data);
327 event = OAL_EVENT_AVRCP_CT_DISCONNECTED;
328 __remove_device_from_avrcp_list(event_data);
331 send_event_bda_trace(event, event_data, sizeof(bt_address_t), (bt_address_t*)bd_addr);
334 notif_event_avrcp_ct_play_status_t __hal_to_oal_play_status(btrc_play_status_t play_status)
336 notif_event_avrcp_ct_play_status_t status = OAL_PLAY_STATUS_ERROR;
338 switch (play_status) {
339 case BTRC_PLAYSTATE_STOPPED:
340 status = OAL_PLAY_STATUS_STOPPED;
342 case BTRC_PLAYSTATE_PLAYING:
343 status = OAL_PLAY_STATUS_PLAYING;
345 case BTRC_PLAYSTATE_PAUSED:
346 status = OAL_PLAY_STATUS_PAUSED;
348 case BTRC_PLAYSTATE_FWD_SEEK:
349 status = OAL_PLAY_STATUS_FWD_SEEK;
351 case BTRC_PLAYSTATE_REV_SEEK:
352 status = OAL_PLAY_STATUS_REV_SEEK;
355 BT_INFO("Incorrect Play status");
362 static avrcp_ct_player_settings_t *__get_player_setting(bt_address_t *address)
364 avrcp_ct_player_info_t *player_info;
367 player_info = __get_player_info_from_list(address);
371 return &player_info->player_setting;
374 static void cb_avrcp_ct_btrc_playerapplicationsetting_changed(
375 bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals)
377 avrcp_ct_property_value_t *event_data = NULL;
381 avrcp_ct_player_settings_t *player_setting;
383 bdt_bd2str((bt_address_t *)bd_addr, &bdstr);
384 player_setting = __get_player_setting((bt_address_t *)bd_addr);
385 if (!player_setting) {
386 BT_INFO("player_setting is NULL");
387 /* Player info not yet added to player_list, first add it to list */
388 __add_device_to_avrcp_list((bt_address_t *)bd_addr);
389 player_setting = __get_player_setting((bt_address_t *)bd_addr);
392 for (i = 0; i < p_vals->num_attr; i++) {
393 event_data = g_new0(avrcp_ct_property_value_t, 1);
395 switch (p_vals->attr_ids[i]) {
396 case BTRC_PLAYER_ATTR_EQUALIZER:
397 event = OAL_EVENT_AVRCP_CT_EQUALIZER_STATUS;
398 event_data->type = OAL_EQUALIZER;
399 event_data->value = p_vals->attr_values[i];
400 player_setting->equalizer = p_vals->attr_values[i];
402 case BTRC_PLAYER_ATTR_REPEAT:
403 event = OAL_EVENT_AVRCP_CT_REPEAT_STATUS;
404 event_data->type = OAL_REPEAT;
405 event_data->value = p_vals->attr_values[i];
406 player_setting->repeat = p_vals->attr_values[i];
408 case BTRC_PLAYER_ATTR_SHUFFLE:
409 event = OAL_EVENT_AVRCP_CT_SHUFFLE_STATUS;
410 event_data->type = OAL_SHUFFLE;
411 event_data->value = p_vals->attr_values[i];
412 player_setting->shuffle = p_vals->attr_values[i];
414 case BTRC_PLAYER_ATTR_SCAN:
415 event = OAL_EVENT_AVRCP_CT_SCAN_STATUS;
416 event_data->type = OAL_SCAN;
417 event_data->value = p_vals->attr_values[i];
418 player_setting->scan = p_vals->attr_values[i];
421 event = OAL_EVENT_END;
426 if (OAL_EVENT_END != event)
427 send_event(event, event_data, sizeof(avrcp_ct_property_value_t));
431 static avrcp_ct_track_info_t *__get_track_info(bt_address_t *address)
433 avrcp_ct_player_info_t *player_info;
436 player_info = __get_player_info_from_list(address);
440 return &player_info->track_info;
443 static void cb_avrcp_ct_btrc_play_position_changed(
444 bt_bdaddr_t *bd_addr, uint32_t song_len, uint32_t song_pos)
446 event_notif_avrcp_ct_notif_info_t *event_data = NULL;
447 avrcp_ct_track_info_t *track_info;
449 track_info = __get_track_info((bt_address_t *)bd_addr);
451 BT_INFO("track_info is NULL");
452 /* Player info not yet added to player_list, first add it to list */
453 __add_device_to_avrcp_list((bt_address_t *)bd_addr);
454 track_info = __get_track_info((bt_address_t *)bd_addr);
456 track_info->song_pos = song_pos;
458 event_data = g_new0(event_notif_avrcp_ct_notif_info_t, 1);
459 event_data->song_pos = song_pos;
460 send_event(OAL_EVENT_AVRCP_CT_NOTIF_PLAY_POS_CHANGED,
461 event_data, sizeof(event_notif_avrcp_ct_notif_info_t));
464 static void cb_avrcp_ct_btrc_play_status_changed(
465 bt_bdaddr_t *bd_addr, btrc_play_status_t play_status)
467 event_notif_avrcp_ct_notif_info_t *event_data = NULL;
468 avrcp_ct_player_settings_t *player_setting;
470 player_setting = __get_player_setting((bt_address_t *)bd_addr);
471 if (!player_setting) {
472 BT_INFO("player_setting is NULL");
473 /* Player info not yet added to player_list, first add it to list */
474 __add_device_to_avrcp_list((bt_address_t *)bd_addr);
475 player_setting = __get_player_setting((bt_address_t *)bd_addr);
478 player_setting->status = play_status;
480 event_data = g_new0(event_notif_avrcp_ct_notif_info_t, 1);
481 event_data->play_status = __hal_to_oal_play_status(play_status);
482 send_event(OAL_EVENT_AVRCP_CT_NOTIF_PLAY_STATUS_CHANGED,
483 event_data, sizeof(event_notif_avrcp_ct_notif_info_t));
486 static void cb_avrcp_ct_btrc_passthrough_rsp(bt_bdaddr_t *bd_addr, int id, int state)
488 avrcp_ct_pass_cmd_key_code_t key_code;
489 avrcp_ct_pass_state_t key_state;
490 avrcp_ct_pass_cmd_t *event_data;
492 event_data = g_new0(avrcp_ct_pass_cmd_t, 1);
497 event_data->key_code = key_code;
498 event_data->key_state = key_state;
499 send_event(OAL_EVENT_AVRCP_CT_PASS_CMD_RES,
500 event_data, sizeof(avrcp_ct_pass_cmd_t));
502 BT_ERR("Invalid pass through command key code");
507 static void cb_avrcp_ct_btrc_setplayerapplicationsetting_rsp(
508 bt_bdaddr_t *bd_addr, uint8_t accepted)
510 avrcp_ct_playersetting_t *event_data;
512 event_data = g_new0(avrcp_ct_playersetting_t, 1);
514 event_data->accepted = accepted;
515 send_event(OAL_EVENT_AVRCP_CT_PLAYER_SETTING_RES,
516 event_data, sizeof(avrcp_ct_playersetting_t));
519 static void cb_avrcp_ct_trak_info_chnaged(bt_bdaddr_t *device_address,
520 uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
523 avrcp_ct_track_info_t *track_info;
524 event_avrcp_ct_media_info_t *event_data = NULL;
526 track_info = __get_track_info((bt_address_t *)device_address);
528 BT_INFO("track_info is NULL");
529 /* Player info not yet added to player_list, first add it to list */
530 __add_device_to_avrcp_list((bt_address_t *)device_address);
531 track_info = __get_track_info((bt_address_t *)device_address);
534 event_data = g_new0(event_avrcp_ct_media_info_t, 1);
535 for (idx = 0; idx < num_attr; idx++) {
536 BT_INFO("idx [%d]", p_attrs[idx].attr_id);
538 switch (p_attrs[idx].attr_id) {
539 case BTRC_MEDIA_ATTR_ID_TITLE:
540 g_strlcpy((char *)track_info->title_info, (const char *)&p_attrs[idx].text,
541 MEDIA_ATTIRBUTE_STRING_LENGTH);
542 g_strlcpy((char *)event_data->title_info, (const char *)&p_attrs[idx].text,
543 MEDIA_ATTIRBUTE_STRING_LENGTH);
545 case BTRC_MEDIA_ATTR_ID_ARTIST:
546 g_strlcpy((char *)track_info->artist_info, (const char *)&p_attrs[idx].text,
547 MEDIA_ATTIRBUTE_STRING_LENGTH);
548 g_strlcpy((char *)event_data->artist_info, (const char *)&p_attrs[idx].text,
549 MEDIA_ATTIRBUTE_STRING_LENGTH);
551 case BTRC_MEDIA_ATTR_ID_ALBUM:
552 g_strlcpy((char *)track_info->album_info, (const char *)&p_attrs[idx].text,
553 MEDIA_ATTIRBUTE_STRING_LENGTH);
554 g_strlcpy((char *)event_data->album_info, (const char *)&p_attrs[idx].text,
555 MEDIA_ATTIRBUTE_STRING_LENGTH);
557 case BTRC_MEDIA_ATTR_ID_GENRE:
558 g_strlcpy((char *)track_info->genre_info, (const char *)&p_attrs[idx].text,
559 MEDIA_ATTIRBUTE_STRING_LENGTH);
560 g_strlcpy((char *)event_data->genre_info, (const char *)&p_attrs[idx].text,
561 MEDIA_ATTIRBUTE_STRING_LENGTH);
563 case BTRC_MEDIA_ATTR_ID_NUM_TRACKS:
564 if (p_attrs[idx].text != NULL) {
565 track_info->total_track = g_ascii_strtoll(
566 (const gchar *)p_attrs[idx].text, NULL, 10);
567 event_data->total_track = track_info->total_track;
570 case BTRC_MEDIA_ATTR_ID_TRACK_NUM:
571 if (p_attrs[idx].text != NULL) {
572 track_info->track_number = g_ascii_strtoll(
573 (const gchar *)p_attrs[idx].text, NULL, 10);
574 event_data->track_number = track_info->track_number;
577 case BTRC_MEDIA_ATTR_ID_PLAYING_TIME:
578 track_info->playing_time = g_ascii_strtoll(
579 (const gchar *)p_attrs[idx].text, NULL, 10);
580 event_data->playing_time = (uint64_t) track_info->playing_time;
587 send_event(OAL_EVENT_AVRCP_CT_NOTIF_TRACK_CHANGE,
588 event_data, sizeof(event_avrcp_ct_media_info_t));
592 oal_status_t __avrcp_ct_send_pass_through_cmd(bt_address_t *device_address,
593 avrcp_ct_pass_cmd_key_code_t key_code, avrcp_ct_pass_state_t key_state)
595 int result = OAL_STATUS_SUCCESS;
601 CHECK_OAL_AVRCP_CTRL_ENABLED();
603 BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
605 status = avrcp_ct_interface->send_pass_through_cmd((bt_bdaddr_t *)device_address,
606 key_code, key_state);
607 if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
608 BT_ERR("OAL, send pass through cmd failed err: %s", status2string(status));
609 result = convert_to_oal_status(status);
614 oal_status_t avrcp_ct_play(bt_address_t *device_address)
616 oal_status_t result = OAL_STATUS_SUCCESS;
620 result = __avrcp_ct_send_pass_through_cmd(device_address,
621 OAL_RC_PASS_CMD_PLAY, PRESS_STATE);
626 oal_status_t avrcp_ct_pause(bt_address_t *device_address)
628 oal_status_t result = OAL_STATUS_SUCCESS;
632 result = __avrcp_ct_send_pass_through_cmd(device_address,
633 OAL_RC_PASS_CMD_PAUSE, PRESS_STATE);
638 oal_status_t avrcp_ct_stop(bt_address_t *device_address)
640 oal_status_t result = OAL_STATUS_SUCCESS;
644 result = __avrcp_ct_send_pass_through_cmd(device_address,
645 OAL_RC_PASS_CMD_STOP, PRESS_STATE);
650 oal_status_t avrcp_ct_next_track(bt_address_t *device_address)
652 oal_status_t result = OAL_STATUS_SUCCESS;
656 result = __avrcp_ct_send_pass_through_cmd(device_address,
657 OAL_RC_PASS_CMD_NEXT, PRESS_STATE);
662 oal_status_t avrcp_ct_prev_track(bt_address_t *device_address)
664 oal_status_t result = OAL_STATUS_SUCCESS;
668 result = __avrcp_ct_send_pass_through_cmd(device_address,
669 OAL_RC_PASS_CMD_PREVIOUS, PRESS_STATE);
674 oal_status_t avrcp_ct_volume_up(bt_address_t *device_address)
676 oal_status_t result = OAL_STATUS_SUCCESS;
680 result = __avrcp_ct_send_pass_through_cmd(device_address,
681 OAL_RC_PASS_CMD_VOLUME_UP, PRESS_STATE);
686 oal_status_t avrcp_ct_volume_down(bt_address_t *device_address)
688 oal_status_t result = OAL_STATUS_SUCCESS;
692 result = __avrcp_ct_send_pass_through_cmd(device_address,
693 OAL_RC_PASS_CMD_VOLUME_DOWN, PRESS_STATE);
698 oal_status_t avrcp_ct_fforward(bt_address_t *device_address, avrcp_ct_pass_state_t press_state)
700 oal_status_t result = OAL_STATUS_SUCCESS;
703 switch (press_state) {
705 result = __avrcp_ct_send_pass_through_cmd(device_address,
706 OAL_RC_PASS_CMD_PRESS_FAST_FORWARD, press_state);
709 result = __avrcp_ct_send_pass_through_cmd(device_address,
710 OAL_RC_PASS_CMD_RELEASE_FAST_FORWARD, press_state);
713 result = OAL_STATUS_INVALID_PARAM;
720 oal_status_t avrcp_ct_rewind(bt_address_t *device_address, avrcp_ct_pass_state_t press_state)
722 oal_status_t result = OAL_STATUS_SUCCESS;
725 switch (press_state) {
727 result = __avrcp_ct_send_pass_through_cmd(device_address,
728 OAL_RC_PASS_CMD_PRESS_REWIND, press_state);
731 result = __avrcp_ct_send_pass_through_cmd(device_address,
732 OAL_RC_PASS_CMD_RELEASE_REWIND, press_state);
735 result = OAL_STATUS_INVALID_PARAM;
742 uint8_t __oal_to_hal_property_type(avrcp_ct_player_property_type_t type)
744 uint8_t property_type = 0;
748 property_type = BTRC_PLAYER_ATTR_EQUALIZER;
751 property_type = BTRC_PLAYER_ATTR_REPEAT;
754 property_type = BTRC_PLAYER_ATTR_SHUFFLE;
757 property_type = BTRC_PLAYER_ATTR_SCAN;
760 BT_ERR(" Invalid Property type[%d]", type);
764 return property_type;
767 oal_status_t avrcp_ct_set_property(bt_address_t *device_address, avrcp_ct_player_property_type_t type, uint32_t value)
769 int result = OAL_STATUS_SUCCESS;
770 uint8_t property_type;
776 CHECK_OAL_AVRCP_CTRL_ENABLED();
777 BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
779 property_type = __oal_to_hal_property_type(type);
781 status = avrcp_ct_interface->set_player_app_setting_cmd((bt_bdaddr_t *)device_address, NO_OF_ATTRIBUTE,
782 (uint8_t*)&property_type, (uint8_t*)&value);
783 if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
784 BT_ERR("OAL, Set property failed err: %s", status2string(status));
785 result = convert_to_oal_status(status);
788 result = OAL_STATUS_INTERNAL_ERROR;
793 oal_status_t avrcp_transport_set_property(bt_address_t *device_address, int type, unsigned int value)
795 int result = OAL_STATUS_SUCCESS;
801 CHECK_OAL_AVRCP_CTRL_ENABLED();
802 BT_INFO("BT Audio Address: %s", bdt_bd2str(device_address, &bdstr));
805 status = avrcp_ct_interface->set_transport_setting_cmd((bt_bdaddr_t *)device_address, NO_OF_ATTRIBUTE,
807 if ((status != BT_STATUS_SUCCESS) && (status != BT_STATUS_DONE)) {
808 BT_ERR("OAL, Set property failed err: %s", status2string(status));
809 result = convert_to_oal_status(status);
812 result = OAL_STATUS_INTERNAL_ERROR;
817 static gboolean __send_avrcp_property_event(gpointer data)
819 avrcp_ct_property_value_t *event_data = (avrcp_ct_property_value_t *)data;
821 send_event(OAL_EVENT_AVRCP_CT_GET_PROPERTY_RES,
822 event_data, sizeof(avrcp_ct_property_value_t));
826 oal_status_t avrcp_ct_get_property(bt_address_t *device_address, avrcp_ct_player_property_type_t type)
828 avrcp_ct_player_info_t *player_info;
829 avrcp_ct_player_settings_t *player_setting;
830 avrcp_ct_track_info_t *track_info;
831 avrcp_ct_property_value_t *event_data;
834 CHECK_OAL_AVRCP_CTRL_ENABLED();
836 player_info = __get_player_info_from_list(device_address);
838 BT_ERR("Player info not found");
839 return OAL_STATUS_INVALID_PARAM;
842 player_setting = &player_info->player_setting;
843 track_info = &player_info->track_info;
845 event_data = g_new0(avrcp_ct_property_value_t, 1);
846 event_data->type = type;
850 event_data->value = player_setting->equalizer;
853 event_data->value = player_setting->repeat;
856 event_data->value = player_setting->shuffle;
859 event_data->value = player_setting->scan;
861 case OAL_PLAY_POSITION:
862 event_data->value = track_info->song_pos;
865 BT_ERR("Invalid Type [%d]", type);
867 return OAL_STATUS_INVALID_PARAM;
870 g_idle_add(__send_avrcp_property_event, (gpointer)event_data);
871 return OAL_STATUS_SUCCESS;
874 static gboolean __send_avrcp_play_status_event(gpointer data)
876 event_avrcp_ct_play_status_t *event_data = (event_avrcp_ct_play_status_t *)data;
878 send_event(OAL_EVENT_AVRCP_CT_PLAY_STATUS,
879 event_data, sizeof(event_avrcp_ct_play_status_t));
884 oal_status_t avrcp_ct_get_play_status(bt_address_t *device_address)
886 avrcp_ct_player_info_t *player_info;
887 avrcp_ct_player_settings_t *player_setting;
888 avrcp_ct_track_info_t *track_info;
889 event_avrcp_ct_play_status_t *event_data = NULL;
892 CHECK_OAL_AVRCP_CTRL_ENABLED();
894 player_info = __get_player_info_from_list(device_address);
896 BT_ERR("Player info not found");
897 return OAL_STATUS_INVALID_PARAM;
900 player_setting = &player_info->player_setting;
901 track_info = &player_info->track_info;
903 event_data = g_new0(event_avrcp_ct_play_status_t, 1);
904 event_data->song_len = track_info->playing_time;
905 event_data->song_pos = track_info->song_pos;
907 switch (player_setting->status) {
908 case BTRC_PLAYSTATE_STOPPED:
909 event_data->play_status = OAL_PLAY_STATUS_STOPPED;
911 case BTRC_PLAYSTATE_PLAYING:
912 event_data->play_status = OAL_PLAY_STATUS_PLAYING;
914 case BTRC_PLAYSTATE_PAUSED:
915 event_data->play_status = OAL_PLAY_STATUS_PAUSED;
917 case BTRC_PLAYSTATE_FWD_SEEK:
918 event_data->play_status = OAL_PLAY_STATUS_FWD_SEEK;
920 case BTRC_PLAYSTATE_REV_SEEK:
921 event_data->play_status = OAL_PLAY_STATUS_REV_SEEK;
924 event_data->play_status = OAL_PLAY_STATUS_ERROR;
928 g_idle_add(__send_avrcp_play_status_event, (gpointer)event_data);
929 return OAL_STATUS_SUCCESS;
932 static gboolean __send_media_attribute_event(gpointer data)
934 event_avrcp_ct_media_info_t *event_data = (event_avrcp_ct_media_info_t *)data;
936 send_event(OAL_EVENT_AVRCP_CT_MEDIA_INFO,
937 event_data, sizeof(event_avrcp_ct_media_info_t));
942 oal_status_t avrcp_ct_get_media_attribute(bt_address_t *device_address)
944 avrcp_ct_track_info_t *track_info;
945 event_avrcp_ct_media_info_t *event_data;
949 CHECK_OAL_AVRCP_CTRL_ENABLED();
951 OAL_CHECK_PARAMETER(device_address, return);
953 track_info = __get_track_info(device_address);
955 BT_ERR("Player info not found");
956 return OAL_STATUS_INVALID_PARAM;
959 event_data = g_new0(event_avrcp_ct_media_info_t, 1);
960 g_strlcpy((char *)event_data->title_info, (const char *)track_info->title_info,
961 MEDIA_ATTIRBUTE_STRING_LENGTH);
962 g_strlcpy((char *)event_data->album_info, (const char *)track_info->album_info,
963 MEDIA_ATTIRBUTE_STRING_LENGTH);
964 g_strlcpy((char *)event_data->genre_info, (const char *)track_info->genre_info,
965 MEDIA_ATTIRBUTE_STRING_LENGTH);
966 g_strlcpy((char *)event_data->artist_info, (const char *)track_info->artist_info,
967 MEDIA_ATTIRBUTE_STRING_LENGTH);
968 event_data->playing_time = (uint64_t)track_info->playing_time;
969 event_data->total_track = track_info->total_track;
970 event_data->track_number = track_info->track_number;
972 g_idle_add(__send_media_attribute_event, (gpointer)event_data);
974 return OAL_STATUS_SUCCESS;