• 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_SOURCE_INTPUT_NODE_H
17 #define HPAE_SOURCE_INTPUT_NODE_H
18 #include <memory>
19 #include "hpae_node.h"
20 #include "hpae_pcm_buffer.h"
21 #include "source/i_audio_capture_source.h"
22 #include "common/hdi_adapter_type.h"
23 #include "common/hdi_adapter_info.h"
24 #include "manager/hdi_adapter_manager.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 namespace HPAE {
29 
30 class HpaeSourceInputNode : public OutputNode<HpaePcmBuffer *> {
31 public:
32     HpaeSourceInputNode(HpaeNodeInfo &nodeInfo);
33     HpaeSourceInputNode(std::vector<HpaeNodeInfo> &nodeInfos);
34     virtual ~HpaeSourceInputNode();
35     virtual void DoProcess() override;
36     virtual bool Reset() override;
37     virtual bool ResetAll() override;
38     std::shared_ptr<HpaeNode> GetSharedInstance() final;
39 
40     OutputPort<HpaePcmBuffer*> *GetOutputPort() final;
41     OutputPort<HpaePcmBuffer*> *GetOutputPort(HpaeNodeInfo &nodeInfo, bool isDisConnect = false) final;
42     HpaeSourceBufferType GetOutputPortBufferType(HpaeNodeInfo &nodeInfo) final;
43     int32_t GetCapturerSourceInstance(const std::string &deviceClass, const std::string &deviceNetId,
44         const SourceType &sourceType, const std::string &sourceName);
45     int32_t CapturerSourceInit(IAudioSourceAttr &attr);
46     int32_t CapturerSourceDeInit();
47     int32_t CapturerSourceFlush(void);
48     int32_t CapturerSourcePause(void);
49     int32_t CapturerSourceReset(void);
50     int32_t CapturerSourceResume(void);
51     int32_t CapturerSourceStart(void);
52     int32_t CapturerSourceStop(void);
53     StreamManagerState GetSourceState(void);
54     int32_t SetSourceState(StreamManagerState sourceState);
55     int32_t WriteCapturerData(char *data, int32_t dataSize);
56     size_t GetOutputPortNum();
57     size_t GetOutputPortNum(HpaeNodeInfo &nodeInfo);
58     HpaeSourceInputNodeType GetSourceInputNodeType();
59     void SetSourceInputNodeType(HpaeSourceInputNodeType type);
60     HpaeNodeInfo& GetNodeInfoWithInfo(HpaeSourceBufferType &type);
61     void UpdateAppsUidAndSessionId(std::vector<int32_t> &appsUid, std::vector<int32_t> &sessionsId);
62     uint32_t GetCaptureId() const;
63 private:
64     int32_t GetCapturerSourceAdapter(
65         const std::string &deviceClass, const SourceType &sourceType, const std::string &info);
66     void SetBufferValid(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes);
67     void DoProcessInner(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes);
68     void DoProcessMicInner(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes);
69 
70 private:
71     std::shared_ptr<IAudioCaptureSource> audioCapturerSource_ = nullptr;
72     uint32_t captureId_ = HDI_INVALID_ID;
73     IAudioSourceAttr audioSourceAttr_;
74     std::string defaultSinkName_;
75     std::string defaultSourceName_;
76     StreamManagerState state_ = STREAM_MANAGER_NEW;
77     HpaeSourceInputNodeType sourceInputNodeType_;
78 
79     std::unordered_map<HpaeSourceBufferType, OutputPort<HpaePcmBuffer *>> outputStreamMap_; // output port
80     std::unordered_map<HpaeSourceBufferType, HpaeNodeInfo> nodeInfoMap_; // nodeInfo, portInfo
81     std::unordered_map<HpaeSourceBufferType, PcmBufferInfo> pcmBufferInfoMap_; // bufferInfo
82     std::unordered_map<HpaeSourceBufferType, HpaePcmBuffer> inputAudioBufferMap_; // output buffer
83     std::unordered_map<HpaeSourceBufferType, size_t> frameByteSizeMap_;
84     std::unordered_map<HpaeSourceBufferType, std::vector<char>> historyDataMap_;
85     std::unordered_map<HpaeSourceBufferType, size_t> historyRemainSizeMap_;
86     std::unordered_map<HpaeSourceBufferType, std::vector<char>> capturerFrameDataMap_; // input buffer
87     std::unordered_map<HpaeSourceBufferType, FrameDesc> fdescMap_; // CaptureframeWithEc argument struct
88 };
89 }  // namespace HPAE
90 }  // namespace AudioStandard
91 }  // namespace OHOS
92 #endif