• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_DCAMERA_CLIENT_H
17 #define OHOS_DCAMERA_CLIENT_H
18 
19 #include "icamera_operator.h"
20 
21 #include <queue>
22 
23 #include "camera_info.h"
24 #include "camera_input.h"
25 #include "camera_manager.h"
26 #include "camera_output_capability.h"
27 #include "capture_input.h"
28 #include "capture_output.h"
29 #include "capture_session.h"
30 #include "photo_output.h"
31 #include "preview_output.h"
32 
33 #include "dcamera_photo_surface_listener.h"
34 
35 namespace OHOS {
36 namespace DistributedHardware {
37 class DCameraClient : public ICameraOperator {
38 public:
39     explicit DCameraClient(const std::string& dhId);
40     ~DCameraClient() override;
41 
42     int32_t Init() override;
43     int32_t UnInit() override;
44     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
45     int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos,
46         sptr<Surface>& surface) override;
47     int32_t StopCapture() override;
48     int32_t SetStateCallback(std::shared_ptr<StateCallback>& callback) override;
49     int32_t SetResultCallback(std::shared_ptr<ResultCallback>& callback) override;
50 
51 private:
52     int32_t ConfigCaptureSession(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
53     int32_t ConfigCaptureSessionInner();
54     int32_t CreateCaptureOutput(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
55     int32_t CreatePhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info);
56     int32_t CreatePreviewOutput(std::shared_ptr<DCameraCaptureInfo>& info);
57     int32_t StartCaptureInner(std::shared_ptr<DCameraCaptureInfo>& info);
58     int32_t StartPhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info);
59     void FindCameraMetadata(const std::string& metadataStr);
60     void SetPhotoCaptureRotation(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata,
61         std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting);
62     void SetPhotoCaptureQuality(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata,
63         std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting);
64     void SetPhotoCaptureLocation(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata,
65         std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting);
66     void ReleaseCaptureSession();
67     int32_t CameraServiceErrorType(const int32_t errorType);
68     CameraStandard::CameraFormat ConvertToCameraFormat(int32_t format);
69     void UpdateSettingCache(const std::string& metadataStr);
70 
71 private:
72     constexpr static uint32_t DCAMERA_MAX_METADATA_SIZE = 20;
73     constexpr static int32_t DCAMERA_CAPTURE_ROTATE_360 = 360;
74 
75     bool isInit_;
76     std::string cameraId_;
77     std::queue<std::string> cameraMetadatas_;
78     sptr<IConsumerSurface> photoSurface_;
79     sptr<Surface> previewSurface_;
80     sptr<CameraStandard::CameraDevice> cameraInfo_;
81     sptr<CameraStandard::CameraManager> cameraManager_;
82     sptr<CameraStandard::CaptureSession> captureSession_;
83     sptr<CameraStandard::CaptureInput> cameraInput_;
84     sptr<CameraStandard::CaptureOutput> photoOutput_;
85     sptr<CameraStandard::CaptureOutput> previewOutput_;
86     sptr<DCameraPhotoSurfaceListener> photoListener_;
87     std::shared_ptr<StateCallback> stateCallback_;
88     std::shared_ptr<ResultCallback> resultCallback_;
89 };
90 } // namespace DistributedHardware
91 } // namespace OHOS
92 #endif // OHOS_DCAMERA_CLIENT_H