• 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 #ifndef HPAE_AUDIOFORMAT_CONVERTER_H
16 #define HPAE_AUDIOFORMAT_CONVERTER_H
17 #include "audio_stream_info.h"
18 #include "hpae_plugin_node.h"
19 #include "channel_converter.h"
20 #include "audio_proresampler.h"
21 #ifdef ENABLE_HOOK_PCM
22     #include "hpae_pcm_dumper.h"
23 #endif
24 namespace OHOS {
25 namespace AudioStandard {
26 namespace HPAE {
27 class HpaeAudioFormatConverterNode : public HpaePluginNode {
28 public:
29     HpaeAudioFormatConverterNode(HpaeNodeInfo preNodeInfo, HpaeNodeInfo nodeInfo);
30     virtual ~HpaeAudioFormatConverterNode();
31     void RegisterCallback(INodeFormatInfoCallback *callback);
32     void ConnectWithInfo(const std::shared_ptr<OutputNode<HpaePcmBuffer*>> &preNode, HpaeNodeInfo &nodeInfo) override;
33     void DisConnectWithInfo(const std::shared_ptr<OutputNode<HpaePcmBuffer*>> &preNode,
34         HpaeNodeInfo &nodeInfo) override;
35 protected:
36     HpaePcmBuffer* SignalProcess(const std::vector<HpaePcmBuffer*>& inputs) override;
37 private:
38     bool CheckUpdateInInfo(HpaePcmBuffer *input);
39     bool CheckUpdateOutInfo();
40     int32_t ConverterProcess(float *srcData, float *dstData, float *tmpData, HpaePcmBuffer *input);
41     void CheckAndUpdateInfo(HpaePcmBuffer *input);
42     void UpdateTmpOutPcmBufferInfo(const PcmBufferInfo &outPcmBufferInfo);
43     PcmBufferInfo pcmBufferInfo_;
44     HpaePcmBuffer converterOutput_;
45     HpaeNodeInfo preNodeInfo_;
46     std::unique_ptr<Resampler> resampler_ = nullptr;
47     ChannelConverter channelConverter_;
48     HpaePcmBuffer tmpOutBuf_; // cache between resample and converter
49     // if there is render effect, the effect node decides the output format of converter node
50     INodeFormatInfoCallback *nodeFormatInfoCallback_ = nullptr;
51 #ifdef ENABLE_HOOK_PCM
52     std::unique_ptr<HpaePcmDumper> outputPcmDumper_ = nullptr;
53 #endif
54 };
55 
56 } // HPAE
57 } // AudioStandard
58 } // OHOS
59 #endif
60