1 /******************************************************************************
2  *
3  *  Copyright 2015 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 #include "device/include/esco_parameters.h"
20 
21 #include <bluetooth/log.h>
22 #include <com_android_bluetooth_flags.h>
23 
24 #include "hci/controller_interface.h"
25 #include "main/shim/entry.h"
26 
27 using namespace bluetooth;
28 
29 static const enh_esco_params_t default_esco_parameters[ESCO_NUM_CODECS] = {
30         // CVSD D1
31         {
32                 .transmit_bandwidth = TXRX_64KBITS_RATE,
33                 .receive_bandwidth = TXRX_64KBITS_RATE,
34                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
35                                            .company_id = 0x0000,
36                                            .vendor_specific_codec_id = 0x0000},
37                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
38                                           .company_id = 0x0000,
39                                           .vendor_specific_codec_id = 0x0000},
40                 .transmit_codec_frame_size = 60,
41                 .receive_codec_frame_size = 60,
42                 .input_bandwidth = INPUT_OUTPUT_64K_RATE,
43                 .output_bandwidth = INPUT_OUTPUT_64K_RATE,
44                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
45                                         .company_id = 0x0000,
46                                         .vendor_specific_codec_id = 0x0000},
47                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
48                                          .company_id = 0x0000,
49                                          .vendor_specific_codec_id = 0x0000},
50                 .input_coded_data_size = 16,
51                 .output_coded_data_size = 16,
52                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
53                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
54                 .input_pcm_payload_msb_position = 0,
55                 .output_pcm_payload_msb_position = 0,
56                 .input_data_path = ESCO_DATA_PATH_PCM,
57                 .output_data_path = ESCO_DATA_PATH_PCM,
58                 .input_transport_unit_size = 0x00,
59                 .output_transport_unit_size = 0x00,
60                 .max_latency_ms = 0xFFFF,  // Don't care
61                 .packet_types = (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 |
62                                  ESCO_PKT_TYPES_MASK_HV3),
63                 .retransmission_effort = ESCO_RETRANSMISSION_OFF,
64                 .coding_format = ESCO_CODING_FORMAT_CVSD,
65         },  // CVSD S1
66         {
67                 .transmit_bandwidth = TXRX_64KBITS_RATE,
68                 .receive_bandwidth = TXRX_64KBITS_RATE,
69                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
70                                            .company_id = 0x0000,
71                                            .vendor_specific_codec_id = 0x0000},
72                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
73                                           .company_id = 0x0000,
74                                           .vendor_specific_codec_id = 0x0000},
75                 .transmit_codec_frame_size = 60,
76                 .receive_codec_frame_size = 60,
77                 .input_bandwidth = INPUT_OUTPUT_64K_RATE,
78                 .output_bandwidth = INPUT_OUTPUT_64K_RATE,
79                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
80                                         .company_id = 0x0000,
81                                         .vendor_specific_codec_id = 0x0000},
82                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
83                                          .company_id = 0x0000,
84                                          .vendor_specific_codec_id = 0x0000},
85                 .input_coded_data_size = 16,
86                 .output_coded_data_size = 16,
87                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
88                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
89                 .input_pcm_payload_msb_position = 0,
90                 .output_pcm_payload_msb_position = 0,
91                 .input_data_path = ESCO_DATA_PATH_PCM,
92                 .output_data_path = ESCO_DATA_PATH_PCM,
93                 .input_transport_unit_size = 0x00,
94                 .output_transport_unit_size = 0x00,
95                 .max_latency_ms = 7,
96                 .packet_types = (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 |
97                                  ESCO_PKT_TYPES_MASK_HV3 | ESCO_PKT_TYPES_MASK_EV3 |
98                                  ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5 |
99                                  ESCO_PKT_TYPES_MASK_NO_3_EV3 | ESCO_PKT_TYPES_MASK_NO_2_EV5 |
100                                  ESCO_PKT_TYPES_MASK_NO_3_EV5),
101                 .retransmission_effort = ESCO_RETRANSMISSION_POWER,
102                 .coding_format = ESCO_CODING_FORMAT_CVSD,
103         },
104         // CVSD S3
105         {
106                 .transmit_bandwidth = TXRX_64KBITS_RATE,
107                 .receive_bandwidth = TXRX_64KBITS_RATE,
108                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
109                                            .company_id = 0x0000,
110                                            .vendor_specific_codec_id = 0x0000},
111                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
112                                           .company_id = 0x0000,
113                                           .vendor_specific_codec_id = 0x0000},
114                 .transmit_codec_frame_size = 60,
115                 .receive_codec_frame_size = 60,
116                 .input_bandwidth = INPUT_OUTPUT_64K_RATE,
117                 .output_bandwidth = INPUT_OUTPUT_64K_RATE,
118                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
119                                         .company_id = 0x0000,
120                                         .vendor_specific_codec_id = 0x0000},
121                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
122                                          .company_id = 0x0000,
123                                          .vendor_specific_codec_id = 0x0000},
124                 .input_coded_data_size = 16,
125                 .output_coded_data_size = 16,
126                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
127                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
128                 .input_pcm_payload_msb_position = 0,
129                 .output_pcm_payload_msb_position = 0,
130                 .input_data_path = ESCO_DATA_PATH_PCM,
131                 .output_data_path = ESCO_DATA_PATH_PCM,
132                 .input_transport_unit_size = 0x00,
133                 .output_transport_unit_size = 0x00,
134                 .max_latency_ms = 10,
135                 .packet_types = (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 |
136                                  ESCO_PKT_TYPES_MASK_HV3 | ESCO_PKT_TYPES_MASK_EV3 |
137                                  ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5 |
138                                  ESCO_PKT_TYPES_MASK_NO_3_EV3 | ESCO_PKT_TYPES_MASK_NO_2_EV5 |
139                                  ESCO_PKT_TYPES_MASK_NO_3_EV5),
140                 .retransmission_effort = ESCO_RETRANSMISSION_POWER,
141                 .coding_format = ESCO_CODING_FORMAT_CVSD,
142         },
143         // CVSD S4
144         {
145                 .transmit_bandwidth = TXRX_64KBITS_RATE,
146                 .receive_bandwidth = TXRX_64KBITS_RATE,
147                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
148                                            .company_id = 0x0000,
149                                            .vendor_specific_codec_id = 0x0000},
150                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_CVSD,
151                                           .company_id = 0x0000,
152                                           .vendor_specific_codec_id = 0x0000},
153                 .transmit_codec_frame_size = 60,
154                 .receive_codec_frame_size = 60,
155                 .input_bandwidth = INPUT_OUTPUT_64K_RATE,
156                 .output_bandwidth = INPUT_OUTPUT_64K_RATE,
157                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
158                                         .company_id = 0x0000,
159                                         .vendor_specific_codec_id = 0x0000},
160                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
161                                          .company_id = 0x0000,
162                                          .vendor_specific_codec_id = 0x0000},
163                 .input_coded_data_size = 16,
164                 .output_coded_data_size = 16,
165                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
166                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
167                 .input_pcm_payload_msb_position = 0,
168                 .output_pcm_payload_msb_position = 0,
169                 .input_data_path = ESCO_DATA_PATH_PCM,
170                 .output_data_path = ESCO_DATA_PATH_PCM,
171                 .input_transport_unit_size = 0x00,
172                 .output_transport_unit_size = 0x00,
173                 .max_latency_ms = 12,
174                 .packet_types = (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 |
175                                  ESCO_PKT_TYPES_MASK_HV3 | ESCO_PKT_TYPES_MASK_EV3 |
176                                  ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5 |
177                                  ESCO_PKT_TYPES_MASK_NO_3_EV3 | ESCO_PKT_TYPES_MASK_NO_2_EV5 |
178                                  ESCO_PKT_TYPES_MASK_NO_3_EV5),
179                 .retransmission_effort = ESCO_RETRANSMISSION_QUALITY,
180                 .coding_format = ESCO_CODING_FORMAT_CVSD,
181         },
182         // mSBC T1
183         {
184                 .transmit_bandwidth = TXRX_64KBITS_RATE,
185                 .receive_bandwidth = TXRX_64KBITS_RATE,
186                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_MSBC,
187                                            .company_id = 0x0000,
188                                            .vendor_specific_codec_id = 0x0000},
189                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_MSBC,
190                                           .company_id = 0x0000,
191                                           .vendor_specific_codec_id = 0x0000},
192                 .transmit_codec_frame_size = 60,
193                 .receive_codec_frame_size = 60,
194                 .input_bandwidth = INPUT_OUTPUT_128K_RATE,
195                 .output_bandwidth = INPUT_OUTPUT_128K_RATE,
196                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
197                                         .company_id = 0x0000,
198                                         .vendor_specific_codec_id = 0x0000},
199                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
200                                          .company_id = 0x0000,
201                                          .vendor_specific_codec_id = 0x0000},
202                 .input_coded_data_size = 16,
203                 .output_coded_data_size = 16,
204                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
205                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
206                 .input_pcm_payload_msb_position = 0,
207                 .output_pcm_payload_msb_position = 0,
208                 .input_data_path = ESCO_DATA_PATH_PCM,
209                 .output_data_path = ESCO_DATA_PATH_PCM,
210                 .input_transport_unit_size = 0x00,
211                 .output_transport_unit_size = 0x00,
212                 .max_latency_ms = 8,
213                 .packet_types = (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 |
214                                  ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5 |
215                                  ESCO_PKT_TYPES_MASK_NO_2_EV3),
216                 .retransmission_effort = ESCO_RETRANSMISSION_QUALITY,
217                 .coding_format = ESCO_CODING_FORMAT_MSBC,
218         },
219         // mSBC T2
220         {
221                 .transmit_bandwidth = TXRX_64KBITS_RATE,
222                 .receive_bandwidth = TXRX_64KBITS_RATE,
223                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_MSBC,
224                                            .company_id = 0x0000,
225                                            .vendor_specific_codec_id = 0x0000},
226                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_MSBC,
227                                           .company_id = 0x0000,
228                                           .vendor_specific_codec_id = 0x0000},
229                 .transmit_codec_frame_size = 60,
230                 .receive_codec_frame_size = 60,
231                 .input_bandwidth = INPUT_OUTPUT_128K_RATE,
232                 .output_bandwidth = INPUT_OUTPUT_128K_RATE,
233                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
234                                         .company_id = 0x0000,
235                                         .vendor_specific_codec_id = 0x0000},
236                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
237                                          .company_id = 0x0000,
238                                          .vendor_specific_codec_id = 0x0000},
239                 .input_coded_data_size = 16,
240                 .output_coded_data_size = 16,
241                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
242                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
243                 .input_pcm_payload_msb_position = 0,
244                 .output_pcm_payload_msb_position = 0,
245                 .input_data_path = ESCO_DATA_PATH_PCM,
246                 .output_data_path = ESCO_DATA_PATH_PCM,
247                 .input_transport_unit_size = 0x00,
248                 .output_transport_unit_size = 0x00,
249                 .max_latency_ms = 13,
250                 .packet_types = (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 |
251                                  ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5),
252                 .retransmission_effort = ESCO_RETRANSMISSION_QUALITY,
253                 .coding_format = ESCO_CODING_FORMAT_MSBC,
254         },
255         // LC3 T1
256         {
257                 .transmit_bandwidth = TXRX_64KBITS_RATE,
258                 .receive_bandwidth = TXRX_64KBITS_RATE,
259                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_LC3,
260                                            .company_id = 0x0000,
261                                            .vendor_specific_codec_id = 0x0000},
262                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_LC3,
263                                           .company_id = 0x0000,
264                                           .vendor_specific_codec_id = 0x0000},
265                 .transmit_codec_frame_size = 60,
266                 .receive_codec_frame_size = 60,
267                 .input_bandwidth = INPUT_OUTPUT_256K_RATE,
268                 .output_bandwidth = INPUT_OUTPUT_256K_RATE,
269                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
270                                         .company_id = 0x0000,
271                                         .vendor_specific_codec_id = 0x0000},
272                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
273                                          .company_id = 0x0000,
274                                          .vendor_specific_codec_id = 0x0000},
275                 .input_coded_data_size = 16,
276                 .output_coded_data_size = 16,
277                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
278                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
279                 .input_pcm_payload_msb_position = 0,
280                 .output_pcm_payload_msb_position = 0,
281                 .input_data_path = ESCO_DATA_PATH_PCM,
282                 .output_data_path = ESCO_DATA_PATH_PCM,
283                 .input_transport_unit_size = 0x00,
284                 .output_transport_unit_size = 0x00,
285                 .max_latency_ms = 8,
286                 .packet_types = (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 |
287                                  ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5 |
288                                  ESCO_PKT_TYPES_MASK_NO_2_EV3),
289                 .retransmission_effort = ESCO_RETRANSMISSION_QUALITY,
290                 .coding_format = ESCO_CODING_FORMAT_LC3,
291         },
292         // LC3 T2
293         {
294                 .transmit_bandwidth = TXRX_64KBITS_RATE,
295                 .receive_bandwidth = TXRX_64KBITS_RATE,
296                 .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_LC3,
297                                            .company_id = 0x0000,
298                                            .vendor_specific_codec_id = 0x0000},
299                 .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_LC3,
300                                           .company_id = 0x0000,
301                                           .vendor_specific_codec_id = 0x0000},
302                 .transmit_codec_frame_size = 60,
303                 .receive_codec_frame_size = 60,
304                 .input_bandwidth = INPUT_OUTPUT_256K_RATE,
305                 .output_bandwidth = INPUT_OUTPUT_256K_RATE,
306                 .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
307                                         .company_id = 0x0000,
308                                         .vendor_specific_codec_id = 0x0000},
309                 .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
310                                          .company_id = 0x0000,
311                                          .vendor_specific_codec_id = 0x0000},
312                 .input_coded_data_size = 16,
313                 .output_coded_data_size = 16,
314                 .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
315                 .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
316                 .input_pcm_payload_msb_position = 0,
317                 .output_pcm_payload_msb_position = 0,
318                 .input_data_path = ESCO_DATA_PATH_PCM,
319                 .output_data_path = ESCO_DATA_PATH_PCM,
320                 .input_transport_unit_size = 0x00,
321                 .output_transport_unit_size = 0x00,
322                 .max_latency_ms = 13,
323                 .packet_types = (ESCO_PKT_TYPES_MASK_NO_3_EV3 | ESCO_PKT_TYPES_MASK_NO_2_EV5 |
324                                  ESCO_PKT_TYPES_MASK_NO_3_EV5),
325                 .retransmission_effort = ESCO_RETRANSMISSION_QUALITY,
326                 .coding_format = ESCO_CODING_FORMAT_LC3,
327         },
328         // aptX Voice SWB
329         {.transmit_bandwidth = TXRX_64KBITS_RATE,
330          .receive_bandwidth = TXRX_64KBITS_RATE,
331          .transmit_coding_format = {.coding_format = ESCO_CODING_FORMAT_VS,
332                                     .company_id = 0x000A,
333                                     .vendor_specific_codec_id = 0x0000},
334          .receive_coding_format = {.coding_format = ESCO_CODING_FORMAT_VS,
335                                    .company_id = 0x000A,
336                                    .vendor_specific_codec_id = 0x0000},
337          .transmit_codec_frame_size = 60,
338          .receive_codec_frame_size = 60,
339          .input_bandwidth = INPUT_OUTPUT_128K_RATE,
340          .output_bandwidth = INPUT_OUTPUT_128K_RATE,
341          .input_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
342                                  .company_id = 0x0000,
343                                  .vendor_specific_codec_id = 0x0000},
344          .output_coding_format = {.coding_format = ESCO_CODING_FORMAT_LINEAR,
345                                   .company_id = 0x0000,
346                                   .vendor_specific_codec_id = 0x0000},
347          .input_coded_data_size = 16,
348          .output_coded_data_size = 16,
349          .input_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
350          .output_pcm_data_format = ESCO_PCM_DATA_FORMAT_2_COMP,
351          .input_pcm_payload_msb_position = 0,
352          .output_pcm_payload_msb_position = 0,
353          .input_data_path = ESCO_DATA_PATH_PCM,
354          .output_data_path = ESCO_DATA_PATH_PCM,
355          .input_transport_unit_size = 0x00,
356          .output_transport_unit_size = 0x00,
357          .max_latency_ms = 14,
358          .packet_types = 0x0380,
359          .retransmission_effort = ESCO_RETRANSMISSION_QUALITY}};
360 
esco_parameters_for_codec(esco_codec_t codec,bool offload)361 enh_esco_params_t esco_parameters_for_codec(esco_codec_t codec, bool offload) {
362   log::assert_that((int)codec >= 0, "codec index {}< 0", (int)codec);
363   log::assert_that(codec < ESCO_NUM_CODECS, "codec index {} > {}", (int)codec, ESCO_NUM_CODECS);
364 
365   std::vector<uint8_t> codecIds;
366 
367   auto controller = bluetooth::shim::GetController();
368   if (controller == nullptr) {
369     log::warn("controller is null");
370   } else if (offload) {
371     codecIds = controller->GetLocalSupportedBrEdrCodecIds();
372     if (std::find(codecIds.begin(), codecIds.end(), ESCO_CODING_FORMAT_LC3) == codecIds.end()) {
373       if (codec == ESCO_CODEC_LC3_T1 || codec == ESCO_CODEC_LC3_T2) {
374         log::info("BT controller does not support LC3 codec, use DSP codec");
375         enh_esco_params_t param = default_esco_parameters[codec];
376         param.input_coding_format.coding_format = ESCO_CODING_FORMAT_LC3;
377         param.output_coding_format.coding_format = ESCO_CODING_FORMAT_LC3;
378         param.input_bandwidth = TXRX_64KBITS_RATE;
379         param.output_bandwidth = TXRX_64KBITS_RATE;
380         return param;
381       }
382     }
383   }
384 
385   if (offload) {
386     if (codec == ESCO_CODEC_SWB_Q0 || codec == ESCO_CODEC_SWB_Q1 || codec == ESCO_CODEC_SWB_Q2 ||
387         codec == ESCO_CODEC_SWB_Q3) {
388       return default_esco_parameters[ESCO_CODEC_SWB_Q0];
389     }
390     return default_esco_parameters[codec];
391   }
392 
393   log::assert_that(codec < ESCO_LEGACY_NUM_CODECS, "legacy codec index {} > {}", (int)codec,
394                    ESCO_LEGACY_NUM_CODECS);
395   enh_esco_params_t param = default_esco_parameters[codec];
396   param.input_data_path = param.output_data_path = ESCO_DATA_PATH_HCI;
397 
398   if (codec >= ESCO_CODEC_MSBC_T1) {
399     param.transmit_coding_format.coding_format = ESCO_CODING_FORMAT_TRANSPNT;
400     param.receive_coding_format.coding_format = ESCO_CODING_FORMAT_TRANSPNT;
401     param.input_coding_format.coding_format = ESCO_CODING_FORMAT_TRANSPNT;
402     param.output_coding_format.coding_format = ESCO_CODING_FORMAT_TRANSPNT;
403     param.input_bandwidth = TXRX_64KBITS_RATE;
404     param.output_bandwidth = TXRX_64KBITS_RATE;
405   }
406 
407   if (com::android::bluetooth::flags::fix_hfp_qual_1_9()) {
408     esco_packet_types_t new_packet_types = param.packet_types;
409     if (codec == ESCO_CODEC_CVSD_S3 || codec == ESCO_CODEC_CVSD_S4 || codec == ESCO_CODEC_MSBC_T2 ||
410         codec == ESCO_CODEC_LC3_T2) {
411       new_packet_types = (ESCO_PKT_TYPES_MASK_NO_3_EV3 | ESCO_PKT_TYPES_MASK_NO_2_EV5 |
412                           ESCO_PKT_TYPES_MASK_NO_3_EV5);
413     } else if (codec == ESCO_CODEC_CVSD_S1) {
414       new_packet_types = (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 |
415                           ESCO_PKT_TYPES_MASK_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV3 |
416                           ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5);
417     }
418 
419     if (param.packet_types != new_packet_types) {
420       log::info("Applying restricted packet types for codec {}: 0x{:04x} -> 0x{:04x}", (int)codec,
421                 param.packet_types, new_packet_types);
422       param.packet_types = new_packet_types;
423     }
424   }
425 
426   return param;
427 }
428