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_stub.h"
17 #include "camera_log.h"
18 #include "camera_util.h"
19 #include "metadata_utils.h"
20 #include "camera_service_ipc_interface_code.h"
21
22 namespace OHOS {
23 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int HStreamCaptureStub::OnRemoteRequest(
25 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27 DisableJeMalloc();
28 int errCode = -1;
29
30 if (data.ReadInterfaceToken() != GetDescriptor()) {
31 return errCode;
32 }
33 switch (code) {
34 case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_START):
35 errCode = HStreamCaptureStub::HandleCapture(data);
36 break;
37 case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_CANCEL):
38 errCode = CancelCapture();
39 break;
40 case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_SET_CALLBACK):
41 errCode = HStreamCaptureStub::HandleSetCallback(data);
42 break;
43 case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_RELEASE):
44 errCode = Release();
45 break;
46 case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_SERVICE_SET_THUMBNAIL):
47 errCode = HandleSetThumbnail(data);
48 break;
49 default:
50 MEDIA_ERR_LOG("HStreamCaptureStub request code %{public}u not handled", code);
51 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52 break;
53 }
54
55 return errCode;
56 }
57
HandleCapture(MessageParcel & data)58 int HStreamCaptureStub::HandleCapture(MessageParcel &data)
59 {
60 std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = nullptr;
61 OHOS::Camera::MetadataUtils::DecodeCameraMetadata(data, metadata);
62
63 return Capture(metadata);
64 }
65
HandleSetThumbnail(MessageParcel & data)66 int HStreamCaptureStub::HandleSetThumbnail(MessageParcel &data)
67 {
68 sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
69 if (remoteObj == nullptr) {
70 MEDIA_ERR_LOG("HCameraServiceStub HandleCreatePhotoOutput BufferProducer is null");
71 return IPC_STUB_INVALID_DATA_ERR;
72 }
73 sptr<OHOS::IBufferProducer> producer = iface_cast<OHOS::IBufferProducer>(remoteObj);
74 bool isEnabled = data.ReadBool();
75 int32_t ret = SetThumbnail(isEnabled, producer);
76 MEDIA_DEBUG_LOG("HCameraServiceStub HandleSetThumbnail result: %{public}d", ret);
77 return ret;
78 }
79
HandleSetCallback(MessageParcel & data)80 int HStreamCaptureStub::HandleSetCallback(MessageParcel &data)
81 {
82 auto remoteObject = data.ReadRemoteObject();
83 if (remoteObject == nullptr) {
84 MEDIA_ERR_LOG("HStreamCaptureStub HandleSetCallback StreamCaptureCallback is null");
85 return IPC_STUB_INVALID_DATA_ERR;
86 }
87
88 auto callback = iface_cast<IStreamCaptureCallback>(remoteObject);
89
90 return SetCallback(callback);
91 }
92 } // namespace CameraStandard
93 } // namespace OHOS
94