1 /* 2 * Copyright (c) 2024 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 OFFLINE_AUDIO_EFFECT_SERVER_CHAIN_H 17 #define OFFLINE_AUDIO_EFFECT_SERVER_CHAIN_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 #include <mutex> 24 25 #include "v1_0/effect_types.h" 26 #include "v1_0/ieffect_control.h" 27 #include "v1_0/ieffect_model.h" 28 29 #include "audio_device_info.h" 30 #include "audio_stream_info.h" 31 #include "audio_source_type.h" 32 #include "audio_shared_memory.h" 33 #include "oh_audio_buffer.h" 34 35 namespace OHOS { 36 namespace AudioStandard { 37 using namespace std; 38 39 struct OfflineEffectConfig { 40 uint32_t samplingRate; 41 uint32_t channels; 42 uint32_t format; 43 }; 44 45 struct OfflineEffectIOConfig { 46 OfflineEffectConfig inputCfg; 47 OfflineEffectConfig outputCfg; 48 }; 49 50 class OfflineAudioEffectServerChain { 51 public: 52 OfflineAudioEffectServerChain(const string &chainName); 53 ~OfflineAudioEffectServerChain(); 54 55 static int32_t GetOfflineAudioEffectChains(vector<string> &chainNamesVector); 56 57 int32_t Create(); 58 int32_t SetParam(AudioStreamInfo inInfo, AudioStreamInfo outInfo); 59 int32_t GetEffectBufferSize(uint32_t &inBufferSize, uint32_t &outBufferSize); 60 int32_t Prepare(const shared_ptr<AudioSharedMemory> &bufferIn, const shared_ptr<AudioSharedMemory> &bufferOut); 61 int32_t Process(uint32_t inBufferSize, uint32_t outBufferSize); 62 int32_t Release(); 63 64 private: 65 void InitDump(); 66 67 struct IEffectControl *controller_ = nullptr; 68 struct ControllerId controllerId_ = {}; 69 shared_ptr<AudioSharedMemory> serverBufferIn_ = nullptr; 70 shared_ptr<AudioSharedMemory> serverBufferOut_ = nullptr; 71 uint32_t inBufferSize_ = 0; 72 uint32_t outBufferSize_ = 0; 73 string chainName_; 74 mutex offlineChainMutex_; 75 OfflineEffectIOConfig offlineConfig_ = {}; 76 FILE *dumpFileIn_ = nullptr; 77 FILE *dumpFileOut_ = nullptr; 78 }; 79 } // namespace AudioStandard 80 } // namespace OHOS 81 #endif // OFFLINE_AUDIO_EFFECT_SERVER_CHAIN_H 82