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 ARK_AUDIO_CODEC_DECODER_ADAPTER_H 17 #define ARK_AUDIO_CODEC_DECODER_ADAPTER_H 18 #pragma once 19 20 #include "base/include/ark_web_base_ref_counted.h" 21 #include "base/include/ark_web_types.h" 22 #include "ohos_adapter/include/ark_audio_cenc_info_adapter.h" 23 24 namespace OHOS::ArkWeb { 25 26 /*--ark web(source=webcore)--*/ 27 class ArkAudioDecoderFormatAdapter : public virtual ArkWebBaseRefCounted { 28 public: 29 /*--ark web()--*/ 30 virtual int32_t GetSampleRate() = 0; 31 32 /*--ark web()--*/ 33 virtual int32_t GetChannelCount() = 0; 34 35 /*--ark web()--*/ 36 virtual int64_t GetBitRate() = 0; 37 38 /*--ark web()--*/ 39 virtual int32_t GetMaxInputSize() = 0; 40 41 /*--ark web()--*/ 42 virtual bool GetAACIsAdts() = 0; 43 44 /*--ark web()--*/ 45 virtual int32_t GetAudioSampleFormat() = 0; 46 47 /*--ark web()--*/ 48 virtual int32_t GetIdentificationHeader() = 0; 49 50 /*--ark web()--*/ 51 virtual int32_t GetSetupHeader() = 0; 52 53 /*--ark web()--*/ 54 virtual uint8_t* GetCodecConfig() = 0; 55 56 /*--ark web()--*/ 57 virtual uint32_t GetCodecConfigSize() = 0; 58 59 /*--ark web()--*/ 60 virtual void SetSampleRate(int32_t sampleRate) = 0; 61 62 /*--ark web()--*/ 63 virtual void SetChannelCount(int32_t channelCount) = 0; 64 65 /*--ark web()--*/ 66 virtual void SetBitRate(int64_t bitRate) = 0; 67 68 /*--ark web()--*/ 69 virtual void SetMaxInputSize(int32_t maxInputSize) = 0; 70 71 /*--ark web()--*/ 72 virtual void SetAACIsAdts(bool isAdts) = 0; 73 74 /*--ark web()--*/ 75 virtual void SetAudioSampleFormat(int32_t audioSampleFormat) = 0; 76 77 /*--ark web()--*/ 78 virtual void SetIdentificationHeader(int32_t data) = 0; 79 80 /*--ark web()--*/ 81 virtual void SetSetupHeader(int32_t data) = 0; 82 83 /*--ark web()--*/ 84 virtual void SetCodecConfig(uint8_t* codecConfig) = 0; 85 86 /*--ark web()--*/ 87 virtual void SetCodecConfigSize(uint32_t size) = 0; 88 }; 89 90 /*--ark web(source=webcore)--*/ 91 class ArkAudioDecoderCallbackAdapter : public virtual ArkWebBaseRefCounted { 92 public: 93 /*--ark web()--*/ 94 virtual void OnError(int32_t errorCode) = 0; 95 96 /*--ark web()--*/ 97 virtual void OnOutputFormatChanged() = 0; 98 99 /*--ark web()--*/ 100 virtual void OnInputBufferAvailable(uint32_t index) = 0; 101 102 /*--ark web()--*/ 103 virtual void OnOutputBufferAvailable( 104 uint32_t index, uint8_t *bufferData, int32_t size, int64_t pts, int32_t offset, uint32_t flags) = 0; 105 }; 106 107 /*--ark web(source=webview)--*/ 108 class ArkAudioCodecDecoderAdapter : public virtual ArkWebBaseRefCounted { 109 public: 110 /*--ark web()--*/ 111 virtual int32_t CreateAudioDecoderByMime(const ArkWebString& mimetype) = 0; 112 113 /*--ark web()--*/ 114 virtual int32_t CreateAudioDecoderByName(const ArkWebString& name) = 0; 115 116 /*--ark web()--*/ 117 virtual int32_t ConfigureDecoder(const ArkWebRefPtr<ArkAudioDecoderFormatAdapter> format) = 0; 118 119 /*--ark web()--*/ 120 virtual int32_t SetParameterDecoder(const ArkWebRefPtr<ArkAudioDecoderFormatAdapter> format) = 0; 121 122 /*--ark web()--*/ 123 virtual int32_t PrepareDecoder() = 0; 124 125 /*--ark web()--*/ 126 virtual int32_t StartDecoder() = 0; 127 128 /*--ark web()--*/ 129 virtual int32_t StopDecoder() = 0; 130 131 /*--ark web()--*/ 132 virtual int32_t FlushDecoder() = 0; 133 134 /*--ark web()--*/ 135 virtual int32_t ResetDecoder() = 0; 136 137 /*--ark web()--*/ 138 virtual int32_t ReleaseDecoder() = 0; 139 140 /*--ark web()--*/ 141 virtual int32_t QueueInputBufferDec(uint32_t index, int64_t presentationTimeUs, uint8_t *bufferData, 142 int32_t bufferSize, const ArkWebRefPtr<ArkAudioCencInfoAdapter> cencInfo, 143 bool isEncrypted, uint32_t flag) = 0; 144 145 /*--ark web()--*/ 146 virtual int32_t GetOutputFormatDec(ArkWebRefPtr<ArkAudioDecoderFormatAdapter> format) = 0; 147 148 /*--ark web()--*/ 149 virtual int32_t ReleaseOutputBufferDec(uint32_t index) = 0; 150 151 /*--ark web()--*/ 152 virtual int32_t SetCallbackDec(const ArkWebRefPtr<ArkAudioDecoderCallbackAdapter> callback) = 0; 153 154 /*--ark web()--*/ 155 virtual int32_t SetDecryptionConfig(void *session, bool secureAudio) = 0; 156 }; 157 158 } // namespace OHOS::ArkWeb 159 160 #endif // ARK_AUDIO_CODEC_DECODER_ADAPTER_H 161