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_repeat_proxy.h"
17
18 #include "camera_log.h"
19 #include "camera_service_ipc_interface_code.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
23 static constexpr float SKETCH_RATIO_MAX_VALUE = 100.0f;
HStreamRepeatProxy(const sptr<IRemoteObject> & impl)24 HStreamRepeatProxy::HStreamRepeatProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IStreamRepeat>(impl) {}
25
~HStreamRepeatProxy()26 HStreamRepeatProxy::~HStreamRepeatProxy()
27 {
28 MEDIA_INFO_LOG("~HStreamRepeatProxy is called");
29 }
30
Start()31 int32_t HStreamRepeatProxy::Start()
32 {
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option;
36
37 data.WriteInterfaceToken(GetDescriptor());
38 int error = Remote()->SendRequest(
39 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_START_VIDEO_RECORDING), data, reply, option);
40 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy Start failed, error: %{public}d", error);
41
42 return error;
43 }
44
Stop()45 int32_t HStreamRepeatProxy::Stop()
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>(StreamRepeatInterfaceCode::CAMERA_STOP_VIDEO_RECORDING), data, reply, option);
54 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy Stop failed, error: %{public}d", error);
55
56 return error;
57 }
58
Release()59 int32_t HStreamRepeatProxy::Release()
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>(StreamRepeatInterfaceCode::CAMERA_STREAM_REPEAT_RELEASE), data, reply, option);
68 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy Stop failed, error: %{public}d", error);
69 return error;
70 }
71
SetCallback(sptr<IStreamRepeatCallback> & callback)72 int32_t HStreamRepeatProxy::SetCallback(sptr<IStreamRepeatCallback>& callback)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR, "HStreamRepeatProxy SetCallback callback is null");
79
80 data.WriteInterfaceToken(GetDescriptor());
81 data.WriteRemoteObject(callback->AsObject());
82
83 int error = Remote()->SendRequest(
84 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_STREAM_REPEAT_SET_CALLBACK), data, reply, option);
85 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy SetCallback failed, error: %{public}d", error);
86
87 return error;
88 }
89
UnSetCallback()90 int32_t HStreamRepeatProxy::UnSetCallback()
91 {
92 MessageParcel data;
93 MessageParcel reply;
94 MessageOption option;
95 data.WriteInterfaceToken(GetDescriptor());
96 int error = Remote()->SendRequest(
97 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_STREAM_REPEAT_UNSET_CALLBACK), data, reply, option);
98 if (error != ERR_NONE) {
99 MEDIA_ERR_LOG("HStreamRepeatProxy UnSetCallback failed, error: %{public}d", error);
100 }
101 return error;
102 }
103
AddDeferredSurface(const sptr<OHOS::IBufferProducer> & producer)104 int32_t HStreamRepeatProxy::AddDeferredSurface(const sptr<OHOS::IBufferProducer>& producer)
105 {
106 MessageParcel data;
107 MessageParcel reply;
108 MessageOption option;
109
110 CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_PROXY_ERR,
111 "HStreamRepeatProxy AddDeferredSurface producer is null");
112
113 data.WriteInterfaceToken(GetDescriptor());
114 data.WriteRemoteObject(producer->AsObject());
115 int error = Remote()->SendRequest(
116 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_ADD_DEFERRED_SURFACE), data, reply, option);
117 CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
118 "HStreamRepeatProxy::AddDeferredSurface failed, error: %{public}d", error);
119
120 return error;
121 }
122
ForkSketchStreamRepeat(int32_t width,int32_t height,sptr<IStreamRepeat> & sketchStream,float sketchRatio)123 int32_t HStreamRepeatProxy::ForkSketchStreamRepeat(
124 int32_t width, int32_t height, sptr<IStreamRepeat>& sketchStream, float sketchRatio)
125 {
126 MessageParcel data;
127 MessageParcel reply;
128 MessageOption option;
129
130 CHECK_ERROR_RETURN_RET_LOG(width <= 0 || height <= 0, IPC_PROXY_ERR,
131 "HStreamRepeatProxy ForkSketchStreamRepeat producer is null or invalid size is set");
132
133 data.WriteInterfaceToken(GetDescriptor());
134 data.WriteInt32(width);
135 data.WriteInt32(height);
136 data.WriteFloat(sketchRatio);
137
138 int error = Remote()->SendRequest(
139 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_FORK_SKETCH_STREAM_REPEAT), data, reply, option);
140 auto remoteObject = reply.ReadRemoteObject();
141 if (remoteObject != nullptr) {
142 sketchStream = iface_cast<IStreamRepeat>(remoteObject);
143 } else {
144 MEDIA_ERR_LOG("HCameraServiceProxy ForkSketchStreamRepeat sketchStream is null");
145 error = IPC_PROXY_ERR;
146 }
147 return error;
148 }
149
UpdateSketchRatio(float sketchRatio)150 int32_t HStreamRepeatProxy::UpdateSketchRatio(float sketchRatio)
151 {
152 MessageParcel data;
153 MessageParcel reply;
154 MessageOption option;
155
156 // SketchRatio value could be negative value
157 CHECK_ERROR_RETURN_RET_LOG(sketchRatio > SKETCH_RATIO_MAX_VALUE, IPC_PROXY_ERR,
158 "HStreamRepeatProxy UpdateSketchRatio value is illegal %{public}f", sketchRatio);
159
160 data.WriteInterfaceToken(GetDescriptor());
161 data.WriteFloat(sketchRatio);
162 int error = Remote()->SendRequest(
163 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_UPDATE_SKETCH_RATIO), data, reply, option);
164 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy UpdateSketchRatio failed, error: %{public}d", error);
165 return error;
166 }
167
RemoveSketchStreamRepeat()168 int32_t HStreamRepeatProxy::RemoveSketchStreamRepeat()
169 {
170 MessageParcel data;
171 MessageParcel reply;
172 MessageOption option;
173
174 data.WriteInterfaceToken(GetDescriptor());
175 int error = Remote()->SendRequest(
176 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_REMOVE_SKETCH_STREAM_REPEAT), data, reply, option);
177 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy Stop failed, error: %{public}d", error);
178 return error;
179 }
180
SetFrameRate(int32_t minFrameRate,int32_t maxFrameRate)181 int32_t HStreamRepeatProxy::SetFrameRate(int32_t minFrameRate, int32_t maxFrameRate)
182 {
183 MessageParcel data;
184 MessageParcel reply;
185 MessageOption option;
186
187 data.WriteInterfaceToken(GetDescriptor());
188 data.WriteInt32(minFrameRate);
189 data.WriteInt32(maxFrameRate);
190
191 int error = Remote()->SendRequest(
192 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_STREAM_FRAME_RANGE_SET), data, reply, option);
193 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy SetFrameRate failed, error: %{public}d", error);
194 return error;
195 }
196
EnableSecure(bool isEnable)197 int32_t HStreamRepeatProxy::EnableSecure(bool isEnable)
198 {
199 MessageParcel data;
200 MessageParcel reply;
201 MessageOption option;
202
203 data.WriteInterfaceToken(GetDescriptor());
204 data.WriteBool(isEnable);
205 int error = Remote()->SendRequest(
206 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_ENABLE_SECURE_STREAM), data, reply, option);
207 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy EnableSecure failed, error: %{public}d", error);
208 return error;
209 }
210
SetMirror(bool isEnable)211 int32_t HStreamRepeatProxy::SetMirror(bool isEnable)
212 {
213 MessageParcel data;
214 MessageParcel reply;
215 MessageOption option;
216
217 data.WriteInterfaceToken(GetDescriptor());
218 data.WriteBool(isEnable);
219 int error = Remote()->SendRequest(
220 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_ENABLE_STREAM_MIRROR), data, reply, option);
221 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamRepeatProxy SetMirror failed, error: %{public}d", error);
222 return error;
223 }
224
GetMirror(bool & isEnable)225 int32_t HStreamRepeatProxy::GetMirror(bool& isEnable)
226 {
227 MessageParcel data;
228 MessageParcel reply;
229 MessageOption option;
230
231 data.WriteInterfaceToken(GetDescriptor());
232 int error = Remote()->SendRequest(
233 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_GET_STREAM_MIRROR), data, reply, option);
234 if (error != ERR_NONE) {
235 MEDIA_ERR_LOG("HStreamRepeatProxy GetMirror failed, error: %{public}d", error);
236 }
237 isEnable = reply.ReadBool();
238 MEDIA_DEBUG_LOG("HCameraServiceProxy mirror Enabled is %{public}d", isEnable);
239 return error;
240 }
241
AttachMetaSurface(const sptr<OHOS::IBufferProducer> & producer,int32_t videoMetaType)242 int32_t HStreamRepeatProxy::AttachMetaSurface(const sptr<OHOS::IBufferProducer>& producer, int32_t videoMetaType)
243 {
244 MessageParcel data;
245 MessageParcel reply;
246 MessageOption option;
247
248 CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_PROXY_ERR,
249 "HStreamRepeatProxy AttachMetaSurface producer is null");
250
251 data.WriteInterfaceToken(GetDescriptor());
252 data.WriteRemoteObject(producer->AsObject());
253 data.WriteInt32(videoMetaType);
254 int error = Remote()->SendRequest(
255 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_ATTACH_META_SURFACE), data, reply, option);
256 CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, error,
257 "HStreamRepeatProxy::AttachMetaSurface failed, error: %{public}d", error);
258
259 return error;
260 }
261
SetCameraRotation(bool isEnable,int32_t rotation)262 int32_t HStreamRepeatProxy::SetCameraRotation(bool isEnable, int32_t rotation)
263 {
264 MessageParcel data;
265 MessageParcel reply;
266 MessageOption option;
267
268 data.WriteInterfaceToken(GetDescriptor());
269 data.WriteBool(isEnable);
270 data.WriteInt32(rotation);
271
272 int error = Remote()->SendRequest(
273 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_PRIVIEW_ROTATION), data, reply, option);
274 if (error != ERR_NONE) {
275 MEDIA_ERR_LOG("HStreamRepeatProxy SetCameraRotation failed, error: %{public}d", error);
276 }
277 return error;
278 }
279
SetCameraApi(uint32_t apiCompatibleVersion)280 int32_t HStreamRepeatProxy::SetCameraApi(uint32_t apiCompatibleVersion)
281 {
282 MessageParcel data;
283 MessageParcel reply;
284 MessageOption option;
285
286 data.WriteInterfaceToken(GetDescriptor());
287 data.WriteUint32(apiCompatibleVersion);
288
289 int error = Remote()->SendRequest(
290 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_API_VERSION), data, reply, option);
291 if (error != ERR_NONE) {
292 MEDIA_ERR_LOG("HStreamRepeatProxy SetCameraApi failed, error: %{public}d", error);
293 }
294 return error;
295 }
296
ToggleAutoVideoFrameRate(bool isEnable)297 int32_t HStreamRepeatProxy::ToggleAutoVideoFrameRate(bool isEnable)
298 {
299 MessageParcel data;
300 MessageParcel reply;
301 MessageOption option;
302
303 data.WriteInterfaceToken(GetDescriptor());
304 data.WriteBool(isEnable);
305 int error = Remote()->SendRequest(
306 static_cast<uint32_t>(StreamRepeatInterfaceCode::CAMERA_ENABLE_AUTO_FRAME_RATE), data, reply, option);
307 if (error != ERR_NONE) {
308 MEDIA_ERR_LOG("HStreamRepeatProxy SetCameraRotation failed, error: %{public}d", error);
309 }
310 return error;
311 }
312 } // namespace CameraStandard
313 } // namespace OHOS
314