/* * 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 #include #include #include #include #include "accesstoken_kit.h" #include "privacy_kit.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_0/icamera_host.h" namespace OHOS { namespace CameraStandard { 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_2::IStreamOperatorCallback; class 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 Close() override; int32_t Release() override; int32_t UpdateSetting(const std::shared_ptr& settings) 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; std::shared_ptr GetDeviceAbility(); std::shared_ptr CloneCachedSettings(); std::string GetCameraId(); 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 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 ResetDeviceSettings(); int32_t DispatchDefaultSettingToHdi(); inline void SetStreamOperatorCallback(wptr operatorCallback) { std::lock_guard lock(proxyStreamOperatorCallbackMutex_); proxyStreamOperatorCallback_ = operatorCallback; } inline sptr GetStreamOperatorCallback() { std::lock_guard lock(proxyStreamOperatorCallbackMutex_); return proxyStreamOperatorCallback_.promote(); } void NotifyCameraSessionStatus(bool running); private: class FoldScreenListener; 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 proxyStreamOperatorCallbackMutex_; wptr proxyStreamOperatorCallback_; std::mutex deviceAbilityMutex_; std::shared_ptr deviceAbility_; std::mutex deviceOpenLifeCycleMutex_; std::shared_ptr deviceOpenLifeCycleSettings_; std::string clientName_; int clientUserId_; std::mutex unPrepareZoomMutex_; uint32_t zoomTimerId_; std::atomic inPrepareZoom_; 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(); int32_t CloseDevice(); }; } // namespace CameraStandard } // namespace OHOS #endif // OHOS_CAMERA_H_CAMERA_DEVICE_H