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 "remote_request_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 CAMERA_STREAM_CAPTURE_START:
35 errCode = HStreamCaptureStub::HandleCapture(data);
36 break;
37 case CAMERA_STREAM_CAPTURE_CANCEL:
38 errCode = CancelCapture();
39 break;
40 case CAMERA_STREAM_CAPTURE_SET_CALLBACK:
41 errCode = HStreamCaptureStub::HandleSetCallback(data);
42 break;
43 case CAMERA_STREAM_CAPTURE_RELEASE:
44 errCode = Release();
45 break;
46 default:
47 MEDIA_ERR_LOG("HStreamCaptureStub request code %{public}u not handled", code);
48 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 break;
50 }
51
52 return errCode;
53 }
54
HandleCapture(MessageParcel & data)55 int HStreamCaptureStub::HandleCapture(MessageParcel &data)
56 {
57 std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = nullptr;
58 OHOS::Camera::MetadataUtils::DecodeCameraMetadata(data, metadata);
59
60 return Capture(metadata);
61 }
62
HandleSetCallback(MessageParcel & data)63 int HStreamCaptureStub::HandleSetCallback(MessageParcel &data)
64 {
65 auto remoteObject = data.ReadRemoteObject();
66 if (remoteObject == nullptr) {
67 MEDIA_ERR_LOG("HStreamCaptureStub HandleSetCallback StreamCaptureCallback is null");
68 return IPC_STUB_INVALID_DATA_ERR;
69 }
70
71 auto callback = iface_cast<IStreamCaptureCallback>(remoteObject);
72
73 return SetCallback(callback);
74 }
75 } // namespace CameraStandard
76 } // namespace OHOS
77