• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "AudioProcessStub"
17 #endif
18 
19 #include "audio_process_stub.h"
20 #include "audio_service_log.h"
21 #include "audio_errors.h"
22 #include "audio_utils.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
ProcessCbProxy(const sptr<IRemoteObject> & impl)26 ProcessCbProxy::ProcessCbProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IProcessCb>(impl)
27 {
28 }
29 
~ProcessCbProxy()30 ProcessCbProxy::~ProcessCbProxy()
31 {
32 }
33 
OnEndpointChange(int32_t status)34 int32_t ProcessCbProxy::OnEndpointChange(int32_t status)
35 {
36     MessageParcel data;
37     MessageParcel reply;
38     MessageOption option;
39 
40     CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_OPERATION_FAILED,
41         "Write descriptor failed!");
42 
43     data.WriteInt32(status);
44     int ret = Remote()->SendRequest(IProcessCbMsg::ON_ENDPOINT_CHANGE, data, reply, option);
45     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ERR_OPERATION_FAILED, "OnEndpointChange failed, error: %{public}d", ret);
46     return reply.ReadInt32();
47 }
48 
CheckInterfaceToken(MessageParcel & data)49 bool AudioProcessStub::CheckInterfaceToken(MessageParcel &data)
50 {
51     static auto localDescriptor = IAudioProcess::GetDescriptor();
52     auto remoteDescriptor = data.ReadInterfaceToken();
53     CHECK_AND_RETURN_RET_LOG(remoteDescriptor == localDescriptor, false, "CheckInterFfaceToken failed.");
54     return true;
55 }
56 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)57 int AudioProcessStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
58 {
59     bool ret = CheckInterfaceToken(data);
60     CHECK_AND_RETURN_RET(ret, AUDIO_ERR);
61     Trace trace("AudioProcess::Handle::" + std::to_string(code));
62     if (code >= IAudioProcessMsg::PROCESS_MAX_MSG) {
63         AUDIO_WARNING_LOG("OnRemoteRequest unsupported request code:%{public}d.", code);
64         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65     }
66     switch (code) {
67         case ON_RESOLVE_BUFFER:
68             return HandleResolveBuffer(data, reply);
69         case OH_GET_SESSIONID:
70             return HandleGetSessionId(data, reply);
71         case ON_START:
72             return HandleStart(data, reply);
73         case ON_PAUSE:
74             return HandlePause(data, reply);
75         case ON_RESUME:
76             return HandleResume(data, reply);
77         case ON_STOP:
78             return HandleStop(data, reply);
79         case ON_REQUEST_HANDLE_INFO:
80             return HandleRequestHandleInfo(data, reply);
81         case ON_RELEASE:
82             return HandleRelease(data, reply);
83         case ON_REGISTER_PROCESS_CB:
84             return HandleRegisterProcessCb(data, reply);
85         case ON_REGISTER_THREAD_PRIORITY:
86             return HandleRegisterThreadPriority(data, reply);
87         case ON_SET_DEFAULT_OUTPUT_DEVICE:
88             return HandleSetDefaultOutputDevice(data, reply);
89         case ON_SET_SLITNT_MODE_AND_MIX_WITH_OTHERS:
90             return HandleSetSlientModeAndMixWithOther(data, reply);
91         case ON_SET_SOURCE_DURATION:
92             return HandleSetSourceDuration(data, reply);
93         case ON_SET_UNDERRUN_CNT:
94             return HandleSetUnderrunCount(data, reply);
95         default:
96             AUDIO_WARNING_LOG("OnRemoteRequest unsupported request code:%{public}d.", code);
97             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
98 }
99 }
100 
HandleResolveBuffer(MessageParcel & data,MessageParcel & reply)101 int32_t AudioProcessStub::HandleResolveBuffer(MessageParcel &data, MessageParcel &reply)
102 {
103     AUDIO_INFO_LOG("HandleResolveBuffer");
104     (void)data;
105     std::shared_ptr<OHAudioBuffer> buffer;
106     int32_t ret = ResolveBuffer(buffer);
107     reply.WriteInt32(ret);
108     if (ret == AUDIO_OK && buffer != nullptr) {
109         OHAudioBuffer::WriteToParcel(buffer, reply);
110     } else {
111         AUDIO_ERR_LOG("error: ResolveBuffer failed.");
112         return AUDIO_INVALID_PARAM;
113     }
114 
115     return AUDIO_OK;
116 }
117 
HandleGetSessionId(MessageParcel & data,MessageParcel & reply)118 int32_t AudioProcessStub::HandleGetSessionId(MessageParcel &data, MessageParcel &reply)
119 {
120     (void)data;
121     uint32_t sessionId = 0;
122     int32_t ret = GetSessionId(sessionId);
123     reply.WriteInt32(ret);
124     reply.WriteUint32(sessionId);
125     return AUDIO_OK;
126 }
127 
HandleStart(MessageParcel & data,MessageParcel & reply)128 int32_t AudioProcessStub::HandleStart(MessageParcel &data, MessageParcel &reply)
129 {
130     (void)data;
131     reply.WriteInt32(Start());
132     return AUDIO_OK;
133 }
134 
HandleResume(MessageParcel & data,MessageParcel & reply)135 int32_t AudioProcessStub::HandleResume(MessageParcel &data, MessageParcel &reply)
136 {
137     (void)data;
138     reply.WriteInt32(Resume());
139     return AUDIO_OK;
140 }
141 
HandlePause(MessageParcel & data,MessageParcel & reply)142 int32_t AudioProcessStub::HandlePause(MessageParcel &data, MessageParcel &reply)
143 {
144     bool isFlush = data.ReadBool();
145     reply.WriteInt32(Pause(isFlush));
146     return AUDIO_OK;
147 }
148 
HandleStop(MessageParcel & data,MessageParcel & reply)149 int32_t AudioProcessStub::HandleStop(MessageParcel &data, MessageParcel &reply)
150 {
151     (void)data;
152     reply.WriteInt32(Stop());
153     return AUDIO_OK;
154 }
155 
HandleRequestHandleInfo(MessageParcel & data,MessageParcel & reply)156 int32_t AudioProcessStub::HandleRequestHandleInfo(MessageParcel &data, MessageParcel &reply)
157 {
158     (void)data;
159     reply.WriteInt32(RequestHandleInfo());
160     return AUDIO_OK;
161 }
162 
HandleRelease(MessageParcel & data,MessageParcel & reply)163 int32_t AudioProcessStub::HandleRelease(MessageParcel &data, MessageParcel &reply)
164 {
165     bool isSwitchStream = data.ReadBool();
166     reply.WriteInt32(Release(isSwitchStream));
167     return AUDIO_OK;
168 }
169 
HandleRegisterProcessCb(MessageParcel & data,MessageParcel & reply)170 int32_t AudioProcessStub::HandleRegisterProcessCb(MessageParcel &data, MessageParcel &reply)
171 {
172     sptr<IRemoteObject> object = data.ReadRemoteObject();
173     CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_INVALID_PARAM, "obj is null");
174     reply.WriteInt32(RegisterProcessCb(object));
175     return AUDIO_OK;
176 }
177 
HandleRegisterThreadPriority(MessageParcel & data,MessageParcel & reply)178 int32_t AudioProcessStub::HandleRegisterThreadPriority(MessageParcel &data, MessageParcel &reply)
179 {
180     uint32_t tid = data.ReadUint32();
181     std::string bundleName = data.ReadString();
182     reply.WriteInt32(RegisterThreadPriority(tid, bundleName));
183     return AUDIO_OK;
184 }
185 
HandleSetDefaultOutputDevice(MessageParcel & data,MessageParcel & reply)186 int32_t AudioProcessStub::HandleSetDefaultOutputDevice(MessageParcel &data, MessageParcel &reply)
187 {
188     int32_t deviceType = data.ReadInt32();
189     reply.WriteInt32(SetDefaultOutputDevice(static_cast<OHOS::AudioStandard::DeviceType>(deviceType)));
190     return AUDIO_OK;
191 }
192 
HandleSetSlientModeAndMixWithOther(MessageParcel & data,MessageParcel & reply)193 int32_t AudioProcessStub::HandleSetSlientModeAndMixWithOther(MessageParcel &data, MessageParcel &reply)
194 {
195     bool on = data.ReadBool();
196     reply.WriteInt32(SetSilentModeAndMixWithOthers(on));
197     return AUDIO_OK;
198 }
199 
HandleSetSourceDuration(MessageParcel & data,MessageParcel & reply)200 int32_t AudioProcessStub::HandleSetSourceDuration(MessageParcel &data, MessageParcel &reply)
201 {
202     int64_t duration = data.ReadInt64();
203     reply.WriteInt32(SetSourceDuration(duration));
204     return AUDIO_OK;
205 }
206 
HandleSetUnderrunCount(MessageParcel & data,MessageParcel & reply)207 int32_t AudioProcessStub::HandleSetUnderrunCount(MessageParcel &data, MessageParcel &reply)
208 {
209     uint32_t underrunCnt = data.ReadUint32();
210     reply.WriteInt32(SetUnderrunCount(underrunCnt));
211     return AUDIO_OK;
212 }
213 } // namespace AudioStandard
214 } // namespace OHOS
215