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 <bluetooth/log.h>
27 
28 #include <cstdint>
29 
30 #include "bta/include/bta_av_api.h"
31 #include "internal_include/bt_target.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 | \
50    AVRC_SUPF_CT_COVER_ART_GET_IMAGE_PROP | AVRC_SUPF_CT_COVER_ART_GET_IMAGE)
51 
52 #define BTA_AVK_RC_SUPF_TG (AVRC_SUPF_TG_CAT2)
53 
54 /* AVRCP Controller and Targer 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,
85     AVRC_EVT_PLAY_POS_CHANGED,   AVRC_EVT_AVAL_PLAYERS_CHANGE,
86     AVRC_EVT_ADDR_PLAYER_CHANGE, AVRC_EVT_UIDS_CHANGE,
87     AVRC_EVT_NOW_PLAYING_CHANGE,
88     /* TODO: Add support for these events
89     AVRC_EVT_APP_SETTING_CHANGE,
90     */
91 };
92 
93 #ifndef BTA_AV_NUM_RC_EVT_IDS
94 #define BTA_AV_NUM_RC_EVT_IDS \
95   (sizeof(bta_av_meta_caps_evt_ids) / sizeof(bta_av_meta_caps_evt_ids[0]))
96 #endif /* BTA_AV_NUM_RC_EVT_IDS */
97 
get_bta_avk_meta_caps_evt_ids()98 const uint8_t* get_bta_avk_meta_caps_evt_ids() {
99   if (avrcp_absolute_volume_is_enabled()) {
100     static const uint8_t bta_avk_meta_caps_evt_ids[] = {
101         AVRC_EVT_VOLUME_CHANGE,
102     };
103     return bta_avk_meta_caps_evt_ids;
104   } else {
105     return {};
106   }
107 }
108 
109 // These are the only events used with AVRCP1.3
110 const uint8_t bta_av_meta_caps_evt_ids_avrcp13[] = {
111     AVRC_EVT_PLAY_STATUS_CHANGE, 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) / \
118    sizeof(bta_av_meta_caps_evt_ids_avrcp13[0]))
119 #endif /* BTA_AV_NUM_RC_EVT_IDS_AVRCP13 */
120 
121 /* This configuration to be used when we are Src + TG + CT( only for abs vol) */
122 extern const tBTA_AV_CFG bta_av_cfg = {
123     AVRC_CO_METADATA, /* AVRCP Company ID */
124 
125     BTA_AV_RC_SUPF_CT, /* AVRCP controller categories */
126     BTA_AV_RC_SUPF_TG, /* AVRCP target categories */
127     6,                 /* AVDTP audio channel max data queue size */
128     false,             /* true, to accept AVRC 1.3 group nevigation command */
129     2,                 /* company id count in p_meta_co_ids */
130     BTA_AV_NUM_RC_EVT_IDS,    /* event id count in p_meta_evt_ids */
131     BTA_AV_RC_PASS_RSP_CODE,  /* the default response code for pass
132                                  through commands */
133     bta_av_meta_caps_co_ids,  /* the metadata Get Capabilities response
134                                  for company id */
135     bta_av_meta_caps_evt_ids, /* the the metadata Get Capabilities
136                                  response for event id */
137     BTA_AV_RC_CT_NAME,        /* Default AVRCP controller name */
138     BTA_AV_RC_TG_NAME         /* Default AVRCP target name */
139 };
140 
141 /* This configuration to be used when we are Sink + CT + TG( only for abs vol)
142  */
143 
get_bta_avk_cfg()144 const tBTA_AV_CFG* get_bta_avk_cfg() {
145   static const tBTA_AV_CFG bta_avk_cfg = {
146       AVRC_CO_METADATA,   /* AVRCP Company ID */
147       BTA_AVK_RC_SUPF_CT, /* AVRCP controller categories */
148       BTA_AVK_RC_SUPF_TG, /* AVRCP target categories */
149       6,                  /* AVDTP audio channel max data queue size */
150       false, /* true, to accept AVRC 1.3 group nevigation command */
151       2,     /* company id count in p_meta_co_ids */
152       (uint8_t)(avrcp_absolute_volume_is_enabled()
153                     ? 1
154                     : 0),              /* event id count in p_meta_evt_ids */
155       BTA_AV_RC_PASS_RSP_CODE,         /* the default response code for pass
156                                           through commands */
157       bta_av_meta_caps_co_ids,         /* the metadata Get Capabilities response
158                                           for company id */
159       get_bta_avk_meta_caps_evt_ids(), /* the metadata Get Capabilities response
160                                           for event id */
161       {0},                             /* Default AVRCP controller name */
162       {0},                             /* Default AVRCP target name */
163   };
164   return &bta_avk_cfg;
165 }
166 
167 /* This configuration to be used when we are using AVRCP1.3 */
168 extern const tBTA_AV_CFG bta_av_cfg_compatibility = {
169     AVRC_CO_METADATA, /* AVRCP Company ID */
170 
171     BTA_AV_RC_SUPF_CT, /* AVRCP controller categories */
172     AVRC_SUPF_TG_CAT1, /* Only support CAT1 for AVRCP1.3 */
173     6,                 /* AVDTP audio channel max data queue size */
174     false,             /* true, to accept AVRC 1.3 group nevigation command */
175     2,                 /* company id count in p_meta_co_ids */
176     BTA_AV_NUM_RC_EVT_IDS_AVRCP13,    /* event id count for AVRCP1.3 */
177     BTA_AV_RC_PASS_RSP_CODE,          /* the default response code for pass
178                                          through commands */
179     bta_av_meta_caps_co_ids,          /* the metadata Get Capabilities response
180                                          for company id */
181     bta_av_meta_caps_evt_ids_avrcp13, /* the the metadata Get Capabilities
182                                          response for event id, compatible
183                                          with AVRCP1.3 */
184     BTA_AV_RC_CT_NAME,                /* Default AVRCP controller name */
185     BTA_AV_RC_TG_NAME                 /* Default AVRCP target name */
186 };
187 
188 const tBTA_AV_CFG* p_bta_av_cfg = NULL;
189 
190 const uint16_t bta_av_rc_id[] = {
191     0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
192                          4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN, 7=LEFT_UP,
193                          8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU, 11=CONT_MENU,
194                          12=FAV_MENU, 13=EXIT */
195 
196     0, /* not used */
197 
198     0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
199                          4=4, 5=5, 6=6, 7=7,
200                          8=8, 9=9, 10=DOT, 11=ENTER,
201                          12=CLEAR */
202 
203     0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN, 3=SOUND_SEL,
204                          4=INPUT_SEL, 5=DISP_INFO, 6=HELP, 7=PAGE_UP,
205                          8=PAGE_DOWN */
206 
207 /* btui_app provides an example of how to leave the decision of rejecting a
208  command or not
209  * based on which media player is currently addressed (this is only applicable
210  for AVRCP 1.4 or later)
211  * If the decision is per player for a particular rc_id, the related bit is
212  clear (not set)
213  * bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE, 4=PLAY, 5=STOP,
214              6=PAUSE, 7=RECORD, 8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
215              12=BACKWARD */
216 #if (BTA_AV_RC_PASS_RSP_CODE == AVRC_RSP_INTERIM)
217     0x0070, /* PLAY | STOP | PAUSE */
218 #else       /* BTA_AV_RC_PASS_RSP_CODE != AVRC_RSP_INTERIM */
219     0x1b7E, /* PLAY | STOP | PAUSE | FF | RW | VOL_UP | VOL_DOWN | MUTE | FW |
220                BACK */
221 #endif /* BTA_AV_RC_PASS_RSP_CODE */
222 
223     0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
224 
225     0, /* not used */
226 
227     0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
228                         4=F4, 5=F5 */
229 };
230 
231 #if (BTA_AV_RC_PASS_RSP_CODE == AVRC_RSP_INTERIM)
232 const uint16_t bta_av_rc_id_ac[] = {
233     0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
234                          4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN,
235                7=LEFT_UP,
236                          8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU,
237                11=CONT_MENU,
238                          12=FAV_MENU, 13=EXIT */
239 
240     0, /* not used */
241 
242     0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
243                          4=4, 5=5, 6=6, 7=7,
244                          8=8, 9=9, 10=DOT, 11=ENTER,
245                          12=CLEAR */
246 
247     0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN,
248                3=SOUND_SEL,
249                          4=INPUT_SEL, 5=DISP_INFO, 6=HELP,
250                7=PAGE_UP,
251                          8=PAGE_DOWN */
252 
253     /* btui_app provides an example of how to leave the decision of
254      * rejecting a command or not
255      * based on which media player is currently addressed (this is
256      * only applicable for AVRCP 1.4 or later)
257      * If the decision is per player for a particular rc_id, the
258      * related bit is set */
259     0x1800, /* bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE,
260                          4=PLAY, 5=STOP, 6=PAUSE, 7=RECORD,
261                          8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
262                          12=BACKWARD */
263 
264     0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
265 
266     0, /* not used */
267 
268     0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
269                         4=F4, 5=F5 */
270 };
271 uint16_t* p_bta_av_rc_id_ac = (uint16_t*)bta_av_rc_id_ac;
272 #else
273 uint16_t* p_bta_av_rc_id_ac = NULL;
274 #endif
275 
276 uint16_t* p_bta_av_rc_id = (uint16_t*)bta_av_rc_id;
277