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 #ifndef CODER_WRAPPER_H 17 #define CODER_WRAPPER_H 18 19 #include <cstdint> 20 #include <memory> 21 22 #include "codec_interface.h" 23 #include "format.h" 24 #include "media_errors.h" 25 #include "media_info.h" 26 #include "securec.h" 27 28 namespace OHOS { 29 namespace AI { 30 const int16_t AUDIO_ENCODE_PARAM_NUM = 8; 31 const int16_t AUDIO_DECODE_PARAM_NUM = 8; 32 const int16_t AUDIO_FRAME_NUM_IN_BUF = 30; 33 const int16_t AUDIO_AUDIO_POINT_NUM = 1024; 34 const int16_t AUDIO_READ_STREAM_TIME_OUT_MS = 1000; 35 const intptr_t INVALID_HANDLER = -1; 36 37 const CodecType CODEC_PCM_TO_AAC = AUDIO_ENCODER; 38 const CodecType CODEC_AAC_TO_PCM = AUDIO_DECODER; 39 40 enum ConvertType { 41 CONVERT_AAC_TO_PCM = 1000, 42 CONVERT_PCM_TO_AAC 43 }; 44 45 struct CoderConfig { 46 uint32_t bitRate; 47 uint32_t sampleRate; 48 uint32_t channelCount; 49 AudioCodecFormat audioFormat; 50 AudioBitWidth bitWidth = BIT_WIDTH_16; 51 }; 52 53 struct CoderStream { 54 uint8_t *buffer; 55 uint32_t size; 56 }; 57 58 class CoderWrapper { 59 public: 60 CoderWrapper() = default; 61 virtual ~CoderWrapper() = default; 62 63 /* Initializes coder */ 64 virtual int32_t Initialize(const CoderConfig &input) = 0; 65 66 /* Starts coder */ 67 virtual int32_t Start() = 0; 68 69 /* Pushes source CoderStream into coder for coding */ 70 virtual int32_t PushSourceStream(const CoderStream &stream) = 0; 71 72 /* Pulls coded result CoderStream from coder */ 73 virtual int32_t PullCodedStream(CoderStream &stream) = 0; 74 75 /* Stops coder */ 76 virtual int32_t Stop() = 0; 77 78 protected: 79 virtual int32_t InitCodecAttr(const CoderConfig &input) = 0; 80 }; 81 } // namespace AI 82 } // namespace OHOS 83 #endif // CODER_WRAPPER_H