• 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_VOLUME_GROUP_MANAGER_H
16 #define NAPI_AUDIO_VOLUME_GROUP_MANAGER_H
17 
18 #include <iostream>
19 #include <map>
20 #include <vector>
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "napi_async_work.h"
24 #include "audio_system_manager.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 class NapiAudioVolumeGroupManager {
29 public:
30     static napi_value Init(napi_env env, napi_value exports);
31     static napi_value CreateAudioVolumeGroupManagerWrapper(napi_env env, int32_t groupId);
32 
33     static int32_t isConstructSuccess_;
34 
35 private:
36     struct AudioVolumeGroupManagerAsyncContext : public ContextBase {
37         int32_t volType;
38         int32_t volLevel;
39         int32_t volFlag;
40         int32_t deviceType;
41         int32_t ringMode;
42         int32_t scene;
43         int32_t deviceFlag;
44         int32_t intValue;
45         int32_t groupId;
46         int32_t adjustType;
47         int32_t volumeAdjustStatus;
48         bool isMute;
49         bool isActive;
50         bool isTrue;
51         double volumeInDb;
52         std::string key;
53         std::string valueStr;
54         int32_t networkId;
55         double inputMaxAmplitude;
56         double outputMaxAmplitude;
57         bool inputBArgTransFlag;
58         bool outputBArgTransFlag;
59         int32_t policyType;
60         std::shared_ptr<AudioDeviceDescriptor> inputDeviceDescriptor = std::make_shared<AudioDeviceDescriptor>();;
61         std::shared_ptr<AudioDeviceDescriptor> outputDeviceDescriptor = std::make_shared<AudioDeviceDescriptor>();;
62     };
63 
64     static void Destructor(napi_env env, void *nativeObject, void *finalizeHint);
65     static napi_value Construct(napi_env env, napi_callback_info info);
66     static napi_value GetActiveVolumeTypeSync(napi_env env, napi_callback_info info);
67     static napi_value GetVolume(napi_env env, napi_callback_info info);
68     static napi_value GetVolumeSync(napi_env env, napi_callback_info info);
69     static napi_value SetVolume(napi_env env, napi_callback_info info);
70     static napi_value SetVolumeWithFlag(napi_env env, napi_callback_info info);
71     static napi_value GetMaxVolume(napi_env env, napi_callback_info info);
72     static napi_value GetMaxVolumeSync(napi_env env, napi_callback_info info);
73     static napi_value GetMinVolume(napi_env env, napi_callback_info info);
74     static napi_value GetMinVolumeSync(napi_env env, napi_callback_info info);
75     static napi_value SetMute(napi_env env, napi_callback_info info);
76     static napi_value IsStreamMute(napi_env env, napi_callback_info info);
77     static napi_value IsStreamMuteSync(napi_env env, napi_callback_info info);
78     static napi_value SetRingerMode(napi_env env, napi_callback_info info);
79     static napi_value GetRingerMode(napi_env env, napi_callback_info info);
80     static napi_value GetRingerModeSync(napi_env env, napi_callback_info info);
81     static napi_value SetMicrophoneMute(napi_env env, napi_callback_info info);
82     static napi_value IsMicrophoneMute(napi_env env, napi_callback_info info);
83     static napi_value IsMicrophoneMuteSync(napi_env env, napi_callback_info info);
84     static napi_value SetMicMute(napi_env env, napi_callback_info info);
85     static napi_value SetMicMutePersistent(napi_env env, napi_callback_info info);
86     static napi_value GetPersistentMicMuteState(napi_env env, napi_callback_info info);
87     static napi_value IsVolumeUnadjustable(napi_env env, napi_callback_info info);
88     static napi_value AdjustVolumeByStep(napi_env env, napi_callback_info info);
89     static napi_value AdjustSystemVolumeByStep(napi_env env, napi_callback_info info);
90     static napi_value GetSystemVolumeInDb(napi_env env, napi_callback_info info);
91     static napi_value GetSystemVolumeInDbSync(napi_env env, napi_callback_info info);
92     static napi_value On(napi_env env, napi_callback_info info);
93     static napi_value Off(napi_env env, napi_callback_info info);
94     static napi_value GetMaxAmplitudeForOutputDevice(napi_env env, napi_callback_info info);
95     static napi_value GetMaxAmplitudeForInputDevice(napi_env env, napi_callback_info info);
96 
97     static napi_value RegisterCallback(napi_env env, napi_value jsThis, size_t argc, napi_value *args,
98         const std::string &cbName);
99     static napi_value UnregisterCallback(napi_env env, napi_value jsThis, size_t argc, napi_value *args,
100         const std::string &cbName);
101     static void UnregisterRingerModeCallback(NapiAudioVolumeGroupManager *napiAudioVolumeGroupManager,
102         size_t argc, napi_value *args);
103     static void UnregisterMicStateChangeCallback(NapiAudioVolumeGroupManager *napiAudioVolumeGroupManager,
104         size_t argc, napi_value *args);
105     static napi_value RegisterMicStateChangeCallback(napi_env env, napi_value *args, const std::string &cbName,
106         NapiAudioVolumeGroupManager *napiAudioVolumeGroupManager);
107     static napi_value RegisterRingModeCallback(napi_env env, napi_value *args, const std::string &cbName,
108         NapiAudioVolumeGroupManager *napiAudioVolumeGroupManager);
109     static napi_status InitNapiAudioVolumeGroupManager(napi_env env, napi_value &constructor);
110     static bool CheckContextStatus(std::shared_ptr<AudioVolumeGroupManagerAsyncContext> context);
111     static bool CheckAudioVolumeGroupManagerStatus(NapiAudioVolumeGroupManager *napi,
112         std::shared_ptr<AudioVolumeGroupManagerAsyncContext> context);
113     static NapiAudioVolumeGroupManager* GetParamWithSync(const napi_env &env, napi_callback_info info,
114         size_t &argc, napi_value *args);
115 
116     static std::mutex volumeGroupManagerMutex_;
117 
118     std::shared_ptr<AudioGroupManager> audioGroupMngr_ = nullptr;
119     int32_t cachedClientId_ = -1;
120     std::shared_ptr<AudioRingerModeCallback> ringerModecallbackNapi_ = nullptr;
121     std::shared_ptr<AudioManagerMicStateChangeCallback> micStateChangeCallbackNapi_ = nullptr;
122 };
123 }  // namespace AudioStandard
124 }  // namespace OHOS
125 #endif /* NAPI_AUDIO_VOLUME_GROUP_MANAGER_H */
126