1 /*
2 * Copyright (c) 2021-2022 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 "hcapture_session_proxy.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
HCaptureSessionProxy(const sptr<IRemoteObject> & impl)22 HCaptureSessionProxy::HCaptureSessionProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<ICaptureSession>(impl) { }
24
BeginConfig()25 int32_t HCaptureSessionProxy::BeginConfig()
26 {
27 MessageParcel data;
28 MessageParcel reply;
29 MessageOption option;
30
31 data.WriteInterfaceToken(GetDescriptor());
32 int error = Remote()->SendRequest(
33 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_BEGIN_CONFIG), data, reply, option);
34 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy BeginConfig failed, error: %{public}d", error);
35
36 return error;
37 }
38
CanAddInput(sptr<ICameraDeviceService> cameraDevice,bool & result)39 int32_t HCaptureSessionProxy::CanAddInput(sptr<ICameraDeviceService> cameraDevice, bool& result)
40 {
41 MessageParcel data;
42 MessageParcel reply;
43 MessageOption option;
44
45 CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_PROXY_ERR,
46 "HCaptureSessionProxy CanAddInput cameraDevice is null");
47
48 data.WriteInterfaceToken(GetDescriptor());
49 data.WriteRemoteObject(cameraDevice->AsObject());
50 (void)data.WriteBool(result);
51
52 int error = Remote()->SendRequest(
53 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_CAN_ADD_INPUT), data, reply, option);
54 CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
55 "HCaptureSessionProxy CanAddInput failed, error: %{public}d", error);
56 result = reply.ReadBool();
57 MEDIA_DEBUG_LOG("CanAddInput result is %{public}d", result);
58 return error;
59 }
60
AddInput(sptr<ICameraDeviceService> cameraDevice)61 int32_t HCaptureSessionProxy::AddInput(sptr<ICameraDeviceService> cameraDevice)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66
67 CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_PROXY_ERR,
68 "HCaptureSessionProxy AddInput cameraDevice is null");
69
70 data.WriteInterfaceToken(GetDescriptor());
71 data.WriteRemoteObject(cameraDevice->AsObject());
72
73 int error = Remote()->SendRequest(
74 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ADD_INPUT), data, reply, option);
75 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy AddInput failed, error: %{public}d", error);
76
77 return error;
78 }
79
AddOutput(StreamType streamType,sptr<IStreamCommon> stream)80 int32_t HCaptureSessionProxy::AddOutput(StreamType streamType, sptr<IStreamCommon> stream)
81 {
82 MessageParcel data;
83 MessageParcel reply;
84 MessageOption option;
85
86 CHECK_ERROR_RETURN_RET_LOG(stream == nullptr, IPC_PROXY_ERR, "HCaptureSessionProxy AddOutput stream is null");
87
88 data.WriteInterfaceToken(GetDescriptor());
89 data.WriteUint32(static_cast<uint32_t>(streamType));
90 data.WriteRemoteObject(stream->AsObject());
91
92 int error = Remote()->SendRequest(
93 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ADD_OUTPUT), data, reply, option);
94 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy AddOutput failed, error: %{public}d", error);
95
96 return error;
97 }
98
RemoveInput(sptr<ICameraDeviceService> cameraDevice)99 int32_t HCaptureSessionProxy::RemoveInput(sptr<ICameraDeviceService> cameraDevice)
100 {
101 MessageParcel data;
102 MessageParcel reply;
103 MessageOption option;
104
105 CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_PROXY_ERR,
106 "HCaptureSessionProxy RemoveInput cameraDevice is null");
107
108 data.WriteInterfaceToken(GetDescriptor());
109 data.WriteRemoteObject(cameraDevice->AsObject());
110
111 int error = Remote()->SendRequest(
112 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_REMOVE_INPUT), data, reply, option);
113 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy RemoveInput failed, error: %{public}d", error);
114
115 return error;
116 }
117
RemoveOutput(StreamType streamType,sptr<IStreamCommon> stream)118 int32_t HCaptureSessionProxy::RemoveOutput(StreamType streamType, sptr<IStreamCommon> stream)
119 {
120 MessageParcel data;
121 MessageParcel reply;
122 MessageOption option;
123
124 CHECK_ERROR_RETURN_RET_LOG(stream == nullptr, IPC_PROXY_ERR, "HCaptureSessionProxy RemoveOutput stream is null");
125
126 data.WriteInterfaceToken(GetDescriptor());
127 data.WriteUint32(static_cast<uint32_t>(streamType));
128 data.WriteRemoteObject(stream->AsObject());
129
130 int error = Remote()->SendRequest(
131 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_REMOVE_OUTPUT), data, reply, option);
132 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy RemoveOutput failed, error: %{public}d", error);
133
134 return error;
135 }
136
CommitConfig()137 int32_t HCaptureSessionProxy::CommitConfig()
138 {
139 MessageParcel data;
140 MessageParcel reply;
141 MessageOption option;
142
143 data.WriteInterfaceToken(GetDescriptor());
144 int error = Remote()->SendRequest(
145 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_COMMIT_CONFIG), data, reply, option);
146 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy CommitConfig failed, error: %{public}d", error);
147
148 return error;
149 }
150
Start()151 int32_t HCaptureSessionProxy::Start()
152 {
153 MessageParcel data;
154 MessageParcel reply;
155 MessageOption option;
156
157 data.WriteInterfaceToken(GetDescriptor());
158 int error = Remote()->SendRequest(
159 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_START), data, reply, option);
160 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy Start failed, error: %{public}d", error);
161
162 return error;
163 }
164
Stop()165 int32_t HCaptureSessionProxy::Stop()
166 {
167 MessageParcel data;
168 MessageParcel reply;
169 MessageOption option;
170
171 data.WriteInterfaceToken(GetDescriptor());
172 int error = Remote()->SendRequest(
173 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_STOP), data, reply, option);
174 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy Stop failed, error: %{public}d", error);
175
176 return error;
177 }
178
Release()179 int32_t HCaptureSessionProxy::Release()
180 {
181 MessageParcel data;
182 MessageParcel reply;
183 MessageOption option;
184
185 data.WriteInterfaceToken(GetDescriptor());
186 int error = Remote()->SendRequest(
187 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_RELEASE), data, reply, option);
188 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy Release failed, error: %{public}d", error);
189
190 return error;
191 }
192
SetCallback(sptr<ICaptureSessionCallback> & callback)193 int32_t HCaptureSessionProxy::SetCallback(sptr<ICaptureSessionCallback> &callback)
194 {
195 MessageParcel data;
196 MessageParcel reply;
197 MessageOption option;
198
199 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR,
200 "HCaptureSessionProxy SetCallback callback is null");
201
202 data.WriteInterfaceToken(GetDescriptor());
203 data.WriteRemoteObject(callback->AsObject());
204
205 int error = Remote()->SendRequest(
206 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_CALLBACK), data, reply, option);
207 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy SetCallback failed, error: %{public}d", error);
208
209 return error;
210 }
211
UnSetCallback()212 int32_t HCaptureSessionProxy::UnSetCallback()
213 {
214 MessageParcel data;
215 MessageParcel reply;
216 MessageOption option;
217 data.WriteInterfaceToken(GetDescriptor());
218 int error = Remote()->SendRequest(
219 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_UNSET_CALLBACK), data, reply, option);
220 if (error != ERR_NONE) {
221 MEDIA_ERR_LOG("HCaptureSessionProxy UnSetCallback failed, error: %{public}d", error);
222 }
223 return error;
224 }
225
GetSessionState(CaptureSessionState & sessionState)226 int32_t HCaptureSessionProxy::GetSessionState(CaptureSessionState &sessionState)
227 {
228 MessageParcel data;
229 MessageParcel reply;
230 MessageOption option;
231
232 data.WriteInterfaceToken(GetDescriptor());
233 int32_t res = Remote()->SendRequest(
234 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_GET_SESSION_STATE), data, reply, option);
235 CHECK_ERROR_RETURN_RET_LOG(res != ERR_NONE, res,
236 "HCaptureSessionProxy GetSessionState failed, error: %{public}d", res);
237 sessionState = static_cast<CaptureSessionState>(reply.ReadUint32());
238 return res;
239 }
240
GetActiveColorSpace(ColorSpace & colorSpace)241 int32_t HCaptureSessionProxy::GetActiveColorSpace(ColorSpace& colorSpace)
242 {
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option;
246
247 data.WriteInterfaceToken(GetDescriptor());
248 int error = Remote()->SendRequest(
249 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_GET_ACTIVE_COLOR_SPACE), data, reply, option);
250 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
251 "HCaptureSessionProxy GetActiveColorSpace failed, error: %{public}d", error);
252 colorSpace = static_cast<ColorSpace>(reply.ReadInt32());
253 return error;
254 }
255
SetColorSpace(ColorSpace colorSpace,bool isNeedUpdate)256 int32_t HCaptureSessionProxy::SetColorSpace(ColorSpace colorSpace, bool isNeedUpdate)
257 {
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option;
261
262 data.WriteInterfaceToken(GetDescriptor());
263 data.WriteInt32(static_cast<int32_t>(colorSpace));
264 data.WriteBool(isNeedUpdate);
265
266 int error = Remote()->SendRequest(
267 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SET_COLOR_SPACE), data, reply, option);
268 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy SetCallback failed, error: %{public}d", error);
269 return error;
270 }
271
SetSmoothZoom(int32_t mode,int32_t operationMode,float targetZoomRatio,float & duration)272 int32_t HCaptureSessionProxy::SetSmoothZoom(int32_t mode, int32_t operationMode, float targetZoomRatio, float &duration)
273 {
274 MessageParcel data;
275 MessageParcel reply;
276 MessageOption option;
277
278 data.WriteInterfaceToken(GetDescriptor());
279 data.WriteUint32(static_cast<uint32_t>(mode));
280 data.WriteUint32(static_cast<uint32_t>(operationMode));
281 data.WriteFloat(targetZoomRatio);
282 int error = Remote()->SendRequest(
283 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_SMOOTH_ZOOM),
284 data, reply, option);
285 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy set smooth zoom failed, error: %{public}d", error);
286 duration = reply.ReadFloat();
287 return error;
288 }
289
SetFeatureMode(int32_t featureMode)290 int32_t HCaptureSessionProxy::SetFeatureMode(int32_t featureMode)
291 {
292 MessageParcel data;
293 MessageParcel reply;
294 MessageOption option;
295
296 data.WriteInterfaceToken(GetDescriptor());
297 data.WriteInt32(static_cast<int32_t>(featureMode));
298
299 int error = Remote()->SendRequest(
300 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_FEATURE_MODE), data, reply,
301 option);
302 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy SetFeatureMode failed, error: %{public}d", error);
303 return error;
304 }
305
EnableMovingPhoto(bool isEnable)306 int32_t HCaptureSessionProxy::EnableMovingPhoto(bool isEnable)
307 {
308 MessageParcel data;
309 MessageParcel reply;
310 MessageOption option;
311
312 data.WriteInterfaceToken(GetDescriptor());
313 data.WriteBool(isEnable);
314 int error = Remote()->SendRequest(
315 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ENABLE_MOTION_PHOTO),
316 data, reply, option);
317 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
318 "HCaptureSessionProxy enable moving photo failed, error: %{public}d", error);
319 return error;
320 }
321
EnableMovingPhotoMirror(bool isMirror,bool isConfig)322 int32_t HCaptureSessionProxy::EnableMovingPhotoMirror(bool isMirror, bool isConfig)
323 {
324 MessageParcel data;
325 MessageParcel reply;
326 MessageOption option;
327
328 data.WriteInterfaceToken(GetDescriptor());
329 data.WriteBool(isMirror);
330 data.WriteBool(isConfig);
331 int error = Remote()->SendRequest(
332 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_START_MOVING_PHOTO_CAPTURE),
333 data, reply, option);
334 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCaptureSessionProxy start moving capture, error: %{public}d", error);
335 return error;
336 }
337
SetPreviewRotation(std::string & deviceClass)338 int32_t HCaptureSessionProxy::SetPreviewRotation(std::string &deviceClass)
339 {
340 MessageParcel data;
341 MessageParcel reply;
342 MessageOption option;
343
344 data.WriteInterfaceToken(GetDescriptor());
345 data.WriteString(deviceClass);
346 int error = Remote()->SendRequest(
347 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_PREVIEW_ROTATE),
348 data, reply, option);
349 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
350 "HCaptureSessionProxy SetPreviewRotation failed, error: %{public}d", error);
351 return error;
352 }
353
SetCommitConfigFlag(bool isNeedCommitting)354 int32_t HCaptureSessionProxy::SetCommitConfigFlag(bool isNeedCommitting)
355 {
356 MessageParcel data;
357 MessageParcel reply;
358 MessageOption option;
359
360 data.WriteInterfaceToken(GetDescriptor());
361 data.WriteBool(isNeedCommitting);
362 int error = Remote()->SendRequest(
363 static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_COMMIT_CONFIG_FLAG),
364 data, reply, option);
365 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
366 "HCaptureSessionProxy SetCommitConfigFlag failed, error: %{public}d", error);
367 return error;
368 }
369 } // namespace CameraStandard
370 } // namespace OHOS
371