/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_CAMERA_H_CAMERA_DEVICE_H #define OHOS_CAMERA_H_CAMERA_DEVICE_H #define EXPORT_API __attribute__((visibility("default"))) #include #include #include #include #include #include "camera_privacy.h" #include "v1_0/icamera_device_callback.h" #include "camera_metadata_info.h" #include "camera_util.h" #include "hcamera_device_stub.h" #include "hcamera_host_manager.h" #include "v1_0/icamera_device.h" #include "v1_1/icamera_device.h" #include "v1_2/icamera_device.h" #include "v1_3/icamera_device.h" #include "v1_0/icamera_host.h" namespace OHOS { namespace CameraStandard { constexpr int32_t HDI_STREAM_ID_INIT = 1; using OHOS::HDI::Camera::V1_0::CaptureEndedInfo; using OHOS::HDI::Camera::V1_0::CaptureErrorInfo; using OHOS::HDI::Camera::V1_0::ICameraDeviceCallback; using OHOS::HDI::Camera::V1_3::IStreamOperatorCallback; class EXPORT_API HCameraDevice : public HCameraDeviceStub, public ICameraDeviceCallback, public IStreamOperatorCallback { public: explicit HCameraDevice( sptr& cameraHostManager, std::string cameraID, const uint32_t callingTokenId); ~HCameraDevice(); int32_t Open() override; int32_t OpenSecureCamera(uint64_t* secureSeqId) override; int32_t Close() override; int32_t Release() override; int32_t UpdateSetting(const std::shared_ptr& settings) override; int32_t SetUsedAsPosition(uint8_t value) override; int32_t UpdateSettingOnce(const std::shared_ptr& settings); int32_t GetStatus(std::shared_ptr &metaIn, std::shared_ptr &metaOut) override; int32_t GetEnabledResults(std::vector& results) override; int32_t EnableResult(std::vector& results) override; int32_t DisableResult(std::vector& results) override; int32_t ReleaseStreams(std::vector& releaseStreamIds); sptr GetStreamOperator(); int32_t SetCallback(sptr& callback) override; int32_t OnError(OHOS::HDI::Camera::V1_0::ErrorType type, int32_t errorCode) override; int32_t OnResult(uint64_t timestamp, const std::vector& result) override; int32_t OnResult(int32_t streamId, const std::vector& result) override; std::shared_ptr GetDeviceAbility(); std::shared_ptr CloneCachedSettings(); std::string GetCameraId(); int32_t GetCameraType(); bool IsOpenedCameraDevice(); int32_t GetCallerToken(); int32_t CreateAndCommitStreams(std::vector& streamInfos, std::shared_ptr& deviceSettings, int32_t operationMode); int32_t UpdateStreams(std::vector& streamInfos); int32_t OperatePermissionCheck(uint32_t interfaceCode) override; int32_t OnCaptureStarted(int32_t captureId, const std::vector& streamIds) override; int32_t OnCaptureStarted_V1_2( int32_t captureId, const std::vector& infos) override; int32_t OnCaptureEnded(int32_t captureId, const std::vector& infos) override; int32_t OnCaptureEndedExt( int32_t captureId, const std::vector& infos) override; int32_t OnCaptureError(int32_t captureId, const std::vector& infos) override; int32_t OnFrameShutter(int32_t captureId, const std::vector& streamIds, uint64_t timestamp) override; int32_t OnFrameShutterEnd(int32_t captureId, const std::vector& streamIds, uint64_t timestamp) override; int32_t OnCaptureReady(int32_t captureId, const std::vector& streamIds, uint64_t timestamp) override; int32_t ResetDeviceSettings(); int32_t DispatchDefaultSettingToHdi(); void SetDeviceMuteMode(bool muteMode); uint8_t GetUsedAsPosition(); bool GetDeviceMuteMode(); void EnableMovingPhoto(bool isMovingPhotoEnabled); inline void SetStreamOperatorCallback(wptr operatorCallback) { std::lock_guard lock(proxyStreamOperatorCallbackMutex_); proxyStreamOperatorCallback_ = operatorCallback; } inline sptr GetStreamOperatorCallback() { std::lock_guard lock(proxyStreamOperatorCallbackMutex_); return proxyStreamOperatorCallback_.promote(); } inline void SetCameraPrivacy(sptr cameraPrivacy) { std::lock_guard lock(cameraPrivacyMutex_); cameraPrivacy_ = cameraPrivacy; } inline sptr GetCameraPrivacy() { std::lock_guard lock(cameraPrivacyMutex_); return cameraPrivacy_; } inline int32_t GenerateHdiStreamId() { return hdiStreamIdGenerator_.fetch_add(1); } inline void ResetHdiStreamId() { hdiStreamIdGenerator_ = HDI_STREAM_ID_INIT; } void NotifyCameraSessionStatus(bool running); void RemoveResourceWhenHostDied(); int64_t GetSecureCameraSeq(uint64_t* secureSeqId); bool CheckMovingPhotoSupported(int32_t mode); void NotifyCameraStatus(int32_t type); int32_t CloseDevice(); void SetMovingPhotoStartTimeCallback(std::function callback); void SetMovingPhotoEndTimeCallback(std::function callback); private: class FoldScreenListener; static const std::vector> reportTagInfos_; std::mutex opMutex_; // Lock the operations updateSettings_, streamOperator_, and hdiCameraDevice_. std::shared_ptr updateSettings_; sptr streamOperator_; sptr hdiCameraDevice_; std::shared_ptr cachedSettings_; sptr cameraHostManager_; std::string cameraID_; std::atomic isOpenedCameraDevice_; std::mutex deviceSvcCbMutex_; std::mutex cachedSettingsMutex_; static std::mutex g_deviceOpenCloseMutex_; sptr deviceSvcCallback_; std::map> statusSvcCallbacks_; uint32_t callerToken_; std::mutex cameraPrivacyMutex_; sptr cameraPrivacy_; std::mutex proxyStreamOperatorCallbackMutex_; wptr proxyStreamOperatorCallback_; std::mutex deviceAbilityMutex_; std::shared_ptr deviceAbility_; std::mutex deviceOpenLifeCycleMutex_; std::shared_ptr deviceOpenLifeCycleSettings_; std::string clientName_; int clientUserId_; uint8_t usedAsPosition_ = OHOS_CAMERA_POSITION_OTHER; std::mutex unPrepareZoomMutex_; uint32_t zoomTimerId_; std::atomic inPrepareZoom_; std::atomic deviceMuteMode_; bool isHasOpenSecure = false; uint64_t mSecureCameraSeqId = 0L; std::atomic hdiStreamIdGenerator_ = HDI_STREAM_ID_INIT; void UpdateDeviceOpenLifeCycleSettings(std::shared_ptr changedSettings); void ResetDeviceOpenLifeCycleSettings(); sptr GetDeviceServiceCallback(); void ResetCachedSettings(); int32_t InitStreamOperator(); void ReportMetadataDebugLog(const std::shared_ptr& settings); void RegisterFoldStatusListener(); void UnRegisterFoldStatusListener(); void CheckOnResultData(std::shared_ptr cameraResult); int32_t CreateStreams(std::vector& streamInfos); int32_t CommitStreams(std::shared_ptr& deviceSettings, int32_t operationMode); bool CanOpenCamera(); void ResetZoomTimer(); void CheckZoomChange(const std::shared_ptr& settings); void UnPrepareZoom(); int32_t OpenDevice(bool isEnableSecCam = false); void HandleFoldableDevice(); int32_t CheckPermissionBeforeOpenDevice(); bool HandlePrivacyBeforeOpenDevice(); void HandlePrivacyWhenOpenDeviceFail(); void HandlePrivacyAfterCloseDevice(); void DebugLogForSmoothZoom(const std::shared_ptr &settings, uint32_t tag); void DebugLogForAfRegions(const std::shared_ptr &settings, uint32_t tag); void DebugLogForAeRegions(const std::shared_ptr &settings, uint32_t tag); void DebugLogTag(const std::shared_ptr &settings, uint32_t tag, std::string tagName, std::string dfxUbStr); void CreateMuteSetting(std::shared_ptr& settings); int32_t UpdateDeviceSetting(); #ifdef MEMMGR_OVERRID int32_t RequireMemory(const std::string& reason); #endif void GetMovingPhotoStartAndEndTime(std::shared_ptr cameraResult); bool isMovingPhotoEnabled_ = false; std::mutex movingPhotoStartTimeCallbackLock_; std::mutex movingPhotoEndTimeCallbackLock_; std::function movingPhotoStartTimeCallback_; std::function movingPhotoEndTimeCallback_; }; } // namespace CameraStandard } // namespace OHOS #endif // OHOS_CAMERA_H_CAMERA_DEVICE_H