1 /*
2  * Copyright 2023 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 #ifndef MMC_CODEC_SERVER_LC3_UTILS_H_
18 #define MMC_CODEC_SERVER_LC3_UTILS_H_
19 
20 #include <bluetooth/log.h>
21 #include <lc3.h>
22 
23 #include "mmc/proto/mmc_config.pb.h"
24 
25 namespace mmc {
26 
27 // HFP LC3 constants.
28 const int HFP_LC3_H2_HEADER_LEN = 2;
29 const int HFP_LC3_PKT_FRAME_LEN = 58;
30 const int HFP_LC3_PCM_BYTES = 480;
31 
32 // Helper that maps MMC pcm format to lc3 pcm format.
MapLc3PcmFmt(Lc3Param_PcmFmt fmt)33 inline lc3_pcm_format MapLc3PcmFmt(Lc3Param_PcmFmt fmt) {
34   switch (fmt) {
35     case Lc3Param::kLc3PcmFormatS16:
36       return LC3_PCM_FORMAT_S16;
37     case Lc3Param::kLc3PcmFormatS24:
38       return LC3_PCM_FORMAT_S24;
39     default:
40       bluetooth::log::info(
41           "No corresponding LC3 PCM format, return `LC3_PCM_FORMAT_S16`.");
42       return LC3_PCM_FORMAT_S16;
43   }
44 }
45 
46 }  // namespace mmc
47 #endif  // MMC_CODEC_SERVER_LC3_UTILS_H_
48