bt_rc.h
Go to the documentation of this file.
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 */
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 */
47 
48 typedef enum {
56 
57 typedef enum {
61 
62 typedef enum {
68 
69 typedef enum {
78 
79 typedef enum {
85 
86 typedef enum {
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 */
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];
105 
106 typedef struct {
107  uint8_t val;
108  uint16_t charset_id;
109  uint16_t str_len;
110  uint8_t *p_str;
112 
113 typedef struct {
114  uint8_t attr_id;
115  uint16_t charset_id;
116  uint16_t str_len;
117  uint8_t *p_str;
118  uint8_t num_val;
121 
122 typedef struct {
123  uint8_t attr_id;
124  uint8_t num_val;
125  uint8_t attr_val[BTRC_MAX_APP_ATTR_SIZE];
127 
128 typedef struct {
129  uint32_t start_item;
130  uint32_t end_item;
131  uint32_t size;
132  uint32_t attrs[BTRC_MAX_ELEM_ATTR_SIZE];
133  uint8_t attr_count;
135 
136 typedef union
137 {
139  btrc_uid_t track; /* queue position in NowPlaying */
140  uint32_t song_pos;
143 
144 typedef struct {
145  uint8_t id; /* can be attr_id or value_id */
146  uint8_t text[BTRC_MAX_ATTR_STR_LEN];
148 
149 typedef struct {
150  uint32_t attr_id;
151  uint8_t text[BTRC_MAX_ATTR_STR_LEN];
153 
154 /** Callback for the controller's supported feautres */
155 typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
156  btrc_remote_features_t features);
157 
158 /** Callback for play status request */
159 typedef void (* btrc_get_play_status_callback)();
160 
161 /** Callback for list player application attributes (Shuffle, Repeat,...) */
163 
164 /** Callback for list player application attributes (Shuffle, Repeat,...) */
166 
167 /** Callback for getting the current player application settings value
168 ** num_attr: specifies the number of attribute ids contained in p_attrs
169 */
170 typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
171 
172 /** Callback for getting the player application settings attributes' text
173 ** num_attr: specifies the number of attribute ids contained in p_attrs
174 */
175 typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
176 
177 /** Callback for getting the player application settings values' text
178 ** num_attr: specifies the number of value ids contained in p_vals
179 */
180 typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val, uint8_t *p_vals);
181 
182 /** Callback for setting the player application settings values */
184 
185 /** Callback to fetch the get element attributes of the current song
186 ** num_attr: specifies the number of attributes requested in p_attrs
187 */
188 typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs);
189 
190 /** Callback for register notification (Play state change/track change/...)
191 ** param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
192 */
193 typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param);
194 
195 /* AVRCP 1.4 Enhancements */
196 /** Callback for volume change on CT
197 ** volume: Current volume setting on the CT (0-127)
198 */
199 typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype);
200 
201 /** Callback for passthrough commands */
202 typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state);
203 
204 /** BT-RC Target callback structure. */
205 typedef struct {
206  /** set to sizeof(BtRcCallbacks) */
207  size_t size;
221 
222 /** Represents the standard BT-RC AVRCP Target interface. */
223 typedef struct {
224 
225  /** set to sizeof(BtRcInterface) */
226  size_t size;
227  /**
228  * Register the BtRc callbacks
229  */
230  bt_status_t (*init)( btrc_callbacks_t* callbacks );
231 
232  /** Respose to GetPlayStatus request. Contains the current
233  ** 1. Play status
234  ** 2. Song duration/length
235  ** 3. Song position
236  */
237  bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos);
238 
239  /** Lists the support player application attributes (Shuffle/Repeat/...)
240  ** num_attr: Specifies the number of attributes contained in the pointer p_attrs
241  */
242  bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs);
243 
244  /** Lists the support player application attributes (Shuffle Off/On/Group)
245  ** num_val: Specifies the number of values contained in the pointer p_vals
246  */
247  bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals);
248 
249  /** Returns the current application attribute values for each of the specified attr_id */
250  bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals);
251 
252  /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
253  ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
254  */
255  bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs);
256 
257  /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
258  ** num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
259  */
260  bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals);
261 
262  /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
263  ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
264  */
265  bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
266 
267  /** Response to set player attribute request ("Shuffle"/"Repeat")
268  ** rsp_status: Status of setting the player attributes for the current media player
269  */
270  bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status);
271 
272  /* Response to the register notification request (Play state change/track change/...).
273  ** event_id: Refers to the event_id this notification change corresponds too
274  ** type: Response type - interim/changed
275  ** p_params: Based on the event_id, this parameter should be populated
276  */
277  bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
280 
281  /* AVRCP 1.4 enhancements */
282 
283  /**Send current volume setting to remote side. Support limited to SetAbsoluteVolume
284  ** This can be enhanced to support Relative Volume (AVRCP 1.0).
285  ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN opposed to absolute volume level
286  ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
287  */
288  bt_status_t (*set_volume)(uint8_t volume);
289 
290  /** Closes the interface. */
291  void (*cleanup)( void );
293 
294 
295 typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
296 
297 typedef void (* btrc_groupnavigation_rsp_callback) (int id, int key_state);
298 
299 typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
300 
301 typedef void (* btrc_ctrl_getrcfeatures_callback) (bt_bdaddr_t *bd_addr, int features);
302 
303 typedef void (* btrc_ctrl_setabsvol_cmd_callback) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
304 
305 typedef void (* btrc_ctrl_registernotification_abs_vol_callback) (bt_bdaddr_t *bd_addr, uint8_t label);
306 
307 typedef void (* btrc_ctrl_setplayerapplicationsetting_rsp_callback) (bt_bdaddr_t *bd_addr,
308  uint8_t accepted);
309 
310 typedef void (* btrc_ctrl_playerapplicationsetting_callback)(bt_bdaddr_t *bd_addr,
311  uint8_t num_attr,
312  btrc_player_app_attr_t *app_attrs,
313  uint8_t num_ext_attr,
314  btrc_player_app_ext_attr_t *ext_attrs);
315 
316 typedef void (* btrc_ctrl_playerapplicationsetting_changed_callback)(bt_bdaddr_t *bd_addr,
317  btrc_player_settings_t *p_vals);
318 
319 typedef void (* btrc_ctrl_track_changed_callback)(bt_bdaddr_t *bd_addr, uint8_t num_attr,
320  btrc_element_attr_val_t *p_attrs);
321 
322 typedef void (* btrc_ctrl_play_position_changed_callback)(bt_bdaddr_t *bd_addr,
323  uint32_t song_len, uint32_t song_pos);
324 
325 typedef void (* btrc_ctrl_play_status_changed_callback)(bt_bdaddr_t *bd_addr,
326  btrc_play_status_t play_status);
327 
328 /** BT-RC Controller callback structure. */
329 typedef struct {
330  /** set to sizeof(BtRcCallbacks) */
331  size_t size;
345 
346 /** Represents the standard BT-RC AVRCP Controller interface. */
347 typedef struct {
348 
349  /** set to sizeof(BtRcInterface) */
350  size_t size;
351  /**
352  * Register the BtRc callbacks
353  */
354  bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
355 
356  /** send pass through command to target */
357  bt_status_t (*send_pass_through_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
358  uint8_t key_state );
359 
360  /** send group navigation command to target */
361  bt_status_t (*send_group_navigation_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
362  uint8_t key_state );
363 
364  /** send command to set player applicaiton setting attributes to target */
365  bt_status_t (*set_player_app_setting_cmd) (bt_bdaddr_t *bd_addr, uint8_t num_attrib,
366  uint8_t* attrib_ids, uint8_t* attrib_vals);
367 
368  /** send rsp to set_abs_vol received from target */
369  bt_status_t (*set_volume_rsp) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
370 
371  /** send notificaiton rsp for abs vol to target */
372  bt_status_t (*register_abs_vol_rsp) (bt_bdaddr_t *bd_addr, btrc_notification_type_t rsp_type,
373  uint8_t abs_vol, uint8_t label);
374 
375  /** Closes the interface. */
376  void (*cleanup)( void );
378 
379 __END_DECLS
380 
381 #endif /* ANDROID_INCLUDE_BT_RC_H */
void(* btrc_register_notification_callback)(btrc_event_id_t event_id, uint32_t param)
Definition: bt_rc.h:193
uint32_t start_item
Definition: bt_rc.h:129
btrc_register_notification_callback register_notification_cb
Definition: bt_rc.h:217
btrc_connection_state_callback connection_state_cb
Definition: bt_rc.h:334
#define BTRC_MAX_ELEM_ATTR_SIZE
Definition: bt_rc.h:28
#define BTRC_MAX_APP_SETTINGS
Definition: bt_rc.h:25
btrc_player_attr_t
Definition: bt_rc.h:62
btrc_ctrl_setplayerapplicationsetting_rsp_callback setplayerappsetting_rsp_cb
Definition: bt_rc.h:336
btrc_ctrl_playerapplicationsetting_callback playerapplicationsetting_cb
Definition: bt_rc.h:337
void(* btrc_get_player_app_values_text_callback)(uint8_t attr_id, uint8_t num_val, uint8_t *p_vals)
Definition: bt_rc.h:180
void(* btrc_ctrl_setplayerapplicationsetting_rsp_callback)(bt_bdaddr_t *bd_addr, uint8_t accepted)
Definition: bt_rc.h:307
void(* btrc_get_player_app_attrs_text_callback)(uint8_t num_attr, btrc_player_attr_t *p_attrs)
Definition: bt_rc.h:175
void(* btrc_ctrl_play_position_changed_callback)(bt_bdaddr_t *bd_addr, uint32_t song_len, uint32_t song_pos)
Definition: bt_rc.h:322
btrc_ctrl_playerapplicationsetting_changed_callback playerapplicationsetting_changed_cb
Definition: bt_rc.h:338
btrc_ctrl_registernotification_abs_vol_callback registernotification_absvol_cb
Definition: bt_rc.h:340
btrc_notification_type_t
Definition: bt_rc.h:57
btrc_media_attr_t
Definition: bt_rc.h:69
btrc_volume_change_callback volume_change_cb
Definition: bt_rc.h:218
btrc_play_status_t play_status
Definition: bt_rc.h:138
btrc_play_status_t
Definition: bt_rc.h:39
void(* btrc_passthrough_cmd_callback)(int id, int key_state)
Definition: bt_rc.h:202
void(* btrc_ctrl_track_changed_callback)(bt_bdaddr_t *bd_addr, uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
Definition: bt_rc.h:319
btrc_ctrl_getrcfeatures_callback getrcfeatures_cb
Definition: bt_rc.h:335
void(* btrc_set_player_app_value_callback)(btrc_player_settings_t *p_vals)
Definition: bt_rc.h:183
void(* btrc_list_player_app_attr_callback)()
Definition: bt_rc.h:162
size_t size
Definition: bt_rc.h:226
btrc_event_id_t
Definition: bt_rc.h:48
void(* btrc_ctrl_getrcfeatures_callback)(bt_bdaddr_t *bd_addr, int features)
Definition: bt_rc.h:301
btrc_status_t
Definition: bt_rc.h:92
#define BTRC_MAX_APP_ATTR_SIZE
Definition: bt_rc.h:27
bt_status_t
Definition: bluetooth.h:80
void(* btrc_get_player_app_value_callback)(uint8_t num_attr, btrc_player_attr_t *p_attrs)
Definition: bt_rc.h:170
btrc_ctrl_play_position_changed_callback play_position_changed_cb
Definition: bt_rc.h:342
void(* btrc_ctrl_playerapplicationsetting_changed_callback)(bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals)
Definition: bt_rc.h:316
btrc_player_shuffle_val_t
Definition: bt_rc.h:86
btrc_passthrough_cmd_callback passthrough_cmd_cb
Definition: bt_rc.h:219
uint8_t btrc_uid_t[BTRC_UID_SIZE]
Definition: bt_rc.h:30
void(* btrc_ctrl_playerapplicationsetting_callback)(bt_bdaddr_t *bd_addr, uint8_t num_attr, btrc_player_app_attr_t *app_attrs, uint8_t num_ext_attr, btrc_player_app_ext_attr_t *ext_attrs)
Definition: bt_rc.h:310
void(* btrc_groupnavigation_rsp_callback)(int id, int key_state)
Definition: bt_rc.h:297
void(* btrc_passthrough_rsp_callback)(int id, int key_state)
Definition: bt_rc.h:295
btrc_remote_features_t
Definition: bt_rc.h:32
btrc_get_play_status_callback get_play_status_cb
Definition: bt_rc.h:209
void(* btrc_get_element_attr_callback)(uint8_t num_attr, btrc_media_attr_t *p_attrs)
Definition: bt_rc.h:188
btrc_ctrl_setabsvol_cmd_callback setabsvol_cmd_cb
Definition: bt_rc.h:339
btrc_set_player_app_value_callback set_player_app_value_cb
Definition: bt_rc.h:215
void(* btrc_connection_state_callback)(bool state, bt_bdaddr_t *bd_addr)
Definition: bt_rc.h:299
#define BTRC_UID_SIZE
Definition: bt_rc.h:24
btrc_ctrl_track_changed_callback track_changed_cb
Definition: bt_rc.h:341
void(* btrc_ctrl_play_status_changed_callback)(bt_bdaddr_t *bd_addr, btrc_play_status_t play_status)
Definition: bt_rc.h:325
btrc_get_player_app_attrs_text_callback get_player_app_attrs_text_cb
Definition: bt_rc.h:213
btrc_player_settings_t player_setting
Definition: bt_rc.h:141
uint32_t size
Definition: bt_rc.h:131
btrc_get_element_attr_callback get_element_attr_cb
Definition: bt_rc.h:216
void(* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr, btrc_remote_features_t features)
Definition: bt_rc.h:155
void(* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id)
Definition: bt_rc.h:165
uint32_t end_item
Definition: bt_rc.h:130
btrc_get_player_app_values_text_callback get_player_app_values_text_cb
Definition: bt_rc.h:214
void(* btrc_volume_change_callback)(uint8_t volume, uint8_t ctype)
Definition: bt_rc.h:199
size_t size
Definition: bt_rc.h:207
#define BTRC_MAX_ATTR_STR_LEN
Definition: bt_rc.h:23
btrc_list_player_app_values_callback list_player_app_values_cb
Definition: bt_rc.h:211
btrc_player_repeat_val_t
Definition: bt_rc.h:79
void(* btrc_ctrl_setabsvol_cmd_callback)(bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label)
Definition: bt_rc.h:303
uint8_t attr_count
Definition: bt_rc.h:133
btrc_passthrough_rsp_callback passthrough_rsp_cb
Definition: bt_rc.h:332
btrc_remote_features_callback remote_features_cb
Definition: bt_rc.h:208
btrc_get_player_app_value_callback get_player_app_value_cb
Definition: bt_rc.h:212
btrc_ctrl_play_status_changed_callback play_status_changed_cb
Definition: bt_rc.h:343
btrc_groupnavigation_rsp_callback groupnavigation_rsp_cb
Definition: bt_rc.h:333
void(* btrc_ctrl_registernotification_abs_vol_callback)(bt_bdaddr_t *bd_addr, uint8_t label)
Definition: bt_rc.h:305
void(* btrc_get_play_status_callback)()
Definition: bt_rc.h:159
btrc_list_player_app_attr_callback list_player_app_attr_cb
Definition: bt_rc.h:210