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