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 "hcamera_service_proxy.h"
17 #include "camera_log.h"
18 #include "metadata_utils.h"
19 #include "camera_service_ipc_interface_code.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
HCameraProxy(const sptr<IRemoteObject> & impl)23 HCameraProxy::HCameraProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<ICameraBroker>(impl) { }
25 
NotifyCloseCamera(std::string cameraId)26 int32_t HCameraProxy::NotifyCloseCamera(std::string cameraId)
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option;
31 
32     data.WriteInterfaceToken(GetDescriptor());
33     data.WriteString(cameraId);
34     option.SetFlags(option.TF_SYNC);
35     int error = Remote()->SendRequest(
36         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_NOTIFY_CLOSE_CAMERA), data, reply, option);
37     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy notifyCloseCamera failed, error: %{public}d", error);
38     MEDIA_DEBUG_LOG("HCameraServiceProxy notifyCloseCamera");
39 
40     return error;
41 }
42 
NotifyMuteCamera(bool muteMode)43 int32_t HCameraProxy::NotifyMuteCamera(bool muteMode)
44 {
45     MessageParcel data;
46     MessageParcel reply;
47     MessageOption option;
48 
49     data.WriteInterfaceToken(GetDescriptor());
50     data.WriteBool(muteMode);
51     option.SetFlags(option.TF_SYNC);
52     int error = Remote()->SendRequest(
53         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_NOTIFY_MUTE_CAMERA), data, reply, option);
54     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy NotifyMuteCamera failed, error: %{public}d", error);
55     MEDIA_DEBUG_LOG("HCameraServiceProxy NotifyMuteCamera");
56 
57     return error;
58 }
59 
HCameraServiceProxy(const sptr<IRemoteObject> & impl)60 HCameraServiceProxy::HCameraServiceProxy(const sptr<IRemoteObject> &impl)
61     : IRemoteProxy<ICameraService>(impl) { }
62 
GetCameras(std::vector<std::string> & cameraIds,std::vector<std::shared_ptr<Camera::CameraMetadata>> & cameraAbilityList)63 int32_t HCameraServiceProxy::GetCameras(std::vector<std::string> &cameraIds,
64     std::vector<std::shared_ptr<Camera::CameraMetadata>> &cameraAbilityList)
65 {
66     MessageParcel data;
67     MessageParcel reply;
68     MessageOption option;
69     constexpr int32_t MAX_SUPPORTED_CAMERAS = 100;
70 
71     data.WriteInterfaceToken(GetDescriptor());
72     int error = Remote()->SendRequest(
73         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_GET_CAMERAS), data, reply, option);
74     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
75         "HCameraServiceProxy GetCameras failed, error: %{public}d", error);
76 
77     reply.ReadStringVector(&cameraIds);
78     int32_t count = reply.ReadInt32();
79     CHECK_ERROR_RETURN_RET_LOG((cameraIds.size() != static_cast<uint32_t>(count)) || (count > MAX_SUPPORTED_CAMERAS),
80         IPC_PROXY_ERR, "HCameraServiceProxy GetCameras Malformed camera count value");
81 
82     std::shared_ptr<Camera::CameraMetadata> cameraAbility;
83     for (int i = 0; i < count; i++) {
84         Camera::MetadataUtils::DecodeCameraMetadata(reply, cameraAbility);
85         cameraAbilityList.emplace_back(cameraAbility);
86     }
87 
88     return error;
89 }
90 
GetCameraIds(std::vector<std::string> & cameraIds)91 int32_t HCameraServiceProxy::GetCameraIds(std::vector<std::string> &cameraIds)
92 {
93     MessageParcel data;
94     MessageParcel reply;
95     MessageOption option;
96     constexpr int32_t MAX_SUPPORTED_CAMERAS = 100;
97 
98     data.WriteInterfaceToken(GetDescriptor());
99     int error = Remote()->SendRequest(
100         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_GET_CAMERA_IDS), data, reply, option);
101     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
102         "HCameraServiceProxy GetCameraIds failed, error: %{public}d", error);
103 
104     reply.ReadStringVector(&cameraIds);
105     int32_t count = reply.ReadInt32();
106     CHECK_ERROR_RETURN_RET_LOG((cameraIds.size() != static_cast<uint32_t>(count)) || (count > MAX_SUPPORTED_CAMERAS),
107         IPC_PROXY_ERR, "HCameraServiceProxy GetCameraIds Malformed camera count: %{public}d", count);
108 
109     return error;
110 }
111 
GetCameraAbility(std::string & cameraId,std::shared_ptr<Camera::CameraMetadata> & cameraAbility)112 int32_t HCameraServiceProxy::GetCameraAbility(std::string &cameraId,
113     std::shared_ptr<Camera::CameraMetadata> &cameraAbility)
114 {
115     MessageParcel data;
116     MessageParcel reply;
117     MessageOption option;
118 
119     data.WriteInterfaceToken(GetDescriptor());
120     data.WriteString(cameraId);
121     int error = Remote()->SendRequest(
122         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_GET_CAMERA_ABILITY), data, reply, option);
123     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
124         "HCameraServiceProxy GetCameraAbility failed, error: %{public}d", error);
125 
126     Camera::MetadataUtils::DecodeCameraMetadata(reply, cameraAbility);
127 
128     return error;
129 }
130 
CreateCameraDevice(std::string cameraId,sptr<ICameraDeviceService> & device)131 int32_t HCameraServiceProxy::CreateCameraDevice(std::string cameraId, sptr<ICameraDeviceService> &device)
132 {
133     MessageParcel data;
134     MessageParcel reply;
135     MessageOption option;
136 
137     data.WriteInterfaceToken(GetDescriptor());
138     data.WriteString(cameraId);
139 
140     int error = Remote()->SendRequest(
141         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_DEVICE), data, reply, option);
142     if (error != ERR_NONE) {
143         MEDIA_ERR_LOG("HCameraServiceProxy CreateCameraDevice failed, error: %{public}d", error);
144         return error;
145     }
146 
147     auto remoteObject = reply.ReadRemoteObject();
148     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
149         "HCameraServiceProxy CreateCameraDevice CameraDevice is null");
150     device = iface_cast<ICameraDeviceService>(remoteObject);
151 
152     return error;
153 }
154 
SetCameraCallback(sptr<ICameraServiceCallback> & callback)155 int32_t HCameraServiceProxy::SetCameraCallback(sptr<ICameraServiceCallback>& callback)
156 {
157     MessageParcel data;
158     MessageParcel reply;
159     MessageOption option;
160 
161     if (callback == nullptr) {
162         MEDIA_ERR_LOG("HCameraServiceProxy SetCameraCallback callback is null");
163         return IPC_PROXY_ERR;
164     }
165 
166     data.WriteInterfaceToken(GetDescriptor());
167     data.WriteRemoteObject(callback->AsObject());
168 
169     int error = Remote()->SendRequest(
170         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_CAMERA_CALLBACK), data, reply, option);
171     if (error != ERR_NONE) {
172         MEDIA_ERR_LOG("HCameraServiceProxy SetCameraCallback failed, error: %{public}d", error);
173     }
174 
175     return error;
176 }
177 
SetMuteCallback(sptr<ICameraMuteServiceCallback> & callback)178 int32_t HCameraServiceProxy::SetMuteCallback(sptr<ICameraMuteServiceCallback>& callback)
179 {
180     MessageParcel data;
181     MessageParcel reply;
182     MessageOption option;
183 
184     if (callback == nullptr) {
185         MEDIA_ERR_LOG("HCameraServiceProxy SetMuteCallback callback is null");
186         return IPC_PROXY_ERR;
187     }
188 
189     data.WriteInterfaceToken(GetDescriptor());
190     data.WriteRemoteObject(callback->AsObject());
191 
192     int error = Remote()->SendRequest(
193         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_MUTE_CALLBACK), data, reply, option);
194     if (error != ERR_NONE) {
195         MEDIA_ERR_LOG("HCameraServiceProxy SetMuteCallback failed, error: %{public}d", error);
196     }
197 
198     return error;
199 }
200 
SetTorchCallback(sptr<ITorchServiceCallback> & callback)201 int32_t HCameraServiceProxy::SetTorchCallback(sptr<ITorchServiceCallback>& callback)
202 {
203     MessageParcel data;
204     MessageParcel reply;
205     MessageOption option;
206     if (callback == nullptr) {
207         MEDIA_ERR_LOG("HCameraServiceProxy SetTorchCallback callback is null");
208         return IPC_PROXY_ERR;
209     }
210 
211     data.WriteInterfaceToken(GetDescriptor());
212     data.WriteRemoteObject(callback->AsObject());
213 
214     int error = Remote()->SendRequest(
215         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_TORCH_CALLBACK), data, reply, option);
216     if (error != ERR_NONE) {
217         MEDIA_ERR_LOG("HCameraServiceProxy SetTorchCallback failed, error: %{public}d", error);
218     }
219 
220     return error;
221 }
222 
SetFoldStatusCallback(sptr<IFoldServiceCallback> & callback,bool isInnerCallback)223 int32_t HCameraServiceProxy::SetFoldStatusCallback(sptr<IFoldServiceCallback>& callback, bool isInnerCallback)
224 {
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option;
228     if (callback == nullptr) {
229         MEDIA_ERR_LOG("HCameraServiceProxy SetFoldStatusCallback callback is null");
230         return IPC_PROXY_ERR;
231     }
232 
233     data.WriteInterfaceToken(GetDescriptor());
234     data.WriteRemoteObject(callback->AsObject());
235     data.WriteBool(isInnerCallback);
236     int error = Remote()->SendRequest(
237         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_FOLD_CALLBACK), data, reply, option);
238     if (error != ERR_NONE) {
239         MEDIA_ERR_LOG("HCameraServiceProxy SetFoldStatusCallback failed, error: %{public}d", error);
240     }
241 
242     return error;
243 }
244 
CreateCaptureSession(sptr<ICaptureSession> & session,int32_t operationMode)245 int32_t HCameraServiceProxy::CreateCaptureSession(sptr<ICaptureSession>& session, int32_t operationMode)
246 {
247     MessageParcel data;
248     MessageParcel reply;
249     MessageOption option;
250     data.WriteInterfaceToken(GetDescriptor());
251     data.WriteInt32(operationMode);
252     MEDIA_INFO_LOG("HCameraServiceProxy::CreateCaptureSession opMode_= %{public}d", operationMode);
253     int error = Remote()->SendRequest(
254         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_CAPTURE_SESSION), data, reply, option);
255     if (error != ERR_NONE) {
256         MEDIA_ERR_LOG("HCameraServiceProxy CreateCaptureSession failed, error: %{public}d", error);
257         return error;
258     }
259 
260     auto remoteObject = reply.ReadRemoteObject();
261     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
262         "HCameraServiceProxy CreateCaptureSession CaptureSession is null");
263     session = iface_cast<ICaptureSession>(remoteObject);
264 
265     return error;
266 }
267 
CreateDeferredPhotoProcessingSession(int32_t userId,sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredPhotoProcessingSession> & session)268 int32_t HCameraServiceProxy::CreateDeferredPhotoProcessingSession(int32_t userId,
269     sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback>& callback,
270     sptr<DeferredProcessing::IDeferredPhotoProcessingSession>& session)
271 {
272     MessageParcel data;
273     MessageParcel reply;
274     MessageOption option;
275 
276     CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR,
277         "HCameraServiceProxy CreateDeferredPhotoProcessingSession callback is null");
278 
279     data.WriteInterfaceToken(GetDescriptor());
280     data.WriteInt32(userId);
281     data.WriteRemoteObject(callback->AsObject());
282 
283     int error = Remote()->SendRequest(
284         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_DEFERRED_PHOTO_PROCESSING_SESSION),
285         data, reply, option);
286     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
287         "HCameraServiceProxy CreateDeferredPhotoProcessingSession failed, error: %{public}d", error);
288 
289     auto remoteObject = reply.ReadRemoteObject();
290     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
291         "HCameraServiceProxy CreateDeferredPhotoProcessingSession session is null");
292     session = iface_cast<DeferredProcessing::IDeferredPhotoProcessingSession>(remoteObject);
293 
294     return error;
295 }
296 
CreateDeferredVideoProcessingSession(int32_t userId,sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredVideoProcessingSession> & session)297 int32_t HCameraServiceProxy::CreateDeferredVideoProcessingSession(int32_t userId,
298     sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback>& callback,
299     sptr<DeferredProcessing::IDeferredVideoProcessingSession>& session)
300 {
301     MessageParcel data;
302     MessageParcel reply;
303     MessageOption option;
304 
305     CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR,
306         "HCameraServiceProxy CreateDeferredVideoProcessingSession callback is null");
307 
308     data.WriteInterfaceToken(GetDescriptor());
309     data.WriteInt32(userId);
310     data.WriteRemoteObject(callback->AsObject());
311 
312     int error = Remote()->SendRequest(
313         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_DEFERRED_VIDEO_PROCESSING_SESSION),
314         data, reply, option);
315     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
316         "HCameraServiceProxy CreateDeferredVideoProcessingSession failed, error: %{public}d", error);
317 
318     auto remoteObject = reply.ReadRemoteObject();
319     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
320         "HCameraServiceProxy CreateDeferredVideoProcessingSession session is null");
321     session = iface_cast<DeferredProcessing::IDeferredVideoProcessingSession>(remoteObject);
322     return error;
323 }
324 
CreatePhotoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamCapture> & photoOutput)325 int32_t HCameraServiceProxy::CreatePhotoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
326                                                int32_t width, int32_t height,
327                                                sptr<IStreamCapture> &photoOutput)
328 {
329     MessageParcel data;
330     MessageParcel reply;
331     MessageOption option;
332 
333     if (producer == nullptr) {
334         MEDIA_ERR_LOG("HCameraServiceProxy CreatePhotoOutput producer is null");
335         return IPC_PROXY_ERR;
336     }
337 
338     data.WriteInterfaceToken(GetDescriptor());
339     data.WriteRemoteObject(producer->AsObject());
340     data.WriteInt32(format);
341     data.WriteInt32(width);
342     data.WriteInt32(height);
343 
344     int error = Remote()->SendRequest(
345         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_PHOTO_OUTPUT), data, reply, option);
346     if (error != ERR_NONE) {
347         MEDIA_ERR_LOG("HCameraServiceProxy CreatePhotoOutput failed, error: %{public}d", error);
348         return error;
349     }
350 
351     auto remoteObject = reply.ReadRemoteObject();
352     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
353         "HCameraServiceProxy CreatePhotoOutput photoOutput is null");
354     photoOutput = iface_cast<IStreamCapture>(remoteObject);
355 
356     return error;
357 }
358 
CreatePreviewOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)359 int32_t HCameraServiceProxy::CreatePreviewOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
360                                                  int32_t width, int32_t height,
361                                                  sptr<IStreamRepeat>& previewOutput)
362 {
363     MessageParcel data;
364     MessageParcel reply;
365     MessageOption option;
366 
367     if ((producer == nullptr) || (width == 0) || (height == 0)) {
368         MEDIA_ERR_LOG("HCameraServiceProxy CreatePreviewOutput producer is null or invalid size is set");
369         return IPC_PROXY_ERR;
370     }
371 
372     data.WriteInterfaceToken(GetDescriptor());
373     data.WriteRemoteObject(producer->AsObject());
374     data.WriteInt32(format);
375     data.WriteInt32(width);
376     data.WriteInt32(height);
377 
378     int error = Remote()->SendRequest(
379         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT), data, reply, option);
380     if (error != ERR_NONE) {
381         MEDIA_ERR_LOG("HCameraServiceProxy CreatePreviewOutput failed, error: %{public}d", error);
382         return error;
383     }
384     auto remoteObject = reply.ReadRemoteObject();
385     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
386         "HCameraServiceProxy CreatePreviewOutput previewOutput is null");
387     previewOutput = iface_cast<IStreamRepeat>(remoteObject);
388 
389     return error;
390 }
391 
CreateDeferredPreviewOutput(int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)392 int32_t HCameraServiceProxy::CreateDeferredPreviewOutput(int32_t format, int32_t width, int32_t height,
393                                                          sptr<IStreamRepeat> &previewOutput)
394 {
395     MessageParcel data;
396     MessageParcel reply;
397     MessageOption option;
398 
399     if ((width == 0) || (height == 0)) {
400         MEDIA_ERR_LOG("HCameraServiceProxy CreateDeferredPreviewOutput producer is null or invalid size is set");
401         return IPC_PROXY_ERR;
402     }
403 
404     data.WriteInterfaceToken(GetDescriptor());
405     data.WriteInt32(format);
406     data.WriteInt32(width);
407     data.WriteInt32(height);
408 
409     int error = Remote()->SendRequest(
410         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_DEFERRED_PREVIEW_OUTPUT),
411         data, reply, option);
412     if (error != ERR_NONE) {
413         MEDIA_ERR_LOG("HCameraServiceProxy CreateDeferredPreviewOutput failed, error: %{public}d", error);
414         return error;
415     }
416     auto remoteObject = reply.ReadRemoteObject();
417     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
418         "HCameraServiceProxy CreateDeferredPreviewOutput previewOutput is null");
419     previewOutput = iface_cast<IStreamRepeat>(remoteObject);
420 
421     return error;
422 }
423 
CreateDepthDataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamDepthData> & depthDataOutput)424 int32_t HCameraServiceProxy::CreateDepthDataOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
425                                                    int32_t width, int32_t height,
426                                                    sptr<IStreamDepthData>& depthDataOutput)
427 {
428     MessageParcel data;
429     MessageParcel reply;
430     MessageOption option;
431 
432     if ((producer == nullptr) || (width == 0) || (height == 0)) {
433         MEDIA_ERR_LOG("HCameraServiceProxy CreateDepthDataOutput producer is null or invalid size is set");
434         return IPC_PROXY_ERR;
435     }
436 
437     data.WriteInterfaceToken(GetDescriptor());
438     data.WriteRemoteObject(producer->AsObject());
439     data.WriteInt32(format);
440     data.WriteInt32(width);
441     data.WriteInt32(height);
442 
443     int error = Remote()->SendRequest(static_cast<uint32_t>(
444         CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_DEPTH_DATA_OUTPUT), data, reply, option);
445     if (error != ERR_NONE) {
446         MEDIA_ERR_LOG("HCameraServiceProxy CreateDepthDataOutput failed, error: %{public}d", error);
447         return error;
448     }
449     auto remoteObject = reply.ReadRemoteObject();
450     if (remoteObject != nullptr) {
451         depthDataOutput = iface_cast<IStreamDepthData>(remoteObject);
452     } else {
453         MEDIA_ERR_LOG("HCameraServiceProxy CreateDepthDataOutput depthDataOutput is null");
454         error = IPC_PROXY_ERR;
455     }
456     return error;
457 }
458 
CreateMetadataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,std::vector<int32_t> metadataTypes,sptr<IStreamMetadata> & metadataOutput)459 int32_t HCameraServiceProxy::CreateMetadataOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
460                                                   std::vector<int32_t> metadataTypes,
461                                                   sptr<IStreamMetadata>& metadataOutput)
462 {
463     MessageParcel data;
464     MessageParcel reply;
465     MessageOption option;
466 
467     if (producer == nullptr) {
468         MEDIA_ERR_LOG("HCameraServiceProxy CreateMetadataOutput producer is null");
469         return IPC_PROXY_ERR;
470     }
471 
472     data.WriteInterfaceToken(GetDescriptor());
473     data.WriteRemoteObject(producer->AsObject());
474     data.WriteInt32(format);
475     data.WriteInt32Vector(metadataTypes);
476 
477     int error = Remote()->SendRequest(
478         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_METADATA_OUTPUT), data, reply, option);
479     if (error != ERR_NONE) {
480         MEDIA_ERR_LOG("HCameraServiceProxy CreateMetadataOutput failed, error: %{public}d", error);
481         return error;
482     }
483     auto remoteObject = reply.ReadRemoteObject();
484     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
485         "HCameraServiceProxy CreateMetadataOutput metadataOutput is null");
486     metadataOutput = iface_cast<IStreamMetadata>(remoteObject);
487 
488     return error;
489 }
490 
CreateVideoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & videoOutput)491 int32_t HCameraServiceProxy::CreateVideoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
492                                                int32_t width, int32_t height,
493                                                sptr<IStreamRepeat>& videoOutput)
494 {
495     MessageParcel data;
496     MessageParcel reply;
497     MessageOption option;
498 
499     if (producer == nullptr) {
500         MEDIA_ERR_LOG("HCameraServiceProxy CreateVideoOutput producer is null");
501         return IPC_PROXY_ERR;
502     }
503 
504     data.WriteInterfaceToken(GetDescriptor());
505     data.WriteRemoteObject(producer->AsObject());
506     data.WriteInt32(format);
507     data.WriteInt32(width);
508     data.WriteInt32(height);
509 
510     int error = Remote()->SendRequest(
511         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_CREATE_VIDEO_OUTPUT), data, reply, option);
512     if (error != ERR_NONE) {
513         MEDIA_ERR_LOG("HCameraServiceProxy::CreateVideoOutput failed, error: %{public}d", error);
514         return error;
515     }
516 
517     auto remoteObject = reply.ReadRemoteObject();
518     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_PROXY_ERR,
519         "HCameraServiceProxy CreateVideoOutput videoOutput is null");
520     videoOutput = iface_cast<IStreamRepeat>(remoteObject);
521 
522     return error;
523 }
524 
SetListenerObject(const sptr<IRemoteObject> & object)525 int32_t HCameraServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
526 {
527     MessageParcel data;
528     MessageParcel reply;
529     MessageOption option;
530 
531     data.WriteInterfaceToken(GetDescriptor());
532     (void)data.WriteRemoteObject(object);
533     int error = Remote()->SendRequest(
534         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_LISTENER_OBJ), data, reply, option);
535     if (error != ERR_NONE) {
536         MEDIA_ERR_LOG("HCameraServiceProxy::SetListenerObject Set listener obj failed, error: %{public}d", error);
537         return IPC_PROXY_ERR;
538     }
539 
540     return reply.ReadInt32();
541 }
542 
MuteCamera(bool muteMode)543 int32_t HCameraServiceProxy::MuteCamera(bool muteMode)
544 {
545     MessageParcel data;
546     MessageParcel reply;
547     MessageOption option;
548 
549     data.WriteInterfaceToken(GetDescriptor());
550     (void)data.WriteBool(muteMode);
551     int error = Remote()->SendRequest(
552         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_MUTE_CAMERA), data, reply, option);
553     if (error != ERR_NONE) {
554         MEDIA_ERR_LOG("HCameraServiceProxy::MuteCamera failed, error: %{public}d", error);
555     }
556 
557     return error;
558 }
559 
MuteCameraPersist(PolicyType policyType,bool muteMode)560 int32_t HCameraServiceProxy::MuteCameraPersist(PolicyType policyType, bool muteMode)
561 {
562     MessageParcel data;
563     MessageParcel reply;
564     MessageOption option;
565 
566     data.WriteInterfaceToken(GetDescriptor());
567     (void)data.WriteInt32(static_cast<int32_t>(policyType));
568     (void)data.WriteBool(muteMode);
569     int error = Remote()->SendRequest(
570         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_MUTE_CAMERA_PERSIST), data, reply, option);
571     CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
572         "HCameraServiceProxy::MuteCameraPersist failed, error: %{public}d", error);
573 
574     return error;
575 }
576 
PrelaunchCamera()577 int32_t HCameraServiceProxy::PrelaunchCamera()
578 {
579     MessageParcel data;
580     MessageParcel reply;
581     MessageOption option;
582 
583     data.WriteInterfaceToken(GetDescriptor());
584     int error = Remote()->SendRequest(
585         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_PRE_LAUNCH_CAMERA), data, reply, option);
586     if (error != ERR_NONE) {
587         MEDIA_ERR_LOG("HCameraServiceProxy::PrelaunchCamera failed, error: %{public}d", error);
588     }
589 
590     return error;
591 }
592 
SetPrelaunchConfig(std::string cameraId,RestoreParamTypeOhos restoreParamType,int activeTime,EffectParam effectParam)593 int32_t HCameraServiceProxy::SetPrelaunchConfig(std::string cameraId, RestoreParamTypeOhos restoreParamType,
594     int activeTime, EffectParam effectParam)
595 {
596     MessageParcel data;
597     MessageParcel reply;
598     MessageOption option;
599 
600     data.WriteInterfaceToken(GetDescriptor());
601     data.WriteString(cameraId);
602     data.WriteUint32(restoreParamType);
603     data.WriteUint32(activeTime);
604     data.WriteUint32(effectParam.skinSmoothLevel);
605     data.WriteUint32(effectParam.faceSlender);
606     data.WriteUint32(effectParam.skinTone);
607     int32_t error = Remote()->SendRequest(
608         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_PRE_LAUNCH_CAMERA), data, reply, option);
609     if (error != ERR_NONE) {
610         MEDIA_ERR_LOG("HCameraServiceProxy::SetPrelaunchConfig failed, error: %{public}d", error);
611     }
612 
613     return error;
614 }
615 
PreSwitchCamera(const std::string cameraId)616 int32_t HCameraServiceProxy::PreSwitchCamera(const std::string cameraId)
617 {
618     MessageParcel data;
619     MessageParcel reply;
620     MessageOption option;
621     data.WriteInterfaceToken(GetDescriptor());
622     data.WriteString(cameraId);
623     int32_t error = Remote()->SendRequest(
624         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_PRE_SWITCH_CAMERA), data, reply, option);
625     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy::PreSwitchCamera failed, error: %{public}d", error);
626 
627     return error;
628 }
629 
IsCameraMuted(bool & muteMode)630 int32_t HCameraServiceProxy::IsCameraMuted(bool &muteMode)
631 {
632     MessageParcel data;
633     MessageParcel reply;
634     MessageOption option;
635 
636     data.WriteInterfaceToken(GetDescriptor());
637     (void)data.WriteBool(muteMode);
638     int error = Remote()->SendRequest(
639         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_IS_CAMERA_MUTED), data, reply, option);
640     if (error != ERR_NONE) {
641         MEDIA_ERR_LOG("HCameraServiceProxy::IsCameraMuted Set listener obj failed, error: %{public}d", error);
642         return error;
643     }
644 
645     muteMode = reply.ReadBool();
646     MEDIA_DEBUG_LOG("HCameraServiceProxy IsCameraMuted Read muteMode is %{public}d", muteMode);
647 
648     return error;
649 }
650 
SetTorchLevel(float level)651 int32_t HCameraServiceProxy::SetTorchLevel(float level)
652 {
653     MessageParcel data;
654     MessageParcel reply;
655     MessageOption option;
656 
657     data.WriteInterfaceToken(GetDescriptor());
658     data.WriteFloat(level);
659     int error = Remote()->SendRequest(
660         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_SET_TORCH_LEVEL),
661         data, reply, option);
662     if (error != ERR_NONE) {
663         MEDIA_ERR_LOG("HCameraServiceProxy::SetTorchLevel failed, error: %{public}d", error);
664     }
665 
666     return error;
667 }
668 
AllowOpenByOHSide(std::string cameraId,int32_t state,bool & canOpenCamera)669 int32_t HCameraServiceProxy::AllowOpenByOHSide(std::string cameraId, int32_t state, bool &canOpenCamera)
670 {
671     MessageParcel data;
672     MessageParcel reply;
673     MessageOption option;
674 
675     data.WriteInterfaceToken(GetDescriptor());
676     data.WriteString(cameraId);
677     data.WriteInt32(state);
678     (void)data.WriteBool(canOpenCamera);
679 
680     int32_t error = Remote()->SendRequest(
681         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_ALLOW_OPEN_BY_OHSIDE), data, reply, option);
682     CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
683         "HCameraServiceProxy::AllowOpenByOHSide failed, error: %{public}d", error);
684 
685     canOpenCamera = reply.ReadBool();
686     MEDIA_DEBUG_LOG("HCameraServiceProxy::AllowOpenByOHSide read canOpenCamera is %{public}d", canOpenCamera);
687 
688     return error;
689 }
690 
NotifyCameraState(std::string cameraId,int32_t state)691 int32_t HCameraServiceProxy::NotifyCameraState(std::string cameraId, int32_t state)
692 {
693     MessageParcel data;
694     MessageParcel reply;
695     MessageOption option;
696 
697     data.WriteInterfaceToken(GetDescriptor());
698     data.WriteString(cameraId);
699     data.WriteInt32(state);
700     option.SetFlags(option.TF_ASYNC);
701 
702     int32_t error = Remote()->SendRequest(
703         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_NOTIFY_CAMERA_STATE), data, reply, option);
704     CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
705         "HCameraServiceProxy::NotifyCameraState failed, error: %{public}d", error);
706 
707     return error;
708 }
709 
SetPeerCallback(sptr<ICameraBroker> & callback)710 int32_t HCameraServiceProxy::SetPeerCallback(sptr<ICameraBroker>& callback)
711 {
712     MessageParcel data;
713     MessageParcel reply;
714     MessageOption option;
715 
716     CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR,
717         "HCameraServiceProxy SetCallback callback is null");
718 
719     data.WriteInterfaceToken(GetDescriptor());
720     data.WriteRemoteObject(callback->AsObject());
721 
722     int error = Remote()->SendRequest(
723         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_SET_PEER_CALLBACK), data, reply, option);
724     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy::SetCallback failed, error: %{public}d", error);
725 
726     return error;
727 }
728 
UnsetPeerCallback()729 int32_t HCameraServiceProxy::UnsetPeerCallback()
730 {
731     MessageParcel data;
732     MessageParcel reply;
733     MessageOption option;
734 
735     data.WriteInterfaceToken(GetDescriptor());
736 
737     int error = Remote()->SendRequest(
738         static_cast<uint32_t>(CameraServiceDHInterfaceCode::CAMERA_SERVICE_UNSET_PEER_CALLBACK), data, reply, option);
739     CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
740         "HCameraServiceProxy::UnsetPeerCallback failed, error: %{public}d", error);
741 
742     return error;
743 }
744 
DestroyStubObj()745 int32_t HCameraServiceProxy::DestroyStubObj()
746 {
747     MessageParcel data;
748     MessageParcel reply;
749     MessageOption option;
750 
751     data.WriteInterfaceToken(GetDescriptor());
752     int error = Remote()->SendRequest(
753         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_DESTROY_STUB_OBJ), data, reply, option);
754     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy::DestroyStubObj failed, error: %{public}d", error);
755 
756     return error;
757 }
758 
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)759 int32_t HCameraServiceProxy::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
760 {
761     MessageParcel data;
762     MessageParcel reply;
763     MessageOption option;
764 
765     data.WriteInterfaceToken(GetDescriptor());
766     data.WriteInt32(pidList.size());
767     for (auto it = pidList.begin(); it != pidList.end(); it++) {
768         data.WriteInt32(*it);
769     }
770     MEDIA_DEBUG_LOG("isProxy value: %{public}d", isProxy);
771     data.WriteBool(isProxy);
772     int error = Remote()->SendRequest(
773         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_PROXY_FOR_FREEZE), data, reply, option);
774     CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraServiceProxy::ProxyForFreeze failed, error: %{public}d", error);
775 
776     return error;
777 }
ResetAllFreezeStatus()778 int32_t HCameraServiceProxy::ResetAllFreezeStatus()
779 {
780     MessageParcel data;
781     MessageParcel reply;
782     MessageOption option;
783 
784     data.WriteInterfaceToken(GetDescriptor());
785     int error = Remote()->SendRequest(
786         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_RESET_ALL_FREEZE_STATUS),
787         data, reply, option);
788     CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
789         "HCameraServiceProxy::ResetAllFreezeStatus failed, error: %{public}d", error);
790     return error;
791 }
GetDmDeviceInfo(std::vector<std::string> & deviceInfos)792 int32_t HCameraServiceProxy::GetDmDeviceInfo(std::vector<std::string> &deviceInfos)
793 {
794     MessageParcel data;
795     MessageParcel reply;
796     MessageOption option;
797 
798     data.WriteInterfaceToken(GetDescriptor());
799     int error = Remote()->SendRequest(
800         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_GET_DM_DEVICE_INFOS), data, reply, option);
801     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
802         "HCameraServiceProxy GetDmDeviceInfo failed, error: %{public}d", error);
803     reply.ReadStringVector(&deviceInfos);
804 
805     return error;
806 }
GetCameraOutputStatus(int32_t pid,int32_t & status)807 int32_t HCameraServiceProxy::GetCameraOutputStatus(int32_t pid, int32_t &status)
808 {
809     MessageParcel data;
810     MessageParcel reply;
811     MessageOption option;
812 
813     data.WriteInterfaceToken(GetDescriptor());
814     data.WriteInt32(pid);
815     int error = Remote()->SendRequest(
816         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_GET_CAMERA_OUTPUT_STATUS),
817         data, reply, option);
818     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
819         "GetCameraOutputStatus, error: %{public}d", error);
820     status = reply.ReadInt32();
821     return error;
822 }
823 
RequireMemorySize(int32_t memSize)824 int32_t HCameraServiceProxy::RequireMemorySize(int32_t memSize)
825 {
826     MessageParcel data;
827     MessageParcel reply;
828     MessageOption option;
829 
830     data.WriteInterfaceToken(GetDescriptor());
831     data.WriteInt32(memSize);
832     int error = Remote()->SendRequest(
833         static_cast<uint32_t>(CameraServiceInterfaceCode::CAMERA_SERVICE_REQUIRE_MEMORY_SIZE),
834         data, reply, option);
835     CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error, "RequireMemorySize, error: %{public}d", error);
836     return error;
837 }
838 } // namespace CameraStandard
839 } // namespace OHOS
840