1 /*
2 * Copyright (c) 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 "CoreServiceHandler"
17 #endif
18
19 #include "core_service_handler.h"
20
21 #include "audio_errors.h"
22 #include "audio_common_log.h"
23
24 namespace OHOS {
25 namespace AudioStandard {
26 namespace {
27
28 }
29
GetInstance()30 CoreServiceHandler& CoreServiceHandler::GetInstance()
31 {
32 static CoreServiceHandler CoreServiceHandler;
33 return CoreServiceHandler;
34 }
35
CoreServiceHandler()36 CoreServiceHandler::CoreServiceHandler()
37 {
38 AUDIO_INFO_LOG("Ctor");
39 }
40
~CoreServiceHandler()41 CoreServiceHandler::~CoreServiceHandler()
42 {
43 iCoreServiceProvider_ = nullptr;
44 AUDIO_INFO_LOG("Dtor");
45 }
46
ConfigCoreServiceProvider(const sptr<ICoreServiceProviderIpc> coreServiceProvider)47 int32_t CoreServiceHandler::ConfigCoreServiceProvider(const sptr<ICoreServiceProviderIpc> coreServiceProvider)
48 {
49 CHECK_AND_RETURN_RET_LOG(coreServiceProvider != nullptr, ERR_INVALID_PARAM, "Failed with null provider!");
50 if (iCoreServiceProvider_ == nullptr) {
51 iCoreServiceProvider_ = coreServiceProvider;
52 return SUCCESS;
53 }
54 AUDIO_ERR_LOG("Provider is already configed!");
55 return ERR_INVALID_OPERATION;
56 }
57
UpdateSessionOperation(uint32_t sessionId,SessionOperation operation,SessionOperationMsg opMsg)58 int32_t CoreServiceHandler::UpdateSessionOperation(uint32_t sessionId, SessionOperation operation,
59 SessionOperationMsg opMsg)
60 {
61 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
62 return iCoreServiceProvider_->UpdateSessionOperation(sessionId, operation, opMsg);
63 }
64
ReloadCaptureSession(uint32_t sessionId,SessionOperation operation)65 int32_t CoreServiceHandler::ReloadCaptureSession(uint32_t sessionId, SessionOperation operation)
66 {
67 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
68 return iCoreServiceProvider_->ReloadCaptureSession(sessionId, operation);
69 }
70
SetDefaultOutputDevice(const DeviceType defaultOutputDevice,const uint32_t sessionID,const StreamUsage streamUsage,bool isRunning,bool skipForce)71 int32_t CoreServiceHandler::SetDefaultOutputDevice(const DeviceType defaultOutputDevice, const uint32_t sessionID,
72 const StreamUsage streamUsage, bool isRunning, bool skipForce)
73 {
74 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
75 return iCoreServiceProvider_->SetDefaultOutputDevice(defaultOutputDevice, sessionID, streamUsage, isRunning,
76 skipForce);
77 }
78
GetAdapterNameBySessionId(uint32_t sessionId)79 std::string CoreServiceHandler::GetAdapterNameBySessionId(uint32_t sessionId)
80 {
81 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, "", "iCoreServiceProvider_ is nullptr!");
82 std::string ret{};
83 iCoreServiceProvider_->GetAdapterNameBySessionId(sessionId, ret);
84 return ret;
85 }
86
GetProcessDeviceInfoBySessionId(uint32_t sessionId,AudioDeviceDescriptor & deviceInfo,AudioStreamInfo & streamInfo,bool isReloadProcess)87 int32_t CoreServiceHandler::GetProcessDeviceInfoBySessionId(uint32_t sessionId, AudioDeviceDescriptor &deviceInfo,
88 AudioStreamInfo &streamInfo, bool isReloadProcess)
89 {
90 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
91 return iCoreServiceProvider_->GetProcessDeviceInfoBySessionId(sessionId, deviceInfo, streamInfo, isReloadProcess);
92 }
93
GenerateSessionId()94 uint32_t CoreServiceHandler::GenerateSessionId()
95 {
96 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
97 uint32_t ret{};
98 iCoreServiceProvider_->GenerateSessionId(ret);
99 return ret;
100 }
101
SetWakeUpAudioCapturerFromAudioServer(const AudioProcessConfig & config)102 int32_t CoreServiceHandler::SetWakeUpAudioCapturerFromAudioServer(const AudioProcessConfig &config)
103 {
104 CHECK_AND_RETURN_RET_LOG(iCoreServiceProvider_ != nullptr, ERROR, "iCoreServiceProvider_ is nullptr!");
105 int32_t ret = ERROR;
106 iCoreServiceProvider_->SetWakeUpAudioCapturerFromAudioServer(config, ret);
107 return ret;
108 }
109 } // namespace AudioStandard
110 } // namespace OHOS
111