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_STREAM_MGR_NAPI_H_ 17 #define AUDIO_STREAM_MGR_NAPI_H_ 18 19 #include "audio_renderer.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 #include "audio_stream_manager.h" 23 #include "audio_system_manager.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 static const std::string AUDIO_STREAM_MGR_NAPI_CLASS_NAME = "AudioStreamManager"; 28 29 class AudioStreamMgrNapi { 30 public: 31 AudioStreamMgrNapi(); 32 ~AudioStreamMgrNapi(); 33 34 static napi_value Init(napi_env env, napi_value exports); 35 static napi_value CreateStreamManagerWrapper(napi_env env); 36 static napi_value GetStreamManager(napi_env env, napi_callback_info info); 37 38 private: 39 static napi_value GetCurrentAudioRendererInfos(napi_env env, napi_callback_info info); 40 static napi_value GetCurrentAudioCapturerInfos(napi_env env, napi_callback_info info); 41 static napi_value On(napi_env env, napi_callback_info info); 42 static napi_value Off(napi_env env, napi_callback_info info); 43 static napi_value IsAudioRendererLowLatencySupported(napi_env env, napi_callback_info info); 44 static napi_value IsStreamActive(napi_env env, napi_callback_info info); 45 static void RegisterCallback(napi_env env, napi_value jsThis, 46 napi_value* args, const std::string& cbName); 47 static void RegisterCapturerStateChangeCallback(napi_env env, napi_value* args, 48 const std::string& cbName, AudioStreamMgrNapi *streamMgrNapi); 49 static void RegisterRendererStateChangeCallback(napi_env env, napi_value* args, 50 const std::string& cbName, AudioStreamMgrNapi *streamMgrNapi); 51 static void UnregisterCallback(napi_env env, napi_value jsThis, const std::string& cbName); 52 static napi_value Construct(napi_env env, napi_callback_info info); 53 static void Destructor(napi_env env, void *nativeObject, void *finalize_hint); 54 static bool ParseAudioStreamInfo(napi_env env, napi_value root, AudioStreamInfo &audioStreamInfo); 55 static void IsLowLatencySupportedCallback(napi_env env, napi_status status, void *data); 56 napi_env env_; 57 AudioStreamManager *audioStreamMngr_; 58 AudioSystemManager *audioMngr_; 59 int32_t cachedClientId_ = -1; 60 std::shared_ptr<AudioRendererStateChangeCallback> rendererStateChangeCallbackNapi_ = nullptr; 61 std::shared_ptr<AudioCapturerStateChangeCallback> capturerStateChangeCallbackNapi_ = nullptr; 62 }; 63 } // namespace AudioStandard 64 } // namespace OHOS 65 #endif /* AUDIO_STREAM_MGR_NAPI_H_ */ 66