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 "v1_3/ivideo_process_service.h" 25 #include "v1_3/ivideo_process_session.h" 26 #include "v1_3/ivideo_process_callback.h" 27 #include "hdi_common_v1_2.h" 28 29 namespace OHOS::Camera { 30 31 using namespace OHOS::HDI::Camera::V1_3; 32 class HdiCommonV1_3 : public OHOS::Camera::HdiCommonV1_2 { 33 public: 34 void Init(); 35 void Open(int cameraId); 36 void OpenSecureCamera(int cameraId); 37 void Close(); 38 void GetCameraMetadata(int cameraId); 39 void DefaultMeta(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos); 40 void DefaultInfosProfessionalCapture(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos); 41 void DefaultInfosMeta(std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> &infos); 42 void StartProfessionalStream(std::vector<StreamIntent> intents, uint8_t professionalMode); 43 void StartStream(std::vector<StreamIntent> intents, 44 OHOS::HDI::Camera::V1_3::OperationMode mode = OHOS::HDI::Camera::V1_3::NORMAL); 45 void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming); 46 void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds); 47 int32_t DefferredVideoTestInit(); 48 OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraHost> serviceV1_3 = nullptr; 49 OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraDevice> cameraDeviceV1_3 = nullptr; 50 class TestStreamOperatorCallbackV1_3; 51 OHOS::sptr<TestStreamOperatorCallbackV1_3> streamOperatorCallbackV1_3 = nullptr; 52 OHOS::sptr<OHOS::HDI::Camera::V1_3::IStreamOperator> streamOperator_V1_3 = nullptr; 53 std::shared_ptr<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1> streamInfoMeta = nullptr; 54 sptr<OHOS::HDI::Camera::V1_3::IVideoProcessService> videoProcessService_ = nullptr; 55 sptr<OHOS::HDI::Camera::V1_3::IVideoProcessSession> videoProcessSession_ = nullptr; 56 class TestVideoProcessCallback; 57 sptr<TestVideoProcessCallback> videoProcessCallback_ = nullptr; 58 int streamIdMeta = 106; 59 int metaWidth = 1920; 60 int metaHeight = 1080; 61 int captureIdMeta = 2060; 62 63 class TestStreamOperatorCallbackV1_3 : public OHOS::HDI::Camera::V1_3::IStreamOperatorCallback { 64 public: 65 std::shared_ptr<CameraMetadata> streamResultMeta = nullptr; 66 TestStreamOperatorCallbackV1_3() = default; 67 virtual ~TestStreamOperatorCallbackV1_3() = default; 68 int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override; 69 int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos) override; 70 int32_t OnCaptureEndedExt(int32_t captureId, 71 const std::vector<HDI::Camera::V1_3::CaptureEndedInfoExt> &infos) override; 72 int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos) override; 73 int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp) override; 74 int32_t OnCaptureStarted_V1_2(int32_t captureId, 75 const std::vector<HDI::Camera::V1_2::CaptureStartedInfo> &infos) override; 76 int32_t OnCaptureReady(int32_t captureId, const std::vector<int32_t>& streamIds, uint64_t timestamp) override; 77 int32_t OnFrameShutterEnd(int32_t captureId, const std::vector<int32_t>& streamIds, 78 uint64_t timestamp) override; 79 int32_t OnResult(int32_t streamId, const std::vector<uint8_t>& result) override; 80 }; 81 82 using StreamResultCallback = std::function<void (int32_t, const std::shared_ptr<CameraMetadata>)>; 83 static StreamResultCallback streamResultCallback_; 84 85 class TestVideoProcessCallback : public OHOS::HDI::Camera::V1_3::IVideoProcessCallback { 86 public: 87 TestVideoProcessCallback() = default; 88 virtual ~TestVideoProcessCallback() = default; 89 int32_t OnStatusChanged(OHOS::HDI::Camera::V1_2::SessionStatus status); 90 int32_t OnProcessDone(const std::string& videoId); 91 int32_t OnError(const std::string& videoId, OHOS::HDI::Camera::V1_2::ErrorCode errorCode); 92 }; 93 }; 94 } 95 #endif