• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef NAPI_AUDIO_ENUM_H
16 #define NAPI_AUDIO_ENUM_H
17 
18 #include <map>
19 #include <string>
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "tone_player.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 const int32_t REFERENCE_CREATION_COUNT = 1;
28 
29 class NapiAudioEnum {
30 public:
31     NapiAudioEnum();
32     ~NapiAudioEnum();
33     enum AudioSampleFormatNapi {
34         SAMPLE_FORMAT_INVALID = -1,
35         SAMPLE_FORMAT_U8 = 0,
36         SAMPLE_FORMAT_S16LE = 1,
37         SAMPLE_FORMAT_S24LE = 2,
38         SAMPLE_FORMAT_S32LE = 3,
39         SAMPLE_FORMAT_F32LE = 4
40     };
41 
42     enum AudioJsVolumeType {
43         VOLUMETYPE_DEFAULT = -1,
44         VOICE_CALL = 0,
45         RINGTONE = 2,
46         MEDIA = 3,
47         ALARM = 4,
48         ACCESSIBILITY = 5,
49         SYSTEM = 6,
50         VOICE_ASSISTANT = 9,
51         ULTRASONIC = 10,
52         NOTIFICATION = 11,
53         NAVIGATION = 12,
54         VOLUMETYPE_MAX,
55         ALL = 100
56     };
57 
58     enum AudioJsStreamUsage {
59         USAGE_UNKNOW = 0,
60         USAGE_MUSIC = 1,
61         USAGE_VOICE_COMMUNICATION = 2,
62         USAGE_VOICE_ASSISTANT = 3,
63         USAGE_ALARM = 4,
64         USAGE_VOICE_MESSAGE = 5,
65         USAGE_RINGTONE = 6,
66         USAGE_NOTIFICATION = 7,
67         USAGE_ACCESSIBILITY = 8,
68         USAGE_SYSTEM = 9,
69         USAGE_MOVIE = 10,
70         USAGE_GAME = 11,
71         USAGE_AUDIOBOOK = 12,
72         USAGE_NAVIGATION = 13,
73         USAGE_DTMF = 14,
74         USAGE_ENFORCED_TONE = 15,
75         USAGE_ULTRASONIC = 16,
76         USAGE_VIDEO_COMMUNICATION = 17,
77         USAGE_VOICE_CALL_ASSISTANT = 21,
78         USAGE_MAX = 100
79     };
80 
81     enum AudioJsVolumeMode {
82         SYSTEM_GLOBAL = 0,
83         APP_INDIVIDUAL
84     };
85 
86     enum AudioRingMode {
87         RINGER_MODE_SILENT = 0,
88         RINGER_MODE_VIBRATE,
89         RINGER_MODE_NORMAL
90     };
91 
92     enum InterruptMode {
93         SHARE_MODE = 0,
94         INDEPENDENT_MODE = 1
95     };
96 
97     enum FocusType {
98         FOCUS_TYPE_RECORDING
99     };
100 
101     enum CapturerType {
102         TYPE_INVALID = -1,
103         TYPE_MIC = 0,
104         TYPE_VOICE_RECOGNITION = 1,
105         TYPE_WAKEUP = 3,
106         TYPE_VOICE_CALL = 4,
107         TYPE_PLAYBACK_CAPTURE = 2,
108         TYPE_COMMUNICATION = 7,
109         TYPE_MESSAGE = 10,
110         TYPE_REMOTE_CAST = 11,
111         TYPE_VOICE_TRANSCRIPTION = 12,
112         TYPE_CAMCORDER = 13,
113         TYPE_UNPROCESSED = 14,
114         TYPE_LIVE = 17
115     };
116 
117     enum AudioDataCallbackResult {
118         CALLBACK_RESULT_INVALID = -1,
119         CALLBACK_RESULT_VALID = 0,
120     };
121 
122     enum AudioLoopbackModeNapi {
123         LOOPBACK_MODE_HARDWARE = 0
124     };
125 
126     static napi_value Init(napi_env env, napi_value exports);
127     static bool IsLegalInputArgumentInterruptMode(int32_t interruptMode);
128     static bool IsLegalInputArgumentAudioEffectMode(int32_t audioEffectMode);
129     static bool IsLegalInputArgumentVolumeMode(int32_t volumeMode);
130     static bool IsLegalInputArgumentChannelBlendMode(int32_t blendMode);
131     static bool IsLegalCapturerType(int32_t type);
132     static bool IsLegalInputArgumentVolType(int32_t inputType);
133     static bool IsLegalInputArgumentRingMode(int32_t ringMode);
134     static bool IsLegalInputArgumentVolumeAdjustType(int32_t adjustType);
135     static bool IsLegalInputArgumentDeviceType(int32_t deviceType);
136     static bool IsLegalInputArgumentDefaultOutputDeviceType(int32_t deviceType);
137     static bool IsLegalInputArgumentDeviceFlag(int32_t deviceFlag);
138     static bool IsLegalInputArgumentActiveDeviceType(int32_t activeDeviceFlag);
139     static int32_t GetJsAudioVolumeType(AudioStreamType volumeType);
140     static int32_t GetJsStreamUsage(StreamUsage streamUsage);
141     static int32_t GetJsStreamUsageFir(StreamUsage streamUsage);
142     static int32_t GetJsAudioVolumeMode(AudioVolumeMode volumeMode);
143     static bool IsLegalInputArgumentCommunicationDeviceType(int32_t communicationDeviceType);
144     static bool IsValidSourceType(int32_t intValue);
145     static bool IsLegalDeviceUsage(int32_t usage);
146     static bool IsLegalInputArgumentStreamUsage(int32_t streamUsage);
147     static bool IsLegalOutputDeviceType(int32_t deviceType);
148     static AudioVolumeType GetNativeAudioVolumeType(int32_t volumeType);
149     static StreamUsage GetNativeStreamUsage(int32_t streamUsage);
150     static StreamUsage GetNativeStreamUsageFir(int32_t streamUsage);
151     static AudioRingerMode GetNativeAudioRingerMode(int32_t ringMode);
152     static AudioRingMode GetJsAudioRingMode(int32_t ringerMode);
153     static AudioStandard::FocusType GetNativeFocusType(int32_t focusType);
154     static AudioStandard::InterruptMode GetNativeInterruptMode(int32_t interruptMode);
155     static bool IsLegalInputArgumentSpatializationSceneType(int32_t spatializationSceneType);
156     static AudioScene GetJsAudioScene(AudioScene audioScene);
157     static bool IsLegalCapturerState(int32_t state);
158     static bool IsLegalInputArgumentAudioLoopbackMode(int32_t inputMode);
159     static bool IsLegalInputArgumentAudioLoopbackReverbPreset(int32_t preset);
160     static bool IsLegalInputArgumentAudioLoopbackEqualizerPreset(int32_t preset);
161     static bool IsLegalInputArgumentSessionScene(int32_t scene);
162 
163 private:
164     static void Destructor(napi_env env, void *nativeObject, void *finalizeHint);
165     static napi_status InitAudioEnum(napi_env env, napi_value exports);
166     static napi_status InitAudioExternEnum(napi_env env, napi_value exports);
167     static napi_value Construct(napi_env env, napi_callback_info info);
168     static NapiAudioEnum* SetValue(napi_env env, napi_callback_info info, napi_value *args, napi_value &result);
169     static NapiAudioEnum* GetValue(napi_env env, napi_callback_info info);
170     static napi_value GetAudioSampleFormat(napi_env env, napi_callback_info info);
171     static napi_value SetAudioSampleFormat(napi_env env, napi_callback_info info);
172     static napi_value GetAudioChannel(napi_env env, napi_callback_info info);
173     static napi_value SetAudioChannel(napi_env env, napi_callback_info info);
174     static napi_value GetAudioSamplingRate(napi_env env, napi_callback_info info);
175     static napi_value SetAudioSamplingRate(napi_env env, napi_callback_info info);
176     static napi_value GetAudioEncodingType(napi_env env, napi_callback_info info);
177     static napi_value SetAudioEncodingType(napi_env env, napi_callback_info info);
178     static napi_value GetContentType(napi_env env, napi_callback_info info);
179     static napi_value SetContentType(napi_env env, napi_callback_info info);
180     static napi_value GetStreamUsage(napi_env env, napi_callback_info info);
181     static napi_value SetStreamUsage(napi_env env, napi_callback_info info);
182     static napi_value GetDeviceRole(napi_env env, napi_callback_info info);
183     static napi_value SetDeviceRole(napi_env env, napi_callback_info info);
184     static napi_value GetDeviceType(napi_env env, napi_callback_info info);
185     static napi_value SetDeviceType(napi_env env, napi_callback_info info);
186     static napi_value GetVolumeMode(napi_env env, napi_callback_info info);
187     static napi_value SetVolumeMode(napi_env env, napi_callback_info info);
188 
189     static napi_value CreateEnumObject(const napi_env &env, const std::map<std::string, int32_t> &map);
190     static napi_value CreateEnumInt64Object(const napi_env &env, const std::map<std::string, uint64_t> &map);
191     static napi_value CreateLocalNetworkIdObject(napi_env env);
192     static napi_value CreateDefaultVolumeGroupIdObject(napi_env env);
193     static napi_value CreateDefaultInterruptIdObject(napi_env env);
194 
195     static napi_ref sConstructor_;
196     static napi_ref audioChannel_;
197     static napi_ref samplingRate_;
198     static napi_ref encodingType_;
199     static napi_ref contentType_;
200     static napi_ref streamUsage_;
201     static napi_ref audioVolumeMode_;
202     static napi_ref deviceRole_;
203     static napi_ref deviceType_;
204     static napi_ref sourceType_;
205     static napi_ref volumeAdjustType_;
206     static napi_ref channelBlendMode_;
207     static napi_ref audioRendererRate_;
208     static napi_ref interruptEventType_;
209     static napi_ref interruptForceType_;
210     static napi_ref interruptHintType_;
211     static napi_ref audioState_;
212     static napi_ref sampleFormat_;
213     static napi_ref audioEffectMode_;
214     static napi_ref audioPrivacyType_;
215     static napi_ref audioVolumeTypeRef_;
216     static napi_ref deviceFlagRef_;
217     static napi_ref activeDeviceTypeRef_;
218     static napi_ref audioRingModeRef_;
219     static napi_ref deviceChangeType_;
220     static napi_ref interruptActionType_;
221     static napi_ref audioScene_;
222     static napi_ref interruptMode_;
223     static napi_ref focusType_;
224     static napi_ref connectTypeRef_;
225     static napi_ref audioErrors_;
226     static napi_ref communicationDeviceType_;
227     static napi_ref interruptRequestType_;
228     static napi_ref interruptRequestResultType_;
229     static napi_ref toneType_;
230     static napi_ref audioDviceUsage_;
231     static napi_ref audioSpatialDeivceType_;
232     static napi_ref audioChannelLayout_;
233     static napi_ref audioStreamDeviceChangeReason_;
234     static napi_ref spatializationSceneType_;
235     static napi_ref asrNoiseSuppressionMode_;
236     static napi_ref asrAecMode_;
237     static napi_ref asrWhisperDetectionMode_;
238     static napi_ref asrVoiceControlMode_;
239     static napi_ref asrVoiceMuteMode_;
240     static napi_ref policyType_;
241     static napi_ref audioDataCallbackResult_;
242     static napi_ref concurrencyMode_;
243     static napi_ref reason_;
244     static napi_ref audioLoopbackMode_;
245     static napi_ref audioLoopbackStatus_;
246     static napi_ref audioLoopbackReverbPreset_;
247     static napi_ref audioLoopbackEqualizerPreset_;
248     static napi_ref audioSessionScene_;
249     static napi_ref audioSessionStateChangeHint_;
250     static napi_ref outputDeviceChangeRecommendedAction_;
251 
252     static const std::map<std::string, int32_t> audioChannelMap;
253     static const std::map<std::string, int32_t> samplingRateMap;
254     static const std::map<std::string, int32_t> encodingTypeMap;
255     static const std::map<std::string, int32_t> contentTypeMap;
256     static const std::map<std::string, int32_t> streamUsageMap;
257     static const std::map<std::string, int32_t> audioVolumeModeMap;
258     static const std::map<std::string, int32_t> deviceRoleMap;
259     static const std::map<std::string, int32_t> deviceTypeMap;
260     static const std::map<std::string, int32_t> sourceTypeMap;
261     static const std::map<std::string, int32_t> volumeAdjustTypeMap;
262     static const std::map<std::string, int32_t> channelBlendModeMap;
263     static const std::map<std::string, int32_t> rendererRateMap;
264     static const std::map<std::string, int32_t> interruptEventTypeMap;
265     static const std::map<std::string, int32_t> interruptForceTypeMap;
266     static const std::map<std::string, int32_t> interruptHintTypeMap;
267     static const std::map<std::string, int32_t> audioSampleFormatMap;
268     static const std::map<std::string, int32_t> audioStateMap;
269     static const std::map<std::string, int32_t> audioPrivacyTypeMap;
270     static const std::map<std::string, int32_t> effectModeMap;
271     static const std::map<std::string, int32_t> deviceChangeTypeMap;
272     static const std::map<std::string, int32_t> audioSceneMap;
273     static const std::map<std::string, int32_t> interruptActionTypeMap;
274     static const std::map<std::string, int32_t> audioVolumeTypeMap;
275     static const std::map<std::string, int32_t> activeDeviceTypeMap;
276     static const std::map<std::string, int32_t> interruptModeMap;
277     static const std::map<std::string, int32_t> focusTypeMap;
278     static const std::map<std::string, int32_t> audioErrorsMap;
279     static const std::map<std::string, int32_t> communicationDeviceTypeMap;
280     static const std::map<std::string, int32_t> interruptRequestTypeMap;
281     static const std::map<std::string, int32_t> interruptRequestResultTypeMap;
282     static const std::map<std::string, int32_t> deviceFlagMap;
283     static const std::map<std::string, int32_t> connectTypeMap;
284     static const std::map<std::string, int32_t> audioRingModeMap;
285     static const std::map<std::string, int32_t> toneTypeMap;
286     static const std::map<std::string, int32_t> audioDeviceUsageMap;
287     static const std::map<std::string, int32_t> audioSpatialDeivceTypeMap;
288     static const std::map<std::string, uint64_t> audioChannelLayoutMap;
289     static const std::map<std::string, int32_t> audioDeviceChangeReasonMap;
290     static const std::map<std::string, int32_t> spatializationSceneTypeMap;
291     static const std::map<std::string, int32_t> asrNoiseSuppressionModeMap;
292     static const std::map<std::string, int32_t> asrAecModeMap;
293     static const std::map<std::string, int32_t> asrWhisperDetectionModeMap;
294     static const std::map<std::string, int32_t> asrVoiceControlModeMap;
295     static const std::map<std::string, int32_t> asrVoiceMuteModeMap;
296     static const std::map<std::string, int32_t> policyTypeMap;
297     static const std::map<std::string, int32_t> audioDataCallbackResultMap;
298     static const std::map<std::string, int32_t> concurrencyModeMap;
299     static const std::map<std::string, int32_t> reasonMap;
300     static const std::map<std::string, int32_t> audioLoopbackModeMap;
301     static const std::map<std::string, int32_t> audioLoopbackStatusMap;
302     static const std::map<std::string, int32_t> audioLoopbackReverbPresetMap;
303     static const std::map<std::string, int32_t> audioLoopbackEqualizerPresetMap;
304     static const std::map<std::string, int32_t> audioSessionSceneMap;
305     static const std::map<std::string, int32_t> audioSessionStateChangeHintMap;
306     static const std::map<std::string, int32_t> outputDeviceChangeRecommendedActionMap;
307     static std::unique_ptr<AudioParameters> sAudioParameters_;
308 
309     std::unique_ptr<AudioParameters> audioParameters_;
310     napi_env env_;
311 };
312 } // namespace AudioStandard
313 } // namespace OHOS
314 #endif // OHOS_NAPI_AUDIO_ENUM_H
315