1 /******************************************************************************
2  *
3  *  Copyright (C) 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 <stddef.h>
27 
28 #include "bt_common.h"
29 #include "bt_target.h"
30 #include "bta_api.h"
31 #include "bta_av_int.h"
32 
33 #ifndef BTA_AV_RC_COMP_ID
34 #define BTA_AV_RC_COMP_ID AVRC_CO_GOOGLE
35 #endif
36 
37 #ifndef BTA_AV_RC_PASS_RSP_CODE
38 #define BTA_AV_RC_PASS_RSP_CODE BTA_AV_RSP_NOT_IMPL
39 #endif
40 
41 const uint32_t bta_av_meta_caps_co_ids[] = {AVRC_CO_METADATA, AVRC_CO_BROADCOM};
42 
43 /* AVRCP supported categories */
44 #define BTA_AV_RC_SUPF_CT (AVRC_SUPF_CT_CAT2)
45 #define BTA_AVK_RC_SUPF_CT (AVRC_SUPF_CT_CAT1 | AVRC_SUPF_CT_BROWSE)
46 #define BTA_AVK_RC_SUPF_TG (AVRC_SUPF_TG_CAT2)
47 
48 /* AVRCP Controller and Targer default name */
49 #ifndef BTA_AV_RC_CT_NAME
50 #define BTA_AV_RC_CT_NAME "AVRC Controller"
51 #endif
52 
53 #ifndef BTA_AV_RC_TG_NAME
54 #define BTA_AV_RC_TG_NAME "AVRC Target"
55 #endif
56 
57 /* Added to modify
58  *	1. flush timeout
59  *	2. Remove Group navigation support in SupportedFeatures
60  *	3. GetCapabilities supported event_ids list
61  *	4. GetCapabilities supported event_ids count
62 */
63 /* Flushing partial avdtp packets can cause some headsets to disconnect the link
64    if receiving partial a2dp frames */
65 const uint16_t bta_av_audio_flush_to[] = {
66     0, /* 1 stream */
67     0, /* 2 streams */
68     0, /* 3 streams */
69     0, /* 4 streams */
70     0  /* 5 streams */
71 };     /* AVDTP audio transport channel flush timeout */
72 
73 /* Note: Android doesnt support AVRC_SUPF_TG_GROUP_NAVI  */
74 /* Note: if AVRC_SUPF_TG_GROUP_NAVI is set, bta_av_cfg.avrc_group should be true
75  */
76 #ifndef BTA_AV_RC_SUPF_TG
77 #if (AVRC_METADATA_INCLUDED == TRUE)
78 #define BTA_AV_RC_SUPF_TG                          \
79   (AVRC_SUPF_TG_CAT1 | AVRC_SUPF_TG_MULTI_PLAYER | \
80    AVRC_SUPF_TG_BROWSE) /* TODO: | AVRC_SUPF_TG_APP_SETTINGS) */
81 #else
82 #define BTA_AV_RC_SUPF_TG (AVRC_SUPF_TG_CAT1)
83 #endif
84 #endif
85 
86 /*
87  * If the number of event IDs is changed in this array, BTA_AV_ NUM_RC_EVT_IDS
88  * also needs to be changed.
89  */
90 const uint8_t bta_av_meta_caps_evt_ids[] = {
91     AVRC_EVT_PLAY_STATUS_CHANGE, AVRC_EVT_TRACK_CHANGE,
92     AVRC_EVT_PLAY_POS_CHANGED,   AVRC_EVT_AVAL_PLAYERS_CHANGE,
93     AVRC_EVT_ADDR_PLAYER_CHANGE, AVRC_EVT_UIDS_CHANGE,
94     AVRC_EVT_NOW_PLAYING_CHANGE,
95     /* TODO: Add support for these events
96     AVRC_EVT_APP_SETTING_CHANGE,
97     */
98 };
99 #ifndef BTA_AV_NUM_RC_EVT_IDS
100 #define BTA_AV_NUM_RC_EVT_IDS \
101   (sizeof(bta_av_meta_caps_evt_ids) / sizeof(bta_av_meta_caps_evt_ids[0]))
102 #endif /* BTA_AV_NUM_RC_EVT_IDS */
103 
104 const uint8_t bta_avk_meta_caps_evt_ids[] = {
105 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
106     AVRC_EVT_VOLUME_CHANGE,
107 #endif
108 };
109 #ifndef BTA_AVK_NUM_RC_EVT_IDS
110 #define BTA_AVK_NUM_RC_EVT_IDS \
111   (sizeof(bta_avk_meta_caps_evt_ids) / sizeof(bta_avk_meta_caps_evt_ids[0]))
112 #endif /* BTA_AVK_NUM_RC_EVT_IDS */
113 
114 /* the MTU for the AVRCP browsing channel */
115 #ifndef BTA_AV_MAX_RC_BR_MTU
116 #define BTA_AV_MAX_RC_BR_MTU 1008
117 #endif
118 
119 /* This configuration to be used when we are Src + TG + CT( only for abs vol) */
120 const tBTA_AV_CFG bta_av_cfg = {
121     BTA_AV_RC_COMP_ID, /* AVRCP Company ID */
122 #if (AVRC_METADATA_INCLUDED == TRUE)
123     512,                  /* AVRCP MTU at L2CAP for control channel */
124     BTA_AV_MAX_RC_BR_MTU, /* AVRCP MTU at L2CAP for browsing channel */
125 #else
126     48,                   /* AVRCP MTU at L2CAP for control channel */
127     BTA_AV_MAX_RC_BR_MTU, /* AVRCP MTU at L2CAP for browsing channel */
128 #endif
129     BTA_AV_RC_SUPF_CT,     /* AVRCP controller categories */
130     BTA_AV_RC_SUPF_TG,     /* AVRCP target categories */
131     672,                   /* AVDTP signaling channel MTU at L2CAP */
132     BTA_AV_MAX_A2DP_MTU,   /* AVDTP audio transport channel MTU at L2CAP
133                               */
134     bta_av_audio_flush_to, /* AVDTP audio transport channel flush
135                               timeout */
136     6,                     /* AVDTP audio channel max data queue size */
137     BTA_AV_MAX_VDP_MTU,    /* AVDTP video transport channel MTU at L2CAP */
138     600,                   /* AVDTP video transport channel flush timeout */
139     false, /* true, to accept AVRC 1.3 group nevigation command */
140     2,     /* company id count in p_meta_co_ids */
141     BTA_AV_NUM_RC_EVT_IDS,    /* event id count in p_meta_evt_ids */
142     BTA_AV_RC_PASS_RSP_CODE,  /* the default response code for pass
143                                  through commands */
144     bta_av_meta_caps_co_ids,  /* the metadata Get Capabilities response
145                                  for company id */
146     bta_av_meta_caps_evt_ids, /* the the metadata Get Capabilities
147                                  response for event id */
148     NULL,                     /* the action function table for VDP stream */
149     NULL,                     /* action function to register VDP */
150     BTA_AV_RC_CT_NAME,        /* Default AVRCP controller name */
151     BTA_AV_RC_TG_NAME         /* Default AVRCP target name */
152 };
153 
154 /* This configuration to be used when we are Sink + CT + TG( only for abs vol)
155  */
156 const tBTA_AV_CFG bta_avk_cfg = {
157     AVRC_CO_METADATA, /* AVRCP Company ID */
158 #if (AVRC_METADATA_INCLUDED == TRUE)
159     512, /* AVRCP MTU at L2CAP for control channel */
160 #else
161     48,                   /* AVRCP MTU at L2CAP for control channel */
162 #endif
163     BTA_AV_MAX_RC_BR_MTU,  /* AVRCP MTU at L2CAP for browsing channel */
164     BTA_AVK_RC_SUPF_CT,    /* AVRCP controller categories */
165     BTA_AVK_RC_SUPF_TG,    /* AVRCP target categories */
166     672,                   /* AVDTP signaling channel MTU at L2CAP */
167     BTA_AV_MAX_A2DP_MTU,   /* AVDTP audio transport channel MTU at L2CAP
168                               */
169     bta_av_audio_flush_to, /* AVDTP audio transport channel flush
170                               timeout */
171     6,                     /* AVDTP audio channel max data queue size */
172     BTA_AV_MAX_VDP_MTU,    /* AVDTP video transport channel MTU at L2CAP */
173     600,                   /* AVDTP video transport channel flush timeout */
174     false, /* true, to accept AVRC 1.3 group nevigation command */
175     2,     /* company id count in p_meta_co_ids */
176     BTA_AVK_NUM_RC_EVT_IDS,    /* event id count in p_meta_evt_ids */
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_avk_meta_caps_evt_ids, /* the the metadata Get Capabilities
182                                   response for event id */
183     NULL,                      /* the action function table for VDP stream */
184     NULL,                      /* action function to register VDP */
185     {0},                       /* Default AVRCP controller name */
186     {0},                       /* Default AVRCP target name */
187 };
188 
189 tBTA_AV_CFG* p_bta_av_cfg = NULL;
190 
191 const uint16_t bta_av_rc_id[] = {
192     0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
193                          4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN, 7=LEFT_UP,
194                          8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU, 11=CONT_MENU,
195                          12=FAV_MENU, 13=EXIT */
196 
197     0, /* not used */
198 
199     0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
200                          4=4, 5=5, 6=6, 7=7,
201                          8=8, 9=9, 10=DOT, 11=ENTER,
202                          12=CLEAR */
203 
204     0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN, 3=SOUND_SEL,
205                          4=INPUT_SEL, 5=DISP_INFO, 6=HELP, 7=PAGE_UP,
206                          8=PAGE_DOWN */
207 
208 /* btui_app provides an example of how to leave the decision of rejecting a
209  command or not
210  * based on which media player is currently addressed (this is only applicable
211  for AVRCP 1.4 or later)
212  * If the decision is per player for a particular rc_id, the related bit is
213  clear (not set)
214  * bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE, 4=PLAY, 5=STOP,
215              6=PAUSE, 7=RECORD, 8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
216              12=BACKWARD */
217 #if (BTA_AV_RC_PASS_RSP_CODE == BTA_AV_RSP_INTERIM)
218     0x0070, /* PLAY | STOP | PAUSE */
219 #else       /* BTA_AV_RC_PASS_RSP_CODE != BTA_AV_RSP_INTERIM */
220 #if (BTA_AVRCP_FF_RW_SUPPORT == TRUE)
221     0x1b7E, /* PLAY | STOP | PAUSE | FF | RW | VOL_UP | VOL_DOWN | MUTE | FW |
222                BACK */
223 #else  /* BTA_AVRCP_FF_RW_SUPPORT == FALSE */
224     0x187E, /* PLAY | STOP | PAUSE | VOL_UP | VOL_DOWN | MUTE | FW | BACK */
225 #endif /* BTA_AVRCP_FF_RW_SUPPORT */
226 #endif /* BTA_AV_RC_PASS_RSP_CODE */
227 
228     0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
229 
230     0, /* not used */
231 
232     0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
233                         4=F4, 5=F5 */
234 };
235 
236 #if (BTA_AV_RC_PASS_RSP_CODE == BTA_AV_RSP_INTERIM)
237 const uint16_t bta_av_rc_id_ac[] = {
238     0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
239                          4=RIGHT, 5=RIGHT_UP, 6=RIGHT_DOWN,
240                7=LEFT_UP,
241                          8=LEFT_DOWN, 9=ROOT_MENU, 10=SETUP_MENU,
242                11=CONT_MENU,
243                          12=FAV_MENU, 13=EXIT */
244 
245     0, /* not used */
246 
247     0x0000, /* bit mask: 0=0, 1=1, 2=2, 3=3,
248                          4=4, 5=5, 6=6, 7=7,
249                          8=8, 9=9, 10=DOT, 11=ENTER,
250                          12=CLEAR */
251 
252     0x0000, /* bit mask: 0=CHAN_UP, 1=CHAN_DOWN, 2=PREV_CHAN,
253                3=SOUND_SEL,
254                          4=INPUT_SEL, 5=DISP_INFO, 6=HELP,
255                7=PAGE_UP,
256                          8=PAGE_DOWN */
257 
258     /* btui_app provides an example of how to leave the decision of
259      * rejecting a command or not
260      * based on which media player is currently addressed (this is
261      * only applicable for AVRCP 1.4 or later)
262      * If the decision is per player for a particular rc_id, the
263      * related bit is set */
264     0x1800, /* bit mask: 0=POWER, 1=VOL_UP, 2=VOL_DOWN, 3=MUTE,
265                          4=PLAY, 5=STOP, 6=PAUSE, 7=RECORD,
266                          8=REWIND, 9=FAST_FOR, 10=EJECT, 11=FORWARD,
267                          12=BACKWARD */
268 
269     0x0000, /* bit mask: 0=ANGLE, 1=SUBPICT */
270 
271     0, /* not used */
272 
273     0x0000 /* bit mask: 0=not used, 1=F1, 2=F2, 3=F3,
274                         4=F4, 5=F5 */
275 };
276 uint16_t* p_bta_av_rc_id_ac = (uint16_t*)bta_av_rc_id_ac;
277 #else
278 uint16_t* p_bta_av_rc_id_ac = NULL;
279 #endif
280 
281 uint16_t* p_bta_av_rc_id = (uint16_t*)bta_av_rc_id;
282