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