• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "accesstoken_kit.h"
20 #include "privacy_kit.h"
21 #include "v1_0/icamera_device_callback.h"
22 #include "camera_metadata_info.h"
23 #include "hcamera_device_stub.h"
24 #include "hcamera_host_manager.h"
25 #include "v1_0/icamera_device.h"
26 #include "v1_0/icamera_host.h"
27 
28 #include <iostream>
29 
30 namespace OHOS {
31 namespace CameraStandard {
32 using namespace OHOS::HDI::Camera::V1_0;
33 class CameraDeviceCallback;
34 
35 const std::string ACCESS_CAMERA = "ohos.permission.CAMERA";
36 
37 class HCameraDevice : public HCameraDeviceStub {
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<IStreamOperator> &streamOperator);
51     sptr<IStreamOperator> GetStreamOperator();
52     int32_t SetCallback(sptr<ICameraDeviceServiceCallback> &callback) override;
53     int32_t SetStatusCallback(std::map<int32_t, sptr<ICameraServiceCallback>> &callbacks);
54     int32_t OnError(const ErrorType type, const int32_t errorMsg);
55     int32_t OnResult(const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata> &result);
56     int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status);
57     std::shared_ptr<OHOS::Camera::CameraMetadata> GetSettings();
58     std::string GetCameraId();
59     bool IsReleaseCameraDevice();
60     bool IsOpenedCameraDevice();
61     int32_t SetReleaseCameraDevice(bool isRelease);
62 
63 private:
64     sptr<ICameraDevice> hdiCameraDevice_;
65     sptr<HCameraHostManager> cameraHostManager_;
66     std::string cameraID_;
67     bool isReleaseCameraDevice_;
68     bool isOpenedCameraDevice_;
69 
70     sptr<ICameraDeviceServiceCallback> deviceSvcCallback_;
71     sptr<CameraDeviceCallback> deviceHDICallback_;
72     std::map<int32_t, sptr<ICameraServiceCallback>> statusSvcCallbacks_;
73     std::shared_ptr<OHOS::Camera::CameraMetadata> updateSettings_;
74     sptr<IStreamOperator> streamOperator_;
75     std::mutex deviceLock_;
76     uint32_t callerToken_;
77     std::vector<int32_t> videoFrameRateRange_;
78 
79     void ReportFlashEvent(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings);
80     void ReportMetadataDebugLog(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings);
81     void GetFrameRateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings);
82 };
83 
84 class CameraDeviceCallback : public ICameraDeviceCallback {
85 public:
86     explicit CameraDeviceCallback(sptr<HCameraDevice> hCameraDevice);
~CameraDeviceCallback()87     virtual ~CameraDeviceCallback()
88     {
89         hCameraDevice_ = nullptr;
90     }
91     int32_t OnError(ErrorType type, int32_t errorCode) override;
92     int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t>& result) override;
93 
94 private:
95     sptr<HCameraDevice> hCameraDevice_;
96 };
97 } // namespace CameraStandard
98 } // namespace OHOS
99 #endif // OHOS_CAMERA_H_CAMERA_DEVICE_H
100