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_callback_proxy.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
HStreamCaptureCallbackProxy(const sptr<IRemoteObject> & impl)22 HStreamCaptureCallbackProxy::HStreamCaptureCallbackProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<IStreamCaptureCallback>(impl) { }
24
OnCaptureStarted(int32_t captureId)25 int32_t HStreamCaptureCallbackProxy::OnCaptureStarted(int32_t captureId)
26 {
27 MessageParcel data;
28 MessageParcel reply;
29 MessageOption option;
30 option.SetFlags(option.TF_ASYNC);
31
32 data.WriteInterfaceToken(GetDescriptor());
33 data.WriteInt32(captureId);
34 int error = Remote()->SendRequest(
35 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED),
36 data, reply, option);
37 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
38 "HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
39
40 return error;
41 }
42
OnCaptureStarted(int32_t captureId,uint32_t exposureTime)43 int32_t HStreamCaptureCallbackProxy::OnCaptureStarted(int32_t captureId, uint32_t exposureTime)
44 {
45 MessageParcel data;
46 MessageParcel reply;
47 MessageOption option;
48 option.SetFlags(option.TF_ASYNC);
49
50 data.WriteInterfaceToken(GetDescriptor());
51 data.WriteInt32(captureId);
52 data.WriteUint32(exposureTime);
53 int error = Remote()->SendRequest(
54 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED_V1_2),
55 data, reply, option);
56 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
57 "HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
58
59 return error;
60 }
61
OnCaptureEnded(int32_t captureId,int32_t frameCount)62 int32_t HStreamCaptureCallbackProxy::OnCaptureEnded(int32_t captureId, int32_t frameCount)
63 {
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option;
67 option.SetFlags(option.TF_ASYNC);
68
69 data.WriteInterfaceToken(GetDescriptor());
70 data.WriteInt32(captureId);
71 data.WriteInt32(frameCount);
72 int error = Remote()->SendRequest(
73 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ENDED),
74 data, reply, option);
75 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
76 "HStreamCaptureCallbackProxy OnCaptureEnded failed, error: %{public}d", error);
77
78 return error;
79 }
80
OnCaptureError(int32_t captureId,int32_t errorCode)81 int32_t HStreamCaptureCallbackProxy::OnCaptureError(int32_t captureId, int32_t errorCode)
82 {
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option;
86 option.SetFlags(option.TF_ASYNC);
87
88 data.WriteInterfaceToken(GetDescriptor());
89 data.WriteInt32(captureId);
90 data.WriteInt32(errorCode);
91
92 int error = Remote()->SendRequest(
93 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ERROR),
94 data, reply, option);
95 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
96 "HStreamCaptureCallbackProxy OnCaptureError failed, error: %{public}d", error);
97
98 return error;
99 }
100
OnFrameShutter(int32_t captureId,uint64_t timestamp)101 int32_t HStreamCaptureCallbackProxy::OnFrameShutter(int32_t captureId, uint64_t timestamp)
102 {
103 MessageParcel data;
104 MessageParcel reply;
105 MessageOption option;
106 option.SetFlags(option.TF_ASYNC);
107
108 data.WriteInterfaceToken(GetDescriptor());
109 data.WriteInt32(captureId);
110 data.WriteUint64(timestamp);
111
112 int error = Remote()->SendRequest(
113 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER),
114 data, reply, option);
115 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
116 "HStreamCaptureCallbackProxy OnFrameShutter failed, error: %{public}d", error);
117
118 return error;
119 }
120
OnFrameShutterEnd(int32_t captureId,uint64_t timestamp)121 int32_t HStreamCaptureCallbackProxy::OnFrameShutterEnd(int32_t captureId, uint64_t timestamp)
122 {
123 MessageParcel data;
124 MessageParcel reply;
125 MessageOption option;
126 option.SetFlags(option.TF_ASYNC);
127
128 data.WriteInterfaceToken(GetDescriptor());
129 data.WriteInt32(captureId);
130 data.WriteUint64(timestamp);
131
132 int error = Remote()->SendRequest(
133 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER_END),
134 data, reply, option);
135 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
136 "HStreamCaptureCallbackProxy OnFrameShutterEnd failed, error: %{public}d", error);
137 return error;
138 }
139
OnCaptureReady(int32_t captureId,uint64_t timestamp)140 int32_t HStreamCaptureCallbackProxy::OnCaptureReady(int32_t captureId, uint64_t timestamp)
141 {
142 MessageParcel data;
143 MessageParcel reply;
144 MessageOption option;
145 option.SetFlags(option.TF_ASYNC);
146
147 data.WriteInterfaceToken(GetDescriptor());
148 data.WriteInt32(captureId);
149 data.WriteUint64(timestamp);
150
151 int error = Remote()->SendRequest(
152 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_READY),
153 data, reply, option);
154 CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
155 "HStreamCaptureCallbackProxy OnCaptureReady failed, error: %{public}d", error);
156 return error;
157 }
158
OnOfflineDeliveryFinished(int32_t captureId)159 int32_t HStreamCaptureCallbackProxy::OnOfflineDeliveryFinished(int32_t captureId)
160 {
161 MessageParcel data;
162 MessageParcel reply;
163 MessageOption option;
164 option.SetFlags(option.TF_ASYNC);
165
166 data.WriteInterfaceToken(GetDescriptor());
167 data.WriteInt32(captureId);
168
169 int error = Remote()->SendRequest(
170 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_OFFLINE_DELIVERY_FINISHED),
171 data, reply, option);
172 if (error != ERR_NONE) {
173 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureReady failed, error: %{public}d", error);
174 }
175 return error;
176 }
177 } // namespace CameraStandard
178 } // namespace OHOS