1 /******************************************************************************
2  *
3  *  Copyright 2005-2016 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains compile-time configurable constants for advanced
22  *  audio/video
23  *
24  ******************************************************************************/
25 
26 #include <cstddef>
27 #include <cstdint>
28 
29 #include "avrc_defs.h"
30 #include "bta/av/bta_av_int.h"
31 #include "bta/include/bta_av_api.h"
32 #include "stack/include/avrc_api.h"
33 
34 #ifndef BTA_AV_RC_COMP_ID
35 #define BTA_AV_RC_COMP_ID AVRC_CO_GOOGLE
36 #endif
37 
38 #ifndef BTA_AV_RC_PASS_RSP_CODE
39 #define BTA_AV_RC_PASS_RSP_CODE AVRC_RSP_NOT_IMPL
40 #endif
41 
42 using namespace bluetooth;
43 
44 const uint32_t bta_av_meta_caps_co_ids[] = {AVRC_CO_METADATA, AVRC_CO_BROADCOM};
45 
46 /* AVRCP supported categories */
47 #define BTA_AV_RC_SUPF_CT (AVRC_SUPF_CT_CAT2)
48 #define BTA_AVK_RC_SUPF_CT                                                           \
49   (AVRC_SUPF_CT_CAT1 | AVRC_SUPF_CT_BROWSE | AVRC_SUPF_CT_COVER_ART_GET_IMAGE_PROP | \
50    AVRC_SUPF_CT_COVER_ART_GET_IMAGE)
51 
52 #define BTA_AVK_RC_SUPF_TG (AVRC_SUPF_TG_CAT2)
53 
54 /* AVRCP Controller and Target default name */
55 #ifndef BTA_AV_RC_CT_NAME
56 #define BTA_AV_RC_CT_NAME "AVRC Controller"
57 #endif
58 
59 #ifndef BTA_AV_RC_TG_NAME
60 #define BTA_AV_RC_TG_NAME "AVRC Target"
61 #endif
62 
63 /* Added to modify
64  *	1. flush timeout
65  *	2. Remove Group navigation support in SupportedFeatures
66  *	3. GetCapabilities supported event_ids list
67  *	4. GetCapabilities supported event_ids count
68  */
69 
70 /* Note: Android doesnt support AVRC_SUPF_TG_GROUP_NAVI  */
71 /* Note: if AVRC_SUPF_TG_GROUP_NAVI is set, bta_av_cfg.avrc_group should be true
72  */
73 #ifndef BTA_AV_RC_SUPF_TG
74 #define BTA_AV_RC_SUPF_TG                          \
75   (AVRC_SUPF_TG_CAT1 | AVRC_SUPF_TG_MULTI_PLAYER | \
76    AVRC_SUPF_TG_BROWSE) /* TODO: | AVRC_SUPF_TG_APP_SETTINGS) */
77 #endif
78 
79 /*
80  * If the number of event IDs is changed in this array, BTA_AV_NUM_RC_EVT_IDS
81  * also needs to be changed.
82  */
83 const uint8_t bta_av_meta_caps_evt_ids[] = {
84         AVRC_EVT_PLAY_STATUS_CHANGE,  AVRC_EVT_TRACK_CHANGE,       AVRC_EVT_PLAY_POS_CHANGED,
85         AVRC_EVT_AVAL_PLAYERS_CHANGE, AVRC_EVT_ADDR_PLAYER_CHANGE, AVRC_EVT_UIDS_CHANGE,
86         AVRC_EVT_NOW_PLAYING_CHANGE,
87         /* TODO: Add support for these events
88         AVRC_EVT_APP_SETTING_CHANGE,
89         */
90 };
91 
92 #ifndef BTA_AV_NUM_RC_EVT_IDS
93 #define BTA_AV_NUM_RC_EVT_IDS \
94   (sizeof(bta_av_meta_caps_evt_ids) / sizeof(bta_av_meta_caps_evt_ids[0]))
95 #endif /* BTA_AV_NUM_RC_EVT_IDS */
96 
get_bta_avk_meta_caps_evt_ids()97 static const uint8_t* get_bta_avk_meta_caps_evt_ids() {
98   if (avrcp_absolute_volume_is_enabled()) {
99     static const uint8_t bta_avk_meta_caps_evt_ids[] = {
100             AVRC_EVT_VOLUME_CHANGE,
101     };
102     return bta_avk_meta_caps_evt_ids;
103   } else {
104     return {};
105   }
106 }
107 
108 // These are the only events used with AVRCP1.3
109 const uint8_t bta_av_meta_caps_evt_ids_avrcp13[] = {
110         AVRC_EVT_PLAY_STATUS_CHANGE,
111         AVRC_EVT_TRACK_CHANGE,
112         AVRC_EVT_PLAY_POS_CHANGED,
113 };
114 
115 #ifndef BTA_AV_NUM_RC_EVT_IDS_AVRCP13
116 #define BTA_AV_NUM_RC_EVT_IDS_AVRCP13 \
117   (sizeof(bta_av_meta_caps_evt_ids_avrcp13) / sizeof(bta_av_meta_caps_evt_ids_avrcp13[0]))
118 #endif /* BTA_AV_NUM_RC_EVT_IDS_AVRCP13 */
119 
120 /* This configuration to be used when we are Src + TG + CT( only for abs vol) */
121 extern const tBTA_AV_CFG bta_av_cfg = {
122         AVRC_CO_METADATA, /* AVRCP Company ID */
123 
124         BTA_AV_RC_SUPF_CT,        /* AVRCP controller categories */
125         BTA_AV_RC_SUPF_TG,        /* AVRCP target categories */
126         6,                        /* AVDTP audio channel max data queue size */
127         false,                    /* true, to accept AVRC 1.3 group nevigation command */
128         2,                        /* company id count in p_meta_co_ids */
129         BTA_AV_NUM_RC_EVT_IDS,    /* event id count in p_meta_evt_ids */
130         BTA_AV_RC_PASS_RSP_CODE,  /* the default response code for pass through commands */
131         bta_av_meta_caps_co_ids,  /* the metadata Get Capabilities response for company id */
132         bta_av_meta_caps_evt_ids, /* the metadata Get Capabilities response for event id */
133         BTA_AV_RC_CT_NAME,        /* Default AVRCP controller name */
134         BTA_AV_RC_TG_NAME         /* Default AVRCP target name */
135 };
136 
137 /* This configuration to be used when we are Sink + CT + TG( only for abs vol)
138  */
139 
get_bta_avk_cfg()140 const tBTA_AV_CFG* get_bta_avk_cfg() {
141   static const tBTA_AV_CFG bta_avk_cfg = {
142           AVRC_CO_METADATA,   /* AVRCP Company ID */
143           BTA_AVK_RC_SUPF_CT, /* AVRCP controller categories */
144           BTA_AVK_RC_SUPF_TG, /* AVRCP target categories */
145           6,                  /* AVDTP audio channel max data queue size */
146           false,              /* true, to accept AVRC 1.3 group nevigation command */
147           2,                  /* company id count in p_meta_co_ids */
148           (uint8_t)(avrcp_absolute_volume_is_enabled() ? 1
149                                                        : 0), /* event id count in p_meta_evt_ids */
150           BTA_AV_RC_PASS_RSP_CODE,                           /* the default response code for pass
151                                                                 through commands */
152           bta_av_meta_caps_co_ids,         /* the metadata Get Capabilities response
153                                               for company id */
154           get_bta_avk_meta_caps_evt_ids(), /* the metadata Get Capabilities response
155                                               for event id */
156           {0},                             /* Default AVRCP controller name */
157           {0},                             /* Default AVRCP target name */
158   };
159   return &bta_avk_cfg;
160 }
161 
162 /* This configuration to be used when we are using AVRCP1.3 */
163 extern const tBTA_AV_CFG bta_av_cfg_compatibility = {
164         AVRC_CO_METADATA, /* AVRCP Company ID */
165 
166         BTA_AV_RC_SUPF_CT,                /* AVRCP controller categories */
167         AVRC_SUPF_TG_CAT1,                /* Only support CAT1 for AVRCP1.3 */
168         6,                                /* AVDTP audio channel max data queue size */
169         false,                            /* true, to accept AVRC 1.3 group nevigation command */
170         2,                                /* company id count in p_meta_co_ids */
171         BTA_AV_NUM_RC_EVT_IDS_AVRCP13,    /* event id count for AVRCP1.3 */
172         BTA_AV_RC_PASS_RSP_CODE,          /* the default response code for pass through commands */
173         bta_av_meta_caps_co_ids,          /* the metadata Get Capabilities response
174                                              for company id */
175         bta_av_meta_caps_evt_ids_avrcp13, /* the metadata Get Capabilities
176                                              response for event id, compatible with AVRCP1.3 */
177         BTA_AV_RC_CT_NAME,                /* Default AVRCP controller name */
178         BTA_AV_RC_TG_NAME                 /* Default AVRCP target name */
179 };
180 
181 const tBTA_AV_CFG* p_bta_av_cfg = NULL;
182 
183 const uint16_t bta_av_rc_id[] = {
184         0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
185                              4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN, 7=LEFT_UP,
186                              8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU, 11=CONT_MENU,
187                              12=FAV_MENU, 13=EXIT */
188 
189         0, /* not used */
190 
191         0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
192                              4=4, 5=5, 6=6, 7=7,
193                              8=8, 9=9, 10=DOT, 11=ENTER,
194                              12=CLEAR */
195 
196         0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN, 3=SOUND_SEL,
197                              4=INPUT_SEL, 5=DISP_INFO, 6=HELP, 7=PAGE_UP,
198                              8=PAGE_DOWN */
199 
200 /* btui_app provides an example of how to leave the decision of rejecting a
201  command or not
202  * based on which media player is currently addressed (this is only applicable
203  for AVRCP 1.4 or later)
204  * If the decision is per player for a particular rc_id, the related bit is
205  clear (not set)
206  * bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE, 4=PLAY, 5=STOP,
207              6=PAUSE, 7=RECORD, 8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
208              12=BACKWARD */
209 #if (BTA_AV_RC_PASS_RSP_CODE == AVRC_RSP_INTERIM)
210         0x0070, /* PLAY | STOP | PAUSE */
211 #else           /* BTA_AV_RC_PASS_RSP_CODE != AVRC_RSP_INTERIM */
212         0x1b7E, /* PLAY | STOP | PAUSE | FF | RW | VOL_UP | VOL_DOWN | MUTE | FW |
213                    BACK */
214 #endif          /* BTA_AV_RC_PASS_RSP_CODE */
215 
216         0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
217 
218         0, /* not used */
219 
220         0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
221                             4=F4, 5=F5 */
222 };
223 
224 #if (BTA_AV_RC_PASS_RSP_CODE == AVRC_RSP_INTERIM)
225 const uint16_t bta_av_rc_id_ac[] = {
226         0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
227                              4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN,
228                    7=LEFT_UP,
229                              8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU,
230                    11=CONT_MENU,
231                              12=FAV_MENU, 13=EXIT */
232 
233         0, /* not used */
234 
235         0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
236                              4=4, 5=5, 6=6, 7=7,
237                              8=8, 9=9, 10=DOT, 11=ENTER,
238                              12=CLEAR */
239 
240         0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN,
241                    3=SOUND_SEL,
242                              4=INPUT_SEL, 5=DISP_INFO, 6=HELP,
243                    7=PAGE_UP,
244                              8=PAGE_DOWN */
245 
246         /* btui_app provides an example of how to leave the decision of
247          * rejecting a command or not
248          * based on which media player is currently addressed (this is
249          * only applicable for AVRCP 1.4 or later)
250          * If the decision is per player for a particular rc_id, the
251          * related bit is set */
252         0x1800, /* bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE,
253                              4=PLAY, 5=STOP, 6=PAUSE, 7=RECORD,
254                              8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
255                              12=BACKWARD */
256 
257         0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
258 
259         0, /* not used */
260 
261         0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
262                             4=F4, 5=F5 */
263 };
264 uint16_t* p_bta_av_rc_id_ac = (uint16_t*)bta_av_rc_id_ac;
265 #else
266 uint16_t* p_bta_av_rc_id_ac = NULL;
267 #endif
268 
269 uint16_t* p_bta_av_rc_id = (uint16_t*)bta_av_rc_id;
270