1 /*
2 * Copyright (c) 2024-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
16 #include "multimedia_audio_volume_manager_impl.h"
17 #include "cj_lambda.h"
18 #include "audio_policy_log.h"
19 #include "multimedia_audio_error.h"
20 #include "multimedia_audio_volume_group_manager_impl.h"
21
22 namespace OHOS {
23 namespace AudioStandard {
24 extern "C" {
MMAAudioVolumeManagerImpl()25 MMAAudioVolumeManagerImpl::MMAAudioVolumeManagerImpl()
26 {
27 audioMngr_ = AudioSystemManager::GetInstance();
28 volumeChangeCallback_ = std::make_shared<CjVolumeKeyEventCallback>();
29 cachedClientId_ = getpid();
30 }
31
GetVolumeGroupManager(int32_t groupId,int32_t * errorCode)32 int64_t MMAAudioVolumeManagerImpl::GetVolumeGroupManager(int32_t groupId, int32_t *errorCode)
33 {
34 auto mgr = FFIData::Create<MMAAudioVolumeGroupManagerImpl>(groupId);
35 if (mgr == nullptr) {
36 *errorCode = CJ_ERR_SYSTEM;
37 AUDIO_ERR_LOG("GetVolumeGroupManager failed.");
38 return CJ_ERR_INVALID_RETURN_VALUE;
39 }
40 *errorCode = SUCCESS_CODE;
41 return mgr->GetID();
42 }
43
RegisterCallback(int32_t callbackType,void (* callback)(),int32_t * errorCode)44 void MMAAudioVolumeManagerImpl::RegisterCallback(int32_t callbackType, void (*callback)(), int32_t *errorCode)
45 {
46 if (callbackType != AudioVolumeManagerCallbackType::VOLUME_CHANGE) {
47 return;
48 }
49 auto func = CJLambda::Create(reinterpret_cast<void (*)(CVolumeEvent)>(callback));
50 if (func == nullptr) {
51 AUDIO_ERR_LOG("Register CVolumeEvent event failure!");
52 *errorCode = CJ_ERR_SYSTEM;
53 return;
54 }
55 volumeChangeCallback_->RegisterFunc(func);
56 audioMngr_->RegisterVolumeKeyEventCallback(cachedClientId_, volumeChangeCallback_);
57 }
58 }
59 } // namespace AudioStandard
60 } // namespace OHOS
61