bt_rc.h 11 KB

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