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 AUDIO_WRAPPER_H 17 #define AUDIO_WRAPPER_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <mutex> 22 #include <unordered_map> 23 24 #include "coder_wrapper.h" 25 #include "single_instance.h" 26 27 namespace OHOS { 28 namespace AI { 29 class AudioWrapper { 30 DECLARE_SINGLE_INSTANCE(AudioWrapper); 31 32 public: 33 /* Initializes audio wrapper to convert AAC to PCM. */ 34 int32_t Init(ConvertType typeId, intptr_t &handler); 35 36 /* Sets coder mode, indicate whether to CodecInit. */ 37 void SetCodecMode(bool needCodec); 38 39 /* Sets configuration of specific coder. */ 40 int32_t SetConfig(intptr_t handler, const CoderConfig &config); 41 42 /* Starts specific coder. */ 43 int32_t StartCodec(intptr_t handler); 44 45 /* Convert CoderStream from source to converted. */ 46 int32_t Convert(intptr_t handler, const CoderStream &source, CoderStream &converted); 47 48 /* Deinits specific coder. */ 49 int32_t Deinit(intptr_t handler); 50 51 /* Clears all coders. */ 52 void Release(); 53 54 private: 55 void InitAudioDecoder(intptr_t &handler); 56 57 private: 58 std::mutex mutex_; 59 std::unordered_map<intptr_t, CoderWrapper *> coders_; 60 bool hasInitCodec_ = false; 61 bool needCodec_ = true; 62 }; 63 } // namespace AI 64 } // namespace OHOS 65 #endif // AUDIO_WRAPPER_H