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 class TestUtils { 37 public: 38 static const std::int32_t FILE_PERMISSIONS_FLAG = 00766; 39 static const std::int32_t PREVIEW_SKIP_FRAMES = 10; 40 41 static camera_format_t GetCameraMetadataFormat(CameraFormat format); 42 static uint64_t GetCurrentLocalTimeStamp(); 43 static int32_t SaveYUV(const char* buffer, int32_t size, SurfaceType type); 44 static int32_t SaveJpeg(const char* buffer, int32_t size); 45 static bool IsNumber(const char number[]); 46 static int32_t SaveVideoFile(const char* buffer, int32_t size, VideoSaveMode operationMode, int32_t &fd); 47 }; 48 49 class TestCameraMngerCallback : public CameraManagerCallback { 50 public: 51 explicit TestCameraMngerCallback(const char* testName); 52 virtual ~TestCameraMngerCallback() = default; 53 void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const override; 54 void OnFlashlightStatusChanged(const std::string &cameraID, 55 const FlashStatus flashStatus) const override; 56 57 private: 58 const char* testName_; 59 }; 60 61 class TestDeviceCallback : public ErrorCallback { 62 public: 63 explicit TestDeviceCallback(const char* testName); 64 virtual ~TestDeviceCallback() = default; 65 void OnError(const int32_t errorType, const int32_t errorMsg) const override; 66 67 private: 68 const char* testName_; 69 }; 70 71 class TestPhotoOutputCallback : public PhotoStateCallback { 72 public: 73 explicit TestPhotoOutputCallback(const char* testName); 74 virtual ~TestPhotoOutputCallback() = default; 75 void OnCaptureStarted(const int32_t captureID) const override; 76 void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override; 77 void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override; 78 void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override; 79 80 private: 81 const char* testName_; 82 }; 83 84 class TestPreviewOutputCallback : public PreviewStateCallback { 85 public: 86 explicit TestPreviewOutputCallback(const char* testName); 87 virtual ~TestPreviewOutputCallback() = default; 88 void OnFrameStarted() const override; 89 void OnFrameEnded(const int32_t frameCount) const override; 90 void OnError(const int32_t errorCode) const override; 91 92 private: 93 const char* testName_; 94 }; 95 96 class TestVideoOutputCallback : public VideoStateCallback { 97 public: 98 explicit TestVideoOutputCallback(const char* testName); 99 virtual ~TestVideoOutputCallback() = default; 100 void OnFrameStarted() const override; 101 void OnFrameEnded(const int32_t frameCount) const override; 102 void OnError(const int32_t errorCode) const override; 103 104 private: 105 const char* testName_; 106 }; 107 108 class SurfaceListener : public IBufferConsumerListener { 109 public: 110 SurfaceListener(const char* testName, SurfaceType surfaceType, int32_t &fd, sptr<Surface> surface); 111 virtual ~SurfaceListener() = default; 112 void OnBufferAvailable() override; 113 114 private: 115 const char* testName_; 116 SurfaceType surfaceType_; 117 int32_t &fd_; 118 sptr<Surface> surface_; 119 int32_t previewIndex_ = 0; 120 int32_t secondPreviewIndex_ = 0; 121 }; 122 } // namespace CameraStandard 123 } // namespace OHOS 124 #endif // CAMERA_TEST_COMMON_H 125 126