1 /* 2 * Copyright (c) 2021 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 UTEST_CAMERA_HDI_BASE_H 17 #define UTEST_CAMERA_HDI_BASE_H 18 19 #include <thread> 20 #include <unistd.h> 21 #include <vector> 22 #include <map> 23 #include <gtest/gtest.h> 24 #include <hdf_log.h> 25 #include <osal_mem.h> 26 #include "securec.h" 27 28 #include "camera.h" 29 #include "camera_metadata_info.h" 30 #include "metadata_utils.h" 31 #include "ibuffer.h" 32 #include "v1_0/ioffline_stream_operator.h" 33 #include <surface.h> 34 #include <display_type.h> 35 #include <fcntl.h> 36 #include <stdio.h> 37 #include <sys/ioctl.h> 38 #include <sys/wait.h> 39 40 #include "v1_0/icamera_host.h" 41 #include "v1_0/istream_operator.h" 42 #include "camera_host_callback.h" 43 #include "camera_device_callback.h" 44 #include "v1_0/icamera_device.h" 45 #include "stream_operator_callback.h" 46 #include "v1_0/istream_operator_callback.h" 47 48 #ifdef CAMERA_BUILT_ON_OHOS_LITE 49 #include "camera_device.h" 50 #include "camera_host.h" 51 #include "stream_operator.h" 52 #else 53 #include "if_system_ability_manager.h" 54 #include "iservice_registry.h" 55 #include "v1_0/camera_host_proxy.h" 56 #endif 57 58 using namespace OHOS::HDI::Camera::V1_0; 59 using namespace OHOS; 60 using namespace testing::ext; 61 using namespace OHOS::Camera; 62 63 class CameraHdiBaseTest : public testing::Test { 64 public: 65 static void SetUpTestCase(void); 66 static void TearDownTestCase(void); 67 68 void SetUp(void); 69 void TearDown(void); 70 71 protected: 72 virtual bool InitCameraHost(); 73 virtual bool GetCameraDevice(); 74 virtual bool GetStreamOperator(); 75 virtual bool GetCameraIds(); 76 int32_t SaveToFile(const std::string& path, const void* buffer, int32_t size) const; 77 uint64_t GetCurrentLocalTimeStamp() const; 78 int32_t SaveYUV(const char* type, const void* buffer, int32_t size); 79 80 protected: 81 #ifdef CAMERA_BUILT_ON_OHOS_LITE 82 std::shared_ptr<CameraHost> cameraHost_ = nullptr; 83 std::shared_ptr<ICameraDevice> cameraDevice_ = nullptr; 84 std::shared_ptr<IStreamOperator> streamOperator_ = nullptr; 85 #else 86 sptr<ICameraHost> cameraHost_ = nullptr; 87 sptr<ICameraDevice> cameraDevice_ = nullptr; 88 sptr<IStreamOperator> streamOperator_ = nullptr; 89 #endif 90 91 std::vector<std::string> cameraIds_; 92 int previewBufCnt = 0; 93 int32_t videoFd = -1; 94 }; 95 96 class DemoCameraDeviceCallback : public ICameraDeviceCallback { 97 public: 98 DemoCameraDeviceCallback() = default; 99 virtual ~DemoCameraDeviceCallback() = default; 100 int32_t OnError(ErrorType type, int32_t errorCode) override; 101 int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t>& result) override; 102 }; 103 104 class DemoCameraHostCallback : public ICameraHostCallback { 105 public: 106 DemoCameraHostCallback() = default; 107 virtual ~DemoCameraHostCallback() = default; 108 109 public: 110 int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override; 111 112 int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override; 113 114 int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override; 115 }; 116 117 class DemoStreamOperatorCallback : public IStreamOperatorCallback { 118 public: 119 DemoStreamOperatorCallback() = default; 120 virtual ~DemoStreamOperatorCallback() = default; 121 122 public: 123 int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t>& streamIds) override; 124 int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo>& infos) override; 125 int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo>& infos) override; 126 int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t>& streamIds, uint64_t timestamp) override; 127 }; 128 129 #endif // UTEST_CAMERA_HDI_BASE_H 130