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