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 enum class AudioAdapterSampleFormat { 24 SAMPLE_U8 = 0, 25 SAMPLE_S16LE = 1, 26 SAMPLE_S24LE = 2, 27 SAMPLE_S32LE = 3, 28 SAMPLE_F32LE = 4, 29 INVALID_WIDTH = -1 30 }; 31 32 enum class AudioAdapterSamplingRate { 33 SAMPLE_RATE_8000 = 8000, 34 SAMPLE_RATE_11025 = 11025, 35 SAMPLE_RATE_12000 = 12000, 36 SAMPLE_RATE_16000 = 16000, 37 SAMPLE_RATE_22050 = 22050, 38 SAMPLE_RATE_24000 = 24000, 39 SAMPLE_RATE_32000 = 32000, 40 SAMPLE_RATE_44100 = 44100, 41 SAMPLE_RATE_48000 = 48000, 42 SAMPLE_RATE_64000 = 64000, 43 SAMPLE_RATE_96000 = 96000 44 }; 45 46 enum class AudioAdapterChannel { 47 MONO = 1, 48 STEREO = 2, 49 CHANNEL_3 = 3, 50 CHANNEL_4 = 4, 51 CHANNEL_5 = 5, 52 CHANNEL_6 = 6, 53 CHANNEL_7 = 7, 54 CHANNEL_8 = 8 55 }; 56 57 enum class AudioAdapterEncodingType { 58 ENCODING_PCM = 0, 59 ENCODING_INVALID = -1 60 }; 61 62 enum class AudioAdapterContentType { 63 CONTENT_TYPE_UNKNOWN = 0, 64 CONTENT_TYPE_SPEECH = 1, 65 CONTENT_TYPE_MUSIC = 2, 66 CONTENT_TYPE_MOVIE = 3, 67 CONTENT_TYPE_SONIFICATION = 4, 68 CONTENT_TYPE_RINGTONE = 5 69 }; 70 71 enum class AudioAdapterStreamUsage { 72 STREAM_USAGE_UNKNOWN = 0, 73 STREAM_USAGE_MEDIA = 1, 74 STREAM_USAGE_VOICE_COMMUNICATION = 2, 75 STREAM_USAGE_VOICE_ASSISTANT = 4, 76 STREAM_USAGE_NOTIFICATION_RINGTONE = 6 77 }; 78 79 struct AudioAdapterRendererOptions { 80 AudioAdapterSamplingRate samplingRate; 81 AudioAdapterEncodingType encoding; 82 AudioAdapterSampleFormat format; 83 AudioAdapterChannel channels; 84 AudioAdapterContentType contentType; 85 AudioAdapterStreamUsage streamUsage; 86 int32_t rendererFlags; 87 }; 88 89 enum AudioAdapterCode : int32_t { 90 AUDIO_OK = 0, 91 AUDIO_ERROR = -1, 92 AUDIO_NULL_ERROR = -2, 93 }; 94 95 class AudioRendererCallbackAdapter { 96 public: 97 AudioRendererCallbackAdapter() = default; 98 99 virtual ~AudioRendererCallbackAdapter() = default; 100 101 virtual void OnSuspend() = 0; 102 103 virtual void OnResume() = 0; 104 }; 105 106 class AudioRendererAdapter { 107 public: 108 AudioRendererAdapter() = default; 109 110 virtual ~AudioRendererAdapter() = default; 111 112 virtual int32_t Create(const AudioAdapterRendererOptions &rendererOptions, 113 std::string cachePath = std::string()) = 0; 114 115 virtual bool Start() = 0; 116 117 virtual bool Pause() = 0; 118 119 virtual bool Stop() = 0; 120 121 virtual bool Release() = 0; 122 123 virtual int32_t Write(uint8_t *buffer, size_t bufferSize) = 0; 124 125 virtual int32_t GetLatency(uint64_t &latency) const = 0; 126 127 virtual int32_t SetVolume(float volume) const = 0; 128 129 virtual float GetVolume() const = 0; 130 131 virtual int32_t SetAudioRendererCallback(const std::shared_ptr<AudioRendererCallbackAdapter> &callback) = 0; 132 133 virtual void SetInterruptMode(bool audioExclusive) = 0; 134 135 virtual bool IsRendererStateRunning() = 0; 136 }; 137 } // namespace OHOS::NWeb 138 139 #endif // AUDIO_RENDERER_ADAPTER_H