1 /*
2 * Copyright (c) 2021 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 "stream_operator_callback_stub.h"
17 #include <hdf_log.h>
18 #include <hdf_base.h>
19 #include <hdf_sbuf_ipc.h>
20 #include "stream_operator_callback.h"
21 #include "cmd_common.h"
22
23 namespace OHOS::Camera {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t StreamOperatorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
25 MessageOption &option)
26 {
27 HDF_LOGE("%s: StreamOperatorCallbackStub::OnRemoteRequest entry!", __func__);
28 int32_t ret = HDF_SUCCESS;
29 switch (code) {
30 case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_STARTED: {
31 ret = OnCaptureStartedStub(data, reply, option);
32 break;
33 }
34 case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ENDED: {
35 ret = OnCaptureEndedStub(data, reply, option);
36 break;
37 }
38 case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ERROR: {
39 ret = OnCaptureErrorStub(data, reply, option);
40 break;
41 }
42 case CMD_STREAM_OPERATOR_CALLBACK_ON_FRAME_SHUTTER: {
43 ret = OnFrameShutterStub(data, reply, option);
44 break;
45 }
46 default: {
47 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49 }
50 return ret;
51 }
52
OnCaptureStartedStub(MessageParcel & data,MessageParcel & reply,MessageOption & option)53 int32_t StreamOperatorCallbackStub::OnCaptureStartedStub(MessageParcel &data, MessageParcel &reply,
54 MessageOption &option)
55 {
56 if (data.ReadInterfaceToken() != StreamOperatorCallbackStub::GetDescriptor()) {
57 HDF_LOGE("%{public}s: invalid interface descriptor.", __func__);
58 return INVALID_ARGUMENT;
59 }
60
61 int32_t captureId = data.ReadInt32();
62 std::vector<int32_t> streamIds;
63 if (!data.ReadInt32Vector(&streamIds)) {
64 HDF_LOGE("%{public}s: OnCaptureStarted read streamIds failed.", __func__);
65 return HDF_FAILURE;
66 }
67 OnCaptureStarted(captureId, streamIds);
68
69 return HDF_SUCCESS;
70 }
71
OnCaptureEndedStub(MessageParcel & data,MessageParcel & reply,MessageOption & option)72 int32_t StreamOperatorCallbackStub::OnCaptureEndedStub(MessageParcel &data, MessageParcel &reply,
73 MessageOption &option)
74 {
75 if (data.ReadInterfaceToken() != StreamOperatorCallbackStub::GetDescriptor()) {
76 HDF_LOGE("%{public}s: invalid interface descriptor.", __func__);
77 return INVALID_ARGUMENT;
78 }
79
80 int32_t captureId = data.ReadInt32();
81 int32_t count = data.ReadInt32();
82 std::vector<std::shared_ptr<CaptureEndedInfo>> info;
83 for (int32_t i = 0; i < count; i++) {
84 const CaptureEndedInfo *pInfo =
85 reinterpret_cast<const CaptureEndedInfo*>(
86 data.ReadBuffer(sizeof(CaptureEndedInfo)));
87 if (pInfo == nullptr) {
88 HDF_LOGE("%{public}s: read ended info failed.", __func__);
89 return HDF_FAILURE;
90 }
91 std::shared_ptr<CaptureEndedInfo> captureEndedInfo = std::make_shared<CaptureEndedInfo>();
92 captureEndedInfo->streamId_ = pInfo->streamId_;
93 captureEndedInfo->frameCount_ = pInfo->frameCount_;
94 info.push_back(captureEndedInfo);
95 }
96 OnCaptureEnded(captureId, info);
97
98 return HDF_SUCCESS;
99 }
100
OnCaptureErrorStub(MessageParcel & data,MessageParcel & reply,MessageOption & option)101 int32_t StreamOperatorCallbackStub::OnCaptureErrorStub(MessageParcel &data, MessageParcel &reply,
102 MessageOption &option)
103 {
104 if (data.ReadInterfaceToken() != StreamOperatorCallbackStub::GetDescriptor()) {
105 HDF_LOGE("%{public}s: invalid interface descriptor.", __func__);
106 return INVALID_ARGUMENT;
107 }
108
109 int32_t captureId = data.ReadInt32();
110 int32_t count = data.ReadInt32();
111 std::vector<std::shared_ptr<CaptureErrorInfo>> info;
112 for (int32_t i = 0; i < count; i++) {
113 const CaptureErrorInfo *pInfo =
114 reinterpret_cast<const CaptureErrorInfo*>(
115 data.ReadBuffer(sizeof(CaptureErrorInfo)));
116 if (pInfo == nullptr) {
117 HDF_LOGE("%{public}s: read error info failed.", __func__);
118 return HDF_FAILURE;
119 }
120 std::shared_ptr<CaptureErrorInfo> captureErrorInfo = std::make_shared<CaptureErrorInfo>();
121 captureErrorInfo->streamId_ = pInfo->streamId_;
122 captureErrorInfo->error_ = pInfo->error_;
123 info.push_back(captureErrorInfo);
124 }
125
126 OnCaptureError(captureId, info);
127 return HDF_SUCCESS;
128 }
129
OnFrameShutterStub(MessageParcel & data,MessageParcel & reply,MessageOption & option)130 int32_t StreamOperatorCallbackStub::OnFrameShutterStub(MessageParcel &data, MessageParcel &reply,
131 MessageOption &option)
132 {
133 if (data.ReadInterfaceToken() != StreamOperatorCallbackStub::GetDescriptor()) {
134 HDF_LOGE("%{public}s: invalid interface descriptor.", __func__);
135 return INVALID_ARGUMENT;
136 }
137
138 int32_t captureId = data.ReadInt32();
139 std::vector<int32_t> streamIds;
140 if (!data.ReadInt32Vector(&streamIds)) {
141 HDF_LOGE("%{public}s: read streamIds failed.", __func__);
142 return HDF_FAILURE;
143 }
144 uint64_t timestamp = data.ReadUint64();
145 OnFrameShutter(captureId, streamIds, timestamp);
146
147 return HDF_SUCCESS;
148 }
149 }
150