Home | History | Annotate | Download | only in hardware
      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_PLAYSTATE_STOPPED = 0x00,    /* Stopped */
     34     BTRC_PLAYSTATE_PLAYING = 0x01,    /* Playing */
     35     BTRC_PLAYSTATE_PAUSED = 0x02,    /* Paused  */
     36     BTRC_PLAYSTATE_FWD_SEEK = 0x03,    /* Fwd Seek*/
     37     BTRC_PLAYSTATE_REV_SEEK = 0x04,    /* Rev Seek*/
     38     BTRC_PLAYSTATE_ERROR = 0xFF,    /* Error   */
     39 } btrc_play_status_t;
     40 
     41 typedef enum {
     42     BTRC_EVT_PLAY_STATUS_CHANGED = 0x01,
     43     BTRC_EVT_TRACK_CHANGE = 0x02,
     44     BTRC_EVT_TRACK_REACHED_END = 0x03,
     45     BTRC_EVT_TRACK_REACHED_START = 0x04,
     46     BTRC_EVT_PLAY_POS_CHANGED = 0x05,
     47     BTRC_EVT_APP_SETTINGS_CHANGED = 0x08,
     48 } btrc_event_id_t;
     49 
     50 typedef enum {
     51     BTRC_NOTIFICATION_TYPE_INTERIM = 0,
     52     BTRC_NOTIFICATION_TYPE_CHANGED = 1,
     53 } btrc_notification_type_t;
     54 
     55 typedef enum {
     56     BTRC_PLAYER_ATTR_EQUALIZER = 0x01,
     57     BTRC_PLAYER_ATTR_REPEAT = 0x02,
     58     BTRC_PLAYER_ATTR_SHUFFLE = 0x03,
     59     BTRC_PLAYER_ATTR_SCAN = 0x04,
     60 } btrc_player_attr_t;
     61 
     62 typedef enum {
     63     BTRC_MEDIA_ATTR_TITLE = 0x01,
     64     BTRC_MEDIA_ATTR_ARTIST = 0x02,
     65     BTRC_MEDIA_ATTR_ALBUM = 0x03,
     66     BTRC_MEDIA_ATTR_TRACK_NUM = 0x04,
     67     BTRC_MEDIA_ATTR_NUM_TRACKS = 0x05,
     68     BTRC_MEDIA_ATTR_GENRE = 0x06,
     69     BTRC_MEDIA_ATTR_PLAYING_TIME = 0x07,
     70 } btrc_media_attr_t;
     71 
     72 typedef enum {
     73     BTRC_PLAYER_VAL_OFF_REPEAT = 0x01,
     74     BTRC_PLAYER_VAL_SINGLE_REPEAT = 0x02,
     75     BTRC_PLAYER_VAL_ALL_REPEAT = 0x03,
     76     BTRC_PLAYER_VAL_GROUP_REPEAT = 0x04
     77 } btrc_player_repeat_val_t;
     78 
     79 typedef enum {
     80     BTRC_PLAYER_VAL_OFF_SHUFFLE = 0x01,
     81     BTRC_PLAYER_VAL_ALL_SHUFFLE = 0x02,
     82     BTRC_PLAYER_VAL_GROUP_SHUFFLE = 0x03
     83 } btrc_player_shuffle_val_t;
     84 
     85 typedef enum {
     86     BTRC_STS_BAD_CMD        = 0x00, /* Invalid command */
     87     BTRC_STS_BAD_PARAM      = 0x01, /* Invalid parameter */
     88     BTRC_STS_NOT_FOUND      = 0x02, /* Specified parameter is wrong or not found */
     89     BTRC_STS_INTERNAL_ERR   = 0x03, /* Internal Error */
     90     BTRC_STS_NO_ERROR       = 0x04  /* Operation Success */
     91 } btrc_status_t;
     92 
     93 typedef struct {
     94     uint8_t num_attr;
     95     uint8_t attr_ids[BTRC_MAX_APP_SETTINGS];
     96     uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
     97 } btrc_player_settings_t;
     98 
     99 typedef union
    100 {
    101     btrc_play_status_t play_status;
    102     btrc_uid_t track; /* queue position in NowPlaying */
    103     uint32_t song_pos;
    104     btrc_player_settings_t player_setting;
    105 } btrc_register_notification_t;
    106 
    107 typedef struct {
    108     uint8_t id; /* can be attr_id or value_id */
    109     uint8_t text[BTRC_MAX_ATTR_STR_LEN];
    110 } btrc_player_setting_text_t;
    111 
    112 typedef struct {
    113     uint32_t attr_id;
    114     uint8_t text[BTRC_MAX_ATTR_STR_LEN];
    115 } btrc_element_attr_val_t;
    116 
    117 /** Callback for play status request */
    118 typedef void (* btrc_get_play_status_callback)();
    119 
    120 /** Callback for list player application attributes (Shuffle, Repeat,...) */
    121 typedef void (* btrc_list_player_app_attr_callback)();
    122 
    123 /** Callback for list player application attributes (Shuffle, Repeat,...) */
    124 typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id);
    125 
    126 /** Callback for getting the current player application settings value
    127 **  num_attr: specifies the number of attribute ids contained in p_attrs
    128 */
    129 typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
    130 
    131 /** Callback for getting the player application settings attributes' text
    132 **  num_attr: specifies the number of attribute ids contained in p_attrs
    133 */
    134 typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
    135 
    136 /** Callback for getting the player application settings values' text
    137 **  num_attr: specifies the number of value ids contained in p_vals
    138 */
    139 typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val, uint8_t *p_vals);
    140 
    141 /** Callback for setting the player application settings values */
    142 typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals);
    143 
    144 /** Callback to fetch the get element attributes of the current song
    145 **  num_attr: specifies the number of attributes requested in p_attrs
    146 */
    147 typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs);
    148 
    149 /** Callback for register notification (Play state change/track change/...)
    150 **  param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
    151 */
    152 typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param);
    153 
    154 /** BT-RC callback structure. */
    155 typedef struct {
    156     /** set to sizeof(BtRcCallbacks) */
    157     size_t      size;
    158     btrc_get_play_status_callback               get_play_status_cb;
    159     btrc_list_player_app_attr_callback          list_player_app_attr_cb;
    160     btrc_list_player_app_values_callback        list_player_app_values_cb;
    161     btrc_get_player_app_value_callback          get_player_app_value_cb;
    162     btrc_get_player_app_attrs_text_callback     get_player_app_attrs_text_cb;
    163     btrc_get_player_app_values_text_callback    get_player_app_values_text_cb;
    164     btrc_set_player_app_value_callback          set_player_app_value_cb;
    165     btrc_get_element_attr_callback              get_element_attr_cb;
    166     btrc_register_notification_callback         register_notification_cb;
    167 } btrc_callbacks_t;
    168 
    169 /** Represents the standard BT-RC interface. */
    170 typedef struct {
    171 
    172     /** set to sizeof(BtRcInterface) */
    173     size_t          size;
    174     /**
    175      * Register the BtRc callbacks
    176      */
    177     bt_status_t (*init)( btrc_callbacks_t* callbacks );
    178 
    179     /** Respose to GetPlayStatus request. Contains the current
    180     **  1. Play status
    181     **  2. Song duration/length
    182     **  3. Song position
    183     */
    184     bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos);
    185 
    186     /** Lists the support player application attributes (Shuffle/Repeat/...)
    187     **  num_attr: Specifies the number of attributes contained in the pointer p_attrs
    188     */
    189     bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs);
    190 
    191     /** Lists the support player application attributes (Shuffle Off/On/Group)
    192     **  num_val: Specifies the number of values contained in the pointer p_vals
    193     */
    194     bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals);
    195 
    196     /** Returns the current application attribute values for each of the specified attr_id */
    197     bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals);
    198 
    199     /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
    200     **  num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
    201     */
    202     bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs);
    203 
    204     /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
    205     **  num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
    206     */
    207     bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals);
    208 
    209     /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
    210     **  num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
    211     */
    212     bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
    213 
    214     /** Response to set player attribute request ("Shuffle"/"Repeat")
    215     **  rsp_status: Status of setting the player attributes for the current media player
    216     */
    217     bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status);
    218 
    219     /* Response to the register notification request (Play state change/track change/...).
    220     ** event_id: Refers to the event_id this notification change corresponds too
    221     ** type: Response type - interim/changed
    222     ** p_params: Based on the event_id, this parameter should be populated
    223     */
    224     bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
    225                                              btrc_notification_type_t type,
    226                                              btrc_register_notification_t *p_param);
    227 
    228     /** Closes the interface. */
    229     void  (*cleanup)( void );
    230 } btrc_interface_t;
    231 
    232 __END_DECLS
    233 
    234 #endif /* ANDROID_INCLUDE_BT_RC_H */
    235