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 #ifndef OHOS_CAMERA_CAMERA_INPUT_H 17 #define OHOS_CAMERA_CAMERA_INPUT_H 18 19 #include <iostream> 20 #include <unordered_map> 21 #include <set> 22 #include <vector> 23 #include "camera_info.h" 24 #include "camera_device.h" 25 #include "capture_input.h" 26 #include "icamera_device_service.h" 27 #include "icamera_device_service_callback.h" 28 namespace OHOS { 29 namespace CameraStandard { 30 class ErrorCallback { 31 public: 32 ErrorCallback() = default; 33 virtual ~ErrorCallback() = default; 34 virtual void OnError(const int32_t errorType, const int32_t errorMsg) const; 35 }; 36 37 class CameraInput : public CaptureInput { 38 public: 39 [[deprecated]] CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraInfo> &camera); 40 CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraDevice> &camera); ~CameraInput()41 ~CameraInput() 42 { 43 cameraObj_ = nullptr; 44 deviceObj_ = nullptr; 45 CameraDeviceSvcCallback_ = nullptr; 46 } 47 48 /** 49 * @brief open camera. 50 */ 51 int Open() override; 52 53 /** 54 * @brief close camera. 55 */ 56 int Close() override; 57 58 /** 59 * @brief create new device control setting. 60 */ 61 [[deprecated]] void LockForControl(); 62 63 /** 64 * @brief submit device control setting. 65 * 66 * @return Returns CAMERA_OK is success. 67 */ 68 [[deprecated]] int32_t UnlockForControl(); 69 70 /** 71 * @brief Get the supported format for photo. 72 * 73 * @return Returns vector of camera_format_t supported format for photo. 74 */ 75 [[deprecated]] std::vector<camera_format_t> GetSupportedPhotoFormats(); 76 77 /** 78 * @brief Get the supported format for video. 79 * 80 * @return Returns vector of camera_format_t supported format for video. 81 */ 82 [[deprecated]] std::vector<camera_format_t> GetSupportedVideoFormats(); 83 84 /** 85 * @brief Get the supported format for preview. 86 * 87 * @return Returns vector of camera_format_t supported format for preview. 88 */ 89 [[deprecated]] std::vector<camera_format_t> GetSupportedPreviewFormats(); 90 91 /** 92 * @brief Get the supported exposure modes. 93 * 94 * @return Returns vector of camera_exposure_mode_enum_t supported exposure modes. 95 */ 96 [[deprecated]] std::vector<camera_exposure_mode_enum_t> GetSupportedExposureModes(); 97 98 /** 99 * @brief Query whether given exposure mode supported. 100 * 101 * @param camera_exposure_mode_enum_t exposure mode to query. 102 * @return True is supported false otherwise. 103 */ 104 [[deprecated]] bool IsExposureModeSupported(camera_exposure_mode_enum_t exposureMode); 105 106 /** 107 * @brief Set exposure mode. 108 * 109 * @param camera_exposure_mode_enum_t exposure mode to be set. 110 */ 111 [[deprecated]] void SetExposureMode(camera_exposure_mode_enum_t exposureMode); 112 113 /** 114 * @brief Get the current exposure mode. 115 * 116 * @return Returns current exposure mode. 117 */ 118 [[deprecated]] camera_exposure_mode_enum_t GetExposureMode(); 119 120 /** 121 * @brief Get the supported Focus modes. 122 * 123 * @return Returns vector of camera_focus_mode_enum_t supported exposure modes. 124 */ 125 [[deprecated]] std::vector<camera_focus_mode_enum_t> GetSupportedFocusModes(); 126 127 /** 128 * @brief Get exposure compensation range. 129 * 130 * @return Returns supported exposure compensation range. 131 */ 132 [[deprecated]] std::vector<int32_t> GetExposureBiasRange(); 133 134 /** 135 * @brief Set exposure compensation value. 136 * 137 * @param exposure compensation value to be set. 138 */ 139 [[deprecated]] void SetExposureBias(int32_t exposureBias); 140 141 /** 142 * @brief Get exposure compensation value. 143 * 144 * @return Returns current exposure compensation value. 145 */ 146 [[deprecated]] int32_t GetExposureValue(); 147 148 /** 149 * @brief Query whether given focus mode supported. 150 * 151 * @param camera_focus_mode_enum_t focus mode to query. 152 * @return True is supported false otherwise. 153 */ 154 [[deprecated]] bool IsFocusModeSupported(camera_focus_mode_enum_t focusMode); 155 156 /** 157 * @brief Set Focus mode. 158 * 159 * @param camera_focus_mode_enum_t focus mode to be set. 160 */ 161 [[deprecated]] void SetFocusMode(camera_focus_mode_enum_t focusMode); 162 163 /** 164 * @brief Get the current focus mode. 165 * 166 * @return Returns current focus mode. 167 */ 168 [[deprecated]] camera_focus_mode_enum_t GetFocusMode(); 169 170 /** 171 * @brief Get focal length. 172 * 173 * @return Returns focal length value. 174 */ 175 [[deprecated]] float GetFocalLength(); 176 177 /** 178 * @brief Get the supported Zoom Ratio range. 179 * 180 * @return Returns vector<float> of supported Zoom ratio range. 181 */ 182 [[deprecated]] std::vector<float> GetSupportedZoomRatioRange(); 183 184 /** 185 * @brief Get the current Zoom Ratio. 186 * 187 * @return Returns current Zoom Ratio. 188 */ 189 [[deprecated]] float GetZoomRatio(); 190 191 /** 192 * @brief Set Zoom ratio. 193 * 194 * @param Zoom ratio to be set. 195 */ 196 [[deprecated]] void SetZoomRatio(float zoomRatio); 197 198 /** 199 * @brief Get the supported Focus modes. 200 * 201 * @return Returns vector of camera_focus_mode_enum_t supported exposure modes. 202 */ 203 [[deprecated]] std::vector<camera_flash_mode_enum_t> GetSupportedFlashModes(); 204 205 /** 206 * @brief Get the current flash mode. 207 * 208 * @return Returns current flash mode. 209 */ 210 [[deprecated]] camera_flash_mode_enum_t GetFlashMode(); 211 212 /** 213 * @brief Set flash mode. 214 * 215 * @param camera_flash_mode_enum_t flash mode to be set. 216 */ 217 [[deprecated]] void SetFlashMode(camera_flash_mode_enum_t flashMode); 218 219 /** 220 * @brief Set the error callback. 221 * which will be called when error occurs. 222 * 223 * @param The ErrorCallback pointer. 224 */ 225 void SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback); 226 227 /** 228 * @brief Release camera input. 229 */ 230 int Release() override; 231 232 /** 233 * @brief Get the camera Id. 234 * 235 * @return Returns the camera Id. 236 */ 237 std::string GetCameraId(); 238 239 /** 240 * @brief Get Camera Device. 241 * 242 * @return Returns Camera Device pointer. 243 */ 244 sptr<ICameraDeviceService> GetCameraDevice(); 245 246 /** 247 * @brief Get ErrorCallback pointer. 248 * 249 * @return Returns ErrorCallback pointer. 250 */ 251 std::shared_ptr<ErrorCallback> GetErrorCallback(); 252 253 /** 254 * @brief get the camera info associated with the device. 255 * 256 * @return Returns camera info. 257 */ 258 sptr<CameraDevice> GetCameraDeviceInfo() override; 259 260 /** 261 * @brief This function is called when there is device setting state change 262 * and process the state callback. 263 * 264 * @param result metadata got from callback from service layer. 265 */ 266 void ProcessDeviceCallbackUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 267 268 /** 269 * @brief This function is called when there is focus state change 270 * and process the focus state callback. 271 * 272 * @param result metadata got from callback from service layer. 273 */ 274 [[deprecated]] void ProcessAutoFocusUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 275 276 /** 277 * @brief This function is called when there is exposure state change 278 * and process the exposure state callback. 279 * 280 * @param result metadata got from callback from service layer. 281 */ 282 [[deprecated]] void ProcessAutoExposureUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 283 284 /** 285 * @brief Get current Camera Settings. 286 * 287 * @return Returns string encoded metadata setting. 288 */ 289 std::string GetCameraSettings(); 290 291 /** 292 * @brief set the camera metadata setting. 293 * 294 * @param string encoded camera metadata setting. 295 * @return Returns 0 if success or appropriate error code if failed. 296 */ 297 int32_t SetCameraSettings(std::string setting); 298 299 private: 300 sptr<CameraDevice> cameraObj_; 301 sptr<ICameraDeviceService> deviceObj_; 302 std::shared_ptr<ErrorCallback> errorCallback_; 303 sptr<ICameraDeviceServiceCallback> CameraDeviceSvcCallback_; 304 std::mutex interfaceMutex_; 305 306 int32_t UpdateSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata); 307 }; 308 } // namespace CameraStandard 309 } // namespace OHOS 310 #endif // OHOS_CAMERA_CAMERA_INPUT_H 311 312