• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hcapture_session_stub.h"
17 #include "camera_log.h"
18 #include "camera_util.h"
19 #include "camera_xcollie.h"
20 #include "camera_service_ipc_interface_code.h"
21 #include "camera_photo_proxy.h"
22 #include <memory>
23 
24 namespace OHOS {
25 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int HCaptureSessionStub::OnRemoteRequest(
27     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
28 {
29     DisableJeMalloc();
30     int errCode = -1;
31 
32     CHECK_ERROR_RETURN_RET(data.ReadInterfaceToken() != GetDescriptor(), errCode);
33     errCode = OperatePermissionCheck(code);
34     CHECK_ERROR_RETURN_RET(errCode != CAMERA_OK, errCode);
35     switch (code) {
36         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_BEGIN_CONFIG):
37             errCode = BeginConfig();
38             break;
39         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_CAN_ADD_INPUT):
40             errCode = HCaptureSessionStub::HandleCanAddInput(data, reply);
41             break;
42         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ADD_INPUT):
43             errCode = HCaptureSessionStub::HandleAddInput(data);
44             break;
45         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ADD_OUTPUT):
46             errCode = HCaptureSessionStub::HandleAddOutput(data);
47             break;
48         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_REMOVE_INPUT):
49             errCode = HCaptureSessionStub::HandleRemoveInput(data);
50             break;
51         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_REMOVE_OUTPUT):
52             errCode = HCaptureSessionStub::HandleRemoveOutput(data);
53             break;
54         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_COMMIT_CONFIG):
55             errCode = CommitConfig();
56             break;
57         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_START):
58             errCode = Start();
59             break;
60         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_STOP):
61             errCode = Stop();
62             break;
63         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_RELEASE):
64             {
65                 CameraXCollie cameraXCollie("hcaptureSessionStub::Release");
66                 errCode = Release();
67             }
68             break;
69         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_CALLBACK):
70             errCode = HandleSetCallback(data);
71             break;
72         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_UNSET_CALLBACK):
73             errCode = UnSetCallback();
74             break;
75         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_GET_SESSION_STATE):
76             errCode = HandleGetSessionState(reply);
77             break;
78         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_SMOOTH_ZOOM):
79             errCode = HandleSetSmoothZoom(data, reply);
80             break;
81         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_GET_ACTIVE_COLOR_SPACE):
82             errCode = HandleGetActiveColorSpace(reply);
83             break;
84         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SET_COLOR_SPACE):
85             errCode = HandleSetColorSpace(data);
86             break;
87         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_FEATURE_MODE):
88             errCode = HandleSetFeatureMode(data);
89             break;
90         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ENABLE_MOTION_PHOTO):
91             errCode = HandleEnableMovingPhoto(data);
92             break;
93         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_START_MOVING_PHOTO_CAPTURE):
94             errCode = HandleStartMovingPhotoCapture(data);
95             break;
96         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_PREVIEW_ROTATE):
97             {
98                 std::string deviceClass = data.ReadString();
99                 errCode = SetPreviewRotation(deviceClass);
100             }
101             break;
102 
103         case static_cast<uint32_t>(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_SET_COMMIT_CONFIG_FLAG):
104             {
105                 bool isNeedCommiting = data.ReadBool();
106                 errCode = SetCommitConfigFlag(isNeedCommiting);
107             }
108             break;
109         default:
110             MEDIA_ERR_LOG("HCaptureSessionStub request code %{public}u not handled", code);
111             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
112             break;
113     }
114 
115     return errCode;
116 }
117 
HandleAddInput(MessageParcel & data)118 int32_t HCaptureSessionStub::HandleAddInput(MessageParcel &data)
119 {
120     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
121     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
122         "HCaptureSessionStub HandleAddInput CameraDevice is null");
123 
124     sptr<ICameraDeviceService> cameraDevice = iface_cast<ICameraDeviceService>(remoteObj);
125     CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_STUB_INVALID_DATA_ERR,
126         "HCaptureSessionStub HandleAddInput Device is null");
127     return AddInput(cameraDevice);
128 }
129 
HandleCanAddInput(MessageParcel & data,MessageParcel & reply)130 int HCaptureSessionStub::HandleCanAddInput(MessageParcel &data, MessageParcel &reply)
131 {
132     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
133     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
134         "HCaptureSessionStub HandleAddInput CameraDevice is null");
135     sptr<ICameraDeviceService> cameraDevice = iface_cast<ICameraDeviceService>(remoteObj);
136     CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_STUB_INVALID_DATA_ERR,
137         "HCaptureSessionStub HandleCanAddInput CameraDevice is null");
138     bool result = false;
139     int32_t ret = CanAddInput(cameraDevice, result);
140     MEDIA_INFO_LOG("HandleCanAddInput ret: %{public}d, result: %{public}d", ret, result);
141     CHECK_ERROR_RETURN_RET_LOG(!(reply.WriteBool(result)), IPC_STUB_WRITE_PARCEL_ERR,
142         "HCaptureSessionStub HandleCanAddInput Write result failed");
143     return ret;
144 }
145 
HandleRemoveInput(MessageParcel & data)146 int32_t HCaptureSessionStub::HandleRemoveInput(MessageParcel &data)
147 {
148     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
149     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
150         "HCaptureSessionStub HandleRemoveInput CameraDevice is null");
151 
152     sptr<ICameraDeviceService> cameraDevice = iface_cast<ICameraDeviceService>(remoteObj);
153     CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, IPC_STUB_INVALID_DATA_ERR,
154         "HCaptureSessionStub HandleRemoveInput CameraDevice is null");
155     return RemoveInput(cameraDevice);
156 }
157 
HandleAddOutput(MessageParcel & data)158 int32_t HCaptureSessionStub::HandleAddOutput(MessageParcel &data)
159 {
160     StreamType streamType = static_cast<StreamType>(data.ReadUint32());
161     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
162     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
163         "HCaptureSessionStub HandleAddOutput remoteObj is null");
164     sptr<IStreamCommon> stream = nullptr;
165     if (streamType == StreamType::CAPTURE) {
166         stream = iface_cast<IStreamCapture>(remoteObj);
167     } else if (streamType == StreamType::REPEAT) {
168         stream = iface_cast<IStreamRepeat>(remoteObj);
169     }  else if (streamType == StreamType::METADATA) {
170         stream = iface_cast<IStreamMetadata>(remoteObj);
171     } else if (streamType == StreamType::DEPTH) {
172         stream = iface_cast<IStreamDepthData>(remoteObj);
173     }
174 
175     return AddOutput(streamType, stream);
176 }
177 
HandleRemoveOutput(MessageParcel & data)178 int32_t HCaptureSessionStub::HandleRemoveOutput(MessageParcel &data)
179 {
180     StreamType streamType = static_cast<StreamType>(data.ReadUint32());
181     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
182     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
183         "HCaptureSessionStub HandleRemoveOutput remoteObj is null");
184     sptr<IStreamCommon> stream = nullptr;
185     if (streamType == StreamType::CAPTURE) {
186         stream = iface_cast<IStreamCapture>(remoteObj);
187     } else if (streamType == StreamType::REPEAT) {
188         stream = iface_cast<IStreamRepeat>(remoteObj);
189     } else if (streamType == StreamType::METADATA) {
190         stream = iface_cast<IStreamMetadata>(remoteObj);
191     } else if (streamType == StreamType::DEPTH) {
192         stream = iface_cast<IStreamDepthData>(remoteObj);
193     }
194     return RemoveOutput(streamType, stream);
195 }
196 
HandleSetCallback(MessageParcel & data)197 int32_t HCaptureSessionStub::HandleSetCallback(MessageParcel &data)
198 {
199     auto remoteObject = data.ReadRemoteObject();
200     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_STUB_INVALID_DATA_ERR,
201         "HCaptureSessionStub HandleSetCallback CaptureSessionCallback is null");
202 
203     auto callback = iface_cast<ICaptureSessionCallback>(remoteObject);
204     CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_STUB_INVALID_DATA_ERR,
205         "HCaptureSessionStub HandleSetCallback callback is null");
206     return SetCallback(callback);
207 }
208 
HandleGetSessionState(MessageParcel & reply)209 int32_t HCaptureSessionStub::HandleGetSessionState(MessageParcel &reply)
210 {
211     CaptureSessionState sessionState;
212     int32_t ret = GetSessionState(sessionState);
213     CHECK_ERROR_RETURN_RET_LOG(!(reply.WriteUint32(static_cast<uint32_t>(sessionState))), IPC_STUB_WRITE_PARCEL_ERR,
214         "HCaptureSessionStub HandleGetSesstionState Write sessionState failed");
215     return ret;
216 }
217 
HandleGetActiveColorSpace(MessageParcel & reply)218 int HCaptureSessionStub::HandleGetActiveColorSpace(MessageParcel &reply)
219 {
220     ColorSpace currColorSpace;
221     int32_t ret = GetActiveColorSpace(currColorSpace);
222     CHECK_ERROR_RETURN_RET_LOG(!(reply.WriteInt32(static_cast<int32_t>(currColorSpace))), IPC_STUB_WRITE_PARCEL_ERR,
223         "HCaptureSessionStub HandleGetActiveColorSpace write colorSpace failed");
224     return ret;
225 }
226 
HandleSetColorSpace(MessageParcel & data)227 int HCaptureSessionStub::HandleSetColorSpace(MessageParcel &data)
228 {
229     ColorSpace colorSpace = static_cast<ColorSpace>(data.ReadInt32());
230     bool isNeedUpdate = data.ReadBool();
231     return SetColorSpace(colorSpace, isNeedUpdate);
232 }
233 
HandleSetSmoothZoom(MessageParcel & data,MessageParcel & reply)234 int HCaptureSessionStub::HandleSetSmoothZoom(MessageParcel &data, MessageParcel &reply)
235 {
236     int smoothZoomType = static_cast<int32_t>(data.ReadUint32());
237     int operationMode = static_cast<int32_t>(data.ReadUint32());
238     float targetZoomRatio = data.ReadFloat();
239     float duration;
240     int32_t ret = SetSmoothZoom(smoothZoomType, operationMode, targetZoomRatio, duration);
241     CHECK_ERROR_RETURN_RET_LOG(!(reply.WriteFloat(duration)), IPC_STUB_WRITE_PARCEL_ERR,
242         "HCaptureSessionStub HandleSetSmoothZoom Write duration failed");
243     return ret;
244 }
245 
HandleSetFeatureMode(MessageParcel & data)246 int HCaptureSessionStub::HandleSetFeatureMode(MessageParcel &data)
247 {
248     CHECK_ERROR_RETURN_RET(!CheckSystemApp(), CAMERA_NO_PERMISSION);
249     int featureMode = static_cast<int>(data.ReadUint32());
250     return SetFeatureMode(featureMode);
251 }
252 
HandleEnableMovingPhoto(MessageParcel & data)253 int32_t HCaptureSessionStub::HandleEnableMovingPhoto(MessageParcel &data)
254 {
255     bool isEnabled = data.ReadBool();
256     return EnableMovingPhoto(isEnabled);
257 }
258 
HandleStartMovingPhotoCapture(MessageParcel & data)259 int32_t HCaptureSessionStub::HandleStartMovingPhotoCapture(MessageParcel &data)
260 {
261     bool isMirror = data.ReadBool();
262     bool isConfig = data.ReadBool();
263     return EnableMovingPhotoMirror(isMirror, isConfig);
264 }
265 } // namespace CameraStandard
266 } // namespace OHOS
267