1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file expected 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 HDI_COMMON_V1_2_H
17 #define HDI_COMMON_V1_2_H
18 
19 #include "v1_2/types.h"
20 #include "v1_2/icamera_host.h"
21 #include "v1_2/icamera_device.h"
22 #include "v1_2/istream_operator.h"
23 #include "v1_2/camera_host_proxy.h"
24 #include "v1_2/image_process_service_proxy.h"
25 #include "v1_2/iimage_process_session.h"
26 #include "v1_2/iimage_process_callback.h"
27 #include "hdi_common_v1_1.h"
28 
29 namespace OHOS::Camera {
30 
31 enum Numbers {
32     ZERO,
33     ONE,
34     TWO,
35     THREE,
36     FOUR,
37     FIVE,
38     SIX,
39     SEVEN,
40     EIGHT,
41     NINE,
42     TEN,
43     SIXTEEN = 16,
44 };
45 
46 using namespace OHOS::HDI::Camera::V1_2;
47 class HdiCommonV1_2 : public OHOS::Camera::HdiCommonV1_1 {
48 public:
49     void Init();
50     int32_t DefferredImageTestInit();
51     void Open(int cameraId);
52     void OpenCameraV1_2(int cameraId);
53     void GetCameraMetadata(int cameraId);
54     void DefaultSketch(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
55     void DefaultInfosPreviewV1_2(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
56     void DefaultInfosSketch(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
57     void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming);
58     void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds);
59     OHOS::sptr<OHOS::HDI::Camera::V1_2::ICameraHost> serviceV1_2 = nullptr;
60     OHOS::sptr<OHOS::HDI::Camera::V1_2::ICameraDevice> cameraDeviceV1_2 = nullptr;
61     OHOS::sptr<OHOS::HDI::Camera::V1_2::IStreamOperatorCallback> streamOperatorCallbackV1_2 = nullptr;
62     OHOS::sptr<OHOS::HDI::Camera::V1_2::ICameraHostCallback> hostCallbackV1_2 = nullptr;
63     OHOS::sptr<OHOS::HDI::Camera::V1_2::IStreamOperator> streamOperator_V1_2 = nullptr;
64     std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> streamInfoSketch = nullptr;
65     sptr<OHOS::HDI::Camera::V1_2::IImageProcessSession> imageProcessSession_ = nullptr;
66     sptr<OHOS::HDI::Camera::V1_2::IImageProcessService> imageProcessService_ = nullptr;
67     class TestImageProcessCallback;
68     sptr<TestImageProcessCallback> imageProcessCallback_ = nullptr;
69     std::vector<std::string> pendingImageIds_;
70     int analyzeFormat = PIXEL_FMT_YCRCB_420_SP;
71     int streamIdSketch = 105;
72     int sketchWidth = 640;
73     int sketchHeight = 480;
74     int captureIdSketch = 2050;
75     uint32_t itemCapacity = 100;
76     uint32_t dataCapacity = 2000;
77     uint32_t dataCount = 1;
78 
79     float statusV1_2;
80     static FlashlightStatus statusCallback;
81 
82     class TestStreamOperatorCallbackV1_2 : public OHOS::HDI::Camera::V1_2::IStreamOperatorCallback {
83     public:
84         TestStreamOperatorCallbackV1_2() = default;
85         virtual ~TestStreamOperatorCallbackV1_2() = default;
86         int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
87         int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos) override;
88         int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos) override;
89         int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp) override;
90         int32_t OnCaptureStarted_V1_2(int32_t captureId,
91             const std::vector<HDI::Camera::V1_2::CaptureStartedInfo> &infos) override;
92     };
93 
94     class TestCameraHostCallbackV1_2 : public OHOS::HDI::Camera::V1_2::ICameraHostCallback {
95     public:
96         TestCameraHostCallbackV1_2() = default;
97         virtual ~TestCameraHostCallbackV1_2() = default;
98 
99         int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override;
100         int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override;
101         int32_t OnFlashlightStatus_V1_2(FlashlightStatus status) override;
102         int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override;
103     };
104 
105     class TestImageProcessCallback : public OHOS::HDI::Camera::V1_2::IImageProcessCallback {
106     public:
107         int32_t coutProcessDone_ = 0;
108         int32_t coutStatusChanged_ = 0;
109         int32_t countError_ = 0;
110         std::string curImageId_;
111         int32_t curErrorCode_ = 0;
112         bool isDone_ = false;
113         OHOS::HDI::Camera::V1_2::ImageBufferInfo curImageBufferInfo_;
114         OHOS::HDI::Camera::V1_2::SessionStatus curStatus_;
115         TestImageProcessCallback() = default;
116         virtual ~TestImageProcessCallback() = default;
117         int32_t OnProcessDone(const std::string& imageId,
118             const OHOS::HDI::Camera::V1_2::ImageBufferInfo& buffer) override;
119         int32_t OnStatusChanged(OHOS::HDI::Camera::V1_2::SessionStatus status) override;
120         int32_t OnError(const std::string& imageId, OHOS::HDI::Camera::V1_2::ErrorCode errorCode) override;
121     };
122 };
123 }
124 #endif