1 /* 2 * Copyright (c) 2022 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_RENDERER_ADAPTER_H 17 #define AUDIO_RENDERER_ADAPTER_H 18 19 #include <memory> 20 #include <string> 21 22 namespace OHOS::NWeb { 23 24 enum class AudioAdapterSampleFormat : int32_t { 25 SAMPLE_U8 = 0, 26 SAMPLE_S16LE = 1, 27 SAMPLE_S24LE = 2, 28 SAMPLE_S32LE = 3, 29 SAMPLE_F32LE = 4, 30 INVALID_WIDTH = -1 31 }; 32 33 enum class AudioAdapterSamplingRate : int32_t { 34 SAMPLE_RATE_8000 = 8000, 35 SAMPLE_RATE_11025 = 11025, 36 SAMPLE_RATE_12000 = 12000, 37 SAMPLE_RATE_16000 = 16000, 38 SAMPLE_RATE_22050 = 22050, 39 SAMPLE_RATE_24000 = 24000, 40 SAMPLE_RATE_32000 = 32000, 41 SAMPLE_RATE_44100 = 44100, 42 SAMPLE_RATE_48000 = 48000, 43 SAMPLE_RATE_64000 = 64000, 44 SAMPLE_RATE_96000 = 96000 45 }; 46 47 enum class AudioAdapterChannel : int32_t { 48 MONO = 1, 49 STEREO = 2, 50 CHANNEL_3 = 3, 51 CHANNEL_4 = 4, 52 CHANNEL_5 = 5, 53 CHANNEL_6 = 6, 54 CHANNEL_7 = 7, 55 CHANNEL_8 = 8 56 }; 57 58 enum class AudioAdapterEncodingType : int32_t { ENCODING_PCM = 0, ENCODING_INVALID = -1 }; 59 60 enum class AudioAdapterContentType : int32_t { 61 CONTENT_TYPE_UNKNOWN = 0, 62 CONTENT_TYPE_SPEECH = 1, 63 CONTENT_TYPE_MUSIC = 2, 64 CONTENT_TYPE_MOVIE = 3, 65 CONTENT_TYPE_SONIFICATION = 4, 66 CONTENT_TYPE_RINGTONE = 5 67 }; 68 69 enum class AudioAdapterStreamUsage : int32_t { 70 STREAM_USAGE_UNKNOWN = 0, 71 STREAM_USAGE_MEDIA = 1, 72 STREAM_USAGE_VOICE_COMMUNICATION = 2, 73 STREAM_USAGE_VOICE_ASSISTANT = 4, 74 STREAM_USAGE_NOTIFICATION_RINGTONE = 6 75 }; 76 77 enum class AudioAdapterConcurrencyMode : int32_t { 78 INVALID = -1, 79 DEFAULT = 0, 80 MIX_WITH_OTHERS = 1, 81 DUCK_OTHERS = 2, 82 PAUSE_OTHERS = 3, 83 SLIENT = 4, 84 }; 85 86 class AudioRendererOptionsAdapter { 87 public: 88 AudioRendererOptionsAdapter() = default; 89 90 virtual ~AudioRendererOptionsAdapter() = default; 91 92 virtual AudioAdapterSamplingRate GetSamplingRate() = 0; 93 94 virtual AudioAdapterEncodingType GetEncodingType() = 0; 95 96 virtual AudioAdapterSampleFormat GetSampleFormat() = 0; 97 98 virtual AudioAdapterChannel GetChannel() = 0; 99 100 virtual AudioAdapterContentType GetContentType() = 0; 101 102 virtual AudioAdapterStreamUsage GetStreamUsage() = 0; 103 104 virtual int32_t GetRenderFlags() = 0; 105 GetConcurrencyMode()106 virtual AudioAdapterConcurrencyMode GetConcurrencyMode() { return AudioAdapterConcurrencyMode::INVALID; } 107 }; 108 109 enum AudioAdapterCode : int32_t { 110 AUDIO_OK = 0, 111 AUDIO_ERROR = -1, 112 AUDIO_NULL_ERROR = -2, 113 }; 114 115 class AudioRendererCallbackAdapter { 116 public: 117 AudioRendererCallbackAdapter() = default; 118 119 virtual ~AudioRendererCallbackAdapter() = default; 120 121 virtual void OnSuspend() = 0; 122 123 virtual void OnResume() = 0; 124 }; 125 126 enum class AudioAdapterDeviceChangeReason : int32_t { 127 UNKNOWN = 0, 128 NEW_DEVICE_AVAILABLE = 1, 129 OLD_DEVICE_UNAVALIABLE = 2, 130 OVERRODE = 3 131 }; 132 133 class AudioOutputChangeCallbackAdapter { 134 public: 135 AudioOutputChangeCallbackAdapter() = default; 136 137 virtual ~AudioOutputChangeCallbackAdapter() = default; 138 OnOutputDeviceChange(int32_t reason)139 virtual void OnOutputDeviceChange(int32_t reason) {} 140 }; 141 142 class AudioRendererAdapter { 143 public: 144 AudioRendererAdapter() = default; 145 146 virtual ~AudioRendererAdapter() = default; 147 148 virtual int32_t Create( 149 const std::shared_ptr<AudioRendererOptionsAdapter> options, std::string cachePath = std::string()) = 0; 150 151 virtual bool Start() = 0; 152 153 virtual bool Pause() = 0; 154 155 virtual bool Stop() = 0; 156 157 virtual bool Release() = 0; 158 159 virtual int32_t Write(uint8_t* buffer, size_t bufferSize) = 0; 160 161 virtual int32_t GetLatency(uint64_t& latency) = 0; 162 163 virtual int32_t SetVolume(float volume) = 0; 164 165 virtual float GetVolume() = 0; 166 167 virtual int32_t SetAudioRendererCallback(const std::shared_ptr<AudioRendererCallbackAdapter>& callback) = 0; 168 169 virtual void SetInterruptMode(bool audioExclusive) = 0; 170 171 virtual bool IsRendererStateRunning() = 0; 172 173 virtual int32_t SetAudioOutputChangeCallback(const std::shared_ptr<AudioOutputChangeCallbackAdapter>& callback) = 0; 174 175 virtual void SetAudioSilentMode(bool isSilentMode) = 0; 176 }; 177 178 } // namespace OHOS::NWeb 179 180 #endif // AUDIO_RENDERER_ADAPTER_H 181