1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_INCLUDE_BT_RC_H 18 #define ANDROID_INCLUDE_BT_RC_H 19 20 __BEGIN_DECLS 21 22 /* Macros */ 23 #define BTRC_MAX_ATTR_STR_LEN 255 24 #define BTRC_UID_SIZE 8 25 #define BTRC_MAX_APP_SETTINGS 8 26 #define BTRC_MAX_FOLDER_DEPTH 4 27 #define BTRC_MAX_APP_ATTR_SIZE 16 28 #define BTRC_MAX_ELEM_ATTR_SIZE 7 29 30 typedef uint8_t btrc_uid_t[BTRC_UID_SIZE]; 31 32 typedef enum { 33 BTRC_FEAT_NONE = 0x00, /* AVRCP 1.0 */ 34 BTRC_FEAT_METADATA = 0x01, /* AVRCP 1.3 */ 35 BTRC_FEAT_ABSOLUTE_VOLUME = 0x02, /* Supports TG role and volume sync */ 36 BTRC_FEAT_BROWSE = 0x04, /* AVRCP 1.4 and up, with Browsing support */ 37 } btrc_remote_features_t; 38 39 typedef enum { 40 BTRC_PLAYSTATE_STOPPED = 0x00, /* Stopped */ 41 BTRC_PLAYSTATE_PLAYING = 0x01, /* Playing */ 42 BTRC_PLAYSTATE_PAUSED = 0x02, /* Paused */ 43 BTRC_PLAYSTATE_FWD_SEEK = 0x03, /* Fwd Seek*/ 44 BTRC_PLAYSTATE_REV_SEEK = 0x04, /* Rev Seek*/ 45 BTRC_PLAYSTATE_ERROR = 0xFF, /* Error */ 46 } btrc_play_status_t; 47 48 typedef enum { 49 BTRC_EVT_PLAY_STATUS_CHANGED = 0x01, 50 BTRC_EVT_TRACK_CHANGE = 0x02, 51 BTRC_EVT_TRACK_REACHED_END = 0x03, 52 BTRC_EVT_TRACK_REACHED_START = 0x04, 53 BTRC_EVT_PLAY_POS_CHANGED = 0x05, 54 BTRC_EVT_APP_SETTINGS_CHANGED = 0x08, 55 } btrc_event_id_t; 56 57 typedef enum { 58 BTRC_NOTIFICATION_TYPE_INTERIM = 0, 59 BTRC_NOTIFICATION_TYPE_CHANGED = 1, 60 } btrc_notification_type_t; 61 62 typedef enum { 63 BTRC_PLAYER_ATTR_EQUALIZER = 0x01, 64 BTRC_PLAYER_ATTR_REPEAT = 0x02, 65 BTRC_PLAYER_ATTR_SHUFFLE = 0x03, 66 BTRC_PLAYER_ATTR_SCAN = 0x04, 67 } btrc_player_attr_t; 68 69 typedef enum { 70 BTRC_MEDIA_ATTR_TITLE = 0x01, 71 BTRC_MEDIA_ATTR_ARTIST = 0x02, 72 BTRC_MEDIA_ATTR_ALBUM = 0x03, 73 BTRC_MEDIA_ATTR_TRACK_NUM = 0x04, 74 BTRC_MEDIA_ATTR_NUM_TRACKS = 0x05, 75 BTRC_MEDIA_ATTR_GENRE = 0x06, 76 BTRC_MEDIA_ATTR_PLAYING_TIME = 0x07, 77 } btrc_media_attr_t; 78 79 typedef enum { 80 BTRC_PLAYER_VAL_OFF_REPEAT = 0x01, 81 BTRC_PLAYER_VAL_SINGLE_REPEAT = 0x02, 82 BTRC_PLAYER_VAL_ALL_REPEAT = 0x03, 83 BTRC_PLAYER_VAL_GROUP_REPEAT = 0x04 84 } btrc_player_repeat_val_t; 85 86 typedef enum { 87 BTRC_PLAYER_VAL_OFF_SHUFFLE = 0x01, 88 BTRC_PLAYER_VAL_ALL_SHUFFLE = 0x02, 89 BTRC_PLAYER_VAL_GROUP_SHUFFLE = 0x03 90 } btrc_player_shuffle_val_t; 91 92 typedef enum { 93 BTRC_STS_BAD_CMD = 0x00, /* Invalid command */ 94 BTRC_STS_BAD_PARAM = 0x01, /* Invalid parameter */ 95 BTRC_STS_NOT_FOUND = 0x02, /* Specified parameter is wrong or not found */ 96 BTRC_STS_INTERNAL_ERR = 0x03, /* Internal Error */ 97 BTRC_STS_NO_ERROR = 0x04 /* Operation Success */ 98 } btrc_status_t; 99 100 typedef struct { 101 uint8_t num_attr; 102 uint8_t attr_ids[BTRC_MAX_APP_SETTINGS]; 103 uint8_t attr_values[BTRC_MAX_APP_SETTINGS]; 104 } btrc_player_settings_t; 105 106 typedef union 107 { 108 btrc_play_status_t play_status; 109 btrc_uid_t track; /* queue position in NowPlaying */ 110 uint32_t song_pos; 111 btrc_player_settings_t player_setting; 112 } btrc_register_notification_t; 113 114 typedef struct { 115 uint8_t id; /* can be attr_id or value_id */ 116 uint8_t text[BTRC_MAX_ATTR_STR_LEN]; 117 } btrc_player_setting_text_t; 118 119 typedef struct { 120 uint32_t attr_id; 121 uint8_t text[BTRC_MAX_ATTR_STR_LEN]; 122 } btrc_element_attr_val_t; 123 124 /** Callback for the controller's supported feautres */ 125 typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr, 126 btrc_remote_features_t features); 127 128 /** Callback for play status request */ 129 typedef void (* btrc_get_play_status_callback)(); 130 131 /** Callback for list player application attributes (Shuffle, Repeat,...) */ 132 typedef void (* btrc_list_player_app_attr_callback)(); 133 134 /** Callback for list player application attributes (Shuffle, Repeat,...) */ 135 typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id); 136 137 /** Callback for getting the current player application settings value 138 ** num_attr: specifies the number of attribute ids contained in p_attrs 139 */ 140 typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs); 141 142 /** Callback for getting the player application settings attributes' text 143 ** num_attr: specifies the number of attribute ids contained in p_attrs 144 */ 145 typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs); 146 147 /** Callback for getting the player application settings values' text 148 ** num_attr: specifies the number of value ids contained in p_vals 149 */ 150 typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val, uint8_t *p_vals); 151 152 /** Callback for setting the player application settings values */ 153 typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals); 154 155 /** Callback to fetch the get element attributes of the current song 156 ** num_attr: specifies the number of attributes requested in p_attrs 157 */ 158 typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs); 159 160 /** Callback for register notification (Play state change/track change/...) 161 ** param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED 162 */ 163 typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param); 164 165 /* AVRCP 1.4 Enhancements */ 166 /** Callback for volume change on CT 167 ** volume: Current volume setting on the CT (0-127) 168 */ 169 typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype); 170 171 /** Callback for passthrough commands */ 172 typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state); 173 174 /** BT-RC callback structure. */ 175 typedef struct { 176 /** set to sizeof(BtRcCallbacks) */ 177 size_t size; 178 btrc_remote_features_callback remote_features_cb; 179 btrc_get_play_status_callback get_play_status_cb; 180 btrc_list_player_app_attr_callback list_player_app_attr_cb; 181 btrc_list_player_app_values_callback list_player_app_values_cb; 182 btrc_get_player_app_value_callback get_player_app_value_cb; 183 btrc_get_player_app_attrs_text_callback get_player_app_attrs_text_cb; 184 btrc_get_player_app_values_text_callback get_player_app_values_text_cb; 185 btrc_set_player_app_value_callback set_player_app_value_cb; 186 btrc_get_element_attr_callback get_element_attr_cb; 187 btrc_register_notification_callback register_notification_cb; 188 btrc_volume_change_callback volume_change_cb; 189 btrc_passthrough_cmd_callback passthrough_cmd_cb; 190 } btrc_callbacks_t; 191 192 /** Represents the standard BT-RC interface. */ 193 typedef struct { 194 195 /** set to sizeof(BtRcInterface) */ 196 size_t size; 197 /** 198 * Register the BtRc callbacks 199 */ 200 bt_status_t (*init)( btrc_callbacks_t* callbacks ); 201 202 /** Respose to GetPlayStatus request. Contains the current 203 ** 1. Play status 204 ** 2. Song duration/length 205 ** 3. Song position 206 */ 207 bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos); 208 209 /** Lists the support player application attributes (Shuffle/Repeat/...) 210 ** num_attr: Specifies the number of attributes contained in the pointer p_attrs 211 */ 212 bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs); 213 214 /** Lists the support player application attributes (Shuffle Off/On/Group) 215 ** num_val: Specifies the number of values contained in the pointer p_vals 216 */ 217 bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals); 218 219 /** Returns the current application attribute values for each of the specified attr_id */ 220 bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals); 221 222 /** Returns the application attributes text ("Shuffle"/"Repeat"/...) 223 ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs 224 */ 225 bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs); 226 227 /** Returns the application attributes text ("Shuffle"/"Repeat"/...) 228 ** num_attr: Specifies the number of attribute values' text contained in the pointer p_vals 229 */ 230 bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals); 231 232 /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist") 233 ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs 234 */ 235 bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs); 236 237 /** Response to set player attribute request ("Shuffle"/"Repeat") 238 ** rsp_status: Status of setting the player attributes for the current media player 239 */ 240 bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status); 241 242 /* Response to the register notification request (Play state change/track change/...). 243 ** event_id: Refers to the event_id this notification change corresponds too 244 ** type: Response type - interim/changed 245 ** p_params: Based on the event_id, this parameter should be populated 246 */ 247 bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id, 248 btrc_notification_type_t type, 249 btrc_register_notification_t *p_param); 250 251 /* AVRCP 1.4 enhancements */ 252 253 /**Send current volume setting to remote side. Support limited to SetAbsoluteVolume 254 ** This can be enhanced to support Relative Volume (AVRCP 1.0). 255 ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN opposed to absolute volume level 256 ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set 257 */ 258 bt_status_t (*set_volume)(uint8_t volume); 259 260 /** Closes the interface. */ 261 void (*cleanup)( void ); 262 } btrc_interface_t; 263 264 __END_DECLS 265 266 #endif /* ANDROID_INCLUDE_BT_RC_H */ 267