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 AUDIO_ENHANCE_CHAIN_H
17 #define AUDIO_ENHANCE_CHAIN_H
18 
19 #include <vector>
20 #include <mutex>
21 #include <map>
22 
23 #include "audio_effect.h"
24 #include "audio_enhance_chain_adapter.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 
29 const std::map<std::string, uint32_t> REF_CHANNEL_NUM_MAP {
30     {"SCENE_VOIP_3A", 2},
31     {"SCENE_RECORD", 0},
32 };
33 
34 struct DataDescription {
35     uint32_t frameLength_;
36     uint32_t sampleRate_;
37     uint32_t dataFormat_;
38     uint32_t micNum_;
39     uint32_t refNum_;
40     uint32_t outChannelNum_;
41 
DataDescriptionDataDescription42     DataDescription(uint32_t frameLength, uint32_t sampleRate, uint32_t dataFormat,
43         uint32_t micNum, uint32_t refNum, uint32_t outChannelNum)
44         : frameLength_(frameLength), sampleRate_(sampleRate), dataFormat_(dataFormat),
45         micNum_(micNum), refNum_(refNum), outChannelNum_(outChannelNum) {}
46 } __attribute__((packed));
47 
48 class AudioEnhanceChain {
49 public:
50     AudioEnhanceChain(const std::string &scene);
51     ~AudioEnhanceChain();
52     void SetEnhanceMode(const std::string &mode);
53     void AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle);
54     void SetHandleConfig(AudioEffectHandle handle, DataDescription desc);
55     int32_t ApplyEnhanceChain(EnhanceBufferAttr *enhanceBufferAttr);
56     bool IsEmptyEnhanceHandles();
57 
58 private:
59     void ReleaseEnhanceChain();
60 
61     bool setConfigFlag_;
62     std::mutex chainMutex_;
63     std::string sceneType_;
64     std::string enhanceMode_;
65     std::vector<AudioEffectHandle> standByEnhanceHandles_;
66     std::vector<AudioEffectLibrary*> enhanceLibHandles_;
67 };
68 
69 }  // namespace AudioStandard
70 }  // namespace OHOS
71 #endif // AUDIO_ENHANCE_CHAIN_H