• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 /**
18  * Vendor Specific A2DP Codecs Support
19  */
20 
21 #define LOG_TAG "a2dp_vendor"
22 
23 #include "a2dp_vendor.h"
24 #include "a2dp_vendor_aptx.h"
25 #include "a2dp_vendor_aptx_hd.h"
26 #include "a2dp_vendor_ldac.h"
27 #include "bt_target.h"
28 #include "osi/include/log.h"
29 #include "osi/include/osi.h"
30 
A2DP_IsVendorSourceCodecValid(const uint8_t * p_codec_info)31 bool A2DP_IsVendorSourceCodecValid(const uint8_t* p_codec_info) {
32   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
33   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
34 
35   // Check for aptX
36   if (vendor_id == A2DP_APTX_VENDOR_ID &&
37       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
38     return A2DP_IsVendorSourceCodecValidAptx(p_codec_info);
39   }
40 
41   // Check for aptX-HD
42   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
43       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
44     return A2DP_IsVendorSourceCodecValidAptxHd(p_codec_info);
45   }
46 
47   // Check for LDAC
48   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
49     return A2DP_IsVendorSourceCodecValidLdac(p_codec_info);
50   }
51 
52   // Add checks based on <vendor_id, codec_id>
53 
54   return false;
55 }
56 
A2DP_IsVendorSinkCodecValid(UNUSED_ATTR const uint8_t * p_codec_info)57 bool A2DP_IsVendorSinkCodecValid(UNUSED_ATTR const uint8_t* p_codec_info) {
58   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
59   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
60 
61   // Add checks based on <vendor_id, codec_id>
62   // NOTE: Should be done only for local Sink codecs.
63 
64   return false;
65 }
66 
A2DP_IsVendorPeerSourceCodecValid(UNUSED_ATTR const uint8_t * p_codec_info)67 bool A2DP_IsVendorPeerSourceCodecValid(
68     UNUSED_ATTR const uint8_t* p_codec_info) {
69   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
70   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
71 
72   // Add checks based on <vendor_id, codec_id>
73   // NOTE: Should be done only for local Sink codecs.
74 
75   return false;
76 }
77 
A2DP_IsVendorPeerSinkCodecValid(const uint8_t * p_codec_info)78 bool A2DP_IsVendorPeerSinkCodecValid(const uint8_t* p_codec_info) {
79   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
80   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
81 
82   // Check for aptX
83   if (vendor_id == A2DP_APTX_VENDOR_ID &&
84       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
85     return A2DP_IsVendorPeerSinkCodecValidAptx(p_codec_info);
86   }
87 
88   // Check for aptX-HD
89   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
90       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
91     return A2DP_IsVendorPeerSinkCodecValidAptxHd(p_codec_info);
92   }
93 
94   // Check for LDAC
95   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
96     return A2DP_IsVendorPeerSinkCodecValidLdac(p_codec_info);
97   }
98 
99   // Add checks based on <vendor_id, codec_id>
100 
101   return false;
102 }
103 
A2DP_IsVendorSinkCodecSupported(UNUSED_ATTR const uint8_t * p_codec_info)104 bool A2DP_IsVendorSinkCodecSupported(UNUSED_ATTR const uint8_t* p_codec_info) {
105   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
106   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
107 
108   // Add checks based on <vendor_id, codec_id>
109   // NOTE: Should be done only for local Sink codecs.
110 
111   return false;
112 }
113 
A2DP_IsVendorPeerSourceCodecSupported(UNUSED_ATTR const uint8_t * p_codec_info)114 bool A2DP_IsVendorPeerSourceCodecSupported(
115     UNUSED_ATTR const uint8_t* p_codec_info) {
116   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
117   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
118 
119   // Add checks based on <vendor_id, codec_id> and peer codec capabilities
120   // NOTE: Should be done only for local Sink codecs.
121 
122   return false;
123 }
124 
A2DP_VendorBuildSrc2SinkConfig(UNUSED_ATTR const uint8_t * p_src_cap,UNUSED_ATTR uint8_t * p_pref_cfg)125 tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(
126     UNUSED_ATTR const uint8_t* p_src_cap, UNUSED_ATTR uint8_t* p_pref_cfg) {
127   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
128   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
129 
130   // Add checks based on <vendor_id, codec_id>
131   // NOTE: Should be done only for local Sink codecs.
132 
133   return A2DP_NS_CODEC_TYPE;
134 }
135 
A2DP_VendorCodecGetVendorId(const uint8_t * p_codec_info)136 uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info) {
137   const uint8_t* p = &p_codec_info[A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX];
138 
139   uint32_t vendor_id = (p[0] & 0x000000ff) | ((p[1] << 8) & 0x0000ff00) |
140                        ((p[2] << 16) & 0x00ff0000) |
141                        ((p[3] << 24) & 0xff000000);
142 
143   return vendor_id;
144 }
145 
A2DP_VendorCodecGetCodecId(const uint8_t * p_codec_info)146 uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info) {
147   const uint8_t* p = &p_codec_info[A2DP_VENDOR_CODEC_CODEC_ID_START_IDX];
148 
149   uint16_t codec_id = (p[0] & 0x00ff) | ((p[1] << 8) & 0xff00);
150 
151   return codec_id;
152 }
153 
A2DP_VendorUsesRtpHeader(bool content_protection_enabled,const uint8_t * p_codec_info)154 bool A2DP_VendorUsesRtpHeader(bool content_protection_enabled,
155                               const uint8_t* p_codec_info) {
156   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
157   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
158 
159   // Check for aptX
160   if (vendor_id == A2DP_APTX_VENDOR_ID &&
161       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
162     return A2DP_VendorUsesRtpHeaderAptx(content_protection_enabled,
163                                         p_codec_info);
164   }
165 
166   // Check for aptX-HD
167   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
168       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
169     return A2DP_VendorUsesRtpHeaderAptxHd(content_protection_enabled,
170                                           p_codec_info);
171   }
172 
173   // Check for LDAC
174   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
175     return A2DP_VendorUsesRtpHeaderLdac(content_protection_enabled,
176                                         p_codec_info);
177   }
178 
179   // Add checks based on <content_protection_enabled, vendor_id, codec_id>
180 
181   return true;
182 }
183 
A2DP_VendorCodecName(UNUSED_ATTR const uint8_t * p_codec_info)184 const char* A2DP_VendorCodecName(UNUSED_ATTR const uint8_t* p_codec_info) {
185   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
186   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
187 
188   // Check for aptX
189   if (vendor_id == A2DP_APTX_VENDOR_ID &&
190       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
191     return A2DP_VendorCodecNameAptx(p_codec_info);
192   }
193 
194   // Check for aptX-HD
195   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
196       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
197     return A2DP_VendorCodecNameAptxHd(p_codec_info);
198   }
199 
200   // Check for LDAC
201   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
202     return A2DP_VendorCodecNameLdac(p_codec_info);
203   }
204 
205   // Add checks based on <vendor_id, codec_id>
206 
207   return "UNKNOWN VENDOR CODEC";
208 }
209 
A2DP_VendorCodecTypeEquals(const uint8_t * p_codec_info_a,const uint8_t * p_codec_info_b)210 bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a,
211                                 const uint8_t* p_codec_info_b) {
212   tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
213   tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
214 
215   if ((codec_type_a != codec_type_b) ||
216       (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
217     return false;
218   }
219 
220   uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
221   uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
222   uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
223   uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
224 
225   if (vendor_id_a != vendor_id_b || codec_id_a != codec_id_b) return false;
226 
227   // Check for aptX
228   if (vendor_id_a == A2DP_APTX_VENDOR_ID &&
229       codec_id_a == A2DP_APTX_CODEC_ID_BLUETOOTH) {
230     return A2DP_VendorCodecTypeEqualsAptx(p_codec_info_a, p_codec_info_b);
231   }
232 
233   // Check for aptX-HD
234   if (vendor_id_a == A2DP_APTX_HD_VENDOR_ID &&
235       codec_id_a == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
236     return A2DP_VendorCodecTypeEqualsAptxHd(p_codec_info_a, p_codec_info_b);
237   }
238 
239   // Check for LDAC
240   if (vendor_id_a == A2DP_LDAC_VENDOR_ID && codec_id_a == A2DP_LDAC_CODEC_ID) {
241     return A2DP_VendorCodecTypeEqualsLdac(p_codec_info_a, p_codec_info_b);
242   }
243 
244   // OPTIONAL: Add extra vendor-specific checks based on the
245   // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
246 
247   return true;
248 }
249 
A2DP_VendorCodecEquals(const uint8_t * p_codec_info_a,const uint8_t * p_codec_info_b)250 bool A2DP_VendorCodecEquals(const uint8_t* p_codec_info_a,
251                             const uint8_t* p_codec_info_b) {
252   tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
253   tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
254 
255   if ((codec_type_a != codec_type_b) ||
256       (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
257     return false;
258   }
259 
260   uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
261   uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
262   uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
263   uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
264 
265   if ((vendor_id_a != vendor_id_b) || (codec_id_a != codec_id_b)) return false;
266 
267   // Check for aptX
268   if (vendor_id_a == A2DP_APTX_VENDOR_ID &&
269       codec_id_a == A2DP_APTX_CODEC_ID_BLUETOOTH) {
270     return A2DP_VendorCodecEqualsAptx(p_codec_info_a, p_codec_info_b);
271   }
272 
273   // Check for aptX-HD
274   if (vendor_id_a == A2DP_APTX_HD_VENDOR_ID &&
275       codec_id_a == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
276     return A2DP_VendorCodecEqualsAptxHd(p_codec_info_a, p_codec_info_b);
277   }
278 
279   // Check for LDAC
280   if (vendor_id_a == A2DP_LDAC_VENDOR_ID && codec_id_a == A2DP_LDAC_CODEC_ID) {
281     return A2DP_VendorCodecEqualsLdac(p_codec_info_a, p_codec_info_b);
282   }
283 
284   // Add extra vendor-specific checks based on the
285   // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
286 
287   return false;
288 }
289 
A2DP_VendorGetTrackSampleRate(const uint8_t * p_codec_info)290 int A2DP_VendorGetTrackSampleRate(const uint8_t* p_codec_info) {
291   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
292   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
293 
294   // Check for aptX
295   if (vendor_id == A2DP_APTX_VENDOR_ID &&
296       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
297     return A2DP_VendorGetTrackSampleRateAptx(p_codec_info);
298   }
299 
300   // Check for aptX-HD
301   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
302       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
303     return A2DP_VendorGetTrackSampleRateAptxHd(p_codec_info);
304   }
305 
306   // Check for LDAC
307   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
308     return A2DP_VendorGetTrackSampleRateLdac(p_codec_info);
309   }
310 
311   // Add checks based on <vendor_id, codec_id>
312 
313   return -1;
314 }
315 
A2DP_VendorGetTrackChannelCount(const uint8_t * p_codec_info)316 int A2DP_VendorGetTrackChannelCount(const uint8_t* p_codec_info) {
317   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
318   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
319 
320   // Check for aptX
321   if (vendor_id == A2DP_APTX_VENDOR_ID &&
322       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
323     return A2DP_VendorGetTrackChannelCountAptx(p_codec_info);
324   }
325 
326   // Check for aptX-HD
327   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
328       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
329     return A2DP_VendorGetTrackChannelCountAptxHd(p_codec_info);
330   }
331 
332   // Check for LDAC
333   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
334     return A2DP_VendorGetTrackChannelCountLdac(p_codec_info);
335   }
336 
337   // Add checks based on <vendor_id, codec_id>
338 
339   return -1;
340 }
341 
A2DP_VendorGetSinkTrackChannelType(UNUSED_ATTR const uint8_t * p_codec_info)342 int A2DP_VendorGetSinkTrackChannelType(
343     UNUSED_ATTR const uint8_t* p_codec_info) {
344   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
345   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
346 
347   // Add checks based on <vendor_id, codec_id>
348   // NOTE: Should be done only for local Sink codecs.
349 
350   return -1;
351 }
352 
A2DP_VendorGetSinkFramesCountToProcess(UNUSED_ATTR uint64_t time_interval_ms,UNUSED_ATTR const uint8_t * p_codec_info)353 int A2DP_VendorGetSinkFramesCountToProcess(
354     UNUSED_ATTR uint64_t time_interval_ms,
355     UNUSED_ATTR const uint8_t* p_codec_info) {
356   // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
357   // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
358 
359   // Add checks based on <vendor_id, codec_id>
360   // NOTE: Should be done only for local Sink codecs.
361 
362   return -1;
363 }
364 
A2DP_VendorGetPacketTimestamp(const uint8_t * p_codec_info,const uint8_t * p_data,uint32_t * p_timestamp)365 bool A2DP_VendorGetPacketTimestamp(const uint8_t* p_codec_info,
366                                    const uint8_t* p_data,
367                                    uint32_t* p_timestamp) {
368   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
369   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
370 
371   // Check for aptX
372   if (vendor_id == A2DP_APTX_VENDOR_ID &&
373       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
374     return A2DP_VendorGetPacketTimestampAptx(p_codec_info, p_data, p_timestamp);
375   }
376 
377   // Check for aptX-HD
378   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
379       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
380     return A2DP_VendorGetPacketTimestampAptxHd(p_codec_info, p_data,
381                                                p_timestamp);
382   }
383 
384   // Check for LDAC
385   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
386     return A2DP_VendorGetPacketTimestampLdac(p_codec_info, p_data, p_timestamp);
387   }
388 
389   // Add checks based on <vendor_id, codec_id>
390 
391   return false;
392 }
393 
A2DP_VendorBuildCodecHeader(const uint8_t * p_codec_info,BT_HDR * p_buf,uint16_t frames_per_packet)394 bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
395                                  uint16_t frames_per_packet) {
396   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
397   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
398 
399   // Check for aptX
400   if (vendor_id == A2DP_APTX_VENDOR_ID &&
401       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
402     return A2DP_VendorBuildCodecHeaderAptx(p_codec_info, p_buf,
403                                            frames_per_packet);
404   }
405 
406   // Check for aptX-HD
407   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
408       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
409     return A2DP_VendorBuildCodecHeaderAptxHd(p_codec_info, p_buf,
410                                              frames_per_packet);
411   }
412 
413   // Check for LDAC
414   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
415     return A2DP_VendorBuildCodecHeaderLdac(p_codec_info, p_buf,
416                                            frames_per_packet);
417   }
418 
419   // Add checks based on <vendor_id, codec_id>
420 
421   return false;
422 }
423 
A2DP_VendorGetEncoderInterface(const uint8_t * p_codec_info)424 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
425     const uint8_t* p_codec_info) {
426   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
427   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
428 
429   // Check for aptX
430   if (vendor_id == A2DP_APTX_VENDOR_ID &&
431       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
432     return A2DP_VendorGetEncoderInterfaceAptx(p_codec_info);
433   }
434 
435   // Check for aptX-HD
436   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
437       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
438     return A2DP_VendorGetEncoderInterfaceAptxHd(p_codec_info);
439   }
440 
441   // Check for LDAC
442   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
443     return A2DP_VendorGetEncoderInterfaceLdac(p_codec_info);
444   }
445 
446   // Add checks based on <vendor_id, codec_id>
447 
448   return NULL;
449 }
450 
A2DP_VendorAdjustCodec(uint8_t * p_codec_info)451 bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info) {
452   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
453   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
454 
455   // Check for aptX
456   if (vendor_id == A2DP_APTX_VENDOR_ID &&
457       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
458     return A2DP_VendorAdjustCodecAptx(p_codec_info);
459   }
460 
461   // Check for aptX-HD
462   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
463       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
464     return A2DP_VendorAdjustCodecAptxHd(p_codec_info);
465   }
466 
467   // Check for LDAC
468   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
469     return A2DP_VendorAdjustCodecLdac(p_codec_info);
470   }
471 
472   // Add checks based on <vendor_id, codec_id>
473 
474   return false;
475 }
476 
A2DP_VendorSourceCodecIndex(const uint8_t * p_codec_info)477 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndex(
478     const uint8_t* p_codec_info) {
479   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
480   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
481 
482   // Check for aptX
483   if (vendor_id == A2DP_APTX_VENDOR_ID &&
484       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
485     return A2DP_VendorSourceCodecIndexAptx(p_codec_info);
486   }
487 
488   // Check for aptX-HD
489   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
490       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
491     return A2DP_VendorSourceCodecIndexAptxHd(p_codec_info);
492   }
493 
494   // Check for LDAC
495   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
496     return A2DP_VendorSourceCodecIndexLdac(p_codec_info);
497   }
498 
499   // Add checks based on <vendor_id, codec_id>
500 
501   return BTAV_A2DP_CODEC_INDEX_MAX;
502 }
503 
A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index)504 const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index) {
505   // Add checks based on codec_index
506   switch (codec_index) {
507     case BTAV_A2DP_CODEC_INDEX_SOURCE_SBC:
508     case BTAV_A2DP_CODEC_INDEX_SINK_SBC:
509     case BTAV_A2DP_CODEC_INDEX_SOURCE_AAC:
510       break;  // These are not vendor-specific codecs
511     case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX:
512       return A2DP_VendorCodecIndexStrAptx();
513     case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD:
514       return A2DP_VendorCodecIndexStrAptxHd();
515     case BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC:
516       return A2DP_VendorCodecIndexStrLdac();
517     // Add a switch statement for each vendor-specific codec
518     case BTAV_A2DP_CODEC_INDEX_MAX:
519       break;
520   }
521 
522   return "UNKNOWN CODEC INDEX";
523 }
524 
A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index,tAVDT_CFG * p_cfg)525 bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index,
526                                 tAVDT_CFG* p_cfg) {
527   // Add checks based on codec_index
528   switch (codec_index) {
529     case BTAV_A2DP_CODEC_INDEX_SOURCE_SBC:
530     case BTAV_A2DP_CODEC_INDEX_SINK_SBC:
531     case BTAV_A2DP_CODEC_INDEX_SOURCE_AAC:
532       break;  // These are not vendor-specific codecs
533     case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX:
534       return A2DP_VendorInitCodecConfigAptx(p_cfg);
535     case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD:
536       return A2DP_VendorInitCodecConfigAptxHd(p_cfg);
537     case BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC:
538       return A2DP_VendorInitCodecConfigLdac(p_cfg);
539     // Add a switch statement for each vendor-specific codec
540     case BTAV_A2DP_CODEC_INDEX_MAX:
541       break;
542   }
543 
544   return false;
545 }
546 
A2DP_VendorDumpCodecInfo(const uint8_t * p_codec_info)547 bool A2DP_VendorDumpCodecInfo(const uint8_t* p_codec_info) {
548   uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
549   uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
550 
551   // Check for aptX
552   if (vendor_id == A2DP_APTX_VENDOR_ID &&
553       codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
554     return A2DP_VendorDumpCodecInfoAptx(p_codec_info);
555   }
556 
557   // Check for aptX-HD
558   if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
559       codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
560     return A2DP_VendorDumpCodecInfoAptxHd(p_codec_info);
561   }
562 
563   // Check for LDAC
564   if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
565     return A2DP_VendorDumpCodecInfoLdac(p_codec_info);
566   }
567 
568   // Add checks based on <vendor_id, codec_id>
569 
570   return false;
571 }
572