• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class AudioRendererOptionsAdapter {
78 public:
79     AudioRendererOptionsAdapter() = default;
80 
81     virtual ~AudioRendererOptionsAdapter() = default;
82 
83     virtual AudioAdapterSamplingRate GetSamplingRate() = 0;
84 
85     virtual AudioAdapterEncodingType GetEncodingType() = 0;
86 
87     virtual AudioAdapterSampleFormat GetSampleFormat() = 0;
88 
89     virtual AudioAdapterChannel GetChannel() = 0;
90 
91     virtual AudioAdapterContentType GetContentType() = 0;
92 
93     virtual AudioAdapterStreamUsage GetStreamUsage() = 0;
94 
95     virtual int32_t GetRenderFlags() = 0;
96 };
97 
98 enum AudioAdapterCode : int32_t {
99     AUDIO_OK = 0,
100     AUDIO_ERROR = -1,
101     AUDIO_NULL_ERROR = -2,
102 };
103 
104 class AudioRendererCallbackAdapter {
105 public:
106     AudioRendererCallbackAdapter() = default;
107 
108     virtual ~AudioRendererCallbackAdapter() = default;
109 
110     virtual void OnSuspend() = 0;
111 
112     virtual void OnResume() = 0;
113 };
114 
115 enum class AudioAdapterDeviceChangeReason : int32_t {
116     UNKNOWN = 0,
117     NEW_DEVICE_AVAILABLE = 1,
118     OLD_DEVICE_UNAVALIABLE = 2,
119     OVERRODE = 3
120 };
121 
122 class AudioOutputChangeCallbackAdapter {
123 public:
124     AudioOutputChangeCallbackAdapter() = default;
125 
126     virtual ~AudioOutputChangeCallbackAdapter() = default;
127 
OnOutputDeviceChange(int32_t reason)128     virtual void OnOutputDeviceChange(int32_t reason) {}
129 };
130 
131 class AudioRendererAdapter {
132 public:
133     AudioRendererAdapter() = default;
134 
135     virtual ~AudioRendererAdapter() = default;
136 
137     virtual int32_t Create(
138         const std::shared_ptr<AudioRendererOptionsAdapter> options, std::string cachePath = std::string()) = 0;
139 
140     virtual bool Start() = 0;
141 
142     virtual bool Pause() = 0;
143 
144     virtual bool Stop() = 0;
145 
146     virtual bool Release() = 0;
147 
148     virtual int32_t Write(uint8_t* buffer, size_t bufferSize) = 0;
149 
150     virtual int32_t GetLatency(uint64_t& latency) = 0;
151 
152     virtual int32_t SetVolume(float volume) = 0;
153 
154     virtual float GetVolume() = 0;
155 
156     virtual int32_t SetAudioRendererCallback(const std::shared_ptr<AudioRendererCallbackAdapter>& callback) = 0;
157 
158     virtual void SetInterruptMode(bool audioExclusive) = 0;
159 
160     virtual bool IsRendererStateRunning() = 0;
161 
162     virtual int32_t SetAudioOutputChangeCallback(const std::shared_ptr<AudioOutputChangeCallbackAdapter>& callback) = 0;
163 
164     virtual void SetAudioSilentMode(bool isSilentMode) = 0;
165 };
166 
167 } // namespace OHOS::NWeb
168 
169 #endif // AUDIO_RENDERER_ADAPTER_H
170