• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 HPAE_CAPTURE_EFFECT_NODE_H
17 #define HPAE_CAPTURE_EFFECT_NODE_H
18 #include <string>
19 #include "hpae_plugin_node.h"
20 #include "hpae_node.h"
21 #include "audio_effect.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 namespace HPAE {
26 
27 constexpr uint32_t SCENE_TYPE_OFFSET = 32;
28 constexpr uint32_t CAPTURER_ID_OFFSET = 16;
29 constexpr uint32_t BITLENGTH = 8;
30 constexpr uint32_t FRAME_LEN = 20;
31 
32 struct CaptureEffectAttr {
33     uint32_t micChannels;
34     uint32_t ecChannels;
35     uint32_t micRefChannels;
36 };
37 
38 class HpaeCaptureEffectNode : public HpaePluginNode {
39 public:
40     HpaeCaptureEffectNode(HpaeNodeInfo &nodeInfo);
41     virtual ~HpaeCaptureEffectNode();
42     virtual bool Reset() override;
43     void ConnectWithInfo(const std::shared_ptr<OutputNode<HpaePcmBuffer*>> &preNode, HpaeNodeInfo &nodeInfo) override;
44     void DisConnectWithInfo(const std::shared_ptr<OutputNode<HpaePcmBuffer*>> &preNode,
45         HpaeNodeInfo &nodeInfo) override;
46     bool GetCapturerEffectConfig(HpaeNodeInfo& nodeInfo, HpaeSourceBufferType type = HPAE_SOURCE_BUFFER_TYPE_MIC);
47     int32_t CaptureEffectCreate(uint64_t sceneKeyCode, CaptureEffectAttr attr);
48     int32_t CaptureEffectRelease(uint64_t sceneKeyCode);
49 protected:
50     HpaePcmBuffer *SignalProcess(const std::vector<HpaePcmBuffer*> &inputs) override;
51 private:
52     void SetCapturerEffectConfig(AudioBufferConfig micConfig, AudioBufferConfig ecConfig,
53         AudioBufferConfig micrefConfig);
54 
55     uint64_t sceneKeyCode_ = 0;
56     std::string sceneType_ = "";
57     uint32_t micBufferLength_ = 0;
58     uint32_t ecBufferLength_ = 0;
59     uint32_t micrefBufferLength_ = 0;
60     std::vector<uint8_t> ecCache_;
61     std::vector<uint8_t> micCache_;
62     std::vector<uint8_t> micRefCache_;
63     std::vector<uint8_t> cacheDataOut_;
64     std::unique_ptr<HpaePcmBuffer> outPcmBuffer_ { nullptr };
65     std::unordered_map<HpaeSourceBufferType, HpaeNodeInfo> capturerEffectConfigMap_;
66 };
67 }  // namespace HPAE
68 }  // namespace AudioStandard
69 }  // namespace OHOS
70 #endif // HPAE_CAPTURE_EFFECT_NODE_H