1 /*
2  * Copyright (c) 2024 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 UT_COMMON_H
17 #define UT_COMMON_H
18 
19 #include "v1_3/types.h"
20 #include "v1_3/icamera_host.h"
21 #include "v1_3/icamera_device.h"
22 #include "v1_3/istream_operator.h"
23 #include "v1_3/camera_host_proxy.h"
24 #include "hdi_common_v1_2.h"
25 
26 namespace OHOS::Camera {
27 
28 using namespace OHOS::HDI::Camera::V1_3;
29 class HdiCommonV1_3 : public OHOS::Camera::HdiCommonV1_2 {
30 public:
31     void Init();
32     void Open(int cameraId);
33     void OpenSecureCamera(int cameraId);
34     void Close();
35     void GetCameraMetadata(int cameraId);
36     void DefaultMeta(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
37     void DefaultInfosProfessionalCapture(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
38     void DefaultInfosMeta(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos);
39     void StartProfessionalStream(std::vector<StreamIntent> intents, uint8_t professionalMode);
40     void StartStream(std::vector<StreamIntent> intents,
41         OHOS::HDI::Camera::V1_3::OperationMode mode = OHOS::HDI::Camera::V1_3::NORMAL);
42     void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming);
43     void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds);
44     OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraHost> serviceV1_3 = nullptr;
45     OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraDevice> cameraDeviceV1_3 = nullptr;
46     class TestStreamOperatorCallbackV1_3;
47     OHOS::sptr<TestStreamOperatorCallbackV1_3> streamOperatorCallbackV1_3 = nullptr;
48     OHOS::sptr<OHOS::HDI::Camera::V1_3::IStreamOperator> streamOperator_V1_3 = nullptr;
49     std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> streamInfoMeta = nullptr;
50     int streamIdMeta = 106;
51     int metaWidth = 1280;
52     int metaHeight = 960;
53     int captureIdMeta = 2060;
54     uint32_t itemCapacity = 100;
55     uint32_t dataCapacity = 2000;
56     uint32_t dataCount = 1;
57 
58     class TestStreamOperatorCallbackV1_3 : public OHOS::HDI::Camera::V1_3::IStreamOperatorCallback {
59     public:
60         std::shared_ptr<CameraMetadata> streamResultMeta = nullptr;
61         TestStreamOperatorCallbackV1_3() = default;
62         virtual ~TestStreamOperatorCallbackV1_3() = default;
63         int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
64         int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos) override;
65         int32_t OnCaptureEndedExt(int32_t captureId,
66             const std::vector<HDI::Camera::V1_3::CaptureEndedInfoExt> &infos) override;
67         int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos) override;
68         int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp) override;
69         int32_t OnCaptureStarted_V1_2(int32_t captureId,
70             const std::vector<HDI::Camera::V1_2::CaptureStartedInfo> &infos) override;
71         int32_t OnCaptureReady(int32_t captureId, const std::vector<int32_t>& streamIds, uint64_t timestamp) override;
72         int32_t OnFrameShutterEnd(int32_t captureId, const std::vector<int32_t>& streamIds,
73             uint64_t timestamp) override;
74         int32_t OnResult(int32_t streamId, const std::vector<uint8_t>& result) override;
75     };
76 
77     using StreamResultCallback = std::function<void (int32_t, const std::shared_ptr<CameraMetadata>)>;
78     static StreamResultCallback streamResultCallback_;
79 };
80 }
81 #endif