• 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 LOG_TAG
16 #define LOG_TAG "NapiAudioStreamMgr"
17 #endif
18 
19 #include "napi_audio_stream_manager.h"
20 #include "napi_audio_error.h"
21 #include "napi_param_utils.h"
22 #include "napi_audio_enum.h"
23 #include "audio_errors.h"
24 #include "audio_manager_log.h"
25 #include "napi_audio_renderer_state_callback.h"
26 #include "napi_audio_capturer_state_callback.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 using namespace std;
31 using namespace HiviewDFX;
32 static __thread napi_ref g_streamMgrConstructor = nullptr;
33 
NapiAudioStreamMgr()34 NapiAudioStreamMgr::NapiAudioStreamMgr()
35     : env_(nullptr), audioStreamMngr_(nullptr) {}
36 
37 NapiAudioStreamMgr::~NapiAudioStreamMgr() = default;
38 
Destructor(napi_env env,void * nativeObject,void * finalizeHint)39 void NapiAudioStreamMgr::Destructor(napi_env env, void *nativeObject, void *finalizeHint)
40 {
41     if (nativeObject == nullptr) {
42         AUDIO_WARNING_LOG("Native object is null");
43         return;
44     }
45     auto obj = static_cast<NapiAudioStreamMgr *>(nativeObject);
46     ObjectRefMap<NapiAudioStreamMgr>::DecreaseRef(obj);
47     AUDIO_INFO_LOG("Decrease obj count");
48 }
49 
Construct(napi_env env,napi_callback_info info)50 napi_value NapiAudioStreamMgr::Construct(napi_env env, napi_callback_info info)
51 {
52     AUDIO_DEBUG_LOG("Construct");
53     napi_status status;
54     napi_value result = nullptr;
55     NapiParamUtils::GetUndefinedValue(env);
56 
57     size_t argc = ARGS_TWO;
58     napi_value argv[ARGS_TWO] = {0};
59     napi_value thisVar = nullptr;
60     void *data = nullptr;
61     napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
62     unique_ptr<NapiAudioStreamMgr> napiStreamMgr = make_unique<NapiAudioStreamMgr>();
63     CHECK_AND_RETURN_RET_LOG(napiStreamMgr != nullptr, result, "No memory");
64 
65     napiStreamMgr->env_ = env;
66     napiStreamMgr->audioStreamMngr_ = AudioStreamManager::GetInstance();
67     napiStreamMgr->cachedClientId_ = getpid();
68     ObjectRefMap<NapiAudioStreamMgr>::Insert(napiStreamMgr.get());
69 
70     status = napi_wrap(env, thisVar, static_cast<void*>(napiStreamMgr.get()),
71         NapiAudioStreamMgr::Destructor, nullptr, nullptr);
72     if (status != napi_ok) {
73         ObjectRefMap<NapiAudioStreamMgr>::Erase(napiStreamMgr.get());
74         return result;
75     }
76     napiStreamMgr.release();
77     return thisVar;
78 }
79 
Init(napi_env env,napi_value exports)80 napi_value NapiAudioStreamMgr::Init(napi_env env, napi_value exports)
81 {
82     napi_status status;
83     napi_value constructor;
84     napi_value result = nullptr;
85     const int32_t refCount = ARGS_ONE;
86     napi_get_undefined(env, &result);
87 
88     napi_property_descriptor audio_stream_mgr_properties[] = {
89         DECLARE_NAPI_FUNCTION("on", On),
90         DECLARE_NAPI_FUNCTION("off", Off),
91         DECLARE_NAPI_FUNCTION("getCurrentAudioRendererInfoArray", GetCurrentAudioRendererInfos),
92         DECLARE_NAPI_FUNCTION("getCurrentAudioRendererInfoArraySync", GetCurrentAudioRendererInfosSync),
93         DECLARE_NAPI_FUNCTION("getCurrentAudioCapturerInfoArray", GetCurrentAudioCapturerInfos),
94         DECLARE_NAPI_FUNCTION("getCurrentAudioCapturerInfoArraySync", GetCurrentAudioCapturerInfosSync),
95         DECLARE_NAPI_FUNCTION("isActive", IsStreamActive),
96         DECLARE_NAPI_FUNCTION("isActiveSync", IsStreamActiveSync),
97         DECLARE_NAPI_FUNCTION("getAudioEffectInfoArray", GetEffectInfoArray),
98         DECLARE_NAPI_FUNCTION("getAudioEffectInfoArraySync", GetEffectInfoArraySync),
99         DECLARE_NAPI_FUNCTION("getHardwareOutputSamplingRate", GetHardwareOutputSamplingRate),
100         DECLARE_NAPI_FUNCTION("getSupportedAudioEffectProperty", GetSupportedAudioEffectProperty),
101         DECLARE_NAPI_FUNCTION("getAudioEffectProperty", GetAudioEffectProperty),
102         DECLARE_NAPI_FUNCTION("setAudioEffectProperty", SetAudioEffectProperty),
103         DECLARE_NAPI_FUNCTION("getSupportedAudioEnhanceProperty", GetSupportedAudioEnhanceProperty),
104         DECLARE_NAPI_FUNCTION("getAudioEnhanceProperty", GetAudioEnhanceProperty),
105         DECLARE_NAPI_FUNCTION("setAudioEnhanceProperty", SetAudioEnhanceProperty),
106     };
107 
108     status = napi_define_class(env, AUDIO_STREAM_MGR_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Construct, nullptr,
109         sizeof(audio_stream_mgr_properties) / sizeof(audio_stream_mgr_properties[PARAM0]),
110         audio_stream_mgr_properties, &constructor);
111     CHECK_AND_RETURN_RET_LOG(status == napi_ok, result, "napi_define_class fail");
112 
113     status = napi_create_reference(env, constructor, refCount, &g_streamMgrConstructor);
114     CHECK_AND_RETURN_RET_LOG(status == napi_ok, result, "napi_create_reference fail");
115     status = napi_set_named_property(env, exports, AUDIO_STREAM_MGR_NAPI_CLASS_NAME.c_str(), constructor);
116     CHECK_AND_RETURN_RET_LOG(status == napi_ok, result, "napi_set_named_property fail");
117     return exports;
118 }
119 
CreateStreamManagerWrapper(napi_env env)120 napi_value NapiAudioStreamMgr::CreateStreamManagerWrapper(napi_env env)
121 {
122     napi_status status;
123     napi_value result = nullptr;
124     napi_value constructor;
125 
126     status = napi_get_reference_value(env, g_streamMgrConstructor, &constructor);
127     if (status != napi_ok) {
128         AUDIO_ERR_LOG("Failed in CreateStreamManagerWrapper, %{public}d", status);
129         goto fail;
130     }
131     status = napi_new_instance(env, constructor, PARAM0, nullptr, &result);
132     if (status != napi_ok) {
133         AUDIO_ERR_LOG("napi_new_instance failed, status:%{public}d", status);
134         goto fail;
135     }
136     return result;
137 
138 fail:
139     napi_get_undefined(env, &result);
140     return result;
141 }
142 
CheckContextStatus(std::shared_ptr<AudioStreamMgrAsyncContext> context)143 bool NapiAudioStreamMgr::CheckContextStatus(std::shared_ptr<AudioStreamMgrAsyncContext> context)
144 {
145     CHECK_AND_RETURN_RET_LOG(context != nullptr, false, "context object is nullptr.");
146     if (context->native == nullptr) {
147         context->SignError(NAPI_ERR_SYSTEM);
148         return false;
149     }
150     return true;
151 }
152 
CheckAudioStreamManagerStatus(NapiAudioStreamMgr * napi,std::shared_ptr<AudioStreamMgrAsyncContext> context)153 bool NapiAudioStreamMgr::CheckAudioStreamManagerStatus(NapiAudioStreamMgr *napi,
154     std::shared_ptr<AudioStreamMgrAsyncContext> context)
155 {
156     CHECK_AND_RETURN_RET_LOG(napi != nullptr, false, "napi object is nullptr.");
157     if (napi->audioStreamMngr_ == nullptr) {
158         context->SignError(NAPI_ERR_SYSTEM);
159         return false;
160     }
161     return true;
162 }
163 
GetParamWithSync(const napi_env & env,napi_callback_info info,size_t & argc,napi_value * args)164 NapiAudioStreamMgr* NapiAudioStreamMgr::GetParamWithSync(const napi_env &env, napi_callback_info info,
165     size_t &argc, napi_value *args)
166 {
167     napi_status status;
168     NapiAudioStreamMgr *napiStreamMgr = nullptr;
169     napi_value jsThis = nullptr;
170     status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr);
171     CHECK_AND_RETURN_RET_LOG(status == napi_ok && jsThis != nullptr, nullptr,
172         "GetParamWithSync fail to napi_get_cb_info");
173 
174     status = napi_unwrap(env, jsThis, (void **)&napiStreamMgr);
175     CHECK_AND_RETURN_RET_LOG(status == napi_ok, nullptr, "napi_unwrap failed");
176     CHECK_AND_RETURN_RET_LOG(napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_  !=
177         nullptr, napiStreamMgr, "GetParamWithSync fail to napi_unwrap");
178     return napiStreamMgr;
179 }
180 
GetCurrentAudioRendererInfos(napi_env env,napi_callback_info info)181 napi_value NapiAudioStreamMgr::GetCurrentAudioRendererInfos(napi_env env, napi_callback_info info)
182 {
183     auto context = std::make_shared<AudioStreamMgrAsyncContext>();
184     if (context == nullptr) {
185         AUDIO_ERR_LOG("GetCurrentAudioRendererInfos failed : no memory");
186         NapiAudioError::ThrowError(env, "GetCurrentAudioRendererInfos failed : no memory",
187             NAPI_ERR_NO_MEMORY);
188         return NapiParamUtils::GetUndefinedValue(env);
189     }
190 
191     context->GetCbInfo(env, info);
192 
193     auto executor = [context]() {
194         CHECK_AND_RETURN_LOG(CheckContextStatus(context), "context object state is error.");
195         auto obj = reinterpret_cast<NapiAudioStreamMgr*>(context->native);
196         ObjectRefMap objectGuard(obj);
197         auto *napiStreamMgr = objectGuard.GetPtr();
198         CHECK_AND_RETURN_LOG(CheckAudioStreamManagerStatus(napiStreamMgr, context),
199             "context object state is error.");
200         context->intValue = napiStreamMgr->audioStreamMngr_->GetCurrentRendererChangeInfos(
201             context->audioRendererChangeInfos);
202         NAPI_CHECK_ARGS_RETURN_VOID(context, context->intValue == SUCCESS,
203             "GetCurrentAudioRendererInfos failed", NAPI_ERR_SYSTEM);
204     };
205 
206     auto complete = [env, context](napi_value &output) {
207         NapiParamUtils::SetRendererChangeInfos(env, context->audioRendererChangeInfos, output);
208     };
209     return NapiAsyncWork::Enqueue(env, context, "GetCurrentAudioRendererInfos", executor, complete);
210 }
211 
GetCurrentAudioRendererInfosSync(napi_env env,napi_callback_info info)212 napi_value NapiAudioStreamMgr::GetCurrentAudioRendererInfosSync(napi_env env, napi_callback_info info)
213 {
214     AUDIO_INFO_LOG("GetCurrentAudioRendererInfosSync");
215     napi_value result = nullptr;
216     size_t argc = PARAM0;
217     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
218     if (argc > 0) {
219         NapiAudioError::ThrowError(env, NAPI_ERROR_INVALID_PARAM);
220     }
221     CHECK_AND_RETURN_RET_LOG(napiStreamMgr!= nullptr, result, "napiStreamMgr is nullptr");
222 
223     vector<std::shared_ptr<AudioRendererChangeInfo>> audioRendererChangeInfos;
224     int32_t ret = napiStreamMgr->audioStreamMngr_->GetCurrentRendererChangeInfos(audioRendererChangeInfos);
225     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, result, "GetCurrentRendererChangeInfos failure!");
226 
227     NapiParamUtils::SetRendererChangeInfos(env, audioRendererChangeInfos, result);
228 
229     return result;
230 }
231 
GetCurrentAudioCapturerInfos(napi_env env,napi_callback_info info)232 napi_value NapiAudioStreamMgr::GetCurrentAudioCapturerInfos(napi_env env, napi_callback_info info)
233 {
234     auto context = std::make_shared<AudioStreamMgrAsyncContext>();
235     if (context == nullptr) {
236         AUDIO_ERR_LOG("GetCurrentAudioCapturerInfos failed : no memory");
237         NapiAudioError::ThrowError(env, "GetCurrentAudioCapturerInfos failed : no memory",
238             NAPI_ERR_NO_MEMORY);
239         return NapiParamUtils::GetUndefinedValue(env);
240     }
241 
242     context->GetCbInfo(env, info);
243 
244     auto executor = [context]() {
245         CHECK_AND_RETURN_LOG(CheckContextStatus(context), "context object state is error.");
246         auto obj = reinterpret_cast<NapiAudioStreamMgr*>(context->native);
247         ObjectRefMap objectGuard(obj);
248         auto *napiStreamMgr = objectGuard.GetPtr();
249         CHECK_AND_RETURN_LOG(CheckAudioStreamManagerStatus(napiStreamMgr, context),
250             "context object state is error.");
251         napiStreamMgr->audioStreamMngr_->GetCurrentCapturerChangeInfos(
252             context->audioCapturerChangeInfos);
253     };
254 
255     auto complete = [env, context](napi_value &output) {
256         NapiParamUtils::SetCapturerChangeInfos(env, context->audioCapturerChangeInfos, output);
257     };
258     return NapiAsyncWork::Enqueue(env, context, "GetCurrentAudioCapturerInfos", executor, complete);
259 }
260 
GetCurrentAudioCapturerInfosSync(napi_env env,napi_callback_info info)261 napi_value NapiAudioStreamMgr::GetCurrentAudioCapturerInfosSync(napi_env env, napi_callback_info info)
262 {
263     AUDIO_INFO_LOG("GetCurrentAudioCapturerInfosSync");
264     napi_value result = nullptr;
265     size_t argc = PARAM0;
266     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
267     if (argc > 0) {
268         NapiAudioError::ThrowError(env, NAPI_ERROR_INVALID_PARAM);
269     }
270     CHECK_AND_RETURN_RET_LOG(napiStreamMgr!= nullptr, result, "napiStreamMgr is nullptr");
271 
272     vector<std::shared_ptr<AudioCapturerChangeInfo>> audioCapturerChangeInfos;
273     int32_t ret = napiStreamMgr->audioStreamMngr_->GetCurrentCapturerChangeInfos(audioCapturerChangeInfos);
274     if (ret != AUDIO_OK) {
275         AUDIO_ERR_LOG("GetCurrentCapturerChangeInfos failure!");
276         return result;
277     }
278     NapiParamUtils::SetCapturerChangeInfos(env, audioCapturerChangeInfos, result);
279 
280     return result;
281 }
282 
IsStreamActive(napi_env env,napi_callback_info info)283 napi_value NapiAudioStreamMgr::IsStreamActive(napi_env env, napi_callback_info info)
284 {
285     auto context = std::make_shared<AudioStreamMgrAsyncContext>();
286     if (context == nullptr) {
287         AUDIO_ERR_LOG("IsStreamActive failed : no memory");
288         NapiAudioError::ThrowError(env, "IsStreamActive failed : no memory", NAPI_ERR_NO_MEMORY);
289         return NapiParamUtils::GetUndefinedValue(env);
290     }
291 
292     auto inputParser = [env, context](size_t argc, napi_value *argv) {
293         NAPI_CHECK_ARGS_RETURN_VOID(context, argc >= ARGS_ONE, "invalid arguments",
294             NAPI_ERR_INVALID_PARAM);
295         context->status = NapiParamUtils::GetValueInt32(env, context->volType, argv[PARAM0]);
296         NAPI_CHECK_ARGS_RETURN_VOID(context, context->status == napi_ok, "getvoltype failed",
297             NAPI_ERR_INVALID_PARAM);
298         if (!NapiAudioEnum::IsLegalInputArgumentVolType(context->volType)) {
299             context->SignError(context->errCode == NAPI_ERR_INVALID_PARAM?
300             NAPI_ERR_INVALID_PARAM : NAPI_ERR_UNSUPPORTED);
301         }
302     };
303     context->GetCbInfo(env, info, inputParser);
304 
305     auto executor = [context]() {
306         CHECK_AND_RETURN_LOG(CheckContextStatus(context), "context object state is error.");
307         auto obj = reinterpret_cast<NapiAudioStreamMgr*>(context->native);
308         ObjectRefMap objectGuard(obj);
309         auto *napiStreamMgr = objectGuard.GetPtr();
310         CHECK_AND_RETURN_LOG(CheckAudioStreamManagerStatus(napiStreamMgr, context),
311             "context object state is error.");
312         context->isActive = napiStreamMgr->audioStreamMngr_->IsStreamActive(
313             NapiAudioEnum::GetNativeAudioVolumeType(context->volType));
314         context->isTrue = context->isActive;
315     };
316 
317     auto complete = [env, context](napi_value &output) {
318         NapiParamUtils::SetValueBoolean(env, context->isTrue, output);
319     };
320     return NapiAsyncWork::Enqueue(env, context, "IsStreamActive", executor, complete);
321 }
322 
IsStreamActiveSync(napi_env env,napi_callback_info info)323 napi_value NapiAudioStreamMgr::IsStreamActiveSync(napi_env env, napi_callback_info info)
324 {
325     napi_value result = nullptr;
326     size_t argc = ARGS_ONE;
327     napi_value args[ARGS_ONE] = {};
328     auto *napiStreamMgr = GetParamWithSync(env, info, argc, args);
329     CHECK_AND_RETURN_RET_LOG(argc >= ARGS_ONE, NapiAudioError::ThrowErrorAndReturn(env,
330         NAPI_ERR_INPUT_INVALID, "mandatory parameters are left unspecified"), "invalid arguments");
331 
332     napi_valuetype valueType = napi_undefined;
333     napi_typeof(env, args[PARAM0], &valueType);
334     CHECK_AND_RETURN_RET_LOG(valueType == napi_number, NapiAudioError::ThrowErrorAndReturn(env,
335         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of volumeType must be number"),
336         "invalid valueType");
337 
338     int32_t volType;
339     NapiParamUtils::GetValueInt32(env, volType, args[PARAM0]);
340     CHECK_AND_RETURN_RET_LOG(NapiAudioEnum::IsLegalInputArgumentVolType(volType),
341         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM,
342         "parameter verification failed: The param of volumeType must be enum AudioVolumeType"), "get volType failed");
343 
344     CHECK_AND_RETURN_RET_LOG(napiStreamMgr != nullptr, result, "napiStreamMgr is nullptr");
345     CHECK_AND_RETURN_RET_LOG(napiStreamMgr->audioStreamMngr_ != nullptr, result,
346         "audioStreamMngr_ is nullptr");
347     bool isActive = napiStreamMgr->audioStreamMngr_->
348         IsStreamActive(NapiAudioEnum::GetNativeAudioVolumeType(volType));
349     NapiParamUtils::SetValueBoolean(env, isActive, result);
350     return result;
351 }
352 
GetEffectInfoArray(napi_env env,napi_callback_info info)353 napi_value NapiAudioStreamMgr::GetEffectInfoArray(napi_env env, napi_callback_info info)
354 {
355     auto context = std::make_shared<AudioStreamMgrAsyncContext>();
356     if (context == nullptr) {
357         AUDIO_ERR_LOG("GetEffectInfoArray failed : no memory");
358         NapiAudioError::ThrowError(env, "GetEffectInfoArray failed : no memory", NAPI_ERR_NO_MEMORY);
359         return NapiParamUtils::GetUndefinedValue(env);
360     }
361 
362     auto inputParser = [env, context](size_t argc, napi_value *argv) {
363         NAPI_CHECK_ARGS_RETURN_VOID(context, argc >= ARGS_ONE, "mandatory parameters are left unspecified",
364             NAPI_ERR_INPUT_INVALID);
365         context->status = NapiParamUtils::GetValueInt32(env, context->streamUsage, argv[PARAM0]);
366         NAPI_CHECK_ARGS_RETURN_VOID(context, context->status == napi_ok,
367             "incorrect parameter types: The type of usage must be number", NAPI_ERR_INPUT_INVALID);
368         if (!NapiAudioEnum::IsLegalInputArgumentStreamUsage(context->streamUsage)) {
369             context->SignError(NAPI_ERR_INVALID_PARAM,
370                 "parameter verification failed: The param of usage must be enum StreamUsage");
371         }
372     };
373     context->GetCbInfo(env, info, inputParser);
374 
375     if ((context->status != napi_ok) && (context->errCode == NAPI_ERR_INPUT_INVALID)) {
376         NapiAudioError::ThrowError(env, context->errCode, context->errMessage);
377         return NapiParamUtils::GetUndefinedValue(env);
378     }
379 
380     auto executor = [context]() {
381         CHECK_AND_RETURN_LOG(CheckContextStatus(context), "context object state is error.");
382         auto obj = reinterpret_cast<NapiAudioStreamMgr*>(context->native);
383         ObjectRefMap objectGuard(obj);
384         auto *napiStreamMgr = objectGuard.GetPtr();
385         CHECK_AND_RETURN_LOG(CheckAudioStreamManagerStatus(napiStreamMgr, context),
386             "context object state is error.");
387         StreamUsage streamUsage = static_cast<StreamUsage>(context->streamUsage);
388         context->intValue = napiStreamMgr->audioStreamMngr_->GetEffectInfoArray(
389             context->audioSceneEffectInfo, streamUsage);
390         NAPI_CHECK_ARGS_RETURN_VOID(context, context->intValue == SUCCESS, "GetEffectInfoArray failed",
391             NAPI_ERR_SYSTEM);
392     };
393 
394     auto complete = [env, context](napi_value &output) {
395         NapiParamUtils::SetEffectInfo(env, context->audioSceneEffectInfo, output);
396     };
397     return NapiAsyncWork::Enqueue(env, context, "GetEffectInfoArray", executor, complete);
398 }
399 
GetEffectInfoArraySync(napi_env env,napi_callback_info info)400 napi_value NapiAudioStreamMgr::GetEffectInfoArraySync(napi_env env, napi_callback_info info)
401 {
402     napi_value result = nullptr;
403     size_t argc = ARGS_ONE;
404     napi_value args[ARGS_ONE] = {};
405     auto *napiStreamMgr = GetParamWithSync(env, info, argc, args);
406     CHECK_AND_RETURN_RET_LOG(argc >= ARGS_ONE, NapiAudioError::ThrowErrorAndReturn(env,
407         NAPI_ERR_INPUT_INVALID, "mandatory parameters are left unspecified"), "invalid arguments");
408 
409     napi_valuetype valueType = napi_undefined;
410     napi_typeof(env, args[PARAM0], &valueType);
411     CHECK_AND_RETURN_RET_LOG(valueType == napi_number, NapiAudioError::ThrowErrorAndReturn(env,
412         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of usage must be number"),
413         "invalid valueType");
414 
415     int32_t streamUsage;
416     NapiParamUtils::GetValueInt32(env, streamUsage, args[PARAM0]);
417     CHECK_AND_RETURN_RET_LOG(NapiAudioEnum::IsLegalInputArgumentStreamUsage(streamUsage),
418         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM,
419         "parameter verification failed: The param of usage must be enum StreamUsage"), "get streamUsage failed");
420 
421     CHECK_AND_RETURN_RET_LOG(napiStreamMgr != nullptr, result, "napiStreamMgr is nullptr");
422     CHECK_AND_RETURN_RET_LOG(napiStreamMgr->audioStreamMngr_ != nullptr, result,
423         "audioStreamMngr_ is nullptr");
424     AudioSceneEffectInfo audioSceneEffectInfo;
425     int32_t ret = napiStreamMgr->audioStreamMngr_->GetEffectInfoArray(audioSceneEffectInfo,
426         static_cast<StreamUsage>(streamUsage));
427     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, result, "GetEffectInfoArray failure!");
428     NapiParamUtils::SetEffectInfo(env, audioSceneEffectInfo, result);
429     return result;
430 }
431 
GetHardwareOutputSamplingRate(napi_env env,napi_callback_info info)432 napi_value NapiAudioStreamMgr::GetHardwareOutputSamplingRate(napi_env env, napi_callback_info info)
433 {
434     napi_value result = nullptr;
435     std::shared_ptr<AudioDeviceDescriptor> deviceDescriptor = nullptr;
436     size_t argc = ARGS_ONE;
437     napi_value args[ARGS_ONE] = {};
438     auto *napiStreamMgr = GetParamWithSync(env, info, argc, args);
439     CHECK_AND_RETURN_RET_LOG(napiStreamMgr != nullptr, result, "napiStreamMgr is nullptr");
440     CHECK_AND_RETURN_RET_LOG(napiStreamMgr->audioStreamMngr_ != nullptr, result,
441         "audioStreamMngr_ is nullptr");
442 
443     if (argc < ARGS_ONE) {
444         int32_t rate = napiStreamMgr->audioStreamMngr_->GetHardwareOutputSamplingRate(deviceDescriptor);
445         NapiParamUtils::SetValueInt32(env, rate, result);
446         return result;
447     }
448 
449     deviceDescriptor = std::make_shared<AudioDeviceDescriptor>();
450     CHECK_AND_RETURN_RET_LOG(deviceDescriptor != nullptr, result, "AudioDeviceDescriptor alloc failed!");
451 
452     bool argTransFlag = false;
453     NapiParamUtils::GetAudioDeviceDescriptor(env, deviceDescriptor, argTransFlag, args[PARAM0]);
454     CHECK_AND_RETURN_RET_LOG(argTransFlag && NapiAudioEnum::IsLegalOutputDeviceType(deviceDescriptor->deviceType_) &&
455         (deviceDescriptor->deviceRole_ == DeviceRole::OUTPUT_DEVICE),
456         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM), "invalid deviceDescriptor");
457 
458     int32_t rate = napiStreamMgr->audioStreamMngr_->GetHardwareOutputSamplingRate(deviceDescriptor);
459     NapiParamUtils::SetValueInt32(env, rate, result);
460     return result;
461 }
462 
RegisterCallback(napi_env env,napi_value jsThis,napi_value * args,const std::string & cbName)463 void NapiAudioStreamMgr::RegisterCallback(napi_env env, napi_value jsThis,
464     napi_value *args, const std::string &cbName)
465 {
466     NapiAudioStreamMgr *napiStreamMgr = nullptr;
467     napi_status status = napi_unwrap(env, jsThis, reinterpret_cast<void **>(&napiStreamMgr));
468     CHECK_AND_RETURN_LOG((status == napi_ok) && (napiStreamMgr != nullptr) &&
469         (napiStreamMgr->audioStreamMngr_ != nullptr), "Failed to retrieve stream mgr napi instance.");
470 
471     if (!cbName.compare(RENDERERCHANGE_CALLBACK_NAME)) {
472         RegisterRendererStateChangeCallback(env, args, cbName, napiStreamMgr);
473     } else if (!cbName.compare(CAPTURERCHANGE_CALLBACK_NAME)) {
474         RegisterCapturerStateChangeCallback(env, args, cbName, napiStreamMgr);
475     } else {
476         AUDIO_ERR_LOG("NapiAudioStreamMgr::No such callback supported");
477         NapiAudioError::ThrowError(env, NAPI_ERR_INVALID_PARAM,
478             "parameter verification failed: The param of type is not supported");
479     }
480 }
481 
RegisterRendererStateChangeCallback(napi_env env,napi_value * args,const std::string & cbName,NapiAudioStreamMgr * napiStreamMgr)482 void NapiAudioStreamMgr::RegisterRendererStateChangeCallback(napi_env env, napi_value *args,
483     const std::string &cbName, NapiAudioStreamMgr *napiStreamMgr)
484 {
485     if (!napiStreamMgr->rendererStateChangeCallbackNapi_) {
486         napiStreamMgr->rendererStateChangeCallbackNapi_ = std::make_shared<NapiAudioRendererStateCallback>(env);
487         CHECK_AND_RETURN_LOG(napiStreamMgr->rendererStateChangeCallbackNapi_ != nullptr,
488             "NapiAudioStreamMgr: Memory Allocation Failed !!");
489 
490         int32_t ret =
491             napiStreamMgr->audioStreamMngr_->RegisterAudioRendererEventListener(napiStreamMgr->cachedClientId_,
492             napiStreamMgr->rendererStateChangeCallbackNapi_);
493         CHECK_AND_RETURN_LOG(ret == SUCCESS,
494             "NapiAudioStreamMgr: Registering of Renderer State Change Callback Failed");
495     }
496 
497     std::shared_ptr<NapiAudioRendererStateCallback> cb =
498     std::static_pointer_cast<NapiAudioRendererStateCallback>(napiStreamMgr->rendererStateChangeCallbackNapi_);
499     cb->SaveCallbackReference(args[PARAM1]);
500     if (!cb->GetRendererStateTsfnFlag()) {
501         cb->CreateRendererStateTsfn(env);
502     }
503 
504     AUDIO_INFO_LOG("OnRendererStateChangeCallback is successful");
505 }
506 
RegisterCapturerStateChangeCallback(napi_env env,napi_value * args,const std::string & cbName,NapiAudioStreamMgr * napiStreamMgr)507 void NapiAudioStreamMgr::RegisterCapturerStateChangeCallback(napi_env env, napi_value *args,
508     const std::string &cbName, NapiAudioStreamMgr *napiStreamMgr)
509 {
510     if (!napiStreamMgr->capturerStateChangeCallbackNapi_) {
511         napiStreamMgr->capturerStateChangeCallbackNapi_ = std::make_shared<NapiAudioCapturerStateCallback>(env);
512         CHECK_AND_RETURN_LOG(napiStreamMgr->capturerStateChangeCallbackNapi_ != nullptr,
513             "Memory Allocation Failed !!");
514 
515         int32_t ret =
516             napiStreamMgr->audioStreamMngr_->RegisterAudioCapturerEventListener(napiStreamMgr->cachedClientId_,
517             napiStreamMgr->capturerStateChangeCallbackNapi_);
518         CHECK_AND_RETURN_LOG(ret == SUCCESS,
519             "Registering of Capturer State Change Callback Failed");
520     }
521     std::lock_guard<std::mutex> lock(napiStreamMgr->capturerStateChangeCallbackNapi_->cbMutex_);
522 
523     std::shared_ptr<NapiAudioCapturerStateCallback> cb =
524         std::static_pointer_cast<NapiAudioCapturerStateCallback>(napiStreamMgr->capturerStateChangeCallbackNapi_);
525     cb->SaveCallbackReference(args[PARAM1]);
526     if (!cb->GetCaptureStateTsfnFlag()) {
527         cb->CreateCaptureStateTsfn(env);
528     }
529 
530     AUDIO_INFO_LOG("OnCapturerStateChangeCallback is successful");
531 }
532 
On(napi_env env,napi_callback_info info)533 napi_value NapiAudioStreamMgr::On(napi_env env, napi_callback_info info)
534 {
535     const size_t requireArgc = ARGS_TWO;
536     size_t argc = ARGS_THREE;
537 
538     napi_value undefinedResult = nullptr;
539     napi_get_undefined(env, &undefinedResult);
540 
541     napi_value args[requireArgc + PARAM1] = {nullptr, nullptr, nullptr};
542     napi_value jsThis = nullptr;
543     napi_status status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr);
544     CHECK_AND_RETURN_RET_LOG(status == napi_ok && argc == requireArgc, NapiAudioError::ThrowErrorAndReturn(env,
545         NAPI_ERR_INPUT_INVALID, "mandatory parameters are left unspecified"),
546         "status or arguments error");
547 
548     napi_valuetype eventType = napi_undefined;
549     napi_typeof(env, args[PARAM0], &eventType);
550     CHECK_AND_RETURN_RET_LOG(eventType == napi_string, NapiAudioError::ThrowErrorAndReturn(env,
551         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of eventType must be string"),
552         "eventType error");
553 
554     std::string callbackName = NapiParamUtils::GetStringArgument(env, args[PARAM0]);
555     AUDIO_DEBUG_LOG("AudioStreamMgrNapi: On callbackName: %{public}s", callbackName.c_str());
556 
557     napi_valuetype handler = napi_undefined;
558 
559     napi_typeof(env, args[PARAM1], &handler);
560     CHECK_AND_RETURN_RET_LOG(handler == napi_function, NapiAudioError::ThrowErrorAndReturn(env,
561         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of callback must be function"),
562         "handler is invalid");
563 
564     RegisterCallback(env, jsThis, args, callbackName);
565     return undefinedResult;
566 }
567 
UnregisterCallback(napi_env env,napi_value jsThis,size_t argc,napi_value * args,const std::string & cbName)568 void NapiAudioStreamMgr::UnregisterCallback(napi_env env, napi_value jsThis,
569     size_t argc, napi_value *args, const std::string &cbName)
570 {
571     AUDIO_INFO_LOG("UnregisterCallback");
572     NapiAudioStreamMgr *napiStreamMgr = nullptr;
573     napi_status status = napi_unwrap(env, jsThis, reinterpret_cast<void **>(&napiStreamMgr));
574     CHECK_AND_RETURN_LOG((status == napi_ok) && (napiStreamMgr != nullptr) &&
575         (napiStreamMgr->audioStreamMngr_ != nullptr), "Failed to retrieve stream mgr napi instance.");
576 
577     if (!cbName.compare(RENDERERCHANGE_CALLBACK_NAME)) {
578         UnregisterRendererChangeCallback(napiStreamMgr, argc, args);
579         AUDIO_INFO_LOG("UnRegistering of renderer State Change Callback successful");
580     } else if (!cbName.compare(CAPTURERCHANGE_CALLBACK_NAME)) {
581         UnregisterCapturerChangeCallback(napiStreamMgr, argc, args);
582         AUDIO_INFO_LOG("UnRegistering of capturer State Change Callback successful");
583     } else {
584         AUDIO_ERR_LOG("No such callback supported");
585         NapiAudioError::ThrowError(env, NAPI_ERR_INVALID_PARAM,
586             "parameter verification failed: The param of type is not supported");
587     }
588 }
589 
UnregisterRendererChangeCallback(NapiAudioStreamMgr * napiStreamMgr,size_t argc,napi_value * args)590 void NapiAudioStreamMgr::UnregisterRendererChangeCallback(NapiAudioStreamMgr *napiStreamMgr,
591     size_t argc, napi_value *args)
592 {
593     CHECK_AND_RETURN_LOG(napiStreamMgr->rendererStateChangeCallbackNapi_ != nullptr,
594         "rendererStateChangeCallbackNapi is nullptr");
595     std::shared_ptr<NapiAudioRendererStateCallback> cb =
596         std::static_pointer_cast<NapiAudioRendererStateCallback>(napiStreamMgr->rendererStateChangeCallbackNapi_);
597     napi_value callback = nullptr;
598     if (argc == ARGS_TWO) {
599         callback = args[PARAM1];
600         CHECK_AND_RETURN_LOG(cb->IsSameCallback(callback),
601             "The callback need to be unregistered is not the same as the registered callback");
602     }
603     int32_t ret = napiStreamMgr->audioStreamMngr_->
604         UnregisterAudioRendererEventListener(napiStreamMgr->cachedClientId_);
605     CHECK_AND_RETURN_LOG(ret == SUCCESS, "Unregister renderer state change callback failed");
606     cb->RemoveCallbackReference(callback);
607     napiStreamMgr->rendererStateChangeCallbackNapi_.reset();
608 }
609 
UnregisterCapturerChangeCallback(NapiAudioStreamMgr * napiStreamMgr,size_t argc,napi_value * args)610 void NapiAudioStreamMgr::UnregisterCapturerChangeCallback(NapiAudioStreamMgr *napiStreamMgr,
611     size_t argc, napi_value *args)
612 {
613     CHECK_AND_RETURN_LOG(napiStreamMgr->capturerStateChangeCallbackNapi_ != nullptr,
614         "capturerStateChangeCallbackNapi is nullptr");
615     std::shared_ptr<NapiAudioCapturerStateCallback> cb =
616         std::static_pointer_cast<NapiAudioCapturerStateCallback>(napiStreamMgr->capturerStateChangeCallbackNapi_);
617     napi_value callback = nullptr;
618     if (argc == ARGS_TWO) {
619         callback = args[PARAM1];
620         CHECK_AND_RETURN_LOG(cb->IsSameCallback(callback),
621             "The callback need to be unregistered is not the same as the registered callback");
622     }
623     int32_t ret = napiStreamMgr->audioStreamMngr_->
624         UnregisterAudioCapturerEventListener(napiStreamMgr->cachedClientId_);
625     CHECK_AND_RETURN_LOG(ret == SUCCESS, "Unregister capturer state change callback failed");
626     cb->RemoveCallbackReference(callback);
627     napiStreamMgr->capturerStateChangeCallbackNapi_.reset();
628 }
629 
Off(napi_env env,napi_callback_info info)630 napi_value NapiAudioStreamMgr::Off(napi_env env, napi_callback_info info)
631 {
632     const size_t requireArgc = ARGS_ONE;
633     size_t argc = ARGS_TWO;
634 
635     napi_value undefinedResult = nullptr;
636     napi_get_undefined(env, &undefinedResult);
637 
638     napi_value args[requireArgc + PARAM2] = {nullptr, nullptr, nullptr};
639     napi_value jsThis = nullptr;
640     napi_status status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr);
641     CHECK_AND_RETURN_RET_LOG(status == napi_ok && argc >= requireArgc, NapiAudioError::ThrowErrorAndReturn(env,
642         NAPI_ERR_INPUT_INVALID,
643         "mandatory parameters are left unspecified"), "status or arguments error");
644 
645     napi_valuetype eventType = napi_undefined;
646     CHECK_AND_RETURN_RET_LOG(napi_typeof(env, args[PARAM0], &eventType) == napi_ok && eventType == napi_string,
647         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID,
648         "incorrect parameter types: The type of eventType must be string"), "eventType error");
649 
650     std::string callbackName = NapiParamUtils::GetStringArgument(env, args[0]);
651     AUDIO_DEBUG_LOG("NapiAudioStreamMgr: Off callbackName: %{public}s", callbackName.c_str());
652 
653     UnregisterCallback(env, jsThis, argc, args, callbackName);
654     return undefinedResult;
655 }
656 
GetSupportedAudioEffectProperty(napi_env env,napi_callback_info info)657 napi_value NapiAudioStreamMgr::GetSupportedAudioEffectProperty(napi_env env, napi_callback_info info)
658 {
659     napi_value result = nullptr;
660     size_t argc = PARAM0;
661     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
662     CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr,
663         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_SYSTEM,
664         "incorrect parameter types: The type of options must be empty"), "argcCount invalid");
665 
666     AudioEffectPropertyArray propertyArray = {};
667     int32_t ret = napiStreamMgr->audioStreamMngr_->GetSupportedAudioEffectProperty(propertyArray);
668     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
669         "interface operation failed"), "get support audio effect property failure!");
670 
671     napi_status status = NapiParamUtils::SetEffectProperty(env, propertyArray, result);
672     CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env,
673         NAPI_ERR_SYSTEM, "Combining property data fail"), "fill support effect property failed");
674 
675     return result;
676 }
677 
GetSupportedAudioEnhanceProperty(napi_env env,napi_callback_info info)678 napi_value NapiAudioStreamMgr::GetSupportedAudioEnhanceProperty(napi_env env, napi_callback_info info)
679 {
680     napi_value result = nullptr;
681     size_t argc = PARAM0;
682     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
683     CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr,
684         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_SYSTEM,
685         "incorrect parameter types: The type of options must be empty"), "argcCount invalid");
686 
687     AudioEnhancePropertyArray propertyArray = {};
688     int32_t ret = napiStreamMgr->audioStreamMngr_->GetSupportedAudioEnhanceProperty(propertyArray);
689     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
690         "interface operation failed"), "get support audio enhance property failure!");
691 
692     napi_status status = NapiParamUtils::SetEnhanceProperty(env, propertyArray, result);
693     CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env,
694         NAPI_ERR_SYSTEM, "Combining property data fail"), "fill enhance property failed");
695     return result;
696 }
697 
GetAudioEffectProperty(napi_env env,napi_callback_info info)698 napi_value NapiAudioStreamMgr::GetAudioEffectProperty(napi_env env, napi_callback_info info)
699 {
700     napi_value result = nullptr;
701     size_t argc = PARAM0;
702     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
703     CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr,
704         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_SYSTEM,
705         "incorrect parameter types: The type of options must be empty"), "argcCount invalid");
706 
707     AudioEffectPropertyArray propertyArray = {};
708     int32_t ret = napiStreamMgr->audioStreamMngr_->GetAudioEffectProperty(propertyArray);
709     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
710         "interface operation failed"), "get audio enhance property failure!");
711 
712     napi_status status = NapiParamUtils::SetEffectProperty(env, propertyArray, result);
713     CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env,
714         NAPI_ERR_SYSTEM, "combining property data fail"), "fill effect property failed");
715 
716     return result;
717 }
718 
SetAudioEffectProperty(napi_env env,napi_callback_info info)719 napi_value NapiAudioStreamMgr::SetAudioEffectProperty(napi_env env, napi_callback_info info)
720 {
721     napi_value result = nullptr;
722     size_t argc = ARGS_ONE;
723     napi_value args[ARGS_ONE] = {};
724     auto *napiStreamMgr = GetParamWithSync(env, info, argc, args);
725     CHECK_AND_RETURN_RET_LOG(argc == ARGS_ONE && napiStreamMgr != nullptr &&
726         napiStreamMgr->audioStreamMngr_ != nullptr, NapiAudioError::ThrowErrorAndReturn(env,
727         NAPI_ERR_INPUT_INVALID,
728         "parameter verification failed: mandatory parameters are left unspecified"), "argcCount invalid");
729 
730     napi_valuetype valueType = napi_undefined;
731     napi_typeof(env, args[PARAM0], &valueType);
732     CHECK_AND_RETURN_RET_LOG(valueType == napi_object, NapiAudioError::ThrowErrorAndReturn(env,
733         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of options must be array"),
734         "invaild valueType");
735 
736     AudioEffectPropertyArray propertyArray = {};
737     napi_status status = NapiParamUtils::GetEffectPropertyArray(env, propertyArray, args[PARAM0]);
738     CHECK_AND_RETURN_RET_LOG(status == napi_ok && propertyArray.property.size() > 0,
739         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM,
740         "parameter verification failed: mandatory parameters are left unspecified"), "status or arguments error");
741 
742     int32_t ret = napiStreamMgr->audioStreamMngr_->SetAudioEffectProperty(propertyArray);
743     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
744         "interface operation failed"), "set audio effect property failure!");
745 
746     return result;
747 }
748 
GetAudioEnhanceProperty(napi_env env,napi_callback_info info)749 napi_value NapiAudioStreamMgr::GetAudioEnhanceProperty(napi_env env, napi_callback_info info)
750 {
751     napi_value result = nullptr;
752     size_t argc = PARAM0;
753     auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr);
754     CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr,
755         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_SYSTEM,
756         "incorrect parameter types: The type of options must be empty"), "argcCount invalid");
757 
758     AudioEnhancePropertyArray propertyArray = {};
759     int32_t ret = napiStreamMgr->audioStreamMngr_->GetAudioEnhanceProperty(propertyArray);
760     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
761         "interface operation failed"), "get audio enhance property failure!");
762 
763     napi_status status = NapiParamUtils::SetEnhanceProperty(env, propertyArray, result);
764     CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env,
765         NAPI_ERR_SYSTEM, "combining property data fail"), "fill effect property failed");
766 
767     return result;
768 }
769 
SetAudioEnhanceProperty(napi_env env,napi_callback_info info)770 napi_value NapiAudioStreamMgr::SetAudioEnhanceProperty(napi_env env, napi_callback_info info)
771 {
772     napi_value result = nullptr;
773     size_t argc = ARGS_ONE;
774     napi_value args[ARGS_ONE] = {};
775     auto *napiStreamMgr = GetParamWithSync(env, info, argc, args);
776     CHECK_AND_RETURN_RET_LOG(argc == ARGS_ONE && napiStreamMgr != nullptr &&
777         napiStreamMgr->audioStreamMngr_ != nullptr, NapiAudioError::ThrowErrorAndReturn(env,
778         NAPI_ERR_INPUT_INVALID,
779         "parameter verification failed: mandatory parameters are left unspecified"), "argcCount invalid");
780 
781     napi_valuetype valueType = napi_undefined;
782     napi_typeof(env, args[PARAM0], &valueType);
783     CHECK_AND_RETURN_RET_LOG(valueType == napi_object, NapiAudioError::ThrowErrorAndReturn(env,
784         NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of options must be array"),
785         "invaild valueType");
786 
787     AudioEnhancePropertyArray propertyArray = {};
788     napi_status status = NapiParamUtils::GetEnhancePropertyArray(env, propertyArray, args[PARAM0]);
789     CHECK_AND_RETURN_RET_LOG(status == napi_ok && propertyArray.property.size() > 0,
790         NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM,
791         "parameter verification failed: mandatory parameters are left unspecified"), "status or arguments error");
792 
793     int32_t ret = napiStreamMgr->audioStreamMngr_->SetAudioEnhanceProperty(propertyArray);
794     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK,  NapiAudioError::ThrowErrorAndReturn(env, ret,
795         "interface operation failed"), "set audio enhance property failure!");
796 
797     return result;
798 }
799 
800 }  // namespace AudioStandard
801 }  // namespace OHOS
802