• 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_COBUFFER_NODE_H
17 #define HPAE_COBUFFER_NODE_H
18 #include <memory>
19 #include <mutex>
20 #include "audio_ring_cache.h"
21 #include "high_resolution_timer.h"
22 #include "hpae_node.h"
23 #include "hpae_pcm_buffer.h"
24 
25 #ifdef ENABLE_HOOK_PCM
26 #include "hpae_pcm_dumper.h"
27 #endif
28 
29 namespace OHOS {
30 namespace AudioStandard {
31 namespace HPAE {
32 
33 enum class FrameFlag {
34     FIRST_FRAME,
35     SECOND_FRAME,
36     OTHER_FRAME,
37 };
38 class HpaeCoBufferNode : public OutputNode<HpaePcmBuffer *>, public InputNode<HpaePcmBuffer *> {
39 public:
40     HpaeCoBufferNode();
41     virtual ~HpaeCoBufferNode();
42     void DoProcess() override;
43     bool Reset() override;
44     bool ResetAll() override;
45 
46     std::shared_ptr<HpaeNode> GetSharedInstance() override;
47     OutputPort<HpaePcmBuffer*>* GetOutputPort() override;
48     void Connect(const std::shared_ptr<OutputNode<HpaePcmBuffer*>>& preNode) override;
49     void DisConnect(const std::shared_ptr<OutputNode<HpaePcmBuffer*>>& preNode) override;
50     void Enqueue(HpaePcmBuffer* buffer) override;
51     void SetLatency(uint32_t latency);
52     void SetOutputClusterConnected(bool isConnect);
53     bool IsOutputClusterConnected();
54 private:
55     void FillSilenceFramesInner(uint32_t latencyMs);
56     void ProcessInputFrameInner(HpaePcmBuffer* buffer);
57     void ProcessOutputFrameInner();
58     std::mutex mutex_;
59     bool enqueueRunning_ = false;
60     InputPort<HpaePcmBuffer *> inputStream_;
61     OutputPort<HpaePcmBuffer *> outputStream_;
62     PcmBufferInfo pcmBufferInfo_;
63     HpaePcmBuffer coBufferOut_;
64     HpaePcmBuffer silenceData_;
65     std::unique_ptr<AudioRingCache> ringCache_ = nullptr;
66     int32_t enqueueCount_ = 1;
67     uint64_t latency_  = 0; // in ms
68     bool isOutputClusterConnected_ = false;
69     std::set<HpaeProcessorType> connectedProcessCluster_;
70 #ifdef ENABLE_HOOK_PCM
71     std::unique_ptr<HpaePcmDumper> inputPcmDumper_;
72     std::unique_ptr<HpaePcmDumper> outputPcmDumper_;
73 #endif
74 };
75 }  // namespace HPAE
76 }  // namespace AudioStandard
77 }  // namespace OHOS
78 #endif