• 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         default:
88             AUDIO_WARNING_LOG("OnRemoteRequest unsupported request code:%{public}d.", code);
89             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
90 }
91 }
92 
HandleResolveBuffer(MessageParcel & data,MessageParcel & reply)93 int32_t AudioProcessStub::HandleResolveBuffer(MessageParcel &data, MessageParcel &reply)
94 {
95     AUDIO_INFO_LOG("HandleResolveBuffer");
96     (void)data;
97     std::shared_ptr<OHAudioBuffer> buffer;
98     int32_t ret = ResolveBuffer(buffer);
99     reply.WriteInt32(ret);
100     if (ret == AUDIO_OK && buffer != nullptr) {
101         OHAudioBuffer::WriteToParcel(buffer, reply);
102     } else {
103         AUDIO_ERR_LOG("error: ResolveBuffer failed.");
104         return AUDIO_INVALID_PARAM;
105     }
106 
107     return AUDIO_OK;
108 }
109 
HandleGetSessionId(MessageParcel & data,MessageParcel & reply)110 int32_t AudioProcessStub::HandleGetSessionId(MessageParcel &data, MessageParcel &reply)
111 {
112     (void)data;
113     uint32_t sessionId = 0;
114     int32_t ret = GetSessionId(sessionId);
115     reply.WriteInt32(ret);
116     reply.WriteUint32(sessionId);
117     return AUDIO_OK;
118 }
119 
HandleStart(MessageParcel & data,MessageParcel & reply)120 int32_t AudioProcessStub::HandleStart(MessageParcel &data, MessageParcel &reply)
121 {
122     (void)data;
123     reply.WriteInt32(Start());
124     return AUDIO_OK;
125 }
126 
HandleResume(MessageParcel & data,MessageParcel & reply)127 int32_t AudioProcessStub::HandleResume(MessageParcel &data, MessageParcel &reply)
128 {
129     (void)data;
130     reply.WriteInt32(Resume());
131     return AUDIO_OK;
132 }
133 
HandlePause(MessageParcel & data,MessageParcel & reply)134 int32_t AudioProcessStub::HandlePause(MessageParcel &data, MessageParcel &reply)
135 {
136     bool isFlush = data.ReadBool();
137     reply.WriteInt32(Pause(isFlush));
138     return AUDIO_OK;
139 }
140 
HandleStop(MessageParcel & data,MessageParcel & reply)141 int32_t AudioProcessStub::HandleStop(MessageParcel &data, MessageParcel &reply)
142 {
143     (void)data;
144     reply.WriteInt32(Stop());
145     return AUDIO_OK;
146 }
147 
HandleRequestHandleInfo(MessageParcel & data,MessageParcel & reply)148 int32_t AudioProcessStub::HandleRequestHandleInfo(MessageParcel &data, MessageParcel &reply)
149 {
150     (void)data;
151     reply.WriteInt32(RequestHandleInfo());
152     return AUDIO_OK;
153 }
154 
HandleRelease(MessageParcel & data,MessageParcel & reply)155 int32_t AudioProcessStub::HandleRelease(MessageParcel &data, MessageParcel &reply)
156 {
157     bool isSwitchStream = data.ReadBool();
158     reply.WriteInt32(Release(isSwitchStream));
159     return AUDIO_OK;
160 }
161 
HandleRegisterProcessCb(MessageParcel & data,MessageParcel & reply)162 int32_t AudioProcessStub::HandleRegisterProcessCb(MessageParcel &data, MessageParcel &reply)
163 {
164     sptr<IRemoteObject> object = data.ReadRemoteObject();
165     CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_INVALID_PARAM, "obj is null");
166     reply.WriteInt32(RegisterProcessCb(object));
167     return AUDIO_OK;
168 }
169 
HandleRegisterThreadPriority(MessageParcel & data,MessageParcel & reply)170 int32_t AudioProcessStub::HandleRegisterThreadPriority(MessageParcel &data, MessageParcel &reply)
171 {
172     uint32_t tid = data.ReadUint32();
173     std::string bundleName = data.ReadString();
174     reply.WriteInt32(RegisterThreadPriority(tid, bundleName));
175     return AUDIO_OK;
176 }
177 } // namespace AudioStandard
178 } // namespace OHOS
179