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
16 #include "audio_process_stub.h"
17 #include "audio_log.h"
18 #include "audio_errors.h"
19
20 namespace OHOS {
21 namespace AudioStandard {
ProcessCbProxy(const sptr<IRemoteObject> & impl)22 ProcessCbProxy::ProcessCbProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IProcessCb>(impl)
23 {
24 AUDIO_INFO_LOG("ProcessCbProxy()");
25 }
26
~ProcessCbProxy()27 ProcessCbProxy::~ProcessCbProxy()
28 {
29 AUDIO_INFO_LOG("~ProcessCbProxy()");
30 }
31
OnEndpointChange(int32_t status)32 int32_t ProcessCbProxy::OnEndpointChange(int32_t status)
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option;
37
38 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_OPERATION_FAILED,
39 "Write descriptor failed!");
40
41 data.WriteInt32(status);
42 int ret = Remote()->SendRequest(IProcessCbMsg::ON_ENDPOINT_CHANGE, data, reply, option);
43 CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ERR_OPERATION_FAILED, "OnEndpointChange failed, error: %{public}d", ret);
44 return reply.ReadInt32();
45 }
46
CheckInterfaceToken(MessageParcel & data)47 bool AudioProcessStub::CheckInterfaceToken(MessageParcel &data)
48 {
49 static auto localDescriptor = IAudioProcess::GetDescriptor();
50 auto remoteDescriptor = data.ReadInterfaceToken();
51 if (remoteDescriptor != localDescriptor) {
52 AUDIO_ERR_LOG("CheckInterFfaceToken failed.");
53 return false;
54 }
55 return true;
56 }
57
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)58 int AudioProcessStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
59 {
60 if (!CheckInterfaceToken(data)) {
61 return AUDIO_ERR;
62 }
63 if (code >= IAudioProcessMsg::PROCESS_MAX_MSG) {
64 AUDIO_WARNING_LOG("OnRemoteRequest unsupported request code:%{public}d.", code);
65 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67 return (this->*funcList_[code])(data, reply);
68 }
69
HandleResolveBuffer(MessageParcel & data,MessageParcel & reply)70 int32_t AudioProcessStub::HandleResolveBuffer(MessageParcel &data, MessageParcel &reply)
71 {
72 (void)data;
73 std::shared_ptr<OHAudioBuffer> buffer;
74 int32_t ret = ResolveBuffer(buffer);
75 reply.WriteInt32(ret);
76 if (ret == AUDIO_OK && buffer != nullptr) {
77 OHAudioBuffer::WriteToParcel(buffer, reply);
78 } else {
79 AUDIO_ERR_LOG("error: ResolveBuffer failed.");
80 return AUDIO_INVALID_PARAM;
81 }
82
83 return AUDIO_OK;
84 }
85
HandleStart(MessageParcel & data,MessageParcel & reply)86 int32_t AudioProcessStub::HandleStart(MessageParcel &data, MessageParcel &reply)
87 {
88 (void)data;
89 reply.WriteInt32(Start());
90 return AUDIO_OK;
91 }
92
HandleResume(MessageParcel & data,MessageParcel & reply)93 int32_t AudioProcessStub::HandleResume(MessageParcel &data, MessageParcel &reply)
94 {
95 (void)data;
96 reply.WriteInt32(Resume());
97 return AUDIO_OK;
98 }
99
HandlePause(MessageParcel & data,MessageParcel & reply)100 int32_t AudioProcessStub::HandlePause(MessageParcel &data, MessageParcel &reply)
101 {
102 bool isFlush = data.ReadBool();
103 reply.WriteInt32(Pause(isFlush));
104 return AUDIO_OK;
105 }
106
HandleStop(MessageParcel & data,MessageParcel & reply)107 int32_t AudioProcessStub::HandleStop(MessageParcel &data, MessageParcel &reply)
108 {
109 (void)data;
110 reply.WriteInt32(Stop());
111 return AUDIO_OK;
112 }
113
HandleRequestHandleInfo(MessageParcel & data,MessageParcel & reply)114 int32_t AudioProcessStub::HandleRequestHandleInfo(MessageParcel &data, MessageParcel &reply)
115 {
116 (void)data;
117 reply.WriteInt32(RequestHandleInfo());
118 return AUDIO_OK;
119 }
120
HandleRelease(MessageParcel & data,MessageParcel & reply)121 int32_t AudioProcessStub::HandleRelease(MessageParcel &data, MessageParcel &reply)
122 {
123 (void)data;
124 reply.WriteInt32(Release());
125 return AUDIO_OK;
126 }
127
HandleRegisterProcessCb(MessageParcel & data,MessageParcel & reply)128 int32_t AudioProcessStub::HandleRegisterProcessCb(MessageParcel &data, MessageParcel &reply)
129 {
130 sptr<IRemoteObject> object = data.ReadRemoteObject();
131 if (object == nullptr) {
132 AUDIO_ERR_LOG("AudioProcessStub: HandleRegisterProcessCb obj is null");
133 return AUDIO_INVALID_PARAM;
134 }
135 reply.WriteInt32(RegisterProcessCb(object));
136 return AUDIO_OK;
137 }
138 } // namespace AudioStandard
139 } // namespace OHOS
140