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 "hstream_capture_proxy.h"
17 #include "camera_log.h"
18 #include "camera_photo_proxy.h"
19 #include "camera_service_ipc_interface_code.h"
20 #include "metadata_utils.h"
21 #include "picture_interface.h"
22
23 namespace OHOS {
24 namespace CameraStandard {
HStreamCaptureProxy(const sptr<IRemoteObject> & impl)25 HStreamCaptureProxy::HStreamCaptureProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<IStreamCapture>(impl) { }
27
Capture(const std::shared_ptr<Camera::CameraMetadata> & captureSettings)28 int32_t HStreamCaptureProxy::Capture(const std::shared_ptr<Camera::CameraMetadata> &captureSettings)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33
34 data.WriteInterfaceToken(GetDescriptor());
35 CHECK_ERROR_RETURN_RET_LOG(!(Camera::MetadataUtils::EncodeCameraMetadata(captureSettings, data)), IPC_PROXY_ERR,
36 "HStreamCaptureProxy Capture EncodeCameraMetadata failed");
37
38 int error = Remote()->SendRequest(
39 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_START), data, reply, option);
40 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy Capture failed, error: %{public}d", error);
41
42 return error;
43 }
44
CancelCapture()45 int32_t HStreamCaptureProxy::CancelCapture()
46 {
47 MessageParcel data;
48 MessageParcel reply;
49 MessageOption option;
50
51 data.WriteInterfaceToken(GetDescriptor());
52 int error = Remote()->SendRequest(
53 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_CANCEL), data, reply, option);
54 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy CancelCapture failed, error: %{public}d", error);
55
56 return error;
57 }
58
ConfirmCapture()59 int32_t HStreamCaptureProxy::ConfirmCapture()
60 {
61 MessageParcel data;
62 MessageParcel reply;
63 MessageOption option;
64
65 data.WriteInterfaceToken(GetDescriptor());
66 int error = Remote()->SendRequest(
67 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_CONFIRM), data, reply, option);
68 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy ConfirmCapture failed, error: %{public}d", error);
69
70 return error;
71 }
72
Release()73 int32_t HStreamCaptureProxy::Release()
74 {
75 MessageParcel data;
76 MessageParcel reply;
77 MessageOption option;
78
79 data.WriteInterfaceToken(GetDescriptor());
80 int error = Remote()->SendRequest(
81 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_RELEASE), data, reply, option);
82 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy Release failed, error: %{public}d", error);
83
84 return error;
85 }
86
SetCallback(sptr<IStreamCaptureCallback> & callback)87 int32_t HStreamCaptureProxy::SetCallback(sptr<IStreamCaptureCallback> &callback)
88 {
89 MessageParcel data;
90 MessageParcel reply;
91 MessageOption option;
92
93 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR, "HStreamCaptureProxy SetCallback callback is null");
94
95 data.WriteInterfaceToken(GetDescriptor());
96 data.WriteRemoteObject(callback->AsObject());
97
98 int error = Remote()->SendRequest(
99 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_SET_CALLBACK), data, reply, option);
100 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy SetCallback failed, error: %{public}d", error);
101
102 return error;
103 }
104
UnSetCallback()105 int32_t HStreamCaptureProxy::UnSetCallback()
106 {
107 MessageParcel data;
108 MessageParcel reply;
109 MessageOption option;
110 data.WriteInterfaceToken(GetDescriptor());
111 int error = Remote()->SendRequest(
112 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_UNSET_CALLBACK), data, reply, option);
113 if (error != ERR_NONE) {
114 MEDIA_ERR_LOG("HStreamCaptureProxy SetCallback failed, error: %{public}d", error);
115 }
116 return error;
117 }
118
SetThumbnail(bool isEnabled,const sptr<OHOS::IBufferProducer> & producer)119 int32_t HStreamCaptureProxy::SetThumbnail(bool isEnabled, const sptr<OHOS::IBufferProducer> &producer)
120 {
121 MessageParcel data;
122 MessageParcel reply;
123 MessageOption option;
124
125 CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_PROXY_ERR,
126 "HStreamCaptureProxy CreatePhotoOutput producer is null");
127
128 data.WriteInterfaceToken(GetDescriptor());
129 data.WriteRemoteObject(producer->AsObject());
130 data.WriteBool(isEnabled);
131
132 int error = Remote()->SendRequest(
133 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_SERVICE_SET_THUMBNAIL), data, reply, option);
134 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy SetThumbnail failed, error: %{public}d", error);
135 return error;
136 }
137
EnableRawDelivery(bool enabled)138 int32_t HStreamCaptureProxy::EnableRawDelivery(bool enabled)
139 {
140 MessageParcel data;
141 MessageParcel reply;
142 MessageOption option;
143
144 data.WriteInterfaceToken(GetDescriptor());
145 data.WriteBool(enabled);
146
147 int error = Remote()->SendRequest(
148 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_RAW_DELIVERY), data, reply, option);
149 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy EnableRawDelivery failed, error: %{public}d", error);
150 return error;
151 }
152
EnableMovingPhoto(bool enabled)153 int32_t HStreamCaptureProxy::EnableMovingPhoto(bool enabled)
154 {
155 MessageParcel data;
156 MessageParcel reply;
157 MessageOption option;
158
159 data.WriteInterfaceToken(GetDescriptor());
160 data.WriteBool(enabled);
161
162 int error = Remote()->SendRequest(
163 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_MOVING_PHOTO), data, reply, option);
164 if (error != ERR_NONE) {
165 MEDIA_ERR_LOG("HStreamCaptureProxy EnableMovingPhoto failed, error: %{public}d", error);
166 }
167 return error;
168 }
169
SetBufferProducerInfo(const std::string bufName,const sptr<OHOS::IBufferProducer> & producer)170 int32_t HStreamCaptureProxy::SetBufferProducerInfo(const std::string bufName,
171 const sptr<OHOS::IBufferProducer> &producer)
172 {
173 MessageParcel data;
174 MessageParcel reply;
175 MessageOption option;
176
177 CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_PROXY_ERR,
178 "HStreamCaptureProxy SetRawPhotoStreamInfo producer is null");
179
180 data.WriteInterfaceToken(GetDescriptor());
181 data.WriteString(bufName);
182 data.WriteRemoteObject(producer->AsObject());
183
184 int error = Remote()->SendRequest(
185 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_SET_BUFFER_PRODUCER_INFO), data, reply, option);
186 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy SetBufferProducerInfo failed, error: %{public}d",
187 error);
188 return error;
189 }
190
DeferImageDeliveryFor(int32_t type)191 int32_t HStreamCaptureProxy::DeferImageDeliveryFor(int32_t type)
192 {
193 MessageParcel data;
194 MessageParcel reply;
195 MessageOption option;
196
197 data.WriteInterfaceToken(GetDescriptor());
198 data.WriteInt32(type);
199
200 int error = Remote()->SendRequest(
201 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_SERVICE_ENABLE_DEFERREDTYPE), data, reply, option);
202 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy DeferImageDeliveryFor failed, error: %{public}d",
203 error);
204 return error;
205 }
206
IsDeferredPhotoEnabled()207 int32_t HStreamCaptureProxy::IsDeferredPhotoEnabled()
208 {
209 MessageParcel data;
210 MessageParcel reply;
211 MessageOption option;
212
213 data.WriteInterfaceToken(GetDescriptor());
214
215 int error = Remote()->SendRequest(
216 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_GET_DEFERRED_PHOTO), data, reply, option);
217 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy IsDeferredPhotoEnabled failed, error: %{public}d",
218 error);
219 return error;
220 }
221
IsDeferredVideoEnabled()222 int32_t HStreamCaptureProxy::IsDeferredVideoEnabled()
223 {
224 MessageParcel data;
225 MessageParcel reply;
226 MessageOption option;
227
228 data.WriteInterfaceToken(GetDescriptor());
229
230 int error = Remote()->SendRequest(
231 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_GET_DEFERRED_VIDEO), data, reply, option);
232 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamCaptureProxy IsDeferredVideoEnabled failed, error: %{public}d",
233 error);
234 return error;
235 }
236
SetMovingPhotoVideoCodecType(int32_t videoCodecType)237 int32_t HStreamCaptureProxy::SetMovingPhotoVideoCodecType(int32_t videoCodecType)
238 {
239 MessageParcel data;
240 MessageParcel reply;
241 MessageOption option;
242
243 data.WriteInterfaceToken(GetDescriptor());
244 data.WriteInt32(videoCodecType);
245
246 int error = Remote()->SendRequest(
247 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_SET_VIDEO_CODEC_TYPE), data, reply, option);
248 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
249 "HStreamCaptureProxy IsDeferredVideoEnabled failed, error: %{public}d", error);
250 return error;
251 }
252
UpdateMediaLibraryPhotoAssetProxy(sptr<CameraPhotoProxy> photoProxy)253 int32_t HStreamCaptureProxy::UpdateMediaLibraryPhotoAssetProxy(sptr<CameraPhotoProxy> photoProxy)
254 {
255 MessageParcel data;
256 MessageParcel reply;
257 MessageOption option;
258 CHECK_ERROR_RETURN_RET_LOG(photoProxy == nullptr, IPC_PROXY_ERR,
259 "HStreamCaptureProxy UpdateMediaLibraryPhotoAssetProxy photoProxy is null");
260 data.WriteInterfaceToken(GetDescriptor());
261 photoProxy->WriteToParcel(data);
262 int error = Remote()->SendRequest(
263 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ADD_MEDIA_LIBRARY_PHOTO_PROXY),
264 data, reply, option);
265 if (error != ERR_NONE) {
266 MEDIA_ERR_LOG("HStreamRepeatProxy SetCameraRotation failed, error: %{public}d", error);
267 }
268 return error;
269 }
270
SetCameraPhotoRotation(bool isEnable)271 int32_t HStreamCaptureProxy::SetCameraPhotoRotation(bool isEnable)
272 {
273 MessageParcel data;
274 MessageParcel reply;
275 MessageOption option;
276
277 data.WriteInterfaceToken(GetDescriptor());
278 data.WriteBool(isEnable);
279
280 int error = Remote()->SendRequest(
281 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_PHOTO_ROTATION), data, reply, option);
282 if (error != ERR_NONE) {
283 MEDIA_ERR_LOG("HStreamCaptureProxy SetCameraPhotoRotation failed, error: %{public}d", error);
284 }
285 return error;
286 }
287
AcquireBufferToPrepareProxy(int32_t captureId)288 int32_t HStreamCaptureProxy::AcquireBufferToPrepareProxy(int32_t captureId)
289 {
290 MessageParcel data;
291 MessageParcel reply;
292 MessageOption option;
293
294 data.WriteInterfaceToken(GetDescriptor());
295 data.WriteInt32(captureId);
296 int error = Remote()->SendRequest(
297 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_CAPTURE_DFX), data, reply, option);
298 if (error != ERR_NONE) {
299 MEDIA_ERR_LOG("HStreamRepeatProxy AcquireBufferToPrepareProxy failed, error: %{public}d", error);
300 }
301 return error;
302 }
303
304
EnableOfflinePhoto(bool isEnable)305 int32_t HStreamCaptureProxy::EnableOfflinePhoto(bool isEnable)
306 {
307 MessageParcel data;
308 MessageParcel reply;
309 MessageOption option;
310
311 data.WriteInterfaceToken(GetDescriptor());
312 data.WriteBool(isEnable);
313 int error = Remote()->SendRequest(
314 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_OFFLINE_PHOTO), data, reply, option);
315 if (error != ERR_NONE) {
316 MEDIA_ERR_LOG("HStreamRepeatProxy EnableOfflinePhoto failed, error: %{public}d", error);
317 }
318 return error;
319 }
320
CreateMediaLibrary(sptr<CameraPhotoProxy> & photoProxy,std::string & uri,int32_t & cameraShotType,std::string & burstKey,int64_t timestamp)321 int32_t HStreamCaptureProxy::CreateMediaLibrary(sptr<CameraPhotoProxy> &photoProxy,
322 std::string &uri, int32_t &cameraShotType, std::string &burstKey, int64_t timestamp)
323 {
324 MessageParcel data;
325 MessageParcel reply;
326 MessageOption option;
327 CHECK_ERROR_RETURN_RET_LOG(photoProxy == nullptr, IPC_PROXY_ERR,
328 "HCaptureSessionProxy CreateMediaLibrary photoProxy is null");
329 data.WriteInterfaceToken(GetDescriptor());
330 photoProxy->WriteToParcel(data);
331 data.WriteInt64(timestamp);
332 int error = Remote()->SendRequest(
333 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CREATE_MEDIA_LIBRARY_MANAGER),
334 data, reply, option);
335 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
336 "HCaptureSessionProxy CreateMediaLibrary failed, error: %{public}d", error);
337 uri = reply.ReadString();
338 cameraShotType = reply.ReadInt32();
339 burstKey = reply.ReadString();
340 return error;
341 }
342
CreateMediaLibrary(std::shared_ptr<PictureIntf> picture,sptr<CameraPhotoProxy> & photoProxy,std::string & uri,int32_t & cameraShotType,std::string & burstKey,int64_t timestamp)343 int32_t HStreamCaptureProxy::CreateMediaLibrary(std::shared_ptr<PictureIntf> picture,
344 sptr<CameraPhotoProxy> &photoProxy, std::string &uri, int32_t &cameraShotType,
345 std::string &burstKey, int64_t timestamp)
346 {
347 MessageParcel data;
348 MessageParcel reply;
349 MessageOption option;
350 if (picture == nullptr || photoProxy == nullptr) {
351 MEDIA_ERR_LOG("HStreamCaptureProxy CreateMediaLibrary picture or photoProxy is null");
352 return IPC_PROXY_ERR;
353 }
354 data.WriteInterfaceToken(GetDescriptor());
355 MEDIA_DEBUG_LOG("HStreamCaptureProxy CreateMediaLibrary picture->Marshalling E");
356 CHECK_ERROR_PRINT_LOG(!picture->Marshalling(data), "HStreamCaptureProxy picture Marshalling failed");
357 MEDIA_DEBUG_LOG("HStreamCaptureProxy CreateMediaLibrary picture->Marshalling X");
358 photoProxy->WriteToParcel(data);
359 data.WriteInt64(timestamp);
360 int error = Remote()->SendRequest(
361 static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CREATE_MEDIA_LIBRARY_MANAGER_PICTURE),
362 data, reply, option);
363 if (error != ERR_NONE) {
364 MEDIA_ERR_LOG("HStreamCaptureProxy CreateMediaLibrary failed, error: %{public}d", error);
365 }
366 uri = reply.ReadString();
367 cameraShotType = reply.ReadInt32();
368 burstKey = reply.ReadString();
369 return error;
370 }
371 } // namespace CameraStandard
372 } // namespace OHOS
373