• 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 AUDIO_CODEC_DECODER_ADAPTER_H
17 #define AUDIO_CODEC_DECODER_ADAPTER_H
18 
19 #include <vector>
20 #include <memory>
21 #include <cstdint>
22 #include <string>
23 #include "media_codec_adapter.h"
24 #include "audio_cenc_info_adapter.h"
25 
26 namespace OHOS::NWeb {
27 
28 enum class AudioDecoderAdapterCode : int32_t {
29     DECODER_OK = 0,
30     DECODER_ERROR = 1,
31     DECODER_RETRY = 2
32 };
33 
34 class AudioDecoderFormatAdapter {
35 public:
36     AudioDecoderFormatAdapter() = default;
37 
38     virtual ~AudioDecoderFormatAdapter() = default;
39 
40     virtual int32_t GetSampleRate() = 0;
41 
42     virtual int32_t GetChannelCount() = 0;
43 
44     virtual int64_t GetBitRate() = 0;
45 
46     virtual int32_t GetMaxInputSize() = 0;
47 
48     virtual bool GetAACIsAdts() = 0;
49 
50     virtual int32_t GetAudioSampleFormat() = 0;
51 
52     virtual int32_t GetIdentificationHeader() = 0;
53 
54     virtual int32_t GetSetupHeader() = 0;
55 
56     virtual uint8_t* GetCodecConfig() = 0;
57 
58     virtual uint32_t GetCodecConfigSize() = 0;
59 
60     virtual void SetSampleRate(int32_t sampleRate) = 0;
61 
62     virtual void SetChannelCount(int32_t channelCount) = 0;
63 
64     virtual void SetBitRate(int64_t bitRate) = 0;
65 
66     virtual void SetMaxInputSize(int32_t maxInputSize) = 0;
67 
68     virtual void SetAACIsAdts(bool isAdts) = 0;
69 
70     virtual void SetAudioSampleFormat(int32_t audioSampleFormat) = 0;
71 
72     virtual void SetIdentificationHeader(int32_t idHeader) = 0;
73 
74     virtual void SetSetupHeader(int32_t setupHeader) = 0;
75 
76     virtual void SetCodecConfig(uint8_t* codecConfig) = 0;
77 
78     virtual void SetCodecConfigSize(uint32_t size) = 0;
79 };
80 
81 class AudioDecoderCallbackAdapter {
82 public:
83     AudioDecoderCallbackAdapter() = default;
84 
85     virtual ~AudioDecoderCallbackAdapter() = default;
86 
87     virtual void OnError(int32_t errorCode) = 0;
88 
89     virtual void OnOutputFormatChanged() = 0;
90 
91     virtual void OnInputBufferAvailable(uint32_t index) = 0;
92 
93     virtual void OnOutputBufferAvailable(
94         uint32_t index, uint8_t *bufferData, int32_t size, int64_t pts, int32_t offset, uint32_t flags) = 0;
95 };
96 
97 class AudioCodecDecoderAdapter {
98 public:
99     AudioCodecDecoderAdapter() = default;
100 
101     virtual ~AudioCodecDecoderAdapter() = default;
102 
103     virtual AudioDecoderAdapterCode CreateAudioDecoderByMime(const std::string& mimetype) = 0;
104 
105     virtual AudioDecoderAdapterCode CreateAudioDecoderByName(const std::string& name) = 0;
106 
107     virtual AudioDecoderAdapterCode ConfigureDecoder(const std::shared_ptr<AudioDecoderFormatAdapter> format) = 0;
108 
109     virtual AudioDecoderAdapterCode SetParameterDecoder(const std::shared_ptr<AudioDecoderFormatAdapter> format) = 0;
110 
111     virtual AudioDecoderAdapterCode PrepareDecoder() = 0;
112 
113     virtual AudioDecoderAdapterCode StartDecoder() = 0;
114 
115     virtual AudioDecoderAdapterCode StopDecoder() = 0;
116 
117     virtual AudioDecoderAdapterCode FlushDecoder() = 0;
118 
119     virtual AudioDecoderAdapterCode ResetDecoder() = 0;
120 
121     virtual AudioDecoderAdapterCode ReleaseDecoder() = 0;
122 
123     virtual AudioDecoderAdapterCode QueueInputBufferDec(uint32_t index, int64_t presentationTimeUs, uint8_t *bufferData,
124         int32_t bufferSize, std::shared_ptr<AudioCencInfoAdapter> cencInfo, bool isEncrypted, BufferFlag flag) = 0;
125 
126     virtual AudioDecoderAdapterCode GetOutputFormatDec(std::shared_ptr<AudioDecoderFormatAdapter> format) = 0;
127 
128     virtual AudioDecoderAdapterCode ReleaseOutputBufferDec(uint32_t index) = 0;
129 
130     virtual AudioDecoderAdapterCode SetCallbackDec(const std::shared_ptr<AudioDecoderCallbackAdapter> callback) = 0;
131 
132     virtual AudioDecoderAdapterCode SetDecryptionConfig(void *session, bool secureAudio) = 0;
133 };
134 
135 } // namespace OHOS::NWeb
136 
137 #endif // AUDIO_CODEC_DECODER_ADAPTER_H
138