1 /* 2 * Copyright (c) 2025 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 CAMERA_SESSION_MODULETEST_H 17 #define CAMERA_SESSION_MODULETEST_H 18 19 #include "gtest/gtest.h" 20 21 #include "input/camera_device.h" 22 #include "input/camera_input.h" 23 #include "input/camera_manager.h" 24 #include "input/camera_manager_for_sys.h" 25 #include "output/camera_output_capability.h" 26 #include "session/aperture_video_session.h" 27 #include "session/capture_scene_const.h" 28 #include "session/capture_session.h" 29 #include "session/fluorescence_photo_session.h" 30 #include "session/high_res_photo_session.h" 31 #include "session/light_painting_session.h" 32 #include "session/macro_photo_session.h" 33 #include "session/macro_video_session.h" 34 #include "session/night_session.h" 35 #include "session/panorama_session.h" 36 #include "session/photo_session.h" 37 #include "session/portrait_session.h" 38 #include "session/profession_session.h" 39 #include "session/quick_shot_photo_session.h" 40 #include "session/scan_session.h" 41 #include "session/secure_camera_session.h" 42 #include "session/slow_motion_session.h" 43 #include "session/time_lapse_photo_session.h" 44 #include "session/video_session.h" 45 46 #include "accesstoken_kit.h" 47 #include "camera_error_code.h" 48 #include "camera_log.h" 49 #include "camera_metadata_operator.h" 50 #include "camera_util.h" 51 #include "hap_token_info.h" 52 #include "nativetoken_kit.h" 53 #include "parameter.h" 54 #include "surface.h" 55 #include "system_ability_definition.h" 56 #include "test_common.h" 57 #include "token_setproc.h" 58 59 namespace OHOS { 60 namespace CameraStandard { 61 62 typedef struct { 63 Profile preview; 64 Profile photo; 65 VideoProfile video; 66 } SelectProfiles; 67 68 enum class CAM_PHOTO_EVENTS { 69 CAM_PHOTO_CAPTURE_START = 0, 70 CAM_PHOTO_CAPTURE_END, 71 CAM_PHOTO_CAPTURE_ERR, 72 CAM_PHOTO_FRAME_SHUTTER, 73 CAM_PHOTO_MAX_EVENT, 74 CAM_PHOTO_FRAME_SHUTTER_END, 75 CAM_PHOTO_CAPTURE_READY, 76 CAM_PHOTO_ESTIMATED_CAPTURE_DURATION, 77 CAM_PHOTO_OFFLINE_PHOTOOUTPUT 78 }; 79 80 enum class CAM_PREVIEW_EVENTS { 81 CAM_PREVIEW_FRAME_START = 0, 82 CAM_PREVIEW_FRAME_END, 83 CAM_PREVIEW_FRAME_ERR, 84 CAM_PREVIEW_SKETCH_STATUS_CHANGED, 85 CAM_PREVIEW_MAX_EVENT 86 }; 87 88 enum class CAM_VIDEO_EVENTS { 89 CAM_VIDEO_FRAME_START = 0, 90 CAM_VIDEO_FRAME_END, 91 CAM_VIDEO_FRAME_ERR, 92 CAM_VIDEO_MAX_EVENT 93 }; 94 95 enum class CAM_MACRO_DETECT_EVENTS { 96 CAM_MACRO_EVENT_IDLE = 0, 97 CAM_MACRO_EVENT_ACTIVE, 98 CAM_MACRO_EVENT_MAX_EVENT 99 }; 100 101 enum class CAM_MOON_CAPTURE_BOOST_EVENTS { 102 CAM_MOON_CAPTURE_BOOST_EVENT_IDLE = 0, 103 CAM_MOON_CAPTURE_BOOST_EVENT_ACTIVE, 104 CAM_MOON_CAPTURE_BOOST_EVENT_MAX_EVENT 105 }; 106 107 const int32_t WAIT_TIME_ONE = 1; 108 const int32_t WAIT_TIME_CALLBACK = 1; 109 const int32_t WAIT_TIME_AFTER_CLOSE = 1; 110 const int32_t WAIT_TIME_BEFORE_STOP = 1; 111 const int32_t WAIT_TIME_AFTER_CAPTURE = 1; 112 const int32_t WAIT_TIME_AFTER_START = 2; 113 const int32_t WAIT_TIME_AFTER_SET_AREA = 2; 114 const int32_t WAIT_TIME_AFTER_ATTACH_SKETCH = 2; 115 const int32_t WAIT_TIME_AFTER_DEFERRED_CAPTURE = 2; 116 const int32_t WAIT_TIME_AFTER_RECORDING = 3; 117 118 const int32_t PREVIEW_DEFAULT_WIDTH = 1280; 119 const int32_t PREVIEW_DEFAULT_HEIGHT = 720; 120 const int32_t PHOTO_DEFAULT_WIDTH = 1280; 121 const int32_t PHOTO_DEFAULT_HEIGHT = 960; 122 const int32_t VIDEO_DEFAULT_WIDTH = 1280; 123 const int32_t VIDEO_DEFAULT_HEIGHT = 720; 124 const int32_t SKETCH_DEFAULT_WIDTH = 1280; 125 const int32_t SKETCH_DEFAULT_HEIGHT = 720; 126 const int32_t SKETCH_PREVIEW_MAX_WIDTH = 3000; 127 const int32_t SKETCH_PREVIEW_MIN_HEIGHT = 720; 128 const int32_t PRVIEW_WIDTH_176 = 176; 129 const int32_t PRVIEW_WIDTH_480 = 480; 130 const int32_t PRVIEW_WIDTH_640 = 640; 131 const int32_t PRVIEW_WIDTH_4096 = 4096; 132 const int32_t PRVIEW_WIDTH_4160 = 4160; 133 const int32_t PRVIEW_WIDTH_8192 = 8192; 134 const int32_t PRVIEW_HEIGHT_144 = 144; 135 const int32_t PRVIEW_HEIGHT_480 = 480; 136 const int32_t PRVIEW_HEIGHT_640 = 640; 137 const int32_t PRVIEW_HEIGHT_3072 = 3072; 138 const int32_t PRVIEW_HEIGHT_3120 = 3120; 139 const int32_t PRVIEW_HEIGHT_6144 = 6144; 140 141 const int32_t META_VALUE_10 = 10; 142 const int32_t META_VALUE_100 = 100; 143 const int32_t DEFAULT_AE_VALUE = 1; 144 const int32_t DEFAULT_ISO_VALUE = 1; 145 const int32_t DEFAULT_APERTURE_VALUE = 1; 146 const int32_t DEFAULT_NUMERATOR_VALUE = 1; 147 const int32_t DEFAULT_MIN_FRAME_RATE = 15; 148 const int32_t DEFAULT_MAX_FRAME_RATE = 30; 149 const int32_t DEFAULT_LUMINATION_VALUE = 256; 150 const int32_t DEFAULT_DENOMINATOR_VALUE = 1000000; 151 152 const int32_t MIN_FRAME_RATE = 15; 153 const int32_t MAX_FRAME_RATE = 30; 154 const int32_t CAMERA_NUMBER = 2; 155 const int32_t ZOOM_RATIO = 100; 156 157 static const int32_t VEDIO_FRAMERATES_120 = 120; 158 static const int32_t VEDIO_FRAMERATES_240 = 240; 159 static const int32_t VEDIO_FRAMERATES_SIZE = 2; 160 161 extern std::bitset<static_cast<int>(CAM_PHOTO_EVENTS::CAM_PHOTO_MAX_EVENT)> g_photoEvents; 162 extern std::bitset<static_cast<unsigned int>(CAM_PREVIEW_EVENTS::CAM_PREVIEW_MAX_EVENT)> g_previewEvents; 163 extern std::bitset<static_cast<unsigned int>(CAM_VIDEO_EVENTS::CAM_VIDEO_MAX_EVENT)> g_videoEvents; 164 extern std::bitset<static_cast<unsigned int>(CAM_MACRO_DETECT_EVENTS::CAM_MACRO_EVENT_MAX_EVENT)> g_macroEvents; 165 extern std::bitset<static_cast<unsigned int>(CAM_MOON_CAPTURE_BOOST_EVENTS::CAM_MOON_CAPTURE_BOOST_EVENT_MAX_EVENT)> 166 g_moonCaptureBoostEvents; 167 extern std::unordered_map<std::string, int> g_camStatusMap; 168 extern std::unordered_map<std::string, bool> g_camFlashMap; 169 extern std::shared_ptr<OHOS::Camera::CameraMetadata> g_metaResult; 170 extern std::list<int32_t> g_sketchStatus; 171 extern TorchStatusInfo g_torchInfo; 172 extern int32_t g_previewFd; 173 extern int32_t g_photoFd; 174 extern int32_t g_videoFd; 175 extern int32_t g_sketchFd; 176 extern bool g_camInputOnError; 177 extern bool g_sessionclosed; 178 extern bool g_brightnessStatusChanged; 179 extern bool g_slowMotionStatusChanged; 180 181 class AppCallback : public CameraManagerCallback, 182 public TorchListener, 183 public ErrorCallback, 184 public PhotoStateCallback, 185 public PreviewStateCallback, 186 public ResultCallback, 187 public SlowMotionStateCallback, 188 public MacroStatusCallback, 189 public FeatureDetectionStatusCallback, 190 public FoldListener, 191 public LcdFlashStatusCallback, 192 public BrightnessStatusCallback { 193 public: 194 void OnCameraStatusChanged(const CameraStatusInfo& cameraDeviceInfo) const override; 195 196 void OnFlashlightStatusChanged(const std::string& cameraID, const FlashStatus flashStatus) const override; 197 198 void OnTorchStatusChange(const TorchStatusInfo &torchStatusInfo) const override; 199 200 void OnError(const int32_t errorType, const int32_t errorMsg) const override; 201 202 void OnResult(const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata>& result) const override; 203 204 void OnCaptureStarted(const int32_t captureId) const override; 205 206 void OnCaptureStarted(const int32_t captureId, uint32_t exposureTime) const override; 207 208 void OnCaptureEnded(const int32_t captureId, const int32_t frameCount) const override; 209 210 void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override; 211 212 void OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const override; 213 214 void OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const override; 215 216 void OnEstimatedCaptureDuration(const int32_t duration) const override; 217 218 void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override; 219 220 void OnFrameStarted() const override; 221 222 void OnFrameEnded(const int32_t frameCount) const override; 223 224 void OnError(const int32_t errorCode) const override; 225 226 void OnSketchStatusDataChanged(const SketchStatusData& statusData) const override; 227 228 void OnMacroStatusChanged(MacroStatus status) override; 229 230 void OnFeatureDetectionStatusChanged(SceneFeature feature, FeatureDetectionStatus status) override; 231 232 bool IsFeatureSubscribed(SceneFeature feature) override; 233 234 void OnBrightnessStatusChanged(bool state) override; 235 236 void OnSlowMotionState(const SlowMotionState state) override; 237 238 void OnFoldStatusChanged(const FoldStatusInfo &foldStatusInfo) const override; 239 240 void OnLcdFlashStatusChanged(LcdFlashStatusInfo lcdFlashStatusInfo) override; 241 242 void OnOfflineDeliveryFinished(const int32_t captureId) const override; 243 }; 244 245 class AppVideoCallback : public VideoStateCallback { 246 public: 247 void OnFrameStarted() const override; 248 249 void OnFrameEnded(const int32_t frameCount) const override; 250 251 void OnError(const int32_t errorCode) const override; 252 253 void OnDeferredVideoEnhancementInfo(const CaptureEndedInfoExt info) const override; 254 }; 255 256 class AppMetadataCallback : public MetadataObjectCallback, public MetadataStateCallback { 257 public: 258 void OnMetadataObjectsAvailable(std::vector<sptr<MetadataObject>> metaObjects) const; 259 260 void OnError(int32_t errorCode) const; 261 }; 262 263 class AppSessionCallback : public SessionCallback { 264 public: 265 void OnError(int32_t errorCode); 266 }; 267 268 269 class TestExposureInfoCallback : public ExposureInfoCallback { 270 public: OnExposureInfoChanged(ExposureInfo info)271 void OnExposureInfoChanged(ExposureInfo info) 272 { 273 MEDIA_INFO_LOG("OnExposureInfoChanged start"); 274 } 275 }; 276 277 class TestIsoInfoCallback : public IsoInfoCallback { 278 public: OnIsoInfoChanged(IsoInfo info)279 void OnIsoInfoChanged(IsoInfo info) 280 { 281 MEDIA_INFO_LOG("OnIsoInfoChanged start"); 282 } 283 }; 284 285 class TestApertureInfoCallback : public ApertureInfoCallback { 286 public: OnApertureInfoChanged(ApertureInfo info)287 void OnApertureInfoChanged(ApertureInfo info) 288 { 289 MEDIA_INFO_LOG("OnApertureInfoChanged start"); 290 } 291 }; 292 293 class TestLuminationInfoCallback : public LuminationInfoCallback { 294 public: OnLuminationInfoChanged(LuminationInfo info)295 void OnLuminationInfoChanged(LuminationInfo info) 296 { 297 MEDIA_INFO_LOG("OnLuminationInfoChanged start"); 298 } 299 }; 300 301 class CameraSessionModuleTest : public testing::Test { 302 public: 303 /* SetUpTestCase: The preset action of the test suite is executed before the first test case */ 304 static void SetUpTestCase(void); 305 306 /* TearDownTestCase: The cleanup action of the test suite is executed after the last test case */ 307 static void TearDownTestCase(void); 308 309 /* SetUp: Execute before each test case */ 310 void SetUp(); 311 312 /* TearDown: Execute after each test case */ 313 void TearDown(); 314 315 sptr<CaptureOutput> CreatePreviewOutput(int32_t width, int32_t height); 316 sptr<CaptureOutput> CreatePreviewOutput(Profile& profile); 317 sptr<CaptureOutput> CreatePreviewOutput(); 318 sptr<CaptureOutput> CreatePhotoOutput(int32_t width, int32_t height); 319 sptr<CaptureOutput> CreatePhotoOutput(Profile profile); 320 sptr<CaptureOutput> CreatePhotoOutput(); 321 sptr<CaptureOutput> CreateVideoOutput(int32_t width, int32_t height); 322 sptr<CaptureOutput> CreateVideoOutput(VideoProfile& profile); 323 sptr<CaptureOutput> CreateVideoOutput(); 324 sptr<Surface> CreateSketchSurface(CameraFormat cameraFormat); 325 std::shared_ptr<Profile> GetSketchPreviewProfile(); 326 Profile SelectProfileByRatioAndFormat(sptr<CameraOutputCapability>& modeAbility, 327 camera_rational_t ratio, CameraFormat format); 328 std::optional<Profile> GetPreviewProfileByFormat(sptr<CameraOutputCapability>& modeAbility, 329 uint32_t width, uint32_t height, CameraFormat previewFormat); 330 std::optional<VideoProfile> GetVideoProfileByFormat(sptr<CameraOutputCapability>& modeAbility, 331 uint32_t width, uint32_t height, CameraFormat videoFormat, uint32_t maxFps); 332 void GetSupportedOutputCapability(); 333 void ConfigScanSession(sptr<CaptureOutput> &previewOutput_1, sptr<CaptureOutput> &previewOutput_2); 334 void ConfigSlowMotionSession(sptr<CaptureOutput> &previewOutput, sptr<CaptureOutput> &videoOutput); 335 void ConfigVideoSession(sptr<CaptureOutput> &previewOutput, sptr<CaptureOutput> &videoOutput); 336 bool IsSupportNow(); 337 bool IsSceneModeSupported(SceneMode mode); 338 void FilterPreviewProfiles(std::vector<Profile> &previewProfiles); 339 void ProcessPreviewProfiles(sptr<CameraOutputCapability>& outputcapability); 340 void ProcessSize(); 341 void SetUpInit(); 342 343 CameraFormat previewFormat_; 344 CameraFormat photoFormat_; 345 CameraFormat videoFormat_; 346 int32_t previewWidth_; 347 int32_t previewHeight_; 348 int32_t photoWidth_; 349 int32_t photoHeight_; 350 int32_t videoWidth_; 351 int32_t videoHeight_; 352 sptr<CameraManager> manager_; 353 sptr<CameraManagerForSys> managerForSys_; 354 sptr<CaptureSession> session_; 355 sptr<CaptureSessionForSys> sessionForSys_; 356 sptr<CaptureSession> scanSession_; 357 sptr<SlowMotionSession> slowMotionSession_; 358 sptr<CaptureSession> videoSession_; 359 sptr<CaptureInput> input_; 360 std::vector<sptr<CameraDevice>> cameras_; 361 std::vector<CameraFormat> previewFormats_; 362 std::vector<CameraFormat> photoFormats_; 363 std::vector<CameraFormat> videoFormats_; 364 std::vector<Size> previewSizes_; 365 std::vector<Size> photoSizes_; 366 std::vector<Size> videoSizes_; 367 std::vector<int32_t> videoFrameRates_; 368 std::vector<Profile> previewProfiles_; 369 std::vector<Profile> photoProfiles_; 370 std::vector<VideoProfile> videoProfiles_; 371 }; 372 } // CameraStandard 373 } // OHOS 374 #endif // CAMERA_SESSION_MODULETEST_H 375