• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "OfflineStreamInClient"
17 #endif
18 
19 #include "offline_stream_in_client.h"
20 
21 #include <mutex>
22 
23 #include "ipc_skeleton.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26 
27 #include "audio_manager_base.h"
28 #include "audio_service_log.h"
29 #include "audio_errors.h"
30 #include "istandard_audio_service.h"
31 
32 using namespace std;
33 
34 namespace OHOS {
35 namespace AudioStandard {
36 namespace {
37 mutex g_audioServerProxyMutex;
38 sptr<IStandardAudioService> gAudioServerProxy = nullptr;
GetAudioServerProxy()39 static const sptr<IStandardAudioService> GetAudioServerProxy()
40 {
41     lock_guard<mutex> lock(g_audioServerProxyMutex);
42     if (gAudioServerProxy == nullptr) {
43         auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
44         CHECK_AND_RETURN_RET_LOG(samgr != nullptr, nullptr, "get sa manager failed");
45         sptr<IRemoteObject> object = samgr->GetSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID);
46         CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "get audio service remote object failed");
47         gAudioServerProxy = iface_cast<IStandardAudioService>(object);
48         CHECK_AND_RETURN_RET_LOG(gAudioServerProxy != nullptr, nullptr, "get audio service proxy failed");
49     }
50     sptr<IStandardAudioService> gasp = gAudioServerProxy;
51     return gasp;
52 }
53 }
54 
Create()55 shared_ptr<OfflineStreamInClient> OfflineStreamInClient::Create()
56 {
57     sptr<IStandardAudioService> gasp = GetAudioServerProxy();
58     CHECK_AND_RETURN_RET_LOG(gasp != nullptr, nullptr, "Create failed, can not get service.");
59     int32_t errCode = 0;
60     sptr<IRemoteObject> ipcProxy;
61     gasp->CreateIpcOfflineStream(errCode, ipcProxy);
62     CHECK_AND_RETURN_RET_LOG(errCode == 0, nullptr, "create audio stream fail, errcode is %{public}d.", errCode);
63     CHECK_AND_RETURN_RET_LOG(ipcProxy != nullptr, nullptr, "Create failed with null ipcProxy.");
64     sptr<IIpcOfflineStream> iOfflineStreamProxy = iface_cast<IIpcOfflineStream>(ipcProxy);
65     CHECK_AND_RETURN_RET_LOG(iOfflineStreamProxy != nullptr, nullptr, "Create failed when iface_cast.");
66     shared_ptr<OfflineStreamInClient> stream = make_shared<OfflineStreamInClient>(iOfflineStreamProxy);
67     return stream;
68 }
69 
GetOfflineAudioEffectChains(std::vector<std::string> & effectChains)70 int32_t OfflineStreamInClient::GetOfflineAudioEffectChains(std::vector<std::string> &effectChains)
71 {
72     sptr<IStandardAudioService> gasp = GetAudioServerProxy();
73     CHECK_AND_RETURN_RET_LOG(gasp != nullptr, ERR_OPERATION_FAILED, "Create failed, can not get service.");
74     return gasp->GetOfflineAudioEffectChains(effectChains);
75 }
76 
OfflineStreamInClient(const sptr<IIpcOfflineStream> & ipcProxy)77 OfflineStreamInClient::OfflineStreamInClient(const sptr<IIpcOfflineStream> &ipcProxy) : streamProxy_(ipcProxy) {}
78 
79 #ifdef FEATURE_OFFLINE_EFFECT
CreateOfflineEffectChain(const std::string & effectName)80 int32_t OfflineStreamInClient::CreateOfflineEffectChain(const std::string &effectName) //TEST
81 {
82     CHECK_AND_RETURN_RET_LOG(streamProxy_ != nullptr, ERR_OPERATION_FAILED, "Create failed with null ipcProxy.");
83     return streamProxy_->CreateOfflineEffectChain(effectName);
84 }
85 
ConfigureOfflineEffectChain(const AudioStreamInfo & inInfo,const AudioStreamInfo & outInfo)86 int32_t OfflineStreamInClient::ConfigureOfflineEffectChain(const AudioStreamInfo &inInfo,
87     const AudioStreamInfo &outInfo)
88 {
89     CHECK_AND_RETURN_RET_LOG(streamProxy_ != nullptr, ERR_OPERATION_FAILED, "Configure failed with null ipcProxy.");
90     return streamProxy_->ConfigureOfflineEffectChain(inInfo, outInfo);
91 }
92 
SetParamOfflineEffectChain(const std::vector<uint8_t> & param)93 int32_t OfflineStreamInClient::SetParamOfflineEffectChain(const std::vector<uint8_t> &param)
94 {
95     CHECK_AND_RETURN_RET_LOG(streamProxy_ != nullptr, ERR_OPERATION_FAILED, "Set parameter failed with null ipcProxy.");
96     return streamProxy_->SetParamOfflineEffectChain(param);
97 }
98 
PrepareOfflineEffectChain(std::shared_ptr<AudioSharedMemory> & clientInBuffer,std::shared_ptr<AudioSharedMemory> & clientOutBuffer)99 int32_t OfflineStreamInClient::PrepareOfflineEffectChain(std::shared_ptr<AudioSharedMemory> &clientInBuffer,
100     std::shared_ptr<AudioSharedMemory> &clientOutBuffer)
101 {
102     CHECK_AND_RETURN_RET_LOG(streamProxy_ != nullptr, ERR_OPERATION_FAILED, "Prepare failed with null ipcProxy.");
103     return streamProxy_->PrepareOfflineEffectChain(clientInBuffer, clientOutBuffer);
104 }
105 
ProcessOfflineEffectChain(uint32_t inputSize,uint32_t outputSize)106 int32_t OfflineStreamInClient::ProcessOfflineEffectChain(uint32_t inputSize, uint32_t outputSize)
107 {
108     CHECK_AND_RETURN_RET_LOG(streamProxy_ != nullptr, ERR_OPERATION_FAILED, "Process failed with null ipcProxy.");
109     return streamProxy_->ProcessOfflineEffectChain(inputSize, outputSize);
110 }
111 
ReleaseOfflineEffectChain()112 void OfflineStreamInClient::ReleaseOfflineEffectChain()
113 {
114     CHECK_AND_RETURN_LOG(streamProxy_ != nullptr, "Release failed with null ipcProxy.");
115     streamProxy_->ReleaseOfflineEffectChain();
116 }
117 #endif
118 } // namespace AudioStandard
119 } // namespace OHOS
120