1 /* 2 * Copyright (c) 2021-2022 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 #ifndef CAMERA_TEST_COMMON_H 16 #define CAMERA_TEST_COMMON_H 17 18 #include "input/camera_manager.h" 19 20 namespace OHOS { 21 namespace CameraStandard { 22 enum class VideoSaveMode { 23 CREATE = 0, 24 APPEND, 25 CLOSE 26 }; 27 28 enum class SurfaceType { 29 INVALID = 0, 30 PREVIEW, 31 SECOND_PREVIEW, 32 PHOTO, 33 VIDEO 34 }; 35 36 enum HostDeviceType { 37 /** 38 * Indicates an unknown device type. 39 */ 40 UNKNOWN = 0x00, 41 /** 42 * Indicates a smart phone. 43 */ 44 PHONE = 0x0E, 45 /** 46 * Indicates a smart pad. 47 */ 48 TABLET = 0x11, 49 }; 50 51 52 class TestUtils { 53 public: 54 static const std::int32_t FILE_PERMISSIONS_FLAG = 00766; 55 static const std::int32_t PREVIEW_SKIP_FRAMES = 10; 56 57 static camera_format_t GetCameraMetadataFormat(CameraFormat format); 58 static uint64_t GetCurrentLocalTimeStamp(); 59 static int32_t SaveYUV(const char* buffer, int32_t size, SurfaceType type); 60 static int32_t SaveJpeg(const char* buffer, int32_t size); 61 static bool IsNumber(const char number[]); 62 static int32_t SaveVideoFile(const char* buffer, int32_t size, VideoSaveMode operationMode, int32_t &fd); 63 }; 64 65 class TestCameraMngerCallback : public CameraManagerCallback { 66 public: 67 explicit TestCameraMngerCallback(const char* testName); 68 virtual ~TestCameraMngerCallback() = default; 69 void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const override; 70 void OnFlashlightStatusChanged(const std::string &cameraID, 71 const FlashStatus flashStatus) const override; 72 73 private: 74 const char* testName_; 75 }; 76 77 class TestDeviceCallback : public ErrorCallback { 78 public: 79 explicit TestDeviceCallback(const char* testName); 80 virtual ~TestDeviceCallback() = default; 81 void OnError(const int32_t errorType, const int32_t errorMsg) const override; 82 83 private: 84 const char* testName_; 85 }; 86 87 class TestOnResultCallback : public ResultCallback { 88 public: 89 explicit TestOnResultCallback(const char* testName); 90 virtual ~TestOnResultCallback() = default; 91 void OnResult(const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata> &result) const; 92 93 private: 94 const char* testName_; 95 }; 96 97 class TestPhotoOutputCallback : public PhotoStateCallback { 98 public: 99 explicit TestPhotoOutputCallback(const char* testName); 100 virtual ~TestPhotoOutputCallback() = default; 101 void OnCaptureStarted(const int32_t captureID) const override; 102 void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override; 103 void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override; 104 void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override; 105 106 private: 107 const char* testName_; 108 }; 109 110 class TestPreviewOutputCallback : public PreviewStateCallback { 111 public: 112 explicit TestPreviewOutputCallback(const char* testName); 113 virtual ~TestPreviewOutputCallback() = default; 114 void OnFrameStarted() const override; 115 void OnFrameEnded(const int32_t frameCount) const override; 116 void OnError(const int32_t errorCode) const override; 117 118 private: 119 const char* testName_; 120 }; 121 122 class TestVideoOutputCallback : public VideoStateCallback { 123 public: 124 explicit TestVideoOutputCallback(const char* testName); 125 virtual ~TestVideoOutputCallback() = default; 126 void OnFrameStarted() const override; 127 void OnFrameEnded(const int32_t frameCount) const override; 128 void OnError(const int32_t errorCode) const override; 129 130 private: 131 const char* testName_; 132 }; 133 134 class SurfaceListener : public IBufferConsumerListener { 135 public: 136 SurfaceListener(const char* testName, SurfaceType surfaceType, int32_t &fd, sptr<IConsumerSurface> surface); 137 virtual ~SurfaceListener() = default; 138 void OnBufferAvailable() override; 139 140 private: 141 const char* testName_; 142 SurfaceType surfaceType_; 143 int32_t &fd_; 144 sptr<IConsumerSurface> surface_; 145 int32_t previewIndex_ = 0; 146 int32_t secondPreviewIndex_ = 0; 147 }; 148 } // namespace CameraStandard 149 } // namespace OHOS 150 #endif // CAMERA_TEST_COMMON_H 151 152