1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "btm_sco_def.h"
17 
18 #include <stddef.h>
19 
20 #include "hci/hci_def.h"
21 
22 #define CODEC_FRAME_SIZE 60
23 
24 #define CODED_DATA_SIZE 16
25 
26 #define ESCO_PARAMETERS_TABLE_SIZE 3
27 
28 static BtmEscoParameters g_escoParametersTable[ESCO_PARAMETERS_TABLE_SIZE] = {
29     // CVSD
30     {
31         .transmitCodingFormat =
32             {
33                 .codingFormat = HCI_CODING_FORMAT_CVSD,
34                 .companyID = 0x0000,
35                 .vendorSpecificCodecID = 0x0000,
36             },
37         .receiveCodingFormat =
38             {
39                 .codingFormat = HCI_CODING_FORMAT_CVSD,
40                 .companyID = 0x0000,
41                 .vendorSpecificCodecID = 0x0000,
42             },
43         .transmitCodecFrameSize = CODEC_FRAME_SIZE,
44         .receiveCodecFrameSize = CODEC_FRAME_SIZE,
45         .inputBandwidth = INPUT_OUTPUT_64K_RATE,
46         .outputBandwidth = INPUT_OUTPUT_64K_RATE,
47         .inputCodingFormat =
48             {
49                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
50                 .companyID = 0x0000,
51                 .vendorSpecificCodecID = 0x0000,
52             },
53         .outputCodingFormat =
54             {
55                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
56                 .companyID = 0x0000,
57                 .vendorSpecificCodecID = 0x0000,
58             },
59         .inputCodedDataSize = CODED_DATA_SIZE,
60         .outputCodedDataSize = CODED_DATA_SIZE,
61         .inputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
62         .outputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
63         .inputPCMSamplePayloadMSBPosition = 0,
64         .outputPCMSamplePayloadMSBPosition = 0,
65         .inputDataPath = ESCO_DATA_PATH_PCM,
66         .outputDataPath = ESCO_DATA_PATH_PCM,
67         .inputTransportUnitSize = 0x00,
68         .outputTransportUnitSize = 0x00,
69     },
70     // MSBC T1
71     {
72         .transmitCodingFormat =
73             {
74                 .codingFormat = HCI_CODING_FORMAT_MSBC,
75                 .companyID = 0x0000,
76                 .vendorSpecificCodecID = 0x0000,
77             },
78         .receiveCodingFormat =
79             {
80                 .codingFormat = HCI_CODING_FORMAT_MSBC,
81                 .companyID = 0x0000,
82                 .vendorSpecificCodecID = 0x0000,
83             },
84         .transmitCodecFrameSize = CODEC_FRAME_SIZE,
85         .receiveCodecFrameSize = CODEC_FRAME_SIZE,
86         .inputBandwidth = INPUT_OUTPUT_128K_RATE,
87         .outputBandwidth = INPUT_OUTPUT_128K_RATE,
88         .inputCodingFormat =
89             {
90                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
91                 .companyID = 0x0000,
92                 .vendorSpecificCodecID = 0x0000,
93             },
94         .outputCodingFormat =
95             {
96                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
97                 .companyID = 0x0000,
98                 .vendorSpecificCodecID = 0x0000,
99             },
100         .inputCodedDataSize = CODED_DATA_SIZE,
101         .outputCodedDataSize = CODED_DATA_SIZE,
102         .inputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
103         .outputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
104         .inputPCMSamplePayloadMSBPosition = 0,
105         .outputPCMSamplePayloadMSBPosition = 0,
106         .inputDataPath = ESCO_DATA_PATH_PCM,
107         .outputDataPath = ESCO_DATA_PATH_PCM,
108         .inputTransportUnitSize = 0x00,
109         .outputTransportUnitSize = 0x00,
110     },
111     // MSBC T2
112     {
113         .transmitCodingFormat =
114             {
115                 .codingFormat = HCI_CODING_FORMAT_MSBC,
116                 .companyID = 0x0000,
117                 .vendorSpecificCodecID = 0x0000,
118             },
119         .receiveCodingFormat =
120             {
121                 .codingFormat = HCI_CODING_FORMAT_MSBC,
122                 .companyID = 0x0000,
123                 .vendorSpecificCodecID = 0x0000,
124             },
125         .transmitCodecFrameSize = CODEC_FRAME_SIZE,
126         .receiveCodecFrameSize = CODEC_FRAME_SIZE,
127         .inputBandwidth = INPUT_OUTPUT_128K_RATE,
128         .outputBandwidth = INPUT_OUTPUT_128K_RATE,
129         .inputCodingFormat =
130             {
131                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
132                 .companyID = 0x0000,
133                 .vendorSpecificCodecID = 0x0000,
134             },
135         .outputCodingFormat =
136             {
137                 .codingFormat = HCI_CODING_FORMAT_LINEAR_PCM,
138                 .companyID = 0x0000,
139                 .vendorSpecificCodecID = 0x0000,
140             },
141         .inputCodedDataSize = CODED_DATA_SIZE,
142         .outputCodedDataSize = CODED_DATA_SIZE,
143         .inputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
144         .outputPCMDataFormat = HCI_PCM_DATA_FORMAT_2_COMPLEMENT,
145         .inputPCMSamplePayloadMSBPosition = 0,
146         .outputPCMSamplePayloadMSBPosition = 0,
147         .inputDataPath = ESCO_DATA_PATH_PCM,
148         .outputDataPath = ESCO_DATA_PATH_PCM,
149         .inputTransportUnitSize = 0x00,
150         .outputTransportUnitSize = 0x00,
151     },
152 };
153 
BtmGetEscoParameters(uint8_t codec)154 const BtmEscoParameters *BtmGetEscoParameters(uint8_t codec)
155 {
156     BtmEscoParameters *parameters = NULL;
157     if (codec < ESCO_PARAMETERS_TABLE_SIZE) {
158         parameters = g_escoParametersTable + codec;
159     }
160     return parameters;
161 }