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_H_CAMERA_DEVICE_H 17 #define OHOS_CAMERA_H_CAMERA_DEVICE_H 18 19 #include <iostream> 20 21 #include "accesstoken_kit.h" 22 #include "privacy_kit.h" 23 #include "v1_0/icamera_device_callback.h" 24 #include "camera_metadata_info.h" 25 #include "camera_util.h" 26 #include "hcamera_device_stub.h" 27 #include "hcamera_host_manager.h" 28 #include "v1_0/icamera_device.h" 29 #include "v1_0/icamera_host.h" 30 31 namespace OHOS { 32 namespace CameraStandard { 33 using namespace OHOS::HDI::Camera::V1_0; 34 class IDeviceOperatorsCallback; 35 36 37 class HCameraDevice : public HCameraDeviceStub, public ICameraDeviceCallback { 38 public: 39 HCameraDevice(sptr<HCameraHostManager> &cameraHostManager, std::string cameraID, const uint32_t callingTokenId); 40 ~HCameraDevice(); 41 42 int32_t Open() override; 43 int32_t Close() override; 44 int32_t Release() override; 45 int32_t UpdateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings) override; 46 int32_t GetEnabledResults(std::vector<int32_t> &results) override; 47 int32_t EnableResult(std::vector<int32_t> &results) override; 48 int32_t DisableResult(std::vector<int32_t> &results) override; 49 int32_t GetStreamOperator(sptr<IStreamOperatorCallback> callback, 50 sptr<OHOS::HDI::Camera::V1_1::IStreamOperator> &streamOperator); 51 sptr<OHOS::HDI::Camera::V1_1::IStreamOperator> GetStreamOperator(); 52 int32_t SetCallback(sptr<ICameraDeviceServiceCallback> &callback) override; 53 int32_t OnError(ErrorType type, int32_t errorCode) override; 54 int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t>& result) override; 55 std::shared_ptr<OHOS::Camera::CameraMetadata> GetSettings(); 56 std::string GetCameraId(); 57 bool IsReleaseCameraDevice(); 58 bool IsOpenedCameraDevice(); 59 int32_t SetReleaseCameraDevice(bool isRelease); 60 int32_t SetDeviceOperatorsCallback(wptr<IDeviceOperatorsCallback> callback); 61 int32_t OpenDevice(); 62 int32_t CloseDevice(); 63 int32_t GetCallerToken(); 64 65 private: 66 sptr<OHOS::HDI::Camera::V1_1::ICameraDevice> hdiCameraDevice_; 67 sptr<HCameraHostManager> cameraHostManager_; 68 std::string cameraID_; 69 bool isReleaseCameraDevice_; 70 bool isOpenedCameraDevice_; 71 std::mutex deviceSvcCbMutex_; 72 std::mutex videoFrameRangeMutex_; 73 std::mutex opMutex_; 74 sptr<ICameraDeviceServiceCallback> deviceSvcCallback_; 75 std::map<int32_t, wptr<ICameraServiceCallback>> statusSvcCallbacks_; 76 std::shared_ptr<OHOS::Camera::CameraMetadata> updateSettings_; 77 sptr<OHOS::HDI::Camera::V1_1::IStreamOperator> streamOperator_; 78 uint32_t callerToken_; 79 std::vector<int32_t> videoFrameRateRange_; 80 wptr<IDeviceOperatorsCallback> deviceOperatorsCallback_; 81 82 void ReportFlashEvent(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings); 83 void ReportMetadataDebugLog(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings); 84 void GetFrameRateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings); 85 }; 86 87 class IDeviceOperatorsCallback : public virtual RefBase { 88 public: 89 IDeviceOperatorsCallback() = default; 90 virtual ~IDeviceOperatorsCallback() = default; 91 virtual int32_t DeviceOpen(const std::string& cameraId) = 0; 92 virtual int32_t DeviceClose(const std::string& cameraId, pid_t pidFromSession = 0) = 0; 93 virtual std::vector<sptr<HCameraDevice>> CameraConflictDetection(const std::string& cameraId, 94 bool& isPermisson) = 0; 95 }; 96 } // namespace CameraStandard 97 } // namespace OHOS 98 #endif // OHOS_CAMERA_H_CAMERA_DEVICE_H 99