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_HFP_LC3_MMC_ENCODER_H_
18 #define MMC_CODEC_SERVER_HFP_LC3_MMC_ENCODER_H_
19 
20 #include <lc3.h>
21 
22 #include "mmc/mmc_interface/mmc_interface.h"
23 #include "mmc/proto/mmc_config.pb.h"
24 
25 namespace mmc {
26 
27 // Implementation of MmcInterface.
28 // HfpLc3Encoder wraps lc3 encode libraries.
29 class HfpLc3Encoder : public MmcInterface {
30  public:
31   explicit HfpLc3Encoder();
32   ~HfpLc3Encoder();
33 
34   // HfpLc3Encoder is neither copyable nor movable.
35   HfpLc3Encoder(const HfpLc3Encoder&) = delete;
36   HfpLc3Encoder& operator=(const HfpLc3Encoder&) = delete;
37 
38   // Inits encoder instance.
39   //
40   // Returns:
41   //   Input pcm frame size accepted by the encoder, if init succeeded.
42   //   Negative errno on error, otherwise.
43   int init(ConfigParam config) override;
44 
45   // Releases encoder instance.
46   void cleanup() override;
47 
48   // Encodes data from |i_buf|, and stores the result to |o_buf|.
49   //
50   // Returns:
51   //   Encoded data length, if encode succeeded.
52   //   Negative errno on error, otherwise.
53   int transcode(uint8_t* i_buf, int i_len, uint8_t* o_buf, int o_len) override;
54 
55  private:
56   void* hfp_lc3_encoder_mem_;
57   lc3_encoder_t hfp_lc3_encoder_;
58   Lc3Param param_;
59 };
60 
61 }  // namespace mmc
62 
63 #endif  // MMC_CODEC_SERVER_HFP_LC3_MMC_ENCODER_H_
64