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 <memory> 21 #include <set> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "camera_death_recipient.h" 26 #include "camera_device.h" 27 #include "camera_device_ability_items.h" 28 #include "camera_info.h" 29 #include "capture_input.h" 30 #include "camera_device_service_callback_stub.h" 31 #include "icamera_device_service.h" 32 #include "icamera_device_service_callback.h" 33 #include "metadata_common_utils.h" 34 #include "output/camera_output_capability.h" 35 #include "camera_timer.h" 36 #include "color_space_info_parse.h" 37 namespace OHOS { 38 namespace CameraStandard { 39 class ErrorCallback { 40 public: 41 ErrorCallback() = default; 42 virtual ~ErrorCallback() = default; 43 virtual void OnError(const int32_t errorType, const int32_t errorMsg) const = 0; 44 }; 45 46 class CameraOcclusionDetectCallback { 47 public: 48 CameraOcclusionDetectCallback() = default; 49 virtual ~CameraOcclusionDetectCallback() = default; 50 virtual void OnCameraOcclusionDetected(const uint8_t isCameraOcclusion, const uint8_t isCameraLensDirty) const = 0; 51 }; 52 53 class ResultCallback { 54 public: 55 ResultCallback() = default; 56 virtual ~ResultCallback() = default; 57 virtual void OnResult(const uint64_t timestamp, 58 const std::shared_ptr<OHOS::Camera::CameraMetadata> &result) const = 0; 59 }; 60 61 class CameraInput : public CaptureInput { 62 public: 63 [[deprecated]] explicit CameraInput(sptr<ICameraDeviceService>& deviceObj, sptr<CameraInfo>& camera); 64 explicit CameraInput(sptr<ICameraDeviceService>& deviceObj, sptr<CameraDevice>& camera); 65 virtual ~CameraInput(); 66 67 /** 68 * @brief open camera. 69 */ 70 int Open() override; 71 72 /** 73 * @brief open secure camera. 74 */ 75 int Open(bool isEnableSecureCamera, uint64_t* secureSeqId) override; 76 77 /** 78 * @brief open camera with CameraConcurrentType. 79 */ 80 int Open(int32_t cameraConcurrentType) override; 81 82 /** 83 * @brief close camera. 84 */ 85 int Close() override; 86 87 /** 88 * @brief closeDelayed camera. 89 */ 90 int closeDelayed(int32_t delayTime); 91 92 /** 93 * @brief create new device control setting. 94 */ 95 [[deprecated]] void LockForControl(); 96 97 /** 98 * @brief submit device control setting. 99 * 100 * @return Returns CAMERA_OK is success. 101 */ 102 [[deprecated]] int32_t UnlockForControl(); 103 104 /** 105 * @brief Get the supported format for photo. 106 * 107 * @return Returns vector of camera_format_t supported format for photo. 108 */ 109 [[deprecated]] std::vector<camera_format_t> GetSupportedPhotoFormats(); 110 111 /** 112 * @brief Get the supported format for video. 113 * 114 * @return Returns vector of camera_format_t supported format for video. 115 */ 116 [[deprecated]] std::vector<camera_format_t> GetSupportedVideoFormats(); 117 118 /** 119 * @brief Get the supported format for preview. 120 * 121 * @return Returns vector of camera_format_t supported format for preview. 122 */ 123 [[deprecated]] std::vector<camera_format_t> GetSupportedPreviewFormats(); 124 125 /** 126 * @brief Get the supported exposure modes. 127 * 128 * @return Returns vector of camera_exposure_mode_enum_t supported exposure modes. 129 */ 130 [[deprecated]] std::vector<camera_exposure_mode_enum_t> GetSupportedExposureModes(); 131 132 /** 133 * @brief Query whether given exposure mode supported. 134 * 135 * @param camera_exposure_mode_enum_t exposure mode to query. 136 * @return True is supported false otherwise. 137 */ 138 [[deprecated]] bool IsExposureModeSupported(camera_exposure_mode_enum_t exposureMode); 139 140 /** 141 * @brief Set exposure mode. 142 * 143 * @param camera_exposure_mode_enum_t exposure mode to be set. 144 */ 145 [[deprecated]] void SetExposureMode(camera_exposure_mode_enum_t exposureMode); 146 147 /** 148 * @brief Get the current exposure mode. 149 * 150 * @return Returns current exposure mode. 151 */ 152 [[deprecated]] camera_exposure_mode_enum_t GetExposureMode(); 153 154 /** 155 * @brief Get the supported Focus modes. 156 * 157 * @return Returns vector of camera_focus_mode_enum_t supported exposure modes. 158 */ 159 [[deprecated]] std::vector<camera_focus_mode_enum_t> GetSupportedFocusModes(); 160 161 /** 162 * @brief Get exposure compensation range. 163 * 164 * @return Returns supported exposure compensation range. 165 */ 166 [[deprecated]] std::vector<float> GetExposureBiasRange(); 167 168 /** 169 * @brief Set exposure compensation value. 170 * 171 * @param exposure compensation value to be set. 172 */ 173 [[deprecated]] void SetExposureBias(float exposureBias); 174 175 /** 176 * @brief Get exposure compensation value. 177 * 178 * @return Returns current exposure compensation value. 179 */ 180 [[deprecated]] float GetExposureValue(); 181 182 /** 183 * @brief Query whether given focus mode supported. 184 * 185 * @param camera_focus_mode_enum_t focus mode to query. 186 * @return True is supported false otherwise. 187 */ 188 [[deprecated]] bool IsFocusModeSupported(camera_focus_mode_enum_t focusMode); 189 190 /** 191 * @brief Set Focus mode. 192 * 193 * @param camera_focus_mode_enum_t focus mode to be set. 194 */ 195 [[deprecated]] void SetFocusMode(camera_focus_mode_enum_t focusMode); 196 197 /** 198 * @brief Get the current focus mode. 199 * 200 * @return Returns current focus mode. 201 */ 202 [[deprecated]] camera_focus_mode_enum_t GetFocusMode(); 203 204 /** 205 * @brief Get focal length. 206 * 207 * @return Returns focal length value. 208 */ 209 [[deprecated]] float GetFocalLength(); 210 211 /** 212 * @brief Get the supported Zoom Ratio range. 213 * 214 * @return Returns vector<float> of supported Zoom ratio range. 215 */ 216 [[deprecated]] std::vector<float> GetSupportedZoomRatioRange(); 217 218 /** 219 * @brief Get the current Zoom Ratio. 220 * 221 * @return Returns current Zoom Ratio. 222 */ 223 [[deprecated]] float GetZoomRatio(); 224 225 /** 226 * @brief Set Zoom ratio. 227 * 228 * @param Zoom ratio to be set. 229 */ 230 [[deprecated]] void SetZoomRatio(float zoomRatio); 231 232 /** 233 * @brief Get the supported Focus modes. 234 * 235 * @return Returns vector of camera_focus_mode_enum_t supported exposure modes. 236 */ 237 [[deprecated]] std::vector<camera_flash_mode_enum_t> GetSupportedFlashModes(); 238 239 /** 240 * @brief Get the current flash mode. 241 * 242 * @return Returns current flash mode. 243 */ 244 [[deprecated]] camera_flash_mode_enum_t GetFlashMode(); 245 246 /** 247 * @brief Set flash mode. 248 * 249 * @param camera_flash_mode_enum_t flash mode to be set. 250 */ 251 [[deprecated]] void SetFlashMode(camera_flash_mode_enum_t flashMode); 252 253 /** 254 * @brief Set the error callback. 255 * which will be called when error occurs. 256 * 257 * @param The ErrorCallback pointer. 258 */ 259 void SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback); 260 261 /** 262 * @brief Set the result callback. 263 * which will be called when result callback. 264 * 265 * @param The ResultCallback pointer. 266 */ 267 void SetResultCallback(std::shared_ptr<ResultCallback> resultCallback); 268 269 /** 270 * @brief Set the CameraOcclusionDetect callback. 271 * which will be called when CameraOcclusionDetect callback . 272 * 273 * @param The CameraOcclusionDetect pointer. 274 */ 275 void SetOcclusionDetectCallback(std::shared_ptr<CameraOcclusionDetectCallback> cameraOcclusionDetectCallback); 276 277 /** 278 * @brief Release camera input. 279 */ 280 int Release() override; 281 282 /** 283 * @brief Get the camera Id. 284 * 285 * @return Returns the camera Id. 286 */ 287 std::string GetCameraId(); 288 289 /** 290 * @brief Get Camera Device. 291 * 292 * @return Returns Camera Device pointer. 293 */ 294 sptr<ICameraDeviceService> GetCameraDevice(); 295 296 /** 297 * @brief Set Camera Device pointer. 298 * 299 */ 300 void SetCameraDevice(sptr<ICameraDeviceService> deviceObj); 301 302 /** 303 * @brief Get ErrorCallback pointer. 304 * 305 * @return Returns ErrorCallback pointer. 306 */ 307 std::shared_ptr<ErrorCallback> GetErrorCallback(); 308 309 /** 310 * @brief Get ResultCallback pointer. 311 * 312 * @return Returns ResultCallback pointer. 313 */ 314 std::shared_ptr<ResultCallback> GetResultCallback(); 315 316 /** 317 * @brief Get CameraOcclusionDetectCallback pointer. 318 * 319 * @return Returns CameraOcclusionDetectCallback pointer. 320 */ 321 std::shared_ptr<CameraOcclusionDetectCallback> GetOcclusionDetectCallback(); 322 323 /** 324 * @brief get the camera info associated with the device. 325 * 326 * @return Returns camera info. 327 */ 328 void SetCameraDeviceInfo(sptr<CameraDevice> CameraObj); 329 330 /** 331 * @brief set the camera used as position with the device. 332 * 333 * @return Returns camera info. 334 */ 335 void SetInputUsedAsPosition(CameraPosition usedAsPosition); 336 337 /** 338 *@brief set the cameraObj. 339 */ 340 sptr<CameraDevice> GetCameraDeviceInfo() override; 341 342 /** 343 * @brief This function is called when there is device setting state change 344 * and process the state callback. 345 * 346 * @param result metadata got from callback from service layer. 347 */ 348 void ProcessCallbackUpdates(const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 349 350 /** 351 * @brief This function is called when there is focus state change 352 * and process the focus state callback. 353 * 354 * @param result metadata got from callback from service layer. 355 */ 356 [[deprecated]] void ProcessAutoFocusUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 357 358 /** 359 * @brief This function is called when there is exposure state change 360 * and process the exposure state callback. 361 * 362 * @param result metadata got from callback from service layer. 363 */ 364 [[deprecated]] void ProcessAutoExposureUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result); 365 366 /** 367 * @brief Get current Camera Settings. 368 * 369 * @return Returns string encoded metadata setting. 370 */ 371 std::string GetCameraSettings(); 372 373 /** 374 * @brief set the camera metadata setting. 375 * 376 * @param string encoded camera metadata setting. 377 * @return Returns 0 if success or appropriate error code if failed. 378 */ 379 int32_t SetCameraSettings(std::string setting); 380 381 std::shared_ptr<camera_metadata_item_t> GetMetaSetting(uint32_t metaTag); 382 383 int32_t GetCameraAllVendorTags(std::vector<vendorTag_t> &infos); 384 385 bool MergeMetadata(const std::shared_ptr<OHOS::Camera::CameraMetadata> srcMetadata, 386 std::shared_ptr<OHOS::Camera::CameraMetadata> dstMetadata); 387 void SwitchCameraDevice(sptr<ICameraDeviceService> &deviceObj, sptr<CameraDevice> &cameraObj); 388 void InitCameraInput(); 389 void GetMetadataFromService(sptr<CameraDevice> &cameraObj); 390 void ControlAuxiliary(AuxiliaryType type, AuxiliaryStatus status); 391 void RecoveryOldDevice(); 392 CameraConcurrentLimtedCapability limtedCapabilitySave_; 393 int32_t isConcurrentLimted_ = 0; 394 std::queue<uint32_t>timeQueue_; 395 void UnregisterTime(); 396 private: 397 std::mutex deviceObjMutex_; 398 std::mutex errorCallbackMutex_; 399 std::mutex cameraDeviceInfoMutex_; 400 std::mutex resultCallbackMutex_; 401 std::mutex occlusionCallbackMutex_; 402 sptr<ICameraDeviceService> deviceObj_; 403 sptr<CameraDevice> cameraObj_; 404 std::shared_ptr<ResultCallback> resultCallback_; 405 std::shared_ptr<ErrorCallback> errorCallback_; 406 std::shared_ptr<CameraOcclusionDetectCallback> cameraOcclusionDetectCallback_; 407 sptr<ICameraDeviceServiceCallback> CameraDeviceSvcCallback_; 408 std::mutex interfaceMutex_; 409 sptr<CameraDeathRecipient> deathRecipient_ = nullptr; 410 void CameraServerDied(pid_t pid); 411 int32_t UpdateSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata); 412 int32_t CameraDevicePhysicOpen(sptr<ICameraDeviceService> cameraDevicePhysic, int32_t cameraConcurrentType); 413 void InputRemoveDeathRecipient(); 414 std::map<CameraPosition, camera_position_enum> positionMapping; 415 }; 416 417 class CameraDeviceServiceCallback : public CameraDeviceServiceCallbackStub { 418 public: 419 std::mutex deviceCallbackMutex_; 420 wptr<CameraInput> camInput_ = nullptr; CameraDeviceServiceCallback()421 CameraDeviceServiceCallback() : camInput_(nullptr) { 422 } 423 CameraDeviceServiceCallback(CameraInput * camInput)424 explicit CameraDeviceServiceCallback(CameraInput* camInput) : camInput_(camInput) { 425 } 426 ~CameraDeviceServiceCallback()427 ~CameraDeviceServiceCallback() 428 { 429 std::lock_guard<std::mutex> lock(deviceCallbackMutex_); 430 camInput_ = nullptr; 431 } 432 433 int32_t OnError(const int32_t errorType, const int32_t errorMsg) override; 434 435 int32_t OnResult(const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata> &result) override; 436 }; 437 } // namespace CameraStandard 438 } // namespace OHOS 439 #endif // OHOS_CAMERA_CAMERA_INPUT_H 440 441