From 4b03a297ed13b8db5d4bc6048d9a17aa3088f24b Mon Sep 17 00:00:00 2001 From: qano Date: Fri, 8 Dec 2023 11:02:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4modeManager=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E4=BF=9D=E7=95=99Napi=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qano --- .../entry/src/main/ets/model/CameraService.ts | 12 +- .../js/camera_napi/src/camera_napi_utils.cpp | 13 + .../src/input/camera_manager_napi.cpp | 146 ++++++- .../js/camera_napi/src/input/camera_napi.cpp | 17 +- .../src/mode/mode_manager_napi.cpp | 40 +- .../src/mode/night_session_napi.cpp | 366 +----------------- .../src/mode/photo_session_napi.cpp | 137 +++++++ .../src/mode/portrait_session_napi.cpp | 84 +--- .../src/mode/video_session_napi.cpp | 137 +++++++ .../src/output/camera_output_napi.cpp | 4 +- .../src/session/camera_session_napi.cpp | 86 +--- frameworks/native/camera/BUILD.gn | 3 +- .../native/camera/src/input/camera_device.cpp | 8 +- .../camera/src/input/camera_manager.cpp | 133 +++++-- .../native/camera/src/mode/mode_manager.cpp | 288 -------------- .../camera/src/output/preview_output.cpp | 1 - .../camera/src/session/capture_session.cpp | 28 +- .../camera/src/session/night_session.cpp | 90 +---- .../camera/src/session/photo_session.cpp | 46 +++ .../camera/src/session/scan_session.cpp | 10 +- .../camera/src/session/video_session.cpp | 46 +++ .../include/camera_framework_moduletest.h | 4 +- .../src/camera_framework_moduletest.cpp | 114 +++--- .../include/camera_framework_unittest.h | 2 - .../src/v1_1/camera_framework_unittest.cpp | 79 ++-- .../camera/include/input/camera_device.h | 1 - .../camera/include/input/camera_manager.h | 33 +- .../native/camera/include/mode/mode_manager.h | 106 ----- .../camera/include/session/capture_session.h | 4 +- .../camera/include/session/night_session.h | 30 +- .../camera/include/session/photo_session.h | 46 +++ .../camera/include/session/scan_session.h | 2 +- .../camera/include/session/video_session.h | 45 +++ .../native/test/camera_capture_mode.cpp | 9 +- .../camera_napi/@ohos.multimedia.camera.d.ts | 14 +- interfaces/kits/js/camera_napi/BUILD.gn | 2 + .../camera_napi/include/camera_napi_utils.h | 4 +- .../include/input/camera_info_napi.h | 1 - .../include/input/camera_manager_napi.h | 6 +- .../camera_napi/include/input/camera_napi.h | 6 +- .../include/mode/mode_manager_napi.h | 5 +- .../include/mode/night_session_napi.h | 36 -- .../include/mode/photo_session_napi.h | 43 ++ .../include/mode/portrait_session_napi.h | 1 - .../include/mode/video_session_napi.h | 43 ++ .../include/output/camera_output_napi.h | 3 +- .../include/session/camera_session_napi.h | 93 +++++ .../camera_service/include/hcamera_service.h | 75 ++-- .../camera_service/src/hcamera_service.cpp | 266 +++++++------ 49 files changed, 1333 insertions(+), 1435 deletions(-) create mode 100644 frameworks/js/camera_napi/src/mode/photo_session_napi.cpp create mode 100644 frameworks/js/camera_napi/src/mode/video_session_napi.cpp delete mode 100644 frameworks/native/camera/src/mode/mode_manager.cpp create mode 100644 frameworks/native/camera/src/session/photo_session.cpp create mode 100644 frameworks/native/camera/src/session/video_session.cpp delete mode 100644 interfaces/inner_api/native/camera/include/mode/mode_manager.h create mode 100644 interfaces/inner_api/native/camera/include/session/photo_session.h create mode 100644 interfaces/inner_api/native/camera/include/session/video_session.h create mode 100644 interfaces/kits/js/camera_napi/include/mode/photo_session_napi.h create mode 100644 interfaces/kits/js/camera_napi/include/mode/video_session_napi.h diff --git a/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts b/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts index fcb5856d4..abfb38f44 100644 --- a/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts +++ b/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts @@ -39,10 +39,10 @@ const TAG: string = 'CameraService'; class CameraService { private mediaUtil: MediaUtils = MediaUtils.getInstance(); - private modeManager: camera.ModeManager | undefined = undefined; + private modeManager: camera.CameraManager | undefined = undefined; private cameraManager: camera.CameraManager | undefined = undefined; private cameras: Array | undefined = undefined; - private cameraModes: Array | undefined = undefined; + private sceneModes: Array | undefined = undefined; private cameraOutputCapability: camera.CameraOutputCapability | undefined = undefined; private cameraInput: camera.CameraInput | undefined = undefined; private previewOutput: camera.PreviewOutput | undefined = undefined; @@ -858,8 +858,8 @@ class CameraService { getSupportedModeFn(cameraIndex: number): void { try { - this.cameraModes = this.modeManager.getSupportedModes(this.cameras[cameraIndex]); - Logger.info(TAG, `getSupportedModeFn success: ${this.cameraModes}, length: ${this.cameraModes.length}`); + this.sceneModes = this.modeManager.getSupportedModes(this.cameras[cameraIndex]); + Logger.info(TAG, `getSupportedModeFn success: ${this.sceneModes}, length: ${this.sceneModes.length}`); } catch (error) { let err = error as BusinessError; Logger.error(TAG, `getSupportedModeFn failed: ${JSON.stringify(err)}`); @@ -951,10 +951,10 @@ class CameraService { } } - async portraitSessionFlowFn(cameraModeIndex: number): Promise { + async portraitSessionFlowFn(sceneModeIndex: number): Promise { try { // 创建PortraitSession实例 - this.portraitSession = this.modeManager.createCaptureSession(this.cameraModes[cameraModeIndex]) as camera.PortraitSession; + this.portraitSession = this.modeManager.createCaptureSession(this.sceneModes[sceneModeIndex]) as camera.PortraitSession; // 监听焦距的状态变化 this.onFocusStateChange(); // 监听拍照会话的错误事件 diff --git a/frameworks/js/camera_napi/src/camera_napi_utils.cpp b/frameworks/js/camera_napi/src/camera_napi_utils.cpp index a504d5eaf..29b0bba96 100644 --- a/frameworks/js/camera_napi/src/camera_napi_utils.cpp +++ b/frameworks/js/camera_napi/src/camera_napi_utils.cpp @@ -576,5 +576,18 @@ napi_status CameraNapiUtils::CallPromiseFun( MEDIA_DEBUG_LOG("CallPromiseFun End"); return napi_ok; } + +std::vector CameraNapiUtils::GetPropertyDescriptor( + std::vector> descriptors) +{ + MEDIA_DEBUG_LOG("GetPropertyDescriptor Start %zu", descriptors.size()); + std::vector properties = {}; + std::for_each(descriptors.begin(), descriptors.end(), + [&properties](const std::vector descriptor) { + properties.insert(properties.end(), descriptor.begin(), descriptor.end()); + }); + return properties; +}; + } // namespace CameraStandard } // namespace OHOS diff --git a/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp b/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp index d29305152..c82490512 100644 --- a/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp +++ b/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp @@ -16,6 +16,10 @@ #include "input/camera_manager_napi.h" #include "input/camera_napi.h" #include "input/camera_pre_launch_config_napi.h" +#include "mode/portrait_session_napi.h" +#include "mode/night_session_napi.h" +#include "mode/photo_session_napi.h" +#include "mode/video_session_napi.h" namespace OHOS { namespace CameraStandard { @@ -95,6 +99,7 @@ napi_value CameraManagerNapi::Init(napi_env env, napi_value exports) napi_property_descriptor camera_mgr_properties[] = { // CameraManager DECLARE_NAPI_FUNCTION("getSupportedCameras", GetSupportedCameras), + DECLARE_NAPI_FUNCTION("getSupportedSceneModes", GetSupportedModes), DECLARE_NAPI_FUNCTION("getSupportedOutputCapability", GetSupportedOutputCapability), DECLARE_NAPI_FUNCTION("isCameraMuted", IsCameraMuted), DECLARE_NAPI_FUNCTION("isCameraMuteSupported", IsCameraMuteSupported), @@ -104,6 +109,7 @@ napi_value CameraManagerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setPrelaunchConfig", SetPrelaunchConfig), DECLARE_NAPI_FUNCTION("createCameraInput", CreateCameraInputInstance), DECLARE_NAPI_FUNCTION("createCaptureSession", CreateCameraSessionInstance), + DECLARE_NAPI_FUNCTION("createSession", CreateSessionInstance), DECLARE_NAPI_FUNCTION("createPreviewOutput", CreatePreviewOutputInstance), DECLARE_NAPI_FUNCTION("createDeferredPreviewOutput", CreateDeferredPreviewOutputInstance), DECLARE_NAPI_FUNCTION("createPhotoOutput", CreatePhotoOutputInstance), @@ -238,6 +244,56 @@ napi_value CameraManagerNapi::CreateCameraSessionInstance(napi_env env, napi_cal return result; } +enum JsSceneMode { + JS_CAPTURE = 1, + JS_VIDEO = 2, + JS_PORTRAIT = 3, + JS_NIGHT = 4, +}; + +napi_value CameraManagerNapi::CreateSessionInstance(napi_env env, napi_callback_info info) +{ + MEDIA_INFO_LOG("CreateSessionInstance is called"); + napi_status status; + napi_value result = nullptr; + size_t argc = ARGS_ONE; + napi_value argv[ARGS_ONE]; + napi_value thisVar = nullptr; + + CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar); + + napi_get_undefined(env, &result); + + CameraManagerNapi* cameraManagerNapi = nullptr; + status = napi_unwrap(env, thisVar, reinterpret_cast(&cameraManagerNapi)); + if (status != napi_ok || cameraManagerNapi == nullptr) { + MEDIA_ERR_LOG("napi_unwrap failure!"); + return nullptr; + } + + int32_t jsModeName; + napi_get_value_int32(env, argv[PARAM0], &jsModeName); + MEDIA_INFO_LOG("CameraManagerNapi::CreateSessionInstance mode = %{public}d", jsModeName); + switch (jsModeName) { + case JS_CAPTURE: + result = PhotoSessionNapi::CreateCameraSession(env); + break; + case JS_VIDEO: + result = VideoSessionNapi::CreateCameraSession(env); + break; + case JS_PORTRAIT: + result = PortraitSessionNapi::CreateCameraSession(env); + break; + case JS_NIGHT: + result = NightSessionNapi::CreateCameraSession(env); + break; + default: + MEDIA_ERR_LOG("CameraManagerNapi::CreateSessionInstance mode = %{public}d not supported", jsModeName); + break; + } + return result; +} + bool ParseSize(napi_env env, napi_value root, Size* size) { MEDIA_DEBUG_LOG("ParseSize is called"); @@ -545,14 +601,74 @@ napi_value CameraManagerNapi::GetSupportedCameras(napi_env env, napi_callback_in return result; } +static napi_value CreateJSArray(napi_env env, napi_status status, + std::vector nativeArray) +{ + MEDIA_DEBUG_LOG("CreateJSArray is called"); + napi_value jsArray = nullptr; + napi_value item = nullptr; + + if (nativeArray.empty()) { + MEDIA_ERR_LOG("nativeArray is empty"); + } + + status = napi_create_array(env, &jsArray); + if (status == napi_ok) { + for (size_t i = 0; i < nativeArray.size(); i++) { + napi_create_int32(env, nativeArray[i], &item); + if (napi_set_element(env, jsArray, i, item) != napi_ok) { + MEDIA_ERR_LOG("Failed to create profile napi wrapper object"); + return nullptr; + } + } + } + return jsArray; +} + +napi_value CameraManagerNapi::GetSupportedModes(napi_env env, napi_callback_info info) +{ + MEDIA_INFO_LOG("GetSupportedModes is called"); + napi_status status; + napi_value result = nullptr; + size_t argc = ARGS_ONE; + napi_value argv[ARGS_ONE]; + napi_value thisVar = nullptr; + napi_value jsResult = nullptr; + CameraDeviceNapi* cameraDeviceNapi = nullptr; + CameraManagerNapi* cameraManagerNapi = nullptr; + CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar); + + napi_get_undefined(env, &result); + status = napi_unwrap(env, argv[PARAM0], reinterpret_cast(&cameraDeviceNapi)); + if (status != napi_ok || cameraDeviceNapi == nullptr) { + MEDIA_ERR_LOG("Could not able to read cameraId argument!"); + return result; + } + sptr cameraInfo = cameraDeviceNapi->cameraDevice_; + status = napi_unwrap(env, thisVar, reinterpret_cast(&cameraManagerNapi)); + if (status == napi_ok && cameraManagerNapi != nullptr) { + std::vector modeObjList = cameraManagerNapi->cameraManager_->GetSupportedModes(cameraInfo); + MEDIA_INFO_LOG("CameraManagerNapi::GetSupportedModes size=[%{public}zu]", modeObjList.size()); + jsResult = CreateJSArray(env, status, modeObjList); + if (status == napi_ok) { + return jsResult; + } else { + MEDIA_ERR_LOG("Failed to get modeObjList!, errorCode : %{public}d", status); + } + } else { + MEDIA_ERR_LOG("GetSupportedModes call Failed!"); + } + return result; +} + napi_value CameraManagerNapi::GetSupportedOutputCapability(napi_env env, napi_callback_info info) { MEDIA_INFO_LOG("GetSupportedOutputCapability is called"); napi_status status; napi_value result = nullptr; - size_t argc = ARGS_ONE; - napi_value argv[ARGS_ONE] = {0}; + size_t argc = ARGS_TWO; + napi_value argv[ARGS_TWO] = {0}; napi_value thisVar = nullptr; CameraDeviceNapi* cameraDeviceNapi = nullptr; CameraManagerNapi* cameraManagerNapi = nullptr; @@ -571,7 +687,31 @@ napi_value CameraManagerNapi::GetSupportedOutputCapability(napi_env env, napi_ca return result; } sptr cameraInfo = cameraDeviceNapi->cameraDevice_; - result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo); + if (argc == ARGS_ONE) { + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo); + } else if (argc == ARGS_TWO) { + int32_t sceneMode; + napi_get_value_int32(env, argv[PARAM1], &sceneMode); + MEDIA_INFO_LOG("CameraManagerNapi::GetSupportedOutputCapability mode = %{public}d", sceneMode); + switch (sceneMode) { + case JS_CAPTURE: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::CAPTURE); + break; + case JS_VIDEO: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::VIDEO); + break; + case JS_PORTRAIT: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::PORTRAIT); + break; + case JS_NIGHT: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::NIGHT); + break; + default: + MEDIA_ERR_LOG("CreateCameraSessionInstance mode = %{public}d not supported", sceneMode); + break; + } + } + return result; } diff --git a/frameworks/js/camera_napi/src/input/camera_napi.cpp b/frameworks/js/camera_napi/src/input/camera_napi.cpp index 24641855d..3328c8f45 100644 --- a/frameworks/js/camera_napi/src/input/camera_napi.cpp +++ b/frameworks/js/camera_napi/src/input/camera_napi.cpp @@ -43,7 +43,7 @@ thread_local napi_ref CameraNapi::focusStateRef_ = nullptr; thread_local napi_ref CameraNapi::qualityLevelRef_ = nullptr; thread_local napi_ref CameraNapi::videoStabilizationModeRef_ = nullptr; thread_local napi_ref CameraNapi::hostNameTypeRef_ = nullptr; -thread_local napi_ref CameraNapi::cameraModeRef_ = nullptr; +thread_local napi_ref CameraNapi::sceneModeRef_ = nullptr; thread_local napi_ref CameraNapi::filterTypeRef_ = nullptr; thread_local napi_ref CameraNapi::beautyTypeRef_ = nullptr; thread_local napi_ref CameraNapi::portraitEffectRef_ = nullptr; @@ -132,7 +132,8 @@ napi_value CameraNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_PROPERTY("VideoStabilizationMode", CreateVideoStabilizationModeObject(env)), DECLARE_NAPI_PROPERTY("MetadataObjectType", CreateMetadataObjectType(env)), DECLARE_NAPI_PROPERTY("HostNameType", CreateHostNameType(env)), - DECLARE_NAPI_PROPERTY("CameraMode", CreateCameraMode(env)), + DECLARE_NAPI_PROPERTY("CameraMode", CreateSceneMode(env)), + DECLARE_NAPI_PROPERTY("SceneMode", CreateSceneMode(env)), DECLARE_NAPI_PROPERTY("FilterType", CreateFilterType(env)), DECLARE_NAPI_PROPERTY("BeautyType", CreateBeautyType(env)), DECLARE_NAPI_PROPERTY("PortraitEffect", CreatePortraitEffect(env)), @@ -578,32 +579,32 @@ napi_value CameraNapi::CreateHostNameType(napi_env env) return result; } -napi_value CameraNapi::CreateCameraMode(napi_env env) +napi_value CameraNapi::CreateSceneMode(napi_env env) { - MEDIA_DEBUG_LOG("CreateCameraMode is called"); + MEDIA_DEBUG_LOG("CreateSceneMode is called"); napi_value result = nullptr; napi_status status; status = napi_create_object(env, &result); if (status == napi_ok) { std::string propName; - for (auto itr = mapCameraMode.begin(); itr != mapCameraMode.end(); ++itr) { + for (auto itr = mapSceneMode.begin(); itr != mapSceneMode.end(); ++itr) { propName = itr->first; status = AddNamedProperty(env, result, propName, itr->second); if (status != napi_ok) { - MEDIA_ERR_LOG("Failed to add cameraMode prop!"); + MEDIA_ERR_LOG("Failed to add sceneMode prop!"); break; } propName.clear(); } } if (status == napi_ok) { - status = napi_create_reference(env, result, 1, &cameraModeRef_); + status = napi_create_reference(env, result, 1, &sceneModeRef_); if (status == napi_ok) { return result; } } - MEDIA_ERR_LOG("CreateCameraMode call Failed!"); + MEDIA_ERR_LOG("CreateSceneMode call Failed!"); napi_get_undefined(env, &result); return result; diff --git a/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp b/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp index c27cce82e..7f30eef2e 100644 --- a/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp +++ b/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp @@ -54,7 +54,7 @@ napi_value ModeManagerNapi::ModeManagerNapiConstructor(napi_env env, napi_callba if (status == napi_ok && thisVar != nullptr) { std::unique_ptr obj = std::make_unique(); obj->env_ = env; - obj->modeManager_ = ModeManager::GetInstance(); + obj->modeManager_ = CameraManager::GetInstance(); if (obj->modeManager_ == nullptr) { MEDIA_ERR_LOG("Failure wrapping js to native napi, obj->modeManager_ null"); return result; @@ -87,7 +87,6 @@ napi_value ModeManagerNapi::Init(napi_env env, napi_value exports) napi_status status; napi_value ctorObj; napi_property_descriptor mode_mgr_properties[] = { - // ModeManager DECLARE_NAPI_FUNCTION("getSupportedModes", GetSupportedModes), DECLARE_NAPI_FUNCTION("getSupportedOutputCapability", GetSupportedOutputCapability), DECLARE_NAPI_FUNCTION("createCaptureSession", CreateCameraSessionInstance), @@ -131,14 +130,11 @@ napi_value ModeManagerNapi::CreateModeManager(napi_env env) return result; } -enum JsCameraMode { - JS_NORMAL = 0, +enum JsSceneMode { JS_CAPTURE = 1, JS_VIDEO = 2, JS_PORTRAIT = 3, JS_NIGHT = 4, - JS_PROFESSIONAL = 5, - JS_SLOW_MOTION = 6, }; napi_value ModeManagerNapi::CreateCameraSessionInstance(napi_env env, napi_callback_info info) @@ -165,8 +161,11 @@ napi_value ModeManagerNapi::CreateCameraSessionInstance(napi_env env, napi_callb napi_get_value_int32(env, argv[PARAM0], &jsModeName); MEDIA_INFO_LOG("ModeManagerNapi::CreateCameraSessionInstance mode = %{public}d", jsModeName); switch (jsModeName) { - case JS_NORMAL: - result = CameraSessionNapi::CreateCameraSession(env); + case JS_CAPTURE: + result = PhotoSessionNapi::CreateCameraSession(env); + break; + case JS_VIDEO: + result = VideoSessionNapi::CreateCameraSession(env); break; case JS_PORTRAIT: result = PortraitSessionNapi::CreateCameraSession(env); @@ -182,7 +181,7 @@ napi_value ModeManagerNapi::CreateCameraSessionInstance(napi_env env, napi_callb } static napi_value CreateJSArray(napi_env env, napi_status status, - std::vector nativeArray) + std::vector nativeArray) { MEDIA_DEBUG_LOG("CreateJSArray is called"); napi_value jsArray = nullptr; @@ -227,7 +226,7 @@ napi_value ModeManagerNapi::GetSupportedModes(napi_env env, napi_callback_info i sptr cameraInfo = cameraDeviceNapi->cameraDevice_; status = napi_unwrap(env, thisVar, reinterpret_cast(&modeManagerNapi)); if (status == napi_ok && modeManagerNapi != nullptr) { - std::vector modeObjList = modeManagerNapi->modeManager_->GetSupportedModes(cameraInfo); + std::vector modeObjList = modeManagerNapi->modeManager_->GetSupportedModes(cameraInfo); MEDIA_INFO_LOG("ModeManagerNapi::GetSupportedModes size=[%{public}zu]", modeObjList.size()); jsResult = CreateJSArray(env, status, modeObjList); if (status == napi_ok) { @@ -267,21 +266,24 @@ napi_value ModeManagerNapi::GetSupportedOutputCapability(napi_env env, napi_call return result; } sptr cameraInfo = cameraDeviceNapi->cameraDevice_; - int32_t cameraMode; - napi_get_value_int32(env, argv[PARAM1], &cameraMode); - MEDIA_INFO_LOG("ModeManagerNapi::GetSupportedOutputCapability mode = %{public}d", cameraMode); - switch (cameraMode) { - case JS_NORMAL: - result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, CameraMode::NORMAL); + int32_t sceneMode; + napi_get_value_int32(env, argv[PARAM1], &sceneMode); + MEDIA_INFO_LOG("ModeManagerNapi::GetSupportedOutputCapability mode = %{public}d", sceneMode); + switch (sceneMode) { + case JS_CAPTURE: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::CAPTURE); + break; + case JS_VIDEO: + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::VIDEO); break; case JS_PORTRAIT: - result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, CameraMode::PORTRAIT); + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::PORTRAIT); break; case JS_NIGHT: - result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, CameraMode::NIGHT); + result = CameraOutputCapabilityNapi::CreateCameraOutputCapability(env, cameraInfo, SceneMode::NIGHT); break; default: - MEDIA_ERR_LOG("ModeManagerNapi::CreateCameraSessionInstance mode = %{public}d not supported", cameraMode); + MEDIA_ERR_LOG("ModeManagerNapi::CreateCameraSessionInstance mode = %{public}d not supported", sceneMode); break; } return result; diff --git a/frameworks/js/camera_napi/src/mode/night_session_napi.cpp b/frameworks/js/camera_napi/src/mode/night_session_napi.cpp index 2ab0cd7fc..b798caaae 100644 --- a/frameworks/js/camera_napi/src/mode/night_session_napi.cpp +++ b/frameworks/js/camera_napi/src/mode/night_session_napi.cpp @@ -47,87 +47,19 @@ napi_value NightSessionNapi::Init(napi_env env, napi_value exports) MEDIA_DEBUG_LOG("Init is called"); napi_status status; napi_value ctorObj; - napi_property_descriptor night_session_props[] = { - DECLARE_NAPI_FUNCTION("beginConfig", CameraSessionNapi::BeginConfig), - DECLARE_NAPI_FUNCTION("commitConfig", CameraSessionNapi::CommitConfig), - - DECLARE_NAPI_FUNCTION("canAddInput", CameraSessionNapi::CanAddInput), - DECLARE_NAPI_FUNCTION("addInput", CameraSessionNapi::AddInput), - DECLARE_NAPI_FUNCTION("removeInput", CameraSessionNapi::RemoveInput), - - DECLARE_NAPI_FUNCTION("canAddOutput", CameraSessionNapi::CanAddOutput), - DECLARE_NAPI_FUNCTION("addOutput", CameraSessionNapi::AddOutput), - DECLARE_NAPI_FUNCTION("removeOutput", CameraSessionNapi::RemoveOutput), - - DECLARE_NAPI_FUNCTION("start", CameraSessionNapi::Start), - DECLARE_NAPI_FUNCTION("stop", CameraSessionNapi::Stop), - DECLARE_NAPI_FUNCTION("release", CameraSessionNapi::Release), - - DECLARE_NAPI_FUNCTION("lockForControl", CameraSessionNapi::LockForControl), - DECLARE_NAPI_FUNCTION("unlockForControl", CameraSessionNapi::UnlockForControl), - - DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", - CameraSessionNapi::IsVideoStabilizationModeSupported), - DECLARE_NAPI_FUNCTION("getActiveVideoStabilizationMode", CameraSessionNapi::GetActiveVideoStabilizationMode), - DECLARE_NAPI_FUNCTION("setVideoStabilizationMode", CameraSessionNapi::SetVideoStabilizationMode), - - DECLARE_NAPI_FUNCTION("hasFlash", CameraSessionNapi::HasFlash), - DECLARE_NAPI_FUNCTION("isFlashModeSupported", CameraSessionNapi::IsFlashModeSupported), - DECLARE_NAPI_FUNCTION("getFlashMode", CameraSessionNapi::GetFlashMode), - DECLARE_NAPI_FUNCTION("setFlashMode", CameraSessionNapi::SetFlashMode), - - DECLARE_NAPI_FUNCTION("isExposureModeSupported", CameraSessionNapi::IsExposureModeSupported), - DECLARE_NAPI_FUNCTION("getExposureMode", CameraSessionNapi::GetExposureMode), - DECLARE_NAPI_FUNCTION("setExposureMode", CameraSessionNapi::SetExposureMode), - DECLARE_NAPI_FUNCTION("getExposureBiasRange", CameraSessionNapi::GetExposureBiasRange), - DECLARE_NAPI_FUNCTION("setExposureBias", CameraSessionNapi::SetExposureBias), - DECLARE_NAPI_FUNCTION("getExposureValue", CameraSessionNapi::GetExposureValue), - - DECLARE_NAPI_FUNCTION("getMeteringPoint", CameraSessionNapi::GetMeteringPoint), - DECLARE_NAPI_FUNCTION("setMeteringPoint", CameraSessionNapi::SetMeteringPoint), - - DECLARE_NAPI_FUNCTION("isFocusModeSupported", CameraSessionNapi::IsFocusModeSupported), - DECLARE_NAPI_FUNCTION("getFocusMode", CameraSessionNapi::GetFocusMode), - DECLARE_NAPI_FUNCTION("setFocusMode", CameraSessionNapi::SetFocusMode), - - DECLARE_NAPI_FUNCTION("getFocusPoint", CameraSessionNapi::GetFocusPoint), - DECLARE_NAPI_FUNCTION("setFocusPoint", CameraSessionNapi::SetFocusPoint), - DECLARE_NAPI_FUNCTION("getFocalLength", CameraSessionNapi::GetFocalLength), - - DECLARE_NAPI_FUNCTION("getZoomRatioRange", CameraSessionNapi::GetZoomRatioRange), - DECLARE_NAPI_FUNCTION("getZoomRatio", CameraSessionNapi::GetZoomRatio), - DECLARE_NAPI_FUNCTION("setZoomRatio", CameraSessionNapi::SetZoomRatio), - - DECLARE_NAPI_FUNCTION("getSupportedFilters", CameraSessionNapi::GetSupportedFilters), - DECLARE_NAPI_FUNCTION("getFilter", CameraSessionNapi::GetFilter), - DECLARE_NAPI_FUNCTION("setFilter", CameraSessionNapi::SetFilter), - - DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", CameraSessionNapi::GetSupportedBeautyTypes), - DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", CameraSessionNapi::GetSupportedBeautyRange), - DECLARE_NAPI_FUNCTION("getBeauty", CameraSessionNapi::GetBeauty), - DECLARE_NAPI_FUNCTION("setBeauty", CameraSessionNapi::SetBeauty), - - DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", CameraSessionNapi::GetSupportedColorSpaces), - DECLARE_NAPI_FUNCTION("getActiveColorSpace", CameraSessionNapi::GetActiveColorSpace), - DECLARE_NAPI_FUNCTION("setColorSpace", CameraSessionNapi::SetColorSpace), - + std::vector manual_exposure_props = { DECLARE_NAPI_FUNCTION("getSupportedExposureRange", NightSessionNapi::GetSupportedExposureRange), DECLARE_NAPI_FUNCTION("getExposure", NightSessionNapi::GetExposure), - DECLARE_NAPI_FUNCTION("setExposure", NightSessionNapi::SetExposure), - - DECLARE_NAPI_FUNCTION("getSupportedColorEffects", CameraSessionNapi::GetSupportedColorEffects), - DECLARE_NAPI_FUNCTION("getColorEffect", CameraSessionNapi::GetColorEffect), - DECLARE_NAPI_FUNCTION("setColorEffect", CameraSessionNapi::SetColorEffect), - - DECLARE_NAPI_FUNCTION("on", NightSessionNapi::On), - DECLARE_NAPI_FUNCTION("off", NightSessionNapi::Off), - DECLARE_NAPI_FUNCTION("TryAE", NightSessionNapi::TryAE), - + DECLARE_NAPI_FUNCTION("setExposure", NightSessionNapi::SetExposure) }; + std::vector> descriptors = {camera_process_props, stabilization_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props, manual_exposure_props}; + std::vector night_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); status = napi_define_class(env, NIGHT_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, NightSessionNapiConstructor, nullptr, - sizeof(night_session_props) / sizeof(night_session_props[PARAM0]), - night_session_props, &ctorObj); + night_session_props.size(), + night_session_props.data(), &ctorObj); if (status == napi_ok) { int32_t refCount = 1; status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); @@ -151,7 +83,7 @@ napi_value NightSessionNapi::CreateCameraSession(napi_env env) napi_value constructor; status = napi_get_reference_value(env, sConstructor_, &constructor); if (status == napi_ok) { - sCameraSession_ = ModeManager::GetInstance()->CreateCaptureSession(CameraMode::NIGHT); + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::NIGHT); if (sCameraSession_ == nullptr) { MEDIA_ERR_LOG("Failed to create Camera session instance"); napi_get_undefined(env, &result); @@ -171,32 +103,6 @@ napi_value NightSessionNapi::CreateCameraSession(napi_env env) return result; } -napi_value NightSessionNapi::TryAE(napi_env env, napi_callback_info info) -{ - MEDIA_DEBUG_LOG("TryAE is called"); - napi_status status; - napi_value result = nullptr; - size_t argc = ARGS_ZERO; - napi_value argv[ARGS_ZERO]; - napi_value thisVar = nullptr; - - CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar); - napi_get_undefined(env, &result); - - bool isDoTryAE = true; - uint32_t exposureTime = 0; - NightSessionNapi* nightSessionNapi = nullptr; - status = napi_unwrap(env, thisVar, reinterpret_cast(&nightSessionNapi)); - if (status == napi_ok && nightSessionNapi != nullptr && nightSessionNapi->nightSession_ != nullptr) { - nightSessionNapi->nightSession_->LockForControl(); - nightSessionNapi->nightSession_->DoTryAE(isDoTryAE, exposureTime); - nightSessionNapi->nightSession_->UnlockForControl(); - } else { - MEDIA_ERR_LOG("TryAE call Failed!"); - } - return result; -} - napi_value NightSessionNapi::GetSupportedExposureRange(napi_env env, napi_callback_info info) { MEDIA_DEBUG_LOG("GetSupportedExposureRange is called"); @@ -328,259 +234,5 @@ napi_value NightSessionNapi::NightSessionNapiConstructor(napi_env env, napi_call MEDIA_ERR_LOG("NightSessionNapi call Failed!"); return result; } - -void LongExposureCallbackListener::OnLongExposureCallbackAsync(uint32_t longExposureTime) const -{ - MEDIA_DEBUG_LOG("OnLongExposureCallbackAsync is called"); - uv_loop_s* loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - if (!loop) { - MEDIA_ERR_LOG("failed to get event loop"); - return; - } - uv_work_t* work = new(std::nothrow) uv_work_t; - if (!work) { - MEDIA_ERR_LOG("failed to allocate work"); - return; - } - std::unique_ptr callbackInfo = - std::make_unique(longExposureTime, this); - work->data = callbackInfo.get(); - int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t* work) {}, [] (uv_work_t* work, int status) { - LongExposureCallbackInfo* callbackInfo = reinterpret_cast(work->data); - if (callbackInfo) { - callbackInfo->listener_->OnLongExposureCallback(callbackInfo->longExposureTime_); - delete callbackInfo; - } - delete work; - }, uv_qos_user_initiated); - if (ret) { - MEDIA_ERR_LOG("failed to execute work"); - delete work; - } else { - callbackInfo.release(); - } -} - -void LongExposureCallbackListener::OnLongExposureCallback(uint32_t longExposureTime) const -{ - napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - MEDIA_DEBUG_LOG("OnLongExposureCallback is called"); - napi_value result[ARGS_TWO] = {nullptr, nullptr}; - napi_value callback = nullptr; - napi_value retVal; - for (auto it = longExposureCbList_.begin(); it != longExposureCbList_.end();) { - napi_env env = (*it)->env_; - napi_get_undefined(env, &result[PARAM0]); - napi_create_int32(env, longExposureTime, &result[PARAM1]); - napi_get_reference_value(env, (*it)->cb_, &callback); - napi_call_function(env_, nullptr, callback, ARGS_TWO, result, &retVal); - if ((*it)->isOnce_) { - napi_status status = napi_delete_reference(env, (*it)->cb_); - CHECK_AND_RETURN_LOG(status == napi_ok, "Remove once cb ref: delete reference for callback fail"); - (*it)->cb_ = nullptr; - longExposureCbList_.erase(it); - } else { - it++; - } - } - napi_close_handle_scope(env_, scope); -} - -void LongExposureCallbackListener::OnLongExposure(const uint32_t longExposureTime) -{ - MEDIA_DEBUG_LOG("OnLongExposure is called"); - OnLongExposureCallbackAsync(longExposureTime); -} -void LongExposureCallbackListener::SaveCallbackReference(const std::string &eventType, napi_value callback, bool isOnce) -{ - std::lock_guard lock(mutex_); - for (auto it = longExposureCbList_.begin(); it != longExposureCbList_.end(); ++it) { - bool isSameCallback = CameraNapiUtils::IsSameCallback(env_, callback, (*it)->cb_); - CHECK_AND_RETURN_LOG(!isSameCallback, "SaveCallbackReference: has same callback, nothing to do"); - } - napi_ref callbackRef = nullptr; - const int32_t refCount = 1; - napi_status status = napi_create_reference(env_, callback, refCount, &callbackRef); - CHECK_AND_RETURN_LOG(status == napi_ok && callbackRef != nullptr, - "LongExposureCallback: creating reference for callback fail"); - std::shared_ptr cb = std::make_shared(env_, callbackRef, isOnce); - longExposureCbList_.push_back(cb); - MEDIA_INFO_LOG("Save callback reference success, callback list size [%{public}zu]", - longExposureCbList_.size()); -} - -void LongExposureCallbackListener::RemoveCallbackRef(napi_env env, napi_value callback) -{ - std::lock_guard lock(mutex_); - if (callback == nullptr) { - MEDIA_INFO_LOG("RemoveCallbackRef: js callback is nullptr, remove all callback reference"); - RemoveAllCallbacks(); - return; - } - for (auto it = longExposureCbList_.begin(); it != longExposureCbList_.end(); ++it) { - bool isSameCallback = CameraNapiUtils::IsSameCallback(env_, callback, (*it)->cb_); - if (isSameCallback) { - MEDIA_INFO_LOG("RemoveCallbackRef: find js callback, delete it"); - napi_status status = napi_delete_reference(env, (*it)->cb_); - (*it)->cb_ = nullptr; - CHECK_AND_RETURN_LOG(status == napi_ok, "RemoveCallbackRef: delete reference for callback fail"); - longExposureCbList_.erase(it); - return; - } - } - MEDIA_INFO_LOG("RemoveCallbackRef: js callback no find"); -} - -void LongExposureCallbackListener::RemoveAllCallbacks() -{ - for (auto it = longExposureCbList_.begin(); it != longExposureCbList_.end(); ++it) { - napi_status ret = napi_delete_reference(env_, (*it)->cb_); - if (ret != napi_ok) { - MEDIA_ERR_LOG("RemoveAllCallbackReferences: napi_delete_reference err."); - } - (*it)->cb_ = nullptr; - } - longExposureCbList_.clear(); - MEDIA_INFO_LOG("RemoveAllCallbacks: remove all js callbacks success"); -} - -napi_value NightSessionNapi::On(napi_env env, napi_callback_info info) -{ - CAMERA_SYNC_TRACE; - MEDIA_INFO_LOG("On is called"); - napi_value undefinedResult = nullptr; - size_t argCount = ARGS_TWO; - napi_value argv[ARGS_TWO] = {nullptr, nullptr}; - napi_value thisVar = nullptr; - - napi_get_undefined(env, &undefinedResult); - - CAMERA_NAPI_GET_JS_ARGS(env, info, argCount, argv, thisVar); - NAPI_ASSERT(env, argCount == ARGS_TWO, "requires 2 parameters"); - - if (thisVar == nullptr || argv[PARAM0] == nullptr || argv[PARAM1] == nullptr) { - MEDIA_ERR_LOG("Failed to retrieve details about the callback"); - return undefinedResult; - } - napi_valuetype valueType = napi_undefined; - if (napi_typeof(env, argv[PARAM0], &valueType) != napi_ok || valueType != napi_string - || napi_typeof(env, argv[PARAM1], &valueType) != napi_ok || valueType != napi_function) { - return undefinedResult; - } - std::string eventType = CameraNapiUtils::GetStringArgument(env, argv[PARAM0]); - MEDIA_INFO_LOG("On eventType: %{public}s", eventType.c_str()); - return RegisterCallback(env, thisVar, eventType, argv[PARAM1], false); -} - -napi_value NightSessionNapi::Once(napi_env env, napi_callback_info info) -{ - CAMERA_SYNC_TRACE; - MEDIA_INFO_LOG("Once is called"); - napi_value undefinedResult = nullptr; - size_t argCount = ARGS_TWO; - napi_value argv[ARGS_TWO] = {nullptr, nullptr}; - napi_value thisVar = nullptr; - - napi_get_undefined(env, &undefinedResult); - - CAMERA_NAPI_GET_JS_ARGS(env, info, argCount, argv, thisVar); - NAPI_ASSERT(env, argCount == ARGS_TWO, "requires 2 parameters"); - - if (thisVar == nullptr || argv[PARAM0] == nullptr || argv[PARAM1] == nullptr) { - MEDIA_ERR_LOG("Failed to retrieve details about the callback"); - return undefinedResult; - } - napi_valuetype valueType = napi_undefined; - if (napi_typeof(env, argv[PARAM0], &valueType) != napi_ok || valueType != napi_string - || napi_typeof(env, argv[PARAM1], &valueType) != napi_ok || valueType != napi_function) { - return undefinedResult; - } - std::string eventType = CameraNapiUtils::GetStringArgument(env, argv[PARAM0]); - MEDIA_INFO_LOG("Once eventType: %{public}s", eventType.c_str()); - return RegisterCallback(env, thisVar, eventType, argv[PARAM1], true); -} - -napi_value NightSessionNapi::RegisterCallback(napi_env env, napi_value jsThis, - const string &eventType, napi_value callback, bool isOnce) -{ - MEDIA_DEBUG_LOG("RegisterCallback is called"); - napi_value undefinedResult = nullptr; - napi_get_undefined(env, &undefinedResult); - napi_status status; - - NightSessionNapi* nightSessionNapi = nullptr; - status = napi_unwrap(env, jsThis, reinterpret_cast(&nightSessionNapi)); - NAPI_ASSERT(env, status == napi_ok && nightSessionNapi != nullptr, - "Failed to retrieve nightSessionNapi instance."); - NAPI_ASSERT(env, nightSessionNapi->nightSession_ != nullptr, "cameraSession is null."); - if (eventType.compare("nightExposure") == 0) { - // Set callback for longExposure - if (nightSessionNapi->longExposureCallback_ == nullptr) { - std::shared_ptr longExposureCallback = - make_shared(env); - nightSessionNapi->longExposureCallback_ = longExposureCallback; - nightSessionNapi->nightSession_->SetLongExposureCallback(longExposureCallback); - } - nightSessionNapi->longExposureCallback_->SaveCallbackReference(eventType, callback, isOnce); - } else { - MEDIA_ERR_LOG("Failed to Register Callback: event type is empty!"); - } - return undefinedResult; -} - -napi_value NightSessionNapi::UnregisterCallback(napi_env env, napi_value jsThis, - const std::string &eventType, napi_value callback) -{ - MEDIA_DEBUG_LOG("UnregisterCallback is called"); - napi_value undefinedResult = nullptr; - napi_get_undefined(env, &undefinedResult); - napi_status status; - NightSessionNapi* nightSessionNapi = nullptr; - status = napi_unwrap(env, jsThis, reinterpret_cast(&nightSessionNapi)); - NAPI_ASSERT(env, status == napi_ok && nightSessionNapi != nullptr, - "Failed to retrieve nightSessionNapi instance."); - if (eventType.compare("LongExposure") == 0) { - // Set callback for exposureStateChange - if (nightSessionNapi->longExposureCallback_ == nullptr) { - MEDIA_ERR_LOG("exposureCallback is null"); - } else { - nightSessionNapi->longExposureCallback_->RemoveCallbackRef(env, callback); - } - } else { - MEDIA_ERR_LOG("Failed to Unregister Callback"); - } - return undefinedResult; -} - -napi_value NightSessionNapi::Off(napi_env env, napi_callback_info info) -{ - MEDIA_DEBUG_LOG("Off is called"); - napi_value undefinedResult = nullptr; - napi_get_undefined(env, &undefinedResult); - const size_t minArgCount = 1; - size_t argc = ARGS_TWO; - napi_value argv[ARGS_TWO] = {nullptr, nullptr}; - napi_value thisVar = nullptr; - CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar); - if (argc < minArgCount) { - return undefinedResult; - } - - napi_valuetype valueType = napi_undefined; - if (napi_typeof(env, argv[PARAM0], &valueType) != napi_ok || valueType != napi_string) { - return undefinedResult; - } - - napi_valuetype secondArgsType = napi_undefined; - if (argc > minArgCount && - (napi_typeof(env, argv[PARAM1], &secondArgsType) != napi_ok || secondArgsType != napi_function)) { - return undefinedResult; - } - std::string eventType = CameraNapiUtils::GetStringArgument(env, argv[PARAM0]); - MEDIA_INFO_LOG("Off eventType: %{public}s", eventType.c_str()); - return UnregisterCallback(env, thisVar, eventType, argv[PARAM1]); -} } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp b/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp new file mode 100644 index 000000000..b3fb06778 --- /dev/null +++ b/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mode/photo_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +using namespace std; + +thread_local napi_ref PhotoSessionNapi::sConstructor_ = nullptr; + +PhotoSessionNapi::PhotoSessionNapi() : env_(nullptr), wrapper_(nullptr) +{ +} +PhotoSessionNapi::~PhotoSessionNapi() +{ + MEDIA_DEBUG_LOG("~PhotoSessionNapi is called"); + if (wrapper_ != nullptr) { + napi_delete_reference(env_, wrapper_); + } + if (photoSession_) { + photoSession_ = nullptr; + } +} +void PhotoSessionNapi::PhotoSessionNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint) +{ + MEDIA_DEBUG_LOG("PhotoSessionNapiDestructor is called"); + PhotoSessionNapi* cameraObj = reinterpret_cast(nativeObject); + if (cameraObj != nullptr) { + delete cameraObj; + } +} +napi_value PhotoSessionNapi::Init(napi_env env, napi_value exports) +{ + MEDIA_DEBUG_LOG("Init is called"); + napi_status status; + napi_value ctorObj; + std::vector> descriptors = {camera_process_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props}; + std::vector photo_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); + status = napi_define_class(env, PHOTO_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, + PhotoSessionNapiConstructor, nullptr, + photo_session_props.size(), + photo_session_props.data(), &ctorObj); + if (status == napi_ok) { + int32_t refCount = 1; + status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); + if (status == napi_ok) { + status = napi_set_named_property(env, exports, PHOTO_SESSION_NAPI_CLASS_NAME, ctorObj); + if (status == napi_ok) { + return exports; + } + } + } + MEDIA_ERR_LOG("Init call Failed!"); + return nullptr; +} + +napi_value PhotoSessionNapi::CreateCameraSession(napi_env env) +{ + MEDIA_DEBUG_LOG("CreateCameraSession is called"); + CAMERA_SYNC_TRACE; + napi_status status; + napi_value result = nullptr; + napi_value constructor; + status = napi_get_reference_value(env, sConstructor_, &constructor); + if (status == napi_ok) { + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::CAPTURE); + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("Failed to create Photo session instance"); + napi_get_undefined(env, &result); + return result; + } + status = napi_new_instance(env, constructor, 0, nullptr, &result); + sCameraSession_ = nullptr; + if (status == napi_ok && result != nullptr) { + MEDIA_DEBUG_LOG("success to create Photo session napi instance"); + return result; + } else { + MEDIA_ERR_LOG("Failed to create Photo session napi instance"); + } + } + MEDIA_ERR_LOG("Failed to create Photo session napi instance last"); + napi_get_undefined(env, &result); + return result; +} + +napi_value PhotoSessionNapi::PhotoSessionNapiConstructor(napi_env env, napi_callback_info info) +{ + MEDIA_DEBUG_LOG("PhotoSessionNapiConstructor is called"); + napi_status status; + napi_value result = nullptr; + napi_value thisVar = nullptr; + + napi_get_undefined(env, &result); + CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar); + + if (status == napi_ok && thisVar != nullptr) { + std::unique_ptr obj = std::make_unique(); + obj->env_ = env; + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("sCameraSession_ is null"); + return result; + } + obj->photoSession_ = static_cast(sCameraSession_.GetRefPtr()); + obj->cameraSession_ = obj->photoSession_; + if (obj->photoSession_ == nullptr) { + MEDIA_ERR_LOG("photoSession_ is null"); + return result; + } + status = napi_wrap(env, thisVar, reinterpret_cast(obj.get()), + PhotoSessionNapi::PhotoSessionNapiDestructor, nullptr, nullptr); + if (status == napi_ok) { + obj.release(); + return thisVar; + } else { + MEDIA_ERR_LOG("PhotoSessionNapi Failure wrapping js to native napi"); + } + } + MEDIA_ERR_LOG("PhotoSessionNapi call Failed!"); + return result; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp b/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp index 585e5b445..7fc557b1f 100644 --- a/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp +++ b/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp @@ -47,85 +47,19 @@ napi_value PortraitSessionNapi::Init(napi_env env, napi_value exports) MEDIA_DEBUG_LOG("Init is called"); napi_status status; napi_value ctorObj; - napi_property_descriptor portrait_session_props[] = { - DECLARE_NAPI_FUNCTION("beginConfig", CameraSessionNapi::BeginConfig), - DECLARE_NAPI_FUNCTION("commitConfig", CameraSessionNapi::CommitConfig), - - DECLARE_NAPI_FUNCTION("canAddInput", CameraSessionNapi::CanAddInput), - DECLARE_NAPI_FUNCTION("addInput", CameraSessionNapi::AddInput), - DECLARE_NAPI_FUNCTION("removeInput", CameraSessionNapi::RemoveInput), - - DECLARE_NAPI_FUNCTION("canAddOutput", CameraSessionNapi::CanAddOutput), - DECLARE_NAPI_FUNCTION("addOutput", CameraSessionNapi::AddOutput), - DECLARE_NAPI_FUNCTION("removeOutput", CameraSessionNapi::RemoveOutput), - - DECLARE_NAPI_FUNCTION("start", CameraSessionNapi::Start), - DECLARE_NAPI_FUNCTION("stop", CameraSessionNapi::Stop), - DECLARE_NAPI_FUNCTION("release", CameraSessionNapi::Release), - - DECLARE_NAPI_FUNCTION("lockForControl", CameraSessionNapi::LockForControl), - DECLARE_NAPI_FUNCTION("unlockForControl", CameraSessionNapi::UnlockForControl), - - DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", - CameraSessionNapi::IsVideoStabilizationModeSupported), - DECLARE_NAPI_FUNCTION("getActiveVideoStabilizationMode", CameraSessionNapi::GetActiveVideoStabilizationMode), - DECLARE_NAPI_FUNCTION("setVideoStabilizationMode", CameraSessionNapi::SetVideoStabilizationMode), - - DECLARE_NAPI_FUNCTION("hasFlash", CameraSessionNapi::HasFlash), - DECLARE_NAPI_FUNCTION("isFlashModeSupported", CameraSessionNapi::IsFlashModeSupported), - DECLARE_NAPI_FUNCTION("getFlashMode", CameraSessionNapi::GetFlashMode), - DECLARE_NAPI_FUNCTION("setFlashMode", CameraSessionNapi::SetFlashMode), - - DECLARE_NAPI_FUNCTION("isExposureModeSupported", CameraSessionNapi::IsExposureModeSupported), - DECLARE_NAPI_FUNCTION("getExposureMode", CameraSessionNapi::GetExposureMode), - DECLARE_NAPI_FUNCTION("setExposureMode", CameraSessionNapi::SetExposureMode), - DECLARE_NAPI_FUNCTION("getExposureBiasRange", CameraSessionNapi::GetExposureBiasRange), - DECLARE_NAPI_FUNCTION("setExposureBias", CameraSessionNapi::SetExposureBias), - DECLARE_NAPI_FUNCTION("getExposureValue", CameraSessionNapi::GetExposureValue), - - DECLARE_NAPI_FUNCTION("getMeteringPoint", CameraSessionNapi::GetMeteringPoint), - DECLARE_NAPI_FUNCTION("setMeteringPoint", CameraSessionNapi::SetMeteringPoint), - - DECLARE_NAPI_FUNCTION("isFocusModeSupported", CameraSessionNapi::IsFocusModeSupported), - DECLARE_NAPI_FUNCTION("getFocusMode", CameraSessionNapi::GetFocusMode), - DECLARE_NAPI_FUNCTION("setFocusMode", CameraSessionNapi::SetFocusMode), - - DECLARE_NAPI_FUNCTION("getFocusPoint", CameraSessionNapi::GetFocusPoint), - DECLARE_NAPI_FUNCTION("setFocusPoint", CameraSessionNapi::SetFocusPoint), - DECLARE_NAPI_FUNCTION("getFocalLength", CameraSessionNapi::GetFocalLength), - - DECLARE_NAPI_FUNCTION("getZoomRatioRange", CameraSessionNapi::GetZoomRatioRange), - DECLARE_NAPI_FUNCTION("getZoomRatio", CameraSessionNapi::GetZoomRatio), - DECLARE_NAPI_FUNCTION("setZoomRatio", CameraSessionNapi::SetZoomRatio), - - DECLARE_NAPI_FUNCTION("getSupportedFilters", CameraSessionNapi::GetSupportedFilters), - DECLARE_NAPI_FUNCTION("getFilter", CameraSessionNapi::GetFilter), - DECLARE_NAPI_FUNCTION("setFilter", CameraSessionNapi::SetFilter), - - DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", CameraSessionNapi::GetSupportedBeautyTypes), - DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", CameraSessionNapi::GetSupportedBeautyRange), - DECLARE_NAPI_FUNCTION("getBeauty", CameraSessionNapi::GetBeauty), - DECLARE_NAPI_FUNCTION("setBeauty", CameraSessionNapi::SetBeauty), - - DECLARE_NAPI_FUNCTION("on", CameraSessionNapi::On), - + std::vector portrait_props = { DECLARE_NAPI_FUNCTION("getSupportedPortraitEffects", GetSupportedPortraitEffects), DECLARE_NAPI_FUNCTION("getPortraitEffect", GetPortraitEffect), - DECLARE_NAPI_FUNCTION("setPortraitEffect", SetPortraitEffect), - - DECLARE_NAPI_FUNCTION("getSupportedColorEffects", CameraSessionNapi::GetSupportedColorEffects), - DECLARE_NAPI_FUNCTION("getColorEffect", CameraSessionNapi::GetColorEffect), - DECLARE_NAPI_FUNCTION("setColorEffect", CameraSessionNapi::SetColorEffect), - - DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", CameraSessionNapi::GetSupportedColorSpaces), - DECLARE_NAPI_FUNCTION("getActiveColorSpace", CameraSessionNapi::GetActiveColorSpace), - DECLARE_NAPI_FUNCTION("setColorSpace", CameraSessionNapi::SetColorSpace) + DECLARE_NAPI_FUNCTION("setPortraitEffect", SetPortraitEffect) }; - + std::vector> descriptors = {camera_process_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props, portrait_props}; + std::vector portrait_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); status = napi_define_class(env, PORTRAIT_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, PortraitSessionNapiConstructor, nullptr, - sizeof(portrait_session_props) / sizeof(portrait_session_props[PARAM0]), - portrait_session_props, &ctorObj); + portrait_session_props.size(), + portrait_session_props.data(), &ctorObj); if (status == napi_ok) { int32_t refCount = 1; status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); @@ -149,7 +83,7 @@ napi_value PortraitSessionNapi::CreateCameraSession(napi_env env) napi_value constructor; status = napi_get_reference_value(env, sConstructor_, &constructor); if (status == napi_ok) { - sCameraSession_ = ModeManager::GetInstance()->CreateCaptureSession(CameraMode::PORTRAIT); + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::PORTRAIT); if (sCameraSession_ == nullptr) { MEDIA_ERR_LOG("Failed to create Portrait session instance"); napi_get_undefined(env, &result); diff --git a/frameworks/js/camera_napi/src/mode/video_session_napi.cpp b/frameworks/js/camera_napi/src/mode/video_session_napi.cpp new file mode 100644 index 000000000..22ff6c644 --- /dev/null +++ b/frameworks/js/camera_napi/src/mode/video_session_napi.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mode/video_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +using namespace std; + +thread_local napi_ref VideoSessionNapi::sConstructor_ = nullptr; + +VideoSessionNapi::VideoSessionNapi() : env_(nullptr), wrapper_(nullptr) +{ +} +VideoSessionNapi::~VideoSessionNapi() +{ + MEDIA_DEBUG_LOG("~VideoSessionNapi is called"); + if (wrapper_ != nullptr) { + napi_delete_reference(env_, wrapper_); + } + if (videoSession_) { + videoSession_ = nullptr; + } +} +void VideoSessionNapi::VideoSessionNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint) +{ + MEDIA_DEBUG_LOG("VideoSessionNapiDestructor is called"); + VideoSessionNapi* cameraObj = reinterpret_cast(nativeObject); + if (cameraObj != nullptr) { + delete cameraObj; + } +} +napi_value VideoSessionNapi::Init(napi_env env, napi_value exports) +{ + MEDIA_DEBUG_LOG("Init is called"); + napi_status status; + napi_value ctorObj; + std::vector> descriptors = {camera_process_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props, stabilization_props}; + std::vector video_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); + status = napi_define_class(env, VIDEO_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, + VideoSessionNapiConstructor, nullptr, + video_session_props.size(), + video_session_props.data(), &ctorObj); + if (status == napi_ok) { + int32_t refCount = 1; + status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); + if (status == napi_ok) { + status = napi_set_named_property(env, exports, VIDEO_SESSION_NAPI_CLASS_NAME, ctorObj); + if (status == napi_ok) { + return exports; + } + } + } + MEDIA_ERR_LOG("Init call Failed!"); + return nullptr; +} + +napi_value VideoSessionNapi::CreateCameraSession(napi_env env) +{ + MEDIA_DEBUG_LOG("CreateCameraSession is called"); + CAMERA_SYNC_TRACE; + napi_status status; + napi_value result = nullptr; + napi_value constructor; + status = napi_get_reference_value(env, sConstructor_, &constructor); + if (status == napi_ok) { + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::VIDEO); + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("Failed to create Video session instance"); + napi_get_undefined(env, &result); + return result; + } + status = napi_new_instance(env, constructor, 0, nullptr, &result); + sCameraSession_ = nullptr; + if (status == napi_ok && result != nullptr) { + MEDIA_DEBUG_LOG("success to create Video session napi instance"); + return result; + } else { + MEDIA_ERR_LOG("Failed to create Video session napi instance"); + } + } + MEDIA_ERR_LOG("Failed to create Video session napi instance last"); + napi_get_undefined(env, &result); + return result; +} + +napi_value VideoSessionNapi::VideoSessionNapiConstructor(napi_env env, napi_callback_info info) +{ + MEDIA_DEBUG_LOG("VideoSessionNapiConstructor is called"); + napi_status status; + napi_value result = nullptr; + napi_value thisVar = nullptr; + + napi_get_undefined(env, &result); + CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar); + + if (status == napi_ok && thisVar != nullptr) { + std::unique_ptr obj = std::make_unique(); + obj->env_ = env; + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("sCameraSession_ is null"); + return result; + } + obj->videoSession_ = static_cast(sCameraSession_.GetRefPtr()); + obj->cameraSession_ = obj->videoSession_; + if (obj->videoSession_ == nullptr) { + MEDIA_ERR_LOG("videoSession_ is null"); + return result; + } + status = napi_wrap(env, thisVar, reinterpret_cast(obj.get()), + VideoSessionNapi::VideoSessionNapiDestructor, nullptr, nullptr); + if (status == napi_ok) { + obj.release(); + return thisVar; + } else { + MEDIA_ERR_LOG("VideoSessionNapi Failure wrapping js to native napi"); + } + } + MEDIA_ERR_LOG("VideoSessionNapi call Failed!"); + return result; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/camera_napi/src/output/camera_output_napi.cpp b/frameworks/js/camera_napi/src/output/camera_output_napi.cpp index cb74acc80..f3b7a3f42 100644 --- a/frameworks/js/camera_napi/src/output/camera_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/camera_output_napi.cpp @@ -277,7 +277,7 @@ napi_value CameraOutputCapabilityNapi::CreateCameraOutputCapability(napi_env env } napi_value CameraOutputCapabilityNapi::CreateCameraOutputCapability(napi_env env, - sptr camera, CameraMode modename) + sptr camera, SceneMode modename) { MEDIA_INFO_LOG("CreateCameraOutputCapability is called"); CAMERA_SYNC_TRACE; @@ -291,7 +291,7 @@ napi_value CameraOutputCapabilityNapi::CreateCameraOutputCapability(napi_env env status = napi_get_reference_value(env, sCapabilityConstructor_, &constructor); if (status == napi_ok) { - sCameraOutputCapability_ = ModeManager::GetInstance()->GetSupportedOutputCapability(camera, modename); + sCameraOutputCapability_ = CameraManager::GetInstance()->GetSupportedOutputCapability(camera, modename); if (sCameraOutputCapability_ == nullptr) { MEDIA_ERR_LOG("failed to create CreateCameraOutputCapability"); return result; diff --git a/frameworks/js/camera_napi/src/session/camera_session_napi.cpp b/frameworks/js/camera_napi/src/session/camera_session_napi.cpp index e375ea646..cbad580f5 100644 --- a/frameworks/js/camera_napi/src/session/camera_session_napi.cpp +++ b/frameworks/js/camera_napi/src/session/camera_session_napi.cpp @@ -631,88 +631,14 @@ napi_value CameraSessionNapi::Init(napi_env env, napi_value exports) napi_status status; napi_value ctorObj; int32_t refCount = 1; - - napi_property_descriptor camera_session_props[] = { - DECLARE_NAPI_FUNCTION("beginConfig", BeginConfig), - DECLARE_NAPI_FUNCTION("commitConfig", CommitConfig), - - DECLARE_NAPI_FUNCTION("canAddInput", CanAddInput), - DECLARE_NAPI_FUNCTION("addInput", AddInput), - DECLARE_NAPI_FUNCTION("removeInput", RemoveInput), - - DECLARE_NAPI_FUNCTION("canAddOutput", CanAddOutput), - DECLARE_NAPI_FUNCTION("addOutput", AddOutput), - DECLARE_NAPI_FUNCTION("removeOutput", RemoveOutput), - - DECLARE_NAPI_FUNCTION("start", Start), - DECLARE_NAPI_FUNCTION("stop", Stop), - DECLARE_NAPI_FUNCTION("release", Release), - - DECLARE_NAPI_FUNCTION("lockForControl", LockForControl), - DECLARE_NAPI_FUNCTION("unlockForControl", UnlockForControl), - - DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", IsVideoStabilizationModeSupported), - DECLARE_NAPI_FUNCTION("getActiveVideoStabilizationMode", GetActiveVideoStabilizationMode), - DECLARE_NAPI_FUNCTION("setVideoStabilizationMode", SetVideoStabilizationMode), - - DECLARE_NAPI_FUNCTION("hasFlash", HasFlash), - DECLARE_NAPI_FUNCTION("isFlashModeSupported", IsFlashModeSupported), - DECLARE_NAPI_FUNCTION("getFlashMode", GetFlashMode), - DECLARE_NAPI_FUNCTION("setFlashMode", SetFlashMode), - - DECLARE_NAPI_FUNCTION("isExposureModeSupported", IsExposureModeSupported), - DECLARE_NAPI_FUNCTION("getExposureMode", GetExposureMode), - DECLARE_NAPI_FUNCTION("setExposureMode", SetExposureMode), - DECLARE_NAPI_FUNCTION("getExposureBiasRange", GetExposureBiasRange), - DECLARE_NAPI_FUNCTION("setExposureBias", SetExposureBias), - DECLARE_NAPI_FUNCTION("getExposureValue", GetExposureValue), - - DECLARE_NAPI_FUNCTION("getMeteringPoint", GetMeteringPoint), - DECLARE_NAPI_FUNCTION("setMeteringPoint", SetMeteringPoint), - - DECLARE_NAPI_FUNCTION("isFocusModeSupported", IsFocusModeSupported), - DECLARE_NAPI_FUNCTION("getFocusMode", GetFocusMode), - DECLARE_NAPI_FUNCTION("setFocusMode", SetFocusMode), - - DECLARE_NAPI_FUNCTION("getFocusPoint", GetFocusPoint), - DECLARE_NAPI_FUNCTION("setFocusPoint", SetFocusPoint), - DECLARE_NAPI_FUNCTION("getFocalLength", GetFocalLength), - - DECLARE_NAPI_FUNCTION("getZoomRatioRange", GetZoomRatioRange), - DECLARE_NAPI_FUNCTION("getZoomRatio", GetZoomRatio), - DECLARE_NAPI_FUNCTION("setZoomRatio", SetZoomRatio), - DECLARE_NAPI_FUNCTION("prepareZoom", PrepareZoom), - DECLARE_NAPI_FUNCTION("unPrepareZoom", UnPrepareZoom), - DECLARE_NAPI_FUNCTION("setSmoothZoom", SetSmoothZoom), - - DECLARE_NAPI_FUNCTION("getSupportedFilters", GetSupportedFilters), - DECLARE_NAPI_FUNCTION("getFilter", GetFilter), - DECLARE_NAPI_FUNCTION("setFilter", SetFilter), - - DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", GetSupportedBeautyTypes), - DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", GetSupportedBeautyRange), - DECLARE_NAPI_FUNCTION("getBeauty", GetBeauty), - DECLARE_NAPI_FUNCTION("setBeauty", SetBeauty), - DECLARE_NAPI_FUNCTION("on", On), - DECLARE_NAPI_FUNCTION("once", Once), - DECLARE_NAPI_FUNCTION("off", Off), - - DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", GetSupportedColorSpaces), - DECLARE_NAPI_FUNCTION("getActiveColorSpace", GetActiveColorSpace), - DECLARE_NAPI_FUNCTION("setColorSpace", SetColorSpace), - - DECLARE_NAPI_FUNCTION("getSupportedColorEffects", GetSupportedColorEffects), - DECLARE_NAPI_FUNCTION("getColorEffect", GetColorEffect), - DECLARE_NAPI_FUNCTION("setColorEffect", SetColorEffect), - - DECLARE_NAPI_FUNCTION("isMacroSupported", IsMacroSupported), - DECLARE_NAPI_FUNCTION("enableMacro", EnableMacro), - }; - + std::vector> descriptors = {camera_process_props, stabilization_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props}; + std::vector camera_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); status = napi_define_class(env, CAMERA_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, CameraSessionNapiConstructor, nullptr, - sizeof(camera_session_props) / sizeof(camera_session_props[PARAM0]), - camera_session_props, &ctorObj); + camera_session_props.size(), + camera_session_props.data(), &ctorObj); if (status == napi_ok) { status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); if (status == napi_ok) { diff --git a/frameworks/native/camera/BUILD.gn b/frameworks/native/camera/BUILD.gn index 2ea9814fd..de42df851 100644 --- a/frameworks/native/camera/BUILD.gn +++ b/frameworks/native/camera/BUILD.gn @@ -65,7 +65,6 @@ ohos_shared_library("camera_framework") { "src/input/camera_manager.cpp", "src/input/capture_input.cpp", "src/input/prelaunch_config.cpp", - "src/mode/mode_manager.cpp", "src/output/camera_output_capability.cpp", "src/output/capture_output.cpp", "src/output/metadata_output.cpp", @@ -75,8 +74,10 @@ ohos_shared_library("camera_framework") { "src/output/video_output.cpp", "src/session/capture_session.cpp", "src/session/night_session.cpp", + "src/session/photo_session.cpp", "src/session/portrait_session.cpp", "src/session/scan_session.cpp", + "src/session/video_session.cpp", "src/utils/metadata_common_utils.cpp", ] diff --git a/frameworks/native/camera/src/input/camera_device.cpp b/frameworks/native/camera/src/input/camera_device.cpp index bd71ae5cc..e1bc31ea4 100644 --- a/frameworks/native/camera/src/input/camera_device.cpp +++ b/frameworks/native/camera/src/input/camera_device.cpp @@ -15,7 +15,6 @@ #include #include "camera_metadata_info.h" #include "camera_log.h" -#include "display_manager.h" #include "input/camera_device.h" using namespace std; @@ -113,8 +112,6 @@ void CameraDevice::init(common_metadata_header_t* metadata) foldScreenType_ = itr->second; } } - - isFoldable = OHOS::Rosen::DisplayManager::GetInstance().IsFoldable(); MEDIA_INFO_LOG("camera position: %{public}d, camera type: %{public}d, camera connection type: %{public}d, " "Mirror Supported: %{public}d , camera foldScreen type: %{public}d", @@ -133,9 +130,8 @@ std::shared_ptr CameraDevice::GetMetadata() CameraPosition CameraDevice::GetPosition() { - if (isFoldable && cameraPosition_ == CAMERA_POSITION_FRONT) { - cameraPosition_ = (foldScreenType_ == CAMERA_FOLDSCREEN_UNSPECIFIED) ? CAMERA_POSITION_BACK : - (foldScreenType_ == CAMERA_FOLDSCREEN_INNER) ? CAMERA_POSITION_FOLD_INNER : CAMERA_POSITION_FRONT; + if (cameraPosition_ == CAMERA_POSITION_FRONT && foldScreenType_ == CAMERA_FOLDSCREEN_INNER) { + cameraPosition_ = CAMERA_POSITION_FOLD_INNER; } return cameraPosition_; } diff --git a/frameworks/native/camera/src/input/camera_manager.cpp b/frameworks/native/camera/src/input/camera_manager.cpp index dee7b253a..76e472703 100644 --- a/frameworks/native/camera/src/input/camera_manager.cpp +++ b/frameworks/native/camera/src/input/camera_manager.cpp @@ -30,6 +30,7 @@ using namespace std; namespace OHOS { namespace CameraStandard { +using OHOS::HDI::Camera::V1_2::OperationMode_V1_2; sptr CameraManager::cameraManager_; std::mutex CameraManager::instanceMutex_; @@ -51,6 +52,36 @@ const std::unordered_map CameraManager::fwToMetaC {CAMERA_FORMAT_YCRCB_P010, OHOS_CAMERA_FORMAT_YCRCB_P010} }; +const std::unordered_map g_metaToFwSupportedMode_ = { + {OperationMode_V1_2::NORMAL, NORMAL}, + {OperationMode_V1_2::CAPTURE, CAPTURE}, + {OperationMode_V1_2::VIDEO, VIDEO}, + {OperationMode_V1_2::PORTRAIT, PORTRAIT}, + {OperationMode_V1_2::NIGHT, NIGHT}, + {OperationMode_V1_2::PROFESSIONAL, PROFESSIONAL}, + {OperationMode_V1_2::SLOW_MOTION, SLOW_MOTION}, + {OperationMode_V1_2::SCAN_CODE, SCAN} +}; + +const std::unordered_map g_fwToMetaSupportedMode_ = { + {NORMAL, OperationMode_V1_2::NORMAL}, + {CAPTURE, OperationMode_V1_2::CAPTURE}, + {VIDEO, OperationMode_V1_2::VIDEO}, + {PORTRAIT, OperationMode_V1_2::PORTRAIT}, + {NIGHT, OperationMode_V1_2::NIGHT}, + {PROFESSIONAL, OperationMode_V1_2::PROFESSIONAL}, + {SLOW_MOTION, OperationMode_V1_2::SLOW_MOTION}, + {SCAN, OperationMode_V1_2::SCAN_CODE} +}; + +const std::set isTemplateMode_ = { + SceneMode::CAPTURE, SceneMode::VIDEO +}; + +const std::set isPhotoMode_ = { + SceneMode::CAPTURE, SceneMode::PORTRAIT +}; + CameraManager::CameraManager() { Init(); @@ -153,6 +184,55 @@ sptr CameraManager::CreateCaptureSession() return captureSession; } +sptr CameraManager::CreateCaptureSession(SceneMode mode) +{ + CAMERA_SYNC_TRACE; + sptr session = nullptr; + sptr captureSession = nullptr; + + int32_t retCode = CAMERA_OK; + if (serviceProxy_ == nullptr) { + MEDIA_ERR_LOG("serviceProxy_ is null"); + return nullptr; + } + OperationMode_V1_2 opMode = OperationMode_V1_2::NORMAL; + for (auto itr = g_fwToMetaSupportedMode_.cbegin(); itr != g_fwToMetaSupportedMode_.cend(); itr++) { + if (mode == itr->first) { + opMode = itr->second; + } + } + MEDIA_ERR_LOG("CameraManager CreateCaptureSession E"); + retCode = serviceProxy_->CreateCaptureSession(session, opMode); + MEDIA_ERR_LOG("CameraManager CreateCaptureSession X, %{public}d", retCode); + if (retCode == CAMERA_OK && session != nullptr) { + switch (mode) { + case SceneMode::VIDEO: + captureSession = new(std::nothrow) VideoSession(session); + break; + case SceneMode::CAPTURE: + captureSession = new(std::nothrow) PhotoSession(session); + break; + case SceneMode::PORTRAIT: + captureSession = new(std::nothrow) PortraitSession(session); + break; + case SceneMode::SCAN: + captureSession = new(std::nothrow) ScanSession(session); + break; + case SceneMode::NIGHT: + captureSession = new(std::nothrow) NightSession(session); + break; + default: + captureSession = new(std::nothrow) CaptureSession(session); + break; + } + } else { + MEDIA_ERR_LOG("Failed to get capture session object from hcamera service!, %{public}d", retCode); + return nullptr; + } + captureSession->SetMode(static_cast(mode)); + return captureSession; +} + int CameraManager::CreateCaptureSession(sptr *pCaptureSession) { CAMERA_SYNC_TRACE; @@ -653,7 +733,6 @@ std::vector> CameraManager::GetSupportedCameras() MEDIA_ERR_LOG("serviceProxy_ is null, returning empty list!"); return cameraObjList; } - std::vector> supportedCameras; GetDmDeviceInfo(); retCode = serviceProxy_->GetCameras(cameraIds, cameraAbilityList); if (retCode == CAMERA_OK) { @@ -673,17 +752,37 @@ std::vector> CameraManager::GetSupportedCameras() cameraObj->modePreviewProfiles_[portraitMode] = capability->GetPreviewProfiles(); cameraObj->modePhotoProfiles_[portraitMode] = capability->GetPhotoProfiles(); } - supportedCameras.emplace_back(cameraObj); + cameraObjList.emplace_back(cameraObj); } } else { MEDIA_ERR_LOG("Get camera device failed!, retCode: %{public}d", retCode); } - ChooseDeFaultCameras(supportedCameras); AlignVideoFpsProfile(cameraObjList); return cameraObjList; } +std::vector CameraManager::GetSupportedModes(sptr& camera) +{ + std::vector supportedModes = {}; + + std::shared_ptr metadata = camera->GetMetadata(); + camera_metadata_item_t item; + int32_t ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_CAMERA_MODES, &item); + if (ret != CAM_META_SUCCESS || item.count == 0) { + MEDIA_ERR_LOG("CaptureSession::GetSupportedModes Failed with return code %{public}d", ret); + return supportedModes; + } + for (uint32_t i = 0; i < item.count; i++) { + auto itr = g_metaToFwSupportedMode_.find(static_cast(item.data.u8[i])); + if (itr != g_metaToFwSupportedMode_.end()) { + supportedModes.emplace_back(itr->second); + } + } + MEDIA_INFO_LOG("CameraManager::GetSupportedModes supportedModes size: %{public}zu", supportedModes.size()); + return supportedModes; +} + void CameraManager::AlignVideoFpsProfile(std::vector>& cameraObjList) { MEDIA_ERR_LOG("CameraManager::AlignVideoFpsProfile enter"); @@ -743,26 +842,6 @@ void CameraManager::AlignVideoFpsProfile(std::vector>& camera } } -void CameraManager::ChooseDeFaultCameras(std::vector>& supportedCameras) -{ - for (auto& camera : supportedCameras) { - bool hasDefaultCamera = false; - for (auto& defaultCamera : cameraObjList) { - if ((camera->GetConnectionType() != CAMERA_CONNECTION_USB_PLUGIN) && - (defaultCamera->GetPosition() == camera->GetPosition()) && - (defaultCamera->GetConnectionType() == camera->GetConnectionType())) { - hasDefaultCamera = true; - MEDIA_INFO_LOG("ChooseDeFaultCameras alreadly has default camera"); - } else { - MEDIA_INFO_LOG("ChooseDeFaultCameras need add default camera"); - } - } - if (!hasDefaultCamera) { - cameraObjList.emplace_back(camera); - } - } -} - sptr CameraManager::CreateCameraInput(sptr &camera) { CAMERA_SYNC_TRACE; @@ -925,7 +1004,9 @@ sptr CameraManager::GetSupportedOutputCapability(sptr CameraManager::GetSupportedOutputCapability(sptrSetPreviewProfiles(previewProfiles_); MEDIA_INFO_LOG("SetPreviewProfiles size = %{public}zu", previewProfiles_.size()); - cameraOutputCapability->SetVideoProfiles(vidProfiles_); + if (!isPhotoMode_.count(modeName)) { + cameraOutputCapability->SetVideoProfiles(vidProfiles_); + } MEDIA_INFO_LOG("SetVideoProfiles size = %{public}zu", vidProfiles_.size()); camera_metadata_item_t metadataItem; vector objectTypes = {}; diff --git a/frameworks/native/camera/src/mode/mode_manager.cpp b/frameworks/native/camera/src/mode/mode_manager.cpp deleted file mode 100644 index a7c689135..000000000 --- a/frameworks/native/camera/src/mode/mode_manager.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mode/mode_manager.h" - - -#include "camera_util.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "camera_log.h" -#include "system_ability_definition.h" -#include "camera_error_code.h" -#include "icamera_util.h" -#include "device_manager_impl.h" - -using namespace std; -namespace OHOS { -namespace CameraStandard { -using namespace OHOS::HDI::Camera::V1_1; -using namespace OHOS::HDI::Camera::V1_2; -using OHOS::HDI::Camera::V1_2::OperationMode_V1_2; -sptr ModeManager::modeManager_; -const std::unordered_map ModeManager::metaToFwFormat_ = { - {OHOS_CAMERA_FORMAT_YCRCB_420_SP, CAMERA_FORMAT_YUV_420_SP}, - {OHOS_CAMERA_FORMAT_JPEG, CAMERA_FORMAT_JPEG}, - {OHOS_CAMERA_FORMAT_RGBA_8888, CAMERA_FORMAT_RGBA_8888}, - {OHOS_CAMERA_FORMAT_YCBCR_P010, CAMERA_FORMAT_YCBCR_P010}, - {OHOS_CAMERA_FORMAT_YCRCB_P010, CAMERA_FORMAT_YCRCB_P010} -}; - -const std::unordered_map ModeManager::fwToMetaFormat_ = { - {CAMERA_FORMAT_YUV_420_SP, OHOS_CAMERA_FORMAT_YCRCB_420_SP}, - {CAMERA_FORMAT_JPEG, OHOS_CAMERA_FORMAT_JPEG}, - {CAMERA_FORMAT_RGBA_8888, OHOS_CAMERA_FORMAT_RGBA_8888}, - {CAMERA_FORMAT_YCBCR_P010, OHOS_CAMERA_FORMAT_YCBCR_P010}, - {CAMERA_FORMAT_YCRCB_P010, OHOS_CAMERA_FORMAT_YCRCB_P010} -}; - -const std::unordered_map g_metaToFwSupportedMode_ = { - {OperationMode_V1_2::NORMAL, NORMAL}, - {OperationMode_V1_2::CAPTURE, CAPTURE}, - {OperationMode_V1_2::VIDEO, VIDEO}, - {OperationMode_V1_2::PORTRAIT, PORTRAIT}, - {OperationMode_V1_2::NIGHT, NIGHT}, - {OperationMode_V1_2::PROFESSIONAL, PROFESSIONAL}, - {OperationMode_V1_2::SLOW_MOTION, SLOW_MOTION}, - {OperationMode_V1_2::SCAN_CODE, SCAN} -}; - -const std::unordered_map g_fwToMetaSupportedMode_ = { - {NORMAL, OperationMode_V1_2::NORMAL}, - {CAPTURE, OperationMode_V1_2::CAPTURE}, - {VIDEO, OperationMode_V1_2::VIDEO}, - {PORTRAIT, OperationMode_V1_2::PORTRAIT}, - {NIGHT, OperationMode_V1_2::NIGHT}, - {PROFESSIONAL, OperationMode_V1_2::PROFESSIONAL}, - {SLOW_MOTION, OperationMode_V1_2::SLOW_MOTION}, - {SCAN, OperationMode_V1_2::SCAN_CODE} -}; -ModeManager::ModeManager() -{ - Init(); -} - -ModeManager::~ModeManager() -{ - serviceProxy_ = nullptr; - ModeManager::modeManager_ = nullptr; -} - -sptr &ModeManager::GetInstance() -{ - if (ModeManager::modeManager_ == nullptr) { - MEDIA_INFO_LOG("Initializing mode manager for first time!"); - ModeManager::modeManager_ = new(std::nothrow) ModeManager(); - CHECK_AND_PRINT_LOG(ModeManager::modeManager_ != nullptr, "Failed to new ModeManager"); - } - return ModeManager::modeManager_; -} - -void ModeManager::Init() -{ - CAMERA_SYNC_TRACE; - sptr object = nullptr; - MEDIA_DEBUG_LOG("ModeManager:init srart"); - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - MEDIA_ERR_LOG("ModeManager get System ability manager failed"); - return; - } - MEDIA_DEBUG_LOG("ModeManager:GetSystemAbility srart"); - object = samgr->GetSystemAbility(CAMERA_SERVICE_ID); - if (object == nullptr) { - MEDIA_ERR_LOG("object is null"); - return; - } - serviceProxy_ = iface_cast(object); - if (serviceProxy_ == nullptr) { - MEDIA_ERR_LOG("serviceProxy_ is null"); - return; - } - return; -} - -sptr ModeManager::CreateCaptureSession(CameraMode mode) -{ - CAMERA_SYNC_TRACE; - sptr session = nullptr; - sptr captureSession = nullptr; - - int32_t retCode = CAMERA_OK; - if (serviceProxy_ == nullptr) { - MEDIA_ERR_LOG("serviceProxy_ is null"); - return nullptr; - } - OperationMode_V1_2 opMode = OperationMode_V1_2::NORMAL; - for (auto itr = g_fwToMetaSupportedMode_.cbegin(); itr != g_fwToMetaSupportedMode_.cend(); itr++) { - if (mode == itr->first) { - opMode = itr->second; - } - } - MEDIA_ERR_LOG("ModeManager CreateCaptureSession E"); - retCode = serviceProxy_->CreateCaptureSession(session, opMode); - MEDIA_ERR_LOG("ModeManager CreateCaptureSession X, %{public}d", retCode); - if (retCode == CAMERA_OK && session != nullptr) { - switch (mode) { - case CameraMode::PORTRAIT: - captureSession = new(std::nothrow) PortraitSession(session); - break; - case CameraMode::SCAN: - captureSession = new(std::nothrow) ScanSession(session); - break; - case CameraMode::NIGHT: - captureSession = new(std::nothrow) NightSession(session); - break; - default: - captureSession = new(std::nothrow) CaptureSession(session); - break; - } - } else { - MEDIA_ERR_LOG("Failed to get capture session object from hcamera service!, %{public}d", retCode); - return nullptr; - } - captureSession->SetMode(static_cast(mode)); - return captureSession; -} - -std::vector ModeManager::GetSupportedModes(sptr& camera) -{ - std::vector supportedModes = {}; - - std::shared_ptr metadata = camera->GetMetadata(); - camera_metadata_item_t item; - int32_t ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_CAMERA_MODES, &item); - if (ret != CAM_META_SUCCESS || item.count == 0) { - MEDIA_ERR_LOG("CaptureSession::GetSupportedModes Failed with return code %{public}d", ret); - return supportedModes; - } - for (uint32_t i = 0; i < item.count; i++) { - auto itr = g_metaToFwSupportedMode_.find(static_cast(item.data.u8[i])); - if (itr != g_metaToFwSupportedMode_.end()) { - supportedModes.emplace_back(itr->second); - } - } - MEDIA_INFO_LOG("CaptureSession::GetSupportedModes supportedModes size: %{public}zu", supportedModes.size()); - return supportedModes; -} - -sptr ModeManager::GetSupportedOutputCapability(sptr& camera, - CameraMode modeName) -{ - sptr cameraOutputCapability = nullptr; - cameraOutputCapability = new(std::nothrow) CameraOutputCapability(); - std::shared_ptr metadata = camera->GetMetadata(); - vector objectTypes = {}; - sptr camManagerObj = CameraManager::GetInstance(); - ExtendInfo extendInfo = {}; - camera_metadata_item_t item; - photoProfiles_.clear(); - previewProfiles_.clear(); - vidProfiles_.clear(); - int32_t ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_STREAM_AVAILABLE_EXTEND_CONFIGURATIONS, - &item); - if (ret != CAM_META_SUCCESS || item.count == 0) { - MEDIA_ERR_LOG("Failed get extend stream info %{public}d %{public}d", ret, item.count); - return nullptr; - } - std::shared_ptr modeStreamParse = std::make_shared(); - modeStreamParse->getModeInfo(item.data.i32, item.count, extendInfo); // 解析tag中带的数据信息意义 - for (uint32_t i = 0; i < extendInfo.modeCount; i++) { - if (modeName != 0 && modeName == extendInfo.modeInfo[i].modeName) { - for (uint32_t j = 0; j < extendInfo.modeInfo[i].streamTypeCount; j++) { - OutputCapStreamType streamType = - static_cast(extendInfo.modeInfo[i].streamInfo[j].streamType); - CreateProfile4StreamType(streamType, i, j, extendInfo); - } - break; - } - } - - cameraOutputCapability->SetPhotoProfiles(photoProfiles_); - MEDIA_INFO_LOG("SetPhotoProfiles camera[%{public}s] size = %{public}zu", - camera->GetID().c_str(), photoProfiles_.size()); - cameraOutputCapability->SetPreviewProfiles(previewProfiles_); - MEDIA_INFO_LOG("SetPreviewProfiles camera[%{public}s] size = %{public}zu", - camera->GetID().c_str(), previewProfiles_.size()); - cameraOutputCapability->SetVideoProfiles(vidProfiles_); - MEDIA_INFO_LOG("SetVideoProfiles size = %{public}zu", - vidProfiles_.size()); - camera_metadata_item_t metadataItem; - ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_STATISTICS_FACE_DETECT_MODE, &metadataItem); - if (ret == CAM_META_SUCCESS) { - for (uint32_t index = 0; index < metadataItem.count; index++) { - if (metadataItem.data.u8[index] == OHOS_CAMERA_FACE_DETECT_MODE_SIMPLE) { - objectTypes.push_back(MetadataObjectType::FACE); - } - } - } - cameraOutputCapability->SetSupportedMetadataObjectType(objectTypes); - return cameraOutputCapability; -} - -void ModeManager::CreateProfile4StreamType(OutputCapStreamType streamType, uint32_t modeIndex, - uint32_t streamIndex, ExtendInfo extendInfo) -{ - for (uint32_t k = 0; k < extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfoCount; k++) { - CameraFormat format; - auto itr = metaToFwFormat_.find(static_cast( - extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].format)); - if (itr != metaToFwFormat_.end()) { - format = itr->second; - } else { - format = CAMERA_FORMAT_INVALID; - continue; - } - Size size; - size.width = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].width; - size.height = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].height; - Fps fps; - fps.fixedFps = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].fixedFps; - fps.minFps = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].minFps; - fps.maxFps = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].maxFps; - std::vector abilityId; - abilityId = extendInfo.modeInfo[modeIndex].streamInfo[streamIndex].detailInfo[k].abilityId; - std::string abilityIds = ""; - for (auto id : abilityId) { - abilityIds += std::to_string(id) + ","; - } - if (streamType == OutputCapStreamType::PREVIEW) { - Profile previewProfile = Profile(format, size, fps, abilityId); - MEDIA_ERR_LOG("preview format : %{public}d, width: %{public}d, height: %{public}d" - "support ability: %{public}s", - previewProfile.GetCameraFormat(), previewProfile.GetSize().width, - previewProfile.GetSize().height, - abilityIds.c_str()); - previewProfiles_.push_back(previewProfile); - } else if (streamType == OutputCapStreamType::STILL_CAPTURE) { - Profile snapProfile = Profile(format, size, fps, abilityId); - MEDIA_ERR_LOG("photo format : %{public}d, width: %{public}d, height: %{public}d" - "support ability: %{public}s", - snapProfile.GetCameraFormat(), snapProfile.GetSize().width, snapProfile.GetSize().height, - abilityIds.c_str()); - photoProfiles_.push_back(snapProfile); - } else if (streamType == OutputCapStreamType::VIDEO_STREAM) { - std::vector frameRates = {fps.fixedFps, fps.fixedFps}; - VideoProfile vidProfile = VideoProfile(format, size, frameRates); - MEDIA_ERR_LOG("video format : %{public}d, width: %{public}d, height: %{public}d" - "support ability: %{public}s", - vidProfile.GetCameraFormat(), vidProfile.GetSize().width, vidProfile.GetSize().height, - abilityIds.c_str()); - vidProfiles_.push_back(vidProfile); - } - } -} -} // namespace CameraStandard -} // namespace OHOS diff --git a/frameworks/native/camera/src/output/preview_output.cpp b/frameworks/native/camera/src/output/preview_output.cpp index 4657674ca..871af0687 100644 --- a/frameworks/native/camera/src/output/preview_output.cpp +++ b/frameworks/native/camera/src/output/preview_output.cpp @@ -29,7 +29,6 @@ #include "hstream_repeat_callback_stub.h" #include "image_format.h" #include "metadata_common_utils.h" -#include "mode/mode_manager.h" #include "pixel_map.h" #include "sketch_wrapper.h" diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 212a72b5a..da05b363f 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -22,8 +22,8 @@ #include "capture_output.h" #include "hcapture_session_callback_stub.h" #include "input/camera_input.h" +#include "input/camera_manager.h" #include "camera_log.h" -#include "mode/mode_manager.h" #include "output/photo_output.h" #include "output/preview_output.h" #include "output/video_output.h" @@ -390,11 +390,11 @@ void CaptureSession::SetDefaultColorSpace() return; } -int32_t CaptureSession::CanAddInput(sptr &input) +bool CaptureSession::CanAddInput(sptr &input) { // todo: get Profile passed to createOutput and compare with OutputCapability // if present in capability return ok. - return CameraErrorCode::SUCCESS; + return true; } int32_t CaptureSession::AddInput(sptr &input) @@ -423,11 +423,11 @@ int32_t CaptureSession::AddInput(sptr &input) return ServiceToCameraError(errCode); } -int32_t CaptureSession::CanAddOutput(sptr &output) +bool CaptureSession::CanAddOutput(sptr &output) { // todo: get Profile passed to createOutput and compare with OutputCapability // if present in capability return ok. - return CameraErrorCode::SUCCESS; + return true; } sptr CaptureSession::GetMetaOutput() @@ -2329,10 +2329,10 @@ int32_t CaptureSession::GetMode() int32_t CaptureSession::GetFeaturesMode() { if (isSetMacroEnable_) { - if (modeName_ == CameraMode::CAPTURE) { - return CameraMode::CAPTURE_MACRO; - } else if (modeName_ == CameraMode::VIDEO) { - return CameraMode::VIDEO_MACRO; + if (modeName_ == SceneMode::CAPTURE) { + return SceneMode::CAPTURE_MACRO; + } else if (modeName_ == SceneMode::VIDEO) { + return SceneMode::VIDEO_MACRO; } } return modeName_; @@ -2340,10 +2340,10 @@ int32_t CaptureSession::GetFeaturesMode() vector CaptureSession::GetSubFeatureMods() { - if (modeName_ == CameraMode::CAPTURE) { - return vector { CameraMode::CAPTURE_MACRO }; - } else if (modeName_ == CameraMode::VIDEO) { - return vector { CameraMode::VIDEO_MACRO }; + if (modeName_ == SceneMode::CAPTURE) { + return vector { SceneMode::CAPTURE_MACRO }; + } else if (modeName_ == SceneMode::VIDEO) { + return vector { SceneMode::VIDEO_MACRO }; } return vector {}; } @@ -2940,7 +2940,7 @@ int32_t CaptureSession::SetColorSpace(ColorSpace colorSpace) bool CaptureSession::IsModeWithVideoStream() { - return GetMode() == CameraMode::VIDEO; + return GetMode() == SceneMode::VIDEO; } std::vector CaptureSession::GetSupportedColorEffects() diff --git a/frameworks/native/camera/src/session/night_session.cpp b/frameworks/native/camera/src/session/night_session.cpp index e19d06ff7..8cf700522 100644 --- a/frameworks/native/camera/src/session/night_session.cpp +++ b/frameworks/native/camera/src/session/night_session.cpp @@ -26,7 +26,6 @@ namespace CameraStandard { NightSession::~NightSession() { MEDIA_DEBUG_LOG("Enter Into NightSession::~NightSession()"); - longExposureCallback_ = nullptr; } int32_t NightSession::GetExposureRange(std::vector &exposureRange) @@ -120,97 +119,12 @@ int32_t NightSession::GetExposure(uint32_t &exposureValue) return CameraErrorCode::SUCCESS; } -void NightSession::DoTryAE(bool isTryAe, uint32_t time) -{ - CAMERA_SYNC_TRACE; - if (!(IsSessionCommited() || IsSessionConfiged())) { - MEDIA_ERR_LOG("NightSession::StartLongExposure Session is not Commited"); - return; - } - if (changedMetadata_ == nullptr) { - MEDIA_ERR_LOG("NightSession::StartLongExposure changedMetadata_ is NULL"); - return; - } - - bool status = false; - int32_t ret; - uint32_t count = 1; - camera_metadata_item_t item; - uint8_t doTryAe = isTryAe ? 1 : 0; - if (isTryAe) { - ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_NIGHT_MODE_TRY_AE, &item); - if (ret == CAM_META_ITEM_NOT_FOUND) { - status = changedMetadata_->addEntry(OHOS_CONTROL_NIGHT_MODE_TRY_AE, &doTryAe, count); - } else if (ret == CAM_META_SUCCESS) { - status = changedMetadata_->updateEntry(OHOS_CONTROL_NIGHT_MODE_TRY_AE, &doTryAe, count); - } - uint32_t exposureTime = 0; - ret = GetExposure(exposureTime); - ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_MANUAL_EXPOSURE_TIME, &item); - if (ret == CAM_META_ITEM_NOT_FOUND) { - status = changedMetadata_->addEntry(OHOS_CONTROL_MANUAL_EXPOSURE_TIME, &exposureTime, count); - } else if (ret == CAM_META_SUCCESS) { - status = changedMetadata_->updateEntry(OHOS_CONTROL_MANUAL_EXPOSURE_TIME, &exposureTime, count); - } - if (!status) { - MEDIA_ERR_LOG("NightSession::StartLongExposure Failed to set effect"); - } - } else { - // interrupt the long exposuring; - ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_NIGHT_MODE_TRY_AE, &item); - if (ret == CAM_META_ITEM_NOT_FOUND) { - status = changedMetadata_->addEntry(OHOS_CONTROL_NIGHT_MODE_TRY_AE, &doTryAe, count); - } else if (ret == CAM_META_SUCCESS) { - status = changedMetadata_->updateEntry(OHOS_CONTROL_NIGHT_MODE_TRY_AE, &doTryAe, count); - } - } - SetLongExposureingState(false); - MEDIA_DEBUG_LOG("NightSession::StartLongExposure"); - return; -} - -void NightSession::SetLongExposureingState(bool isExposuring) -{ - isExposuring_ = isExposuring; -} - -bool NightSession::IsLongExposureingState() -{ - return isExposuring_; -} - -void NightSession::SetLongExposureCallback(std::shared_ptr longExposureCallback) -{ - longExposureCallback_ = longExposureCallback; -} - void NightSession::ProcessCallbacks(const uint64_t timestamp, const std::shared_ptr &result) { MEDIA_INFO_LOG("ProcessCallbacks"); - CaptureSession::ProcessCallbacks(timestamp, result); - ProcessLongExposureOnce(result); -} - -void NightSession::ProcessLongExposureOnce(const std::shared_ptr &result) -{ - camera_metadata_item_t item; - common_metadata_header_t* metadata = result->get(); - - int ret = Camera::FindCameraMetadataItem(metadata, OHOS_CAMERA_MESURE_EXPOSURE_TIME, &item); - uint32_t exposureTime = 10000; - if (ret == CAM_META_SUCCESS) { - MEDIA_INFO_LOG("NightSession::ProcessLongExposureOnce exposure time: %{public}d", item.data.i32[0]); - exposureTime = item.data.i32[0]; - } else { - MEDIA_ERR_LOG("NightSession::ProcessLongExposureOnce failed ret = %{public}d", ret); - return; - } - - if (longExposureCallback_ != nullptr && !IsLongExposureingState()) { - longExposureCallback_->OnLongExposure(exposureTime); - SetLongExposureingState(true); - } + ProcessFaceRecUpdates(timestamp, result); + ProcessAutoFocusUpdates(result); } } // CameraStandard } // OHOS diff --git a/frameworks/native/camera/src/session/photo_session.cpp b/frameworks/native/camera/src/session/photo_session.cpp new file mode 100644 index 000000000..17b9c9397 --- /dev/null +++ b/frameworks/native/camera/src/session/photo_session.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/photo_session.h" +#include "input/camera_input.h" +#include "input/camera_manager.h" +#include "output/camera_output_capability.h" +#include "camera_log.h" +#include "camera_error_code.h" +#include "camera_util.h" + +namespace OHOS { +namespace CameraStandard { +PhotoSession::~PhotoSession() +{ +} + +bool PhotoSession::CanAddInput(sptr &input) +{ + // todo: get Profile passed to createOutput and compare with OutputCapability + // if present in capability return ok. + MEDIA_INFO_LOG("Enter Into PhotoSession::CanAddInput"); + return true; +} + +bool PhotoSession::CanAddOutput(sptr &output) +{ + // todo: get Profile passed to createOutput and compare with OutputCapability + // if present in capability return ok. + MEDIA_INFO_LOG("Enter Into PhotoSession::CanAddOutput"); + return true; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/src/session/scan_session.cpp b/frameworks/native/camera/src/session/scan_session.cpp index aa231b035..c78f8a577 100644 --- a/frameworks/native/camera/src/session/scan_session.cpp +++ b/frameworks/native/camera/src/session/scan_session.cpp @@ -15,7 +15,7 @@ #include "session/scan_session.h" #include "input/camera_input.h" -#include "mode/mode_manager.h" +#include "input/camera_manager.h" #include "output/camera_output_capability.h" #include "camera_log.h" #include "camera_error_code.h" @@ -32,12 +32,12 @@ int32_t ScanSession::AddOutput(sptr &output) int32_t result = CAMERA_UNKNOWN_ERROR; if (inputDevice_) { sptr device = inputDevice_->GetCameraDeviceInfo(); - sptr modeManager = ModeManager::GetInstance(); + sptr cameraManager = CameraManager::GetInstance(); sptr outputCapability = nullptr; - if (device != nullptr && modeManager != nullptr) { - outputCapability = modeManager->GetSupportedOutputCapability(device, CameraMode::SCAN); + if (device != nullptr && cameraManager != nullptr) { + outputCapability = cameraManager->GetSupportedOutputCapability(device, SceneMode::SCAN); } else { - MEDIA_ERR_LOG("ScanSession::AddOutput get nullptr to device or modeManager"); + MEDIA_ERR_LOG("ScanSession::AddOutput get nullptr to device or cameraManager"); return CameraErrorCode::DEVICE_DISABLED; } if ((outputCapability != nullptr && outputCapability->GetPreviewProfiles().size() != 0 && diff --git a/frameworks/native/camera/src/session/video_session.cpp b/frameworks/native/camera/src/session/video_session.cpp new file mode 100644 index 000000000..08e2595a4 --- /dev/null +++ b/frameworks/native/camera/src/session/video_session.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/video_session.h" +#include "input/camera_input.h" +#include "input/camera_manager.h" +#include "output/camera_output_capability.h" +#include "camera_log.h" +#include "camera_error_code.h" +#include "camera_util.h" + +namespace OHOS { +namespace CameraStandard { +VideoSession::~VideoSession() +{ +} + +bool VideoSession::CanAddInput(sptr &input) +{ + // todo: get Profile passed to createOutput and compare with OutputCapability + // if present in capability return ok. + MEDIA_INFO_LOG("Enter Into VideoSession::CanAddInput"); + return true; +} + +bool VideoSession::CanAddOutput(sptr &output) +{ + // todo: get Profile passed to createOutput and compare with OutputCapability + // if present in capability return ok. + MEDIA_INFO_LOG("Enter Into VideoSession::CanAddOutput"); + return true; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/test/moduletest/include/camera_framework_moduletest.h b/frameworks/native/camera/test/moduletest/include/camera_framework_moduletest.h index f686c4a10..509ef6cde 100644 --- a/frameworks/native/camera/test/moduletest/include/camera_framework_moduletest.h +++ b/frameworks/native/camera/test/moduletest/include/camera_framework_moduletest.h @@ -20,7 +20,6 @@ #include "input/camera_device.h" #include "input/camera_input.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "session/capture_session.h" #include "session/portrait_session.h" @@ -44,7 +43,6 @@ public: int32_t videoWidth_; int32_t videoHeight_; sptr manager_; - sptr modeManager_; sptr portraitSession_; sptr session_; sptr scanSession_; @@ -96,7 +94,7 @@ public: void TestUnSupportedResolution(int32_t previewWidth, int32_t previewHeight, int32_t photoWidth, int32_t photoHeight, int32_t videoWidth, int32_t videoHeight); bool IsSupportNow(); - bool IsSupportMode(CameraMode mode); + bool IsSupportMode(SceneMode mode); std::shared_ptr GetSketchPreviewProfile(); }; diff --git a/frameworks/native/camera/test/moduletest/src/camera_framework_moduletest.cpp b/frameworks/native/camera/test/moduletest/src/camera_framework_moduletest.cpp index c42c86166..50537cb98 100644 --- a/frameworks/native/camera/test/moduletest/src/camera_framework_moduletest.cpp +++ b/frameworks/native/camera/test/moduletest/src/camera_framework_moduletest.cpp @@ -462,7 +462,7 @@ void CameraFrameworkModuleTest::ConfigScanSession(sptr &previewOu MEDIA_INFO_LOG("old session exist, need release"); session_->Release(); } - scanSession_ = modeManager_ -> CreateCaptureSession(CameraMode::SCAN); + scanSession_ = manager_ -> CreateCaptureSession(SceneMode::SCAN); ASSERT_NE(scanSession_, nullptr); int32_t intResult = scanSession_->BeginConfig(); @@ -693,9 +693,9 @@ bool CameraFrameworkModuleTest::IsSupportNow() return true; } -bool CameraFrameworkModuleTest::IsSupportMode(CameraMode mode) +bool CameraFrameworkModuleTest::IsSupportMode(SceneMode mode) { - std::vector modes = modeManager_->GetSupportedModes(cameras_[0]); + std::vector modes = manager_->GetSupportedModes(cameras_[0]); if (modes.size() == 0) { MEDIA_ERR_LOG("IsSupportMode: modes.size is null"); return false; @@ -769,9 +769,6 @@ void CameraFrameworkModuleTest::SetUp() input_ = manager_->CreateCameraInput(cameras_[0]); ASSERT_NE(input_, nullptr); - modeManager_ = ModeManager::GetInstance(); - ASSERT_NE(modeManager_, nullptr); - sptr camManagerObj = CameraManager::GetInstance(); std::vector> cameraObjList = camManagerObj->GetSupportedCameras(); sptr outputcapability = camManagerObj->GetSupportedOutputCapability(cameraObjList[0]); @@ -2416,20 +2413,23 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_043, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_045, TestSize.Level0) { - CameraMode portraitMode = CameraMode::PORTRAIT; + SceneMode portraitMode = SceneMode::PORTRAIT; if (!IsSupportMode(portraitMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); - ASSERT_NE(modeManagerObj, nullptr); + sptr cameraManagerObj = CameraManager::GetInstance(); + ASSERT_NE(cameraManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + std::vector modes = cameraManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); + + sptr modeAbility = + cameraManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); ASSERT_NE(modeAbility, nullptr); - sptr captureSession = modeManagerObj->CreateCaptureSession(portraitMode); + sptr captureSession = cameraManagerObj->CreateCaptureSession(portraitMode); + ASSERT_NE(captureSession, nullptr); sptr portraitSession = static_cast(captureSession.GetRefPtr()); ASSERT_NE(portraitSession, nullptr); @@ -2491,20 +2491,22 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_045, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_046, TestSize.Level0) { - CameraMode portraitMode = CameraMode::PORTRAIT; + SceneMode portraitMode = SceneMode::PORTRAIT; if (!IsSupportMode(portraitMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); - ASSERT_NE(modeManagerObj, nullptr); + sptr cameraManagerObj = CameraManager::GetInstance(); + ASSERT_NE(cameraManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + std::vector modes = cameraManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); + sptr modeAbility = + cameraManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); ASSERT_NE(modeAbility, nullptr); - sptr captureSession = modeManagerObj->CreateCaptureSession(portraitMode); + sptr captureSession = cameraManagerObj->CreateCaptureSession(portraitMode); + ASSERT_NE(captureSession, nullptr); sptr portraitSession = static_cast(captureSession.GetRefPtr()); ASSERT_NE(portraitSession, nullptr); @@ -2566,19 +2568,21 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_046, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_047, TestSize.Level0) { - CameraMode portraitMode = CameraMode::PORTRAIT; + SceneMode portraitMode = SceneMode::PORTRAIT; if (!IsSupportMode(portraitMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); - ASSERT_NE(modeManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + sptr cameraManagerObj = CameraManager::GetInstance(); + ASSERT_NE(cameraManagerObj, nullptr); + + std::vector modes = cameraManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); + sptr modeAbility = + cameraManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); ASSERT_NE(modeAbility, nullptr); - sptr captureSession = modeManagerObj->CreateCaptureSession(portraitMode); + sptr captureSession = cameraManagerObj->CreateCaptureSession(portraitMode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = static_cast(captureSession.GetRefPtr()); ASSERT_NE(portraitSession, nullptr); @@ -2639,20 +2643,21 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_047, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_048, TestSize.Level0) { - CameraMode portraitMode = CameraMode::PORTRAIT; + SceneMode portraitMode = SceneMode::PORTRAIT; if (!IsSupportMode(portraitMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); - ASSERT_NE(modeManagerObj, nullptr); + sptr cameraManagerObj = CameraManager::GetInstance(); + ASSERT_NE(cameraManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + std::vector modes = cameraManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); + sptr modeAbility = + cameraManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); ASSERT_NE(modeAbility, nullptr); - sptr captureSession = modeManagerObj->CreateCaptureSession(portraitMode); + sptr captureSession = cameraManagerObj->CreateCaptureSession(portraitMode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = static_cast(captureSession.GetRefPtr()); ASSERT_NE(portraitSession, nullptr); @@ -2745,7 +2750,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_scan_050, TestSi MEDIA_INFO_LOG("old session exist, need release"); session_->Release(); } - scanSession_ = modeManager_ -> CreateCaptureSession(CameraMode::SCAN); + scanSession_ = manager_ -> CreateCaptureSession(SceneMode::SCAN); ASSERT_NE(scanSession_, nullptr); int32_t intResult = scanSession_->BeginConfig(); @@ -2786,15 +2791,15 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_scan_051, TestSi { MEDIA_INFO_LOG("teset051 start"); sptr scanModeDevice = cameras_[0]; - vector modeVec = modeManager_ -> GetSupportedModes(scanModeDevice); - EXPECT_TRUE(find(modeVec.begin(), modeVec.end(), CameraMode::SCAN) != modeVec.end()); + vector modeVec = manager_ -> GetSupportedModes(scanModeDevice); + EXPECT_TRUE(find(modeVec.begin(), modeVec.end(), SceneMode::SCAN) != modeVec.end()); for (auto iter : modeVec) { MEDIA_INFO_LOG("get supportedMode : %{public}d", iter); } sptr scanCapability = - modeManager_ -> GetSupportedOutputCapability(scanModeDevice, CameraMode::SCAN); + manager_ -> GetSupportedOutputCapability(scanModeDevice, SceneMode::SCAN); EXPECT_EQ(scanCapability -> GetPhotoProfiles().size(), 0); EXPECT_NE(scanCapability -> GetPreviewProfiles().size(), 0); EXPECT_EQ(scanCapability -> GetVideoProfiles().size(), 0); @@ -6404,7 +6409,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_050, TestSize.Le auto output = CreatePreviewOutput(*previewProfile); ASSERT_NE(output, nullptr); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6459,7 +6464,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_051, TestSize.Le auto output = CreatePreviewOutput(*previewProfile); ASSERT_NE(output, nullptr); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6541,7 +6546,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_052, TestSize.Le bool isSketchSupport = previewOutput->IsSketchSupported(); ASSERT_FALSE(isSketchSupport); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6557,11 +6562,11 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_052, TestSize.Le return; } - session_->SetMode(CameraMode::PORTRAIT); + session_->SetMode(SceneMode::PORTRAIT); int sketchEnableRatio = previewOutput->GetSketchRatio(); EXPECT_LT(sketchEnableRatio, 0); - session_->SetMode(CameraMode::CAPTURE); + session_->SetMode(SceneMode::CAPTURE); sketchEnableRatio = previewOutput->GetSketchRatio(); EXPECT_GT(sketchEnableRatio, 0); @@ -6612,7 +6617,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_053, TestSize.Le auto output = CreatePreviewOutput(*previewProfile); ASSERT_NE(output, nullptr); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6707,7 +6712,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_054, TestSize.Le sptr previewOutput = (sptr&)output; ASSERT_NE(output, nullptr); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6771,7 +6776,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_055, TestSize.Le sptr previewOutput = (sptr&)output; ASSERT_NE(output, nullptr); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -6859,17 +6864,18 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_056, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_057, TestSize.Level0) { - CameraMode portraitMode = CameraMode::PORTRAIT; + SceneMode portraitMode = SceneMode::PORTRAIT; if (!IsSupportMode(portraitMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); + sptr modeManagerObj = CameraManager::GetInstance(); ASSERT_NE(modeManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); + sptr modeAbility = + modeManagerObj->GetSupportedOutputCapability(cameras_[0], portraitMode); ASSERT_NE(modeAbility, nullptr); sptr captureSession = modeManagerObj->CreateCaptureSession(portraitMode); @@ -6917,17 +6923,18 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_057, TestSize.Le */ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_058, TestSize.Level0) { - CameraMode nightMode = CameraMode::NIGHT; + SceneMode nightMode = SceneMode::NIGHT; if (!IsSupportMode(nightMode)) { return; } - sptr modeManagerObj = ModeManager::GetInstance(); + sptr modeManagerObj = CameraManager::GetInstance(); ASSERT_NE(modeManagerObj, nullptr); - std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); + std::vector modes = modeManagerObj->GetSupportedModes(cameras_[0]); ASSERT_TRUE(modes.size() != 0); - sptr modeAbility = modeManagerObj->GetSupportedOutputCapability(cameras_[0], nightMode); + sptr modeAbility = + modeManagerObj->GetSupportedOutputCapability(cameras_[0], nightMode); ASSERT_NE(modeAbility, nullptr); sptr captureSession = modeManagerObj->CreateCaptureSession(nightMode); @@ -6981,7 +6988,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_059, TestSize.Le sptr camInput = (sptr&)input_; camInput->Open(); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -7028,7 +7035,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_060, TestSize.Le sptr camInput = (sptr&)input_; camInput->Open(); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); @@ -7045,6 +7052,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_060, TestSize.Le intResult = session_->CommitConfig(); EXPECT_EQ(intResult, 0); + std::vector colorSpaceLists = session_->GetSupportedColorSpaces(); if (colorSpaceLists.size() != 0) { intResult = session_->SetColorSpace(colorSpaceLists[1]); @@ -7077,7 +7085,7 @@ HWTEST_F(CameraFrameworkModuleTest, camera_framework_moduletest_061, TestSize.Le sptr camInput = (sptr&)input_; camInput->Open(); - session_->SetMode(static_cast(CameraMode::CAPTURE)); + session_->SetMode(static_cast(SceneMode::CAPTURE)); int32_t intResult = session_->BeginConfig(); EXPECT_EQ(intResult, 0); diff --git a/frameworks/native/camera/test/unittest/include/camera_framework_unittest.h b/frameworks/native/camera/test/unittest/include/camera_framework_unittest.h index 15a35f4ef..b4a0bf001 100644 --- a/frameworks/native/camera/test/unittest/include/camera_framework_unittest.h +++ b/frameworks/native/camera/test/unittest/include/camera_framework_unittest.h @@ -19,7 +19,6 @@ #include "gtest/gtest.h" #include "hcamera_service.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" namespace OHOS { namespace CameraStandard { @@ -55,7 +54,6 @@ public: sptr mockCameraDevice; sptr mockCameraHostManager; sptr cameraManager; - sptr modeManager; /* SetUpTestCase:The preset action of the test suite is executed before the first TestCase */ static void SetUpTestCase(void); diff --git a/frameworks/native/camera/test/unittest/src/v1_1/camera_framework_unittest.cpp b/frameworks/native/camera/test/unittest/src/v1_1/camera_framework_unittest.cpp index 957db891f..92d46c067 100644 --- a/frameworks/native/camera/test/unittest/src/v1_1/camera_framework_unittest.cpp +++ b/frameworks/native/camera/test/unittest/src/v1_1/camera_framework_unittest.cpp @@ -386,12 +386,6 @@ public: ~FakeCameraManager() {} }; -class FakeModeManager : public ModeManager { -public: - explicit FakeModeManager(sptr service) : ModeManager(service) {} - ~FakeModeManager() {} -}; - class CallbackListener : public FocusCallback, public ExposureCallback { public: void OnFocusState(FocusState state) override @@ -605,7 +599,6 @@ void CameraFrameworkUnitTest::SetUp() mockCameraDevice = mockCameraHostManager->cameraDevice; mockStreamOperator = mockCameraDevice->streamOperator; cameraManager = new FakeCameraManager(new FakeHCameraService(mockCameraHostManager)); - modeManager = new FakeModeManager(new FakeHCameraService(mockCameraHostManager)); } void CameraFrameworkUnitTest::TearDown() @@ -2053,11 +2046,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_045, TestSize.Level0 /* * Feature: Framework - * Function: Test modeManager and portrait session with beauty/filter/portrait effects + * Function: Test cameraManager and portrait session with beauty/filter/portrait effects * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test modeManager and portrait session with beauty/filter/portrait effects + * CaseDescription: Test cameraManager and portrait session with beauty/filter/portrait effects */ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_046, TestSize.Level0) { @@ -2065,11 +2058,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_046, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _)).Times(2); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); sptr input = cameraManager->CreateCameraInput(cameras[0]); @@ -2081,7 +2074,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_046, TestSize.Level0 std::string cameraSettings = camInput->GetCameraSettings(); camInput->SetCameraSettings(cameraSettings); camInput->GetCameraDevice()->Open(); - sptr captureSession = modeManager->CreateCaptureSession(mode); + sptr captureSession = cameraManager->CreateCaptureSession(mode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); @@ -2122,7 +2115,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_046, TestSize.Level0 /* * Feature: Framework - * Function: Test modeManager with GetSupportedModes + * Function: Test cameraManager with GetSupportedModes * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA @@ -2133,13 +2126,13 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_047, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); std::vector> cameras = cameraManager->GetSupportedCameras(); - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); } /* * Feature: Framework - * Function: Test modeManager with GetSupportedOutputCapability + * Function: Test cameraManager with GetSupportedOutputCapability * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA @@ -2150,32 +2143,32 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_048, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); } /* * Feature: Framework - * Function: Test modeManager with CreateCaptureSession and CommitConfig + * Function: Test cameraManager with CreateCaptureSession and CommitConfig * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test modeManager to CreateCaptureSession + * CaseDescription: Test cameraManager to CreateCaptureSession */ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_049, TestSize.Level0) { EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); sptr input = cameraManager->CreateCameraInput(cameras[0]); @@ -2195,7 +2188,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_049, TestSize.Level0 ASSERT_NE(photo, nullptr); - sptr captureSession = modeManager->CreateCaptureSession(mode); + sptr captureSession = cameraManager->CreateCaptureSession(mode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); @@ -2237,11 +2230,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_050, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _)).Times(2); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); sptr input = cameraManager->CreateCameraInput(cameras[0]); @@ -2261,7 +2254,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_050, TestSize.Level0 sptr photo = CreatePhotoOutput(); ASSERT_NE(photo, nullptr); - sptr captureSession = modeManager->CreateCaptureSession(mode); + sptr captureSession = cameraManager->CreateCaptureSession(mode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); @@ -2307,11 +2300,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_051, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _)).Times(2); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); sptr input = cameraManager->CreateCameraInput(cameras[0]); @@ -2330,7 +2323,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_051, TestSize.Level0 sptr photo = CreatePhotoOutput(); ASSERT_NE(photo, nullptr); - sptr captureSession = modeManager->CreateCaptureSession(mode); + sptr captureSession = cameraManager->CreateCaptureSession(mode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); @@ -2376,11 +2369,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_052, TestSize.Level0 EXPECT_CALL(*mockCameraHostManager, GetCameras(_)); EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _)).Times(2); std::vector> cameras = cameraManager->GetSupportedCameras(); - CameraMode mode = PORTRAIT; - std::vector modes = modeManager->GetSupportedModes(cameras[0]); + SceneMode mode = PORTRAIT; + std::vector modes = cameraManager->GetSupportedModes(cameras[0]); ASSERT_TRUE(modes.size() != 0); - sptr ability = modeManager->GetSupportedOutputCapability(cameras[0], mode); + sptr ability = cameraManager->GetSupportedOutputCapability(cameras[0], mode); ASSERT_NE(ability, nullptr); sptr input = cameraManager->CreateCameraInput(cameras[0]); @@ -2400,7 +2393,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_052, TestSize.Level0 sptr photo = CreatePhotoOutput(); ASSERT_NE(photo, nullptr); - sptr captureSession = modeManager->CreateCaptureSession(mode); + sptr captureSession = cameraManager->CreateCaptureSession(mode); ASSERT_NE(captureSession, nullptr); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); @@ -2555,7 +2548,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_003, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = nullptr; uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); ASSERT_NE(camSession, nullptr); @@ -3184,7 +3177,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_013, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = nullptr; uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); ASSERT_NE(camSession, nullptr); @@ -3250,7 +3243,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_014, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = new StreamOperatorCallback(); uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); ASSERT_NE(camSession, nullptr); @@ -3320,7 +3313,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_015, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = new StreamOperatorCallback(); uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); ASSERT_NE(camSession, nullptr); @@ -3391,7 +3384,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_016, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = new StreamOperatorCallback();; uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); @@ -3462,7 +3455,7 @@ HWTEST_F(CameraFrameworkUnitTest, camera_fwcoverage_unittest_017, TestSize.Level sptr cameraHostManager = (sptr &)mockCameraHostManager; sptr streamOperatorCb = nullptr; uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); - CameraMode mode = PORTRAIT; + SceneMode mode = PORTRAIT; sptr camSession = new(std::nothrow) HCaptureSession(cameraHostManager, streamOperatorCb, callerToken, mode); sptr camSession1 = new(std::nothrow) HCaptureSession(cameraHostManager, diff --git a/interfaces/inner_api/native/camera/include/input/camera_device.h b/interfaces/inner_api/native/camera/include/input/camera_device.h index a053ef77b..65c75dfaa 100644 --- a/interfaces/inner_api/native/camera/include/input/camera_device.h +++ b/interfaces/inner_api/native/camera/include/input/camera_device.h @@ -162,7 +162,6 @@ public: std::unordered_map> modeVideoProfiles_ = {}; private: std::string cameraID_; - bool isFoldable = false; std::shared_ptr metadata_; CameraPosition cameraPosition_ = CAMERA_POSITION_UNSPECIFIED; CameraType cameraType_ = CAMERA_TYPE_DEFAULT; diff --git a/interfaces/inner_api/native/camera/include/input/camera_manager.h b/interfaces/inner_api/native/camera/include/input/camera_manager.h index 5c1f876f0..78a5f3e28 100644 --- a/interfaces/inner_api/native/camera/include/input/camera_manager.h +++ b/interfaces/inner_api/native/camera/include/input/camera_manager.h @@ -26,6 +26,11 @@ #include "hcamera_service_proxy.h" #include "icamera_device_service.h" #include "session/capture_session.h" +#include "session/portrait_session.h" +#include "session/night_session.h" +#include "session/scan_session.h" +#include "session/video_session.h" +#include "session/photo_session.h" #include "output/camera_output_capability.h" #include "output/metadata_output.h" #include "output/photo_output.h" @@ -38,6 +43,19 @@ namespace OHOS { namespace CameraStandard { +enum SceneMode { + NORMAL = 0, + CAPTURE = 1, + VIDEO = 2, + PORTRAIT = 3, + NIGHT = 4, + PROFESSIONAL = 5, + SLOW_MOTION = 6, + SCAN = 7, + CAPTURE_MACRO = 8, + VIDEO_MACRO = 9 +}; + enum CameraDeviceStatus { CAMERA_DEVICE_STATUS_UNAVAILABLE = 0, CAMERA_DEVICE_STATUS_AVAILABLE @@ -174,6 +192,13 @@ public: */ std::vector> GetSupportedCameras(); + /** + * @brief Get support modes. + * + * @return Returns array the mode of current CameraDevice. + */ + std::vector GetSupportedModes(sptr& camera); + /** * @brief Get extend output capaility of the mode of the given camera. * @@ -239,6 +264,13 @@ public: */ sptr CreateCaptureSession(); + /** + * @brief Create capture session. + * + * @return Returns pointer to capture session. + */ + sptr CreateCaptureSession(SceneMode mode); + /** * @brief Create capture session. * @@ -555,7 +587,6 @@ private: void SetTorchServiceCallback(sptr& callback); int32_t CreateListenerObject(); void CameraServerDied(pid_t pid); - void ChooseDeFaultCameras(std::vector>& supportedCameras); void CreateProfile4StreamType(OutputCapStreamType streamType, uint32_t modeIndex, uint32_t streamIndex, ExtendInfo extendInfo); diff --git a/interfaces/inner_api/native/camera/include/mode/mode_manager.h b/interfaces/inner_api/native/camera/include/mode/mode_manager.h deleted file mode 100644 index 09c5afc43..000000000 --- a/interfaces/inner_api/native/camera/include/mode/mode_manager.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_CAMERA_MODE_MANAGER_H -#define OHOS_CAMERA_MODE_MANAGER_H - -#include -#include -#include -#include "input/camera_input.h" -#include "input/camera_info.h" -#include "input/camera_device.h" -#include "input/camera_manager.h" -#include "hcamera_service_proxy.h" -#include "icamera_device_service.h" -#include "session/capture_session.h" -#include "session/portrait_session.h" -#include "session/night_session.h" -#include "session/scan_session.h" -#include "output/camera_output_capability.h" -#include "output/metadata_output.h" -#include "output/photo_output.h" -#include "output/video_output.h" -#include "output/preview_output.h" -#include "hcamera_listener_stub.h" -#include "input/camera_death_recipient.h" -#include "hcamera_service_callback_stub.h" -#include "camera_stream_info_parse.h" - -namespace OHOS { -namespace CameraStandard { -enum CameraMode { - NORMAL = 0, - CAPTURE = 1, - VIDEO = 2, - PORTRAIT = 3, - NIGHT = 4, - PROFESSIONAL = 5, - SLOW_MOTION = 6, - SCAN = 7, - CAPTURE_MACRO = 8, - VIDEO_MACRO = 9 -}; - -class ModeManager : public RefBase { -public: - ~ModeManager(); - /** - * @brief Get mode manager instance. - * - * @return Returns pointer to mode manager instance. - */ - static sptr &GetInstance(); - - /** - * @brief Get support modes. - * - * @return Returns array the mode of current CameraDevice. - */ - std::vector GetSupportedModes(sptr& camera); - - /** - * @brief Create capture session. - * - * @return Returns pointer to capture session. - */ - sptr CreateCaptureSession(CameraMode mode); - - /** - * @brief Get extend output capaility of the mode of the given camera. - * - * @param Camera device for which extend capability need to be fetched. - * @return Returns vector the ability of the mode of cameraDevice of available camera. - */ - sptr GetSupportedOutputCapability(sptr& camera, CameraMode mode); - void CreateProfile4StreamType(OutputCapStreamType streamType, uint32_t modeIndex, - uint32_t streamIndex, ExtendInfo extendInfo); -protected: - explicit ModeManager(sptr serviceProxy) : serviceProxy_(serviceProxy) {} - -private: - ModeManager(); - void Init(); - static sptr modeManager_; - sptr serviceProxy_; - static const std::unordered_map metaToFwFormat_; - static const std::unordered_map fwToMetaFormat_; - std::vector photoProfiles_ = {}; - std::vector previewProfiles_ = {}; - std::vector vidProfiles_ = {}; -}; -} // namespace CameraStandard -} // namespace OHOS -#endif // OHOS_CAMERA_MODE_MANAGER_H diff --git a/interfaces/inner_api/native/camera/include/session/capture_session.h b/interfaces/inner_api/native/camera/include/session/capture_session.h index de61f58b5..b92625bb9 100644 --- a/interfaces/inner_api/native/camera/include/session/capture_session.h +++ b/interfaces/inner_api/native/camera/include/session/capture_session.h @@ -206,7 +206,7 @@ public: * * @param CaptureInput to be added to session. */ - int32_t CanAddInput(sptr& input); + virtual bool CanAddInput(sptr& input); /** * @brief Add CaptureInput for the capture session. @@ -220,7 +220,7 @@ public: * * @param CaptureOutput to be added to session. */ - int32_t CanAddOutput(sptr& output); + virtual bool CanAddOutput(sptr& output); /** * @brief Add CaptureOutput for the capture session. diff --git a/interfaces/inner_api/native/camera/include/session/night_session.h b/interfaces/inner_api/native/camera/include/session/night_session.h index 09fc9a352..1de1dddd2 100644 --- a/interfaces/inner_api/native/camera/include/session/night_session.h +++ b/interfaces/inner_api/native/camera/include/session/night_session.h @@ -29,28 +29,13 @@ namespace OHOS { namespace CameraStandard { -class LongExposureCallback { -public: - LongExposureCallback() = default; - virtual ~LongExposureCallback() = default; - virtual void OnLongExposure(const uint32_t longExposureTime) = 0; -}; class CaptureOutput; class NightSession : public CaptureSession { public: - explicit NightSession(sptr &nightSession): CaptureSession(nightSession) - { - isExposuring_ = true; - } + explicit NightSession(sptr &nightSession): CaptureSession(nightSession) {} NightSession() {}; ~NightSession(); - /** - * @brief start long exposure - * - */ - void DoTryAE(bool isTryAe, uint32_t millisecond = 0); - /** * @brief Get exposure compensation range. * @param vector of exposure bias range. @@ -72,21 +57,8 @@ public: */ int32_t GetExposure(uint32_t &exposureValue); - /** - * @brief Set the exposure callback. - * which will be called when there is exposure state change. - * - * @param The LongExposureCallback pointer. - */ - void SetLongExposureCallback(std::shared_ptr longExposureCallback); void ProcessCallbacks(const uint64_t timestamp, const std::shared_ptr &result) override; - void SetLongExposureingState(bool isExposuring); - bool IsLongExposureingState(); -private: - void ProcessLongExposureOnce(const std::shared_ptr &result); - bool isExposuring_; - std::shared_ptr longExposureCallback_; }; } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/session/photo_session.h b/interfaces/inner_api/native/camera/include/session/photo_session.h new file mode 100644 index 000000000..287294206 --- /dev/null +++ b/interfaces/inner_api/native/camera/include/session/photo_session.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_CAMERA_PHOTO_SESSION_H +#define OHOS_CAMERA_PHOTO_SESSION_H + +#include "capture_session.h" +#include "icapture_session.h" + +namespace OHOS { +namespace CameraStandard { +class PhotoSession : public CaptureSession { +public: + explicit PhotoSession(sptr &photoSession): CaptureSession(photoSession) {} + PhotoSession() {}; + ~PhotoSession(); + + /** + * @brief Determine if the given Input can be added to session. + * + * @param CaptureInput to be added to session. + */ + bool CanAddInput(sptr& input) override; + + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output) override; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif // OHOS_CAMERA_PHOTO_SESSION_H \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/session/scan_session.h b/interfaces/inner_api/native/camera/include/session/scan_session.h index b60108635..51fc73638 100644 --- a/interfaces/inner_api/native/camera/include/session/scan_session.h +++ b/interfaces/inner_api/native/camera/include/session/scan_session.h @@ -27,7 +27,7 @@ public: ScanSession() {}; ~ScanSession(); - virtual int32_t AddOutput(sptr &output); + int32_t AddOutput(sptr &output) override; }; } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/session/video_session.h b/interfaces/inner_api/native/camera/include/session/video_session.h new file mode 100644 index 000000000..ade31fd91 --- /dev/null +++ b/interfaces/inner_api/native/camera/include/session/video_session.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_CAMERA_VIDEO_SESSION_H +#define OHOS_CAMERA_VIDEO_SESSION_H + +#include "capture_session.h" +#include "icapture_session.h" + +namespace OHOS { +namespace CameraStandard { +class VideoSession : public CaptureSession { +public: + explicit VideoSession(sptr &videoSession): CaptureSession(videoSession) {} + VideoSession() {}; + ~VideoSession(); + /** + * @brief Determine if the given Input can be added to session. + * + * @param CaptureInput to be added to session. + */ + bool CanAddInput(sptr& input) override; + + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output) override; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif // OHOS_CAMERA_VIDEO_SESSION_H \ No newline at end of file diff --git a/interfaces/inner_api/native/test/camera_capture_mode.cpp b/interfaces/inner_api/native/test/camera_capture_mode.cpp index 8e63cb761..532521bd4 100644 --- a/interfaces/inner_api/native/test/camera_capture_mode.cpp +++ b/interfaces/inner_api/native/test/camera_capture_mode.cpp @@ -18,7 +18,6 @@ #include #include "input/camera_input.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "output/camera_output_capability.h" #include "camera_log.h" @@ -348,14 +347,14 @@ int main(int argc, char **argv) } } cout<<"Camera ID ="<GetID()<<",camera Position = "<GetPosition()< modeManagerObj = ModeManager::GetInstance(); - std::vector supportedModes = modeManagerObj->GetSupportedModes(device); + sptr modeManagerObj = CameraManager::GetInstance(); + std::vector supportedModes = modeManagerObj->GetSupportedModes(device); std::string modes = ""; for (auto mode : supportedModes) { modes += std::to_string(static_cast(mode)) + " , "; } MEDIA_INFO_LOG("supportedModes : %{public}s", modes.c_str()); - sptr captureSession = modeManagerObj->CreateCaptureSession(CameraMode::PORTRAIT); + sptr captureSession = modeManagerObj->CreateCaptureSession(SceneMode::PORTRAIT); sptr portraitSession = nullptr; portraitSession = static_cast (captureSession.GetRefPtr()); if (portraitSession == nullptr) { @@ -378,7 +377,7 @@ int main(int argc, char **argv) std::vector previewSizes; std::vector photoSizes; sptr outputcapability = - modeManagerObj->GetSupportedOutputCapability(device, CameraMode::PORTRAIT); + modeManagerObj->GetSupportedOutputCapability(device, SceneMode::PORTRAIT); previewProfiles = outputcapability->GetPreviewProfiles(); uint32_t profileIndex = 0; for (auto i : previewProfiles) { diff --git a/interfaces/kits/js/camera_napi/@ohos.multimedia.camera.d.ts b/interfaces/kits/js/camera_napi/@ohos.multimedia.camera.d.ts index e312db435..fbc1f1a03 100644 --- a/interfaces/kits/js/camera_napi/@ohos.multimedia.camera.d.ts +++ b/interfaces/kits/js/camera_napi/@ohos.multimedia.camera.d.ts @@ -94,7 +94,7 @@ declare namespace camera { * @syscap SystemCapability.Multimedia.Camera.Core * @since 10 */ - enum CameraMode { + enum SceneMode { /** * normal mode. * @@ -858,33 +858,33 @@ declare namespace camera { /** * Gets supported mode descriptions. * - * @returns { Array } An array of supported modes. + * @returns { Array } An array of supported modes. * @syscap SystemCapability.Multimedia.Camera.Core * @since 10 */ - getSupportedModes(camera: CameraDevice): Array; + getSupportedModes(camera: CameraDevice): Array; /** * Gets supported output capability in specific mode for specific camera. * * @param { CameraDevice } camera Camera device. - * @param { CameraMode } camera Camera mode. + * @param { SceneMode } camera Camera mode. * @returns { CameraOutputCapability } The camera output capability. * @syscap SystemCapability.Multimedia.Camera.Core * @since 10 */ - getSupportedOutputCapability(camera: CameraDevice, mode: CameraMode): CameraOutputCapability; + getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability; /** * Gets a CaptureSession instance for specific mode. * - * @param { CameraMode } camera Camera mode. + * @param { SceneMode } camera Camera mode. * @returns { CaptureSession } The CaptureSession instance. * @throws { BusinessError } 7400201 - Camera service fatal error. * @syscap SystemCapability.Multimedia.Camera.Core * @since 10 */ - createCaptureSession(mode: CameraMode): CaptureSession; + createCaptureSession(mode: SceneMode): CaptureSession; } /** diff --git a/interfaces/kits/js/camera_napi/BUILD.gn b/interfaces/kits/js/camera_napi/BUILD.gn index d4e79ab5e..b80261e33 100644 --- a/interfaces/kits/js/camera_napi/BUILD.gn +++ b/interfaces/kits/js/camera_napi/BUILD.gn @@ -54,7 +54,9 @@ ohos_shared_library("camera_napi") { "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/input/torch_listener_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/night_session_napi.cpp", + "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp", + "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/video_session_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/output/camera_output_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/output/metadata_object_napi.cpp", diff --git a/interfaces/kits/js/camera_napi/include/camera_napi_utils.h b/interfaces/kits/js/camera_napi/include/camera_napi_utils.h index bb82b56ef..686971276 100644 --- a/interfaces/kits/js/camera_napi/include/camera_napi_utils.h +++ b/interfaces/kits/js/camera_napi/include/camera_napi_utils.h @@ -35,7 +35,6 @@ #include "napi/native_node_api.h" #include "output/photo_output.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "ipc_skeleton.h" #include "tokenid_kit.h" @@ -282,6 +281,9 @@ public: static napi_status CallPromiseFun( napi_env env, napi_value promiseValue, void* data, napi_callback thenCallback, napi_callback catchCallback); + + static std::vector GetPropertyDescriptor( + std::vector> descriptors); }; template diff --git a/interfaces/kits/js/camera_napi/include/input/camera_info_napi.h b/interfaces/kits/js/camera_napi/include/input/camera_info_napi.h index d5a8c8149..e62b7538d 100644 --- a/interfaces/kits/js/camera_napi/include/input/camera_info_napi.h +++ b/interfaces/kits/js/camera_napi/include/input/camera_info_napi.h @@ -20,7 +20,6 @@ #include "camera_log.h" #include "camera_napi_utils.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "input/camera_device.h" #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/interfaces/kits/js/camera_napi/include/input/camera_manager_napi.h b/interfaces/kits/js/camera_napi/include/input/camera_manager_napi.h index f11f6975e..b83317658 100644 --- a/interfaces/kits/js/camera_napi/include/input/camera_manager_napi.h +++ b/interfaces/kits/js/camera_napi/include/input/camera_manager_napi.h @@ -47,18 +47,18 @@ class CameraManagerNapi { public: static napi_value Init(napi_env env, napi_value exports); static napi_value CreateCameraManager(napi_env env); - + static napi_value GetSupportedCameras(napi_env env, napi_callback_info info); + static napi_value GetSupportedModes(napi_env env, napi_callback_info info); static napi_value GetSupportedOutputCapability(napi_env env, napi_callback_info info); static napi_value IsCameraMuted(napi_env env, napi_callback_info info); static napi_value IsCameraMuteSupported(napi_env env, napi_callback_info info); static napi_value MuteCamera(napi_env env, napi_callback_info info); - static napi_value PrelaunchCamera(napi_env env, napi_callback_info info); static napi_value SetPrelaunchConfig(napi_env env, napi_callback_info info); static napi_value IsPrelaunchSupported(napi_env env, napi_callback_info info); - static napi_value GetSupportedCameras(napi_env env, napi_callback_info info); static napi_value CreateCameraInputInstance(napi_env env, napi_callback_info info); static napi_value CreateCameraSessionInstance(napi_env env, napi_callback_info info); + static napi_value CreateSessionInstance(napi_env env, napi_callback_info info); static napi_value CreatePreviewOutputInstance(napi_env env, napi_callback_info info); static napi_value CreateDeferredPreviewOutputInstance(napi_env env, napi_callback_info info); static napi_value CreatePhotoOutputInstance(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/js/camera_napi/include/input/camera_napi.h b/interfaces/kits/js/camera_napi/include/input/camera_napi.h index 835a9028c..a14ed4e3c 100644 --- a/interfaces/kits/js/camera_napi/include/input/camera_napi.h +++ b/interfaces/kits/js/camera_napi/include/input/camera_napi.h @@ -129,7 +129,7 @@ static const std::unordered_map mapExposureState = { {"EXPOSURE_STATE_CONVERGED", 1}, }; -static const std::unordered_map mapCameraMode = { +static const std::unordered_map mapSceneMode = { {"NORMAL", 0}, {"CAPTURE", 1}, {"VIDEO", 2}, @@ -255,7 +255,7 @@ public: static napi_value CreateQualityLevelEnum(napi_env env); static napi_value CreateVideoStabilizationModeObject(napi_env env); static napi_value CreateHostNameType(napi_env env); - static napi_value CreateCameraMode(napi_env env); + static napi_value CreateSceneMode(napi_env env); static napi_value CreateFilterType(napi_env env); static napi_value CreateBeautyType(napi_env env); static napi_value CreatePortraitEffect(napi_env env); @@ -286,7 +286,7 @@ private: static thread_local napi_ref qualityLevelRef_; static thread_local napi_ref videoStabilizationModeRef_; static thread_local napi_ref hostNameTypeRef_; - static thread_local napi_ref cameraModeRef_; + static thread_local napi_ref sceneModeRef_; static thread_local napi_ref filterTypeRef_; static thread_local napi_ref beautyTypeRef_; static thread_local napi_ref portraitEffectRef_; diff --git a/interfaces/kits/js/camera_napi/include/mode/mode_manager_napi.h b/interfaces/kits/js/camera_napi/include/mode/mode_manager_napi.h index c64285a21..ffa1cfba9 100644 --- a/interfaces/kits/js/camera_napi/include/mode/mode_manager_napi.h +++ b/interfaces/kits/js/camera_napi/include/mode/mode_manager_napi.h @@ -20,7 +20,6 @@ #include "hilog/log.h" #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "input/camera_device.h" #include "output/capture_output.h" @@ -31,7 +30,9 @@ #include "output/photo_output_napi.h" #include "output/video_output_napi.h" #include "portrait_session_napi.h" +#include "photo_session_napi.h" #include "night_session_napi.h" +#include "video_session_napi.h" #include "session/camera_session_napi.h" #include "camera_napi_utils.h" @@ -65,7 +66,7 @@ private: napi_env env_; napi_ref wrapper_; - sptr modeManager_; + sptr modeManager_; static thread_local uint32_t modeManagerTaskId; }; diff --git a/interfaces/kits/js/camera_napi/include/mode/night_session_napi.h b/interfaces/kits/js/camera_napi/include/mode/night_session_napi.h index 03a00f626..5e1a27cb3 100644 --- a/interfaces/kits/js/camera_napi/include/mode/night_session_napi.h +++ b/interfaces/kits/js/camera_napi/include/mode/night_session_napi.h @@ -23,31 +23,6 @@ namespace OHOS { namespace CameraStandard { -class LongExposureCallbackListener : public LongExposureCallback { -public: - LongExposureCallbackListener(napi_env env) : env_(env) {} - ~LongExposureCallbackListener() = default; - void OnLongExposure(const uint32_t longExposureTime) override; - void SaveCallbackReference(const std::string &eventType, napi_value callback, bool isOnce); - void RemoveCallbackRef(napi_env env, napi_value callback); - void RemoveAllCallbacks(); - -private: - void OnLongExposureCallback(uint32_t longExposureTime) const; - void OnLongExposureCallbackAsync(uint32_t longExposureTime) const; - - std::mutex mutex_; - napi_env env_; - mutable std::vector> longExposureCbList_; -}; - -struct LongExposureCallbackInfo { - uint32_t longExposureTime_; - const LongExposureCallbackListener* listener_; - LongExposureCallbackInfo(uint32_t longExposureTime, const LongExposureCallbackListener* listener) - : longExposureTime_(longExposureTime), listener_(listener) {} -}; - static const char NIGHT_SESSION_NAPI_CLASS_NAME[] = "NightSession"; class NightSessionNapi : public CameraSessionNapi { public: @@ -62,20 +37,9 @@ public: static napi_value GetSupportedExposureRange(napi_env env, napi_callback_info info); static napi_value GetExposure(napi_env env, napi_callback_info info); static napi_value SetExposure(napi_env env, napi_callback_info info); - - static napi_value TryAE(napi_env env, napi_callback_info info); - static napi_value On(napi_env env, napi_callback_info info); - static napi_value Once(napi_env env, napi_callback_info info); - static napi_value RegisterCallback(napi_env env, napi_value jsThis, - const string &eventType, napi_value callback, bool isOnce); - static napi_value UnregisterCallback(napi_env env, napi_value jsThis, - const std::string &eventType, napi_value callback); - static napi_value Off(napi_env env, napi_callback_info info); napi_env env_; napi_ref wrapper_; sptr nightSession_; - std::shared_ptr longExposureCallback_; - static thread_local napi_ref sConstructor_; }; } diff --git a/interfaces/kits/js/camera_napi/include/mode/photo_session_napi.h b/interfaces/kits/js/camera_napi/include/mode/photo_session_napi.h new file mode 100644 index 000000000..7ec13e5c9 --- /dev/null +++ b/interfaces/kits/js/camera_napi/include/mode/photo_session_napi.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PHOTO_SESSION_NAPI_H +#define PHOTO_SESSION_NAPI_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "session/camera_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +static const char PHOTO_SESSION_NAPI_CLASS_NAME[] = "PohtoSession"; +class PhotoSessionNapi : public CameraSessionNapi { +public: + static napi_value Init(napi_env env, napi_value exports); + static napi_value CreateCameraSession(napi_env env); + PhotoSessionNapi(); + ~PhotoSessionNapi(); + + static void PhotoSessionNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint); + static napi_value PhotoSessionNapiConstructor(napi_env env, napi_callback_info info); + + napi_env env_; + napi_ref wrapper_; + sptr photoSession_; + static thread_local napi_ref sConstructor_; +}; +} +} +#endif /* PHOTO_SESSION_NAPI_H */ diff --git a/interfaces/kits/js/camera_napi/include/mode/portrait_session_napi.h b/interfaces/kits/js/camera_napi/include/mode/portrait_session_napi.h index 8fcc39b79..f87788d14 100644 --- a/interfaces/kits/js/camera_napi/include/mode/portrait_session_napi.h +++ b/interfaces/kits/js/camera_napi/include/mode/portrait_session_napi.h @@ -20,7 +20,6 @@ #include "napi/native_node_api.h" #include "session/camera_session_napi.h" - namespace OHOS { namespace CameraStandard { static const char PORTRAIT_SESSION_NAPI_CLASS_NAME[] = "PortraitSession"; diff --git a/interfaces/kits/js/camera_napi/include/mode/video_session_napi.h b/interfaces/kits/js/camera_napi/include/mode/video_session_napi.h new file mode 100644 index 000000000..690b5bcf4 --- /dev/null +++ b/interfaces/kits/js/camera_napi/include/mode/video_session_napi.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VIDEO_SESSION_NAPI_H +#define VIDEO_SESSION_NAPI_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "session/camera_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +static const char VIDEO_SESSION_NAPI_CLASS_NAME[] = "VideoSession"; +class VideoSessionNapi : public CameraSessionNapi { +public: + static napi_value Init(napi_env env, napi_value exports); + static napi_value CreateCameraSession(napi_env env); + VideoSessionNapi(); + ~VideoSessionNapi(); + + static void VideoSessionNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint); + static napi_value VideoSessionNapiConstructor(napi_env env, napi_callback_info info); + + napi_env env_; + napi_ref wrapper_; + sptr videoSession_; + static thread_local napi_ref sConstructor_; +}; +} +} +#endif /* VIDEO_SESSION_NAPI_H */ diff --git a/interfaces/kits/js/camera_napi/include/output/camera_output_napi.h b/interfaces/kits/js/camera_napi/include/output/camera_output_napi.h index 72962c36d..c0588b87d 100644 --- a/interfaces/kits/js/camera_napi/include/output/camera_output_napi.h +++ b/interfaces/kits/js/camera_napi/include/output/camera_output_napi.h @@ -17,7 +17,6 @@ #define CAMERA_OUTPUT_NAPI_H_ #include "input/camera_manager.h" -#include "mode/mode_manager.h" #include "input/camera_device.h" #include "input/camera_profile_napi.h" #include "output/camera_output_capability.h" @@ -45,7 +44,7 @@ class CameraOutputCapabilityNapi { public: static napi_value Init(napi_env env, napi_value exports); static napi_value CreateCameraOutputCapability(napi_env env, sptr camera); - static napi_value CreateCameraOutputCapability(napi_env env, sptr camera, CameraMode mode); + static napi_value CreateCameraOutputCapability(napi_env env, sptr camera, SceneMode mode); CameraOutputCapabilityNapi(); ~CameraOutputCapabilityNapi(); diff --git a/interfaces/kits/js/camera_napi/include/session/camera_session_napi.h b/interfaces/kits/js/camera_napi/include/session/camera_session_napi.h index 31d5f6042..ced700201 100644 --- a/interfaces/kits/js/camera_napi/include/session/camera_session_napi.h +++ b/interfaces/kits/js/camera_napi/include/session/camera_session_napi.h @@ -272,6 +272,99 @@ struct CameraSessionAsyncContext : public AsyncContext { objectInfo = nullptr; } }; + +static const std::vector camera_process_props = { + DECLARE_NAPI_FUNCTION("beginConfig", CameraSessionNapi::BeginConfig), + DECLARE_NAPI_FUNCTION("commitConfig", CameraSessionNapi::CommitConfig), + + DECLARE_NAPI_FUNCTION("canAddInput", CameraSessionNapi::CanAddInput), + DECLARE_NAPI_FUNCTION("addInput", CameraSessionNapi::AddInput), + DECLARE_NAPI_FUNCTION("removeInput", CameraSessionNapi::RemoveInput), + + DECLARE_NAPI_FUNCTION("canAddOutput", CameraSessionNapi::CanAddOutput), + DECLARE_NAPI_FUNCTION("addOutput", CameraSessionNapi::AddOutput), + DECLARE_NAPI_FUNCTION("removeOutput", CameraSessionNapi::RemoveOutput), + + DECLARE_NAPI_FUNCTION("start", CameraSessionNapi::Start), + DECLARE_NAPI_FUNCTION("stop", CameraSessionNapi::Stop), + DECLARE_NAPI_FUNCTION("release", CameraSessionNapi::Release), + + DECLARE_NAPI_FUNCTION("lockForControl", CameraSessionNapi::LockForControl), + DECLARE_NAPI_FUNCTION("unlockForControl", CameraSessionNapi::UnlockForControl), + + DECLARE_NAPI_FUNCTION("on", CameraSessionNapi::On), + DECLARE_NAPI_FUNCTION("once", CameraSessionNapi::Once), + DECLARE_NAPI_FUNCTION("off", CameraSessionNapi::Off) +}; + +static const std::vector stabilization_props = { + DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", CameraSessionNapi::IsVideoStabilizationModeSupported), + DECLARE_NAPI_FUNCTION("getActiveVideoStabilizationMode", CameraSessionNapi::GetActiveVideoStabilizationMode), + DECLARE_NAPI_FUNCTION("setVideoStabilizationMode", CameraSessionNapi::SetVideoStabilizationMode) +}; + +static const std::vector flash_props = { + DECLARE_NAPI_FUNCTION("hasFlash", CameraSessionNapi::HasFlash), + DECLARE_NAPI_FUNCTION("isFlashModeSupported", CameraSessionNapi::IsFlashModeSupported), + DECLARE_NAPI_FUNCTION("getFlashMode", CameraSessionNapi::GetFlashMode), + DECLARE_NAPI_FUNCTION("setFlashMode", CameraSessionNapi::SetFlashMode) +}; + +static const std::vector auto_exposure_props = { + DECLARE_NAPI_FUNCTION("isExposureModeSupported", CameraSessionNapi::IsExposureModeSupported), + DECLARE_NAPI_FUNCTION("getExposureMode", CameraSessionNapi::GetExposureMode), + DECLARE_NAPI_FUNCTION("setExposureMode", CameraSessionNapi::SetExposureMode), + DECLARE_NAPI_FUNCTION("getExposureBiasRange", CameraSessionNapi::GetExposureBiasRange), + DECLARE_NAPI_FUNCTION("setExposureBias", CameraSessionNapi::SetExposureBias), + DECLARE_NAPI_FUNCTION("getExposureValue", CameraSessionNapi::GetExposureValue), + DECLARE_NAPI_FUNCTION("getMeteringPoint", CameraSessionNapi::GetMeteringPoint), + DECLARE_NAPI_FUNCTION("setMeteringPoint", CameraSessionNapi::SetMeteringPoint) +}; + +static const std::vector focus_props = { + DECLARE_NAPI_FUNCTION("isFocusModeSupported", CameraSessionNapi::IsFocusModeSupported), + DECLARE_NAPI_FUNCTION("getFocusMode", CameraSessionNapi::GetFocusMode), + DECLARE_NAPI_FUNCTION("setFocusMode", CameraSessionNapi::SetFocusMode), + DECLARE_NAPI_FUNCTION("getFocusPoint", CameraSessionNapi::GetFocusPoint), + DECLARE_NAPI_FUNCTION("setFocusPoint", CameraSessionNapi::SetFocusPoint), + DECLARE_NAPI_FUNCTION("getFocalLength", CameraSessionNapi::GetFocalLength) +}; + +static const std::vector zoom_props = { + DECLARE_NAPI_FUNCTION("getZoomRatioRange", CameraSessionNapi::GetZoomRatioRange), + DECLARE_NAPI_FUNCTION("getZoomRatio", CameraSessionNapi::GetZoomRatio), + DECLARE_NAPI_FUNCTION("setZoomRatio", CameraSessionNapi::SetZoomRatio) +}; + +static const std::vector filter_props = { + DECLARE_NAPI_FUNCTION("getSupportedFilters", CameraSessionNapi::GetSupportedFilters), + DECLARE_NAPI_FUNCTION("getFilter", CameraSessionNapi::GetFilter), + DECLARE_NAPI_FUNCTION("setFilter", CameraSessionNapi::SetFilter) +}; + +static const std::vector beauty_props = { + DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", CameraSessionNapi::GetSupportedBeautyTypes), + DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", CameraSessionNapi::GetSupportedBeautyRange), + DECLARE_NAPI_FUNCTION("getBeauty", CameraSessionNapi::GetBeauty), + DECLARE_NAPI_FUNCTION("setBeauty", CameraSessionNapi::SetBeauty) +}; + +static const std::vector color_effect_props = { + DECLARE_NAPI_FUNCTION("getSupportedColorEffects", CameraSessionNapi::GetSupportedColorEffects), + DECLARE_NAPI_FUNCTION("getColorEffect", CameraSessionNapi::GetColorEffect), + DECLARE_NAPI_FUNCTION("setColorEffect", CameraSessionNapi::SetColorEffect) +}; + +static const std::vector macro_props = { + DECLARE_NAPI_FUNCTION("isMacroSupported", CameraSessionNapi::IsMacroSupported), + DECLARE_NAPI_FUNCTION("enableMacro", CameraSessionNapi::EnableMacro) +}; + +static const std::vector color_management_props = { + DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", CameraSessionNapi::GetSupportedColorSpaces), + DECLARE_NAPI_FUNCTION("getActiveColorSpace", CameraSessionNapi::GetActiveColorSpace), + DECLARE_NAPI_FUNCTION("setColorSpace", CameraSessionNapi::SetColorSpace) +}; } // namespace CameraStandard } // namespace OHOS #endif /* CAMERA_SESSION_NAPI_H_ */ diff --git a/services/camera_service/include/hcamera_service.h b/services/camera_service/include/hcamera_service.h index c35a347d7..7e7dd2530 100644 --- a/services/camera_service/include/hcamera_service.h +++ b/services/camera_service/include/hcamera_service.h @@ -35,7 +35,17 @@ namespace OHOS { namespace CameraStandard { +using namespace std; using namespace OHOS::HDI::Camera::V1_0; +struct CameraMetaInfo { + string cameraId; + uint8_t position; + uint8_t connectionType; + shared_ptr cameraAbility; + CameraMetaInfo(string cameraId, uint8_t position, uint8_t connectionType, + shared_ptr cameraAbility) + : cameraId(cameraId), position(position), connectionType (connectionType), cameraAbility(cameraAbility) {} +}; class HCameraService : public SystemAbility, public HCameraServiceStub, public HCameraHostManager::StatusCallback, public IDeviceOperatorsCallback { DECLARE_SYSTEM_ABILITY(HCameraService); @@ -45,9 +55,9 @@ public: explicit HCameraService(int32_t systemAbilityId, bool runOnCreate = true); ~HCameraService() override; - int32_t GetCameras(std::vector &cameraIds, - std::vector> &cameraAbilityList) override; - int32_t CreateCameraDevice(std::string cameraId, sptr &device) override; + int32_t GetCameras(vector &cameraIds, + vector> &cameraAbilityList) override; + int32_t CreateCameraDevice(string cameraId, sptr &device) override; int32_t CreateCaptureSession(sptr &session, int32_t opMode) override; int32_t CreatePhotoOutput(const sptr &producer, int32_t format, int32_t width, int32_t height, @@ -69,17 +79,17 @@ public: int32_t SetTorchCallback(sptr &callback) override; int32_t MuteCamera(bool muteMode) override; int32_t PrelaunchCamera() override; - int32_t SetPrelaunchConfig(std::string cameraId) override; + int32_t SetPrelaunchConfig(string cameraId) override; int32_t IsCameraMuted(bool &muteMode) override; int32_t SetTorchLevel(float level) override; void OnDump() override; void OnStart() override; void OnStop() override; - int32_t Dump(int fd, const std::vector& args) override; + int32_t Dump(int fd, const vector& args) override; // HCameraHostManager::StatusCallback - void OnCameraStatus(const std::string& cameraId, CameraStatus status) override; - void OnFlashlightStatus(const std::string& cameraId, FlashStatus status) override; + void OnCameraStatus(const string& cameraId, CameraStatus status) override; + void OnFlashlightStatus(const string& cameraId, FlashStatus status) override; void OnTorchStatus(TorchStatus status) override; protected: @@ -88,40 +98,43 @@ protected: muteMode_(false) {} private: - void CameraSummary(std::vector cameraIds, std::string& dumpString); - void CameraDumpAbility(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpStreaminfo(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpZoom(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpFlash(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpAF(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpAE(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpSensorInfo(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpVideoStabilization(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpVideoFrameRateRange(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpPrelaunch(common_metadata_header_t* metadataEntry, std::string& dumpString); - void CameraDumpThumbnail(common_metadata_header_t* metadataEntry, std::string& dumpString); - bool IsCameraMuteSupported(std::string cameraId); - bool IsPrelaunchSupported(std::string cameraId); + void CameraSummary(vector cameraIds, string& dumpString); + void CameraDumpAbility(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpStreaminfo(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpZoom(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpFlash(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpAF(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpAE(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpSensorInfo(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpVideoStabilization(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpVideoFrameRateRange(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpPrelaunch(common_metadata_header_t* metadataEntry, string& dumpString); + void CameraDumpThumbnail(common_metadata_header_t* metadataEntry, string& dumpString); + vector> ChooseDeFaultCameras(vector> cameraInfos); + bool IsCameraMuteSupported(string cameraId); + bool IsPrelaunchSupported(string cameraId); int32_t UpdateMuteSetting(sptr cameraDevice, bool muteMode); int32_t UnSetMuteCallback(pid_t pid); int32_t UnSetTorchCallback(pid_t pid); - bool IsDeviceAlreadyOpen(pid_t& tempPid, std::string& tempCameraId, sptr &tempDevice); + bool IsDeviceAlreadyOpen(pid_t& tempPid, string& tempCameraId, sptr &tempDevice); int32_t DeviceClose(sptr cameraDevice); void RegisterSensorCallback(); void UnRegisterSensorCallback(); static void DropDetectionDataCallbackImpl(SensorEvent *event); - std::mutex mutex_; - std::mutex cbMutex_; - std::mutex muteCbMutex_; - std::mutex torchCbMutex_; + mutex mutex_; + mutex cbMutex_; + mutex muteCbMutex_; + mutex torchCbMutex_; sptr cameraHostManager_; sptr streamOperatorCallback_; - std::map> torchServiceCallbacks_; - std::map> cameraMuteServiceCallbacks_; - std::map> cameraServiceCallbacks_; + map> torchServiceCallbacks_; + map> cameraMuteServiceCallbacks_; + map> cameraServiceCallbacks_; bool muteMode_; - std::mutex mapOperatorsLock_; - std::string preCameraId_; + bool isFoldable = false; + bool isFoldableInit = false; + mutex mapOperatorsLock_; + string preCameraId_; SensorUser user; }; } // namespace CameraStandard diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index 16f75e565..2f6dafc78 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -22,6 +22,7 @@ #include "accesstoken_kit.h" #include "camera_log.h" #include "camera_util.h" +#include "display_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -32,6 +33,7 @@ namespace CameraStandard { REGISTER_SYSTEM_ABILITY_BY_ID(HCameraService, CAMERA_SERVICE_ID, true) constexpr int32_t SENSOR_SUCCESS = 0; constexpr int32_t POSTURE_INTERVAL = 1000000; +constexpr uint8_t POSITION_FOLD_INNER = 3; static sptr mCameraService; HCameraService::HCameraService(int32_t systemAbilityId, bool runOnCreate) @@ -44,7 +46,7 @@ HCameraService::~HCameraService() {} void HCameraService::OnStart() { if (cameraHostManager_ == nullptr) { - cameraHostManager_ = new (std::nothrow) HCameraHostManager(this); + cameraHostManager_ = new (nothrow) HCameraHostManager(this); CHECK_AND_RETURN_LOG( cameraHostManager_ != nullptr, "HCameraService OnStart failed to create HCameraHostManager obj"); } @@ -79,69 +81,85 @@ void HCameraService::OnStop() } int32_t HCameraService::GetCameras( - std::vector& cameraIds, std::vector>& cameraAbilityList) + vector& cameraIds, vector>& cameraAbilityList) { CAMERA_SYNC_TRACE; + isFoldable = isFoldableInit ? isFoldable : OHOS::Rosen::DisplayManager::GetInstance().IsFoldable(); + isFoldableInit = true; int32_t ret = cameraHostManager_->GetCameras(cameraIds); if (ret != CAMERA_OK) { MEDIA_ERR_LOG("HCameraService::GetCameras failed"); return ret; } - - std::shared_ptr cameraAbility; + shared_ptr cameraAbility; + vector> cameraInfos; for (auto id : cameraIds) { ret = cameraHostManager_->GetCameraAbility(id, cameraAbility); - if (ret != CAMERA_OK) { + if (ret != CAMERA_OK || cameraAbility == nullptr) { MEDIA_ERR_LOG("HCameraService::GetCameraAbility failed"); return ret; } - - if (cameraAbility == nullptr) { - MEDIA_ERR_LOG("HCameraService::GetCameraAbility return null"); - return CAMERA_INVALID_ARG; - } - camera_metadata_item_t item; common_metadata_header_t* metadata = cameraAbility->get(); - camera_position_enum_t cameraPosition = OHOS_CAMERA_POSITION_OTHER; int ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_POSITION, &item); - if (ret == CAM_META_SUCCESS) { - cameraPosition = static_cast(item.data.u8[0]); + uint8_t cameraPosition = (ret == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_POSITION_OTHER; + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_FOLDSCREEN_TYPE, &item); + uint8_t foldType = (ret == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_FOLDSCREEN_OTHER; + if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_OTHER) { + continue; } - - camera_type_enum_t cameraType = OHOS_CAMERA_TYPE_UNSPECIFIED; - ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_TYPE, &item); - if (ret == CAM_META_SUCCESS) { - cameraType = static_cast(item.data.u8[0]); + if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_INNER) { + cameraPosition = POSITION_FOLD_INNER; } - - camera_connection_type_t connectionType = OHOS_CAMERA_CONNECTION_TYPE_BUILTIN; + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_TYPE, &item); + camera_type_enum_t cameraType = (ret == CAM_META_SUCCESS) ? + static_cast(item.data.u8[0]) : OHOS_CAMERA_TYPE_UNSPECIFIED; ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item); - if (ret == CAM_META_SUCCESS) { - connectionType = static_cast(item.data.u8[0]); - } - - bool isMirrorSupported = false; + camera_connection_type_t connectionType = (ret == CAM_META_SUCCESS) ? + static_cast(item.data.u8[0]) : OHOS_CAMERA_CONNECTION_TYPE_BUILTIN; ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, &item); - if (ret == CAM_META_SUCCESS) { - isMirrorSupported = ((item.data.u8[0] == 1) || (item.data.u8[0] == 0)); - } - + bool isMirrorSupported = (ret == CAM_META_SUCCESS) ? + ((item.data.u8[0] == 1) || (item.data.u8[0] == 0)) : false; CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager GetCameras camera ID:%s, Camera position:%d," " Camera Type:%d, Connection Type:%d, Mirror support:%d", id.c_str(), cameraPosition, cameraType, connectionType, isMirrorSupported)); - cameraAbilityList.emplace_back(cameraAbility); + cameraInfos.emplace_back(make_shared(id, cameraPosition, connectionType, cameraAbility)); + } + vector> choosedCameras = ChooseDeFaultCameras(cameraInfos); + cameraIds.clear(); + cameraAbilityList.clear(); + for (const auto& camera: choosedCameras) { + cameraIds.emplace_back(camera->cameraId); + cameraAbilityList.emplace_back(camera->cameraAbility); } - return ret; } -int32_t HCameraService::CreateCameraDevice(std::string cameraId, sptr& device) +vector> HCameraService::ChooseDeFaultCameras(vector> cameraInfos) +{ + vector> choosedCameras; + for (auto& camera : cameraInfos) { + if (any_of(choosedCameras.begin(), choosedCameras.end(), + [camera](const auto& defaultCamera) { + return (camera->connectionType != OHOS_CAMERA_CONNECTION_TYPE_USB_PLUGIN && + defaultCamera->position == camera->position && + defaultCamera->connectionType == camera->connectionType); + }) + ) { + MEDIA_INFO_LOG("ChooseDeFaultCameras alreadly has default camera"); + } else { + choosedCameras.emplace_back(camera); + } + } + return choosedCameras; +} + +int32_t HCameraService::CreateCameraDevice(string cameraId, sptr& device) { CAMERA_SYNC_TRACE; OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - std::string permissionName = OHOS_PERMISSION_CAMERA; + string permissionName = OHOS_PERMISSION_CAMERA; int32_t ret = CheckPermission(permissionName, callerToken); if (ret != CAMERA_OK) { return ret; @@ -153,8 +171,8 @@ int32_t HCameraService::CreateCameraDevice(std::string cameraId, sptr lock(mapOperatorsLock_); - sptr cameraDevice = new (std::nothrow) HCameraDevice(cameraHostManager_, cameraId, callerToken); + lock_guard lock(mapOperatorsLock_); + sptr cameraDevice = new (nothrow) HCameraDevice(cameraHostManager_, cameraId, callerToken); CHECK_AND_RETURN_RET_LOG(cameraDevice != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateCameraDevice HCameraDevice allocation failed"); @@ -175,17 +193,17 @@ int32_t HCameraService::CreateCameraDevice(std::string cameraId, sptr& session, int32_t opMode) { CAMERA_SYNC_TRACE; - std::lock_guard lock(mutex_); + lock_guard lock(mutex_); sptr captureSession; if (streamOperatorCallback_ == nullptr) { - streamOperatorCallback_ = new (std::nothrow) StreamOperatorCallback(); + streamOperatorCallback_ = new (nothrow) StreamOperatorCallback(); CHECK_AND_RETURN_RET_LOG(streamOperatorCallback_ != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateCaptureSession streamOperatorCallback_ allocation failed"); } OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); captureSession = - new (std::nothrow) HCaptureSession(cameraHostManager_, streamOperatorCallback_, callerToken, opMode); + new (nothrow) HCaptureSession(cameraHostManager_, streamOperatorCallback_, callerToken, opMode); CHECK_AND_RETURN_RET_LOG(captureSession != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateCaptureSession HCaptureSession allocation failed"); captureSession->SetDeviceOperatorsCallback(this); @@ -201,7 +219,7 @@ int32_t HCameraService::CreatePhotoOutput(const sptr& pro MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput producer is null"); return CAMERA_INVALID_ARG; } - sptr streamCapture = new (std::nothrow) HStreamCapture(producer, format, width, height); + sptr streamCapture = new (nothrow) HStreamCapture(producer, format, width, height); CHECK_AND_RETURN_RET_LOG(streamCapture != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreatePhotoOutput HStreamCapture allocation failed"); POWERMGR_SYSEVENT_CAMERA_CONFIG(PHOTO, producer->GetDefaultWidth(), producer->GetDefaultHeight()); @@ -219,7 +237,7 @@ int32_t HCameraService::CreateDeferredPreviewOutput( MEDIA_ERR_LOG("HCameraService::CreateDeferredPreviewOutput producer is null"); return CAMERA_INVALID_ARG; } - streamDeferredPreview = new (std::nothrow) HStreamRepeat(nullptr, format, width, height, RepeatStreamType::PREVIEW); + streamDeferredPreview = new (nothrow) HStreamRepeat(nullptr, format, width, height, RepeatStreamType::PREVIEW); CHECK_AND_RETURN_RET_LOG(streamDeferredPreview != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateDeferredPreviewOutput HStreamRepeat allocation failed"); previewOutput = streamDeferredPreview; @@ -236,7 +254,7 @@ int32_t HCameraService::CreatePreviewOutput(const sptr& p MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput producer is null"); return CAMERA_INVALID_ARG; } - streamRepeatPreview = new (std::nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::PREVIEW); + streamRepeatPreview = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::PREVIEW); CHECK_AND_RETURN_RET_LOG(streamRepeatPreview != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreatePreviewOutput HStreamRepeat allocation failed"); POWERMGR_SYSEVENT_CAMERA_CONFIG(PREVIEW, width, height); @@ -254,7 +272,7 @@ int32_t HCameraService::CreateMetadataOutput( MEDIA_ERR_LOG("HCameraService::CreateMetadataOutput producer is null"); return CAMERA_INVALID_ARG; } - streamMetadata = new (std::nothrow) HStreamMetadata(producer, format); + streamMetadata = new (nothrow) HStreamMetadata(producer, format); CHECK_AND_RETURN_RET_LOG(streamMetadata != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateMetadataOutput HStreamMetadata allocation failed"); @@ -273,7 +291,7 @@ int32_t HCameraService::CreateVideoOutput(const sptr& pro MEDIA_ERR_LOG("HCameraService::CreateVideoOutput producer is null"); return CAMERA_INVALID_ARG; } - streamRepeatVideo = new (std::nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::VIDEO); + streamRepeatVideo = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::VIDEO); CHECK_AND_RETURN_RET_LOG(streamRepeatVideo != nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateVideoOutput HStreamRepeat allocation failed"); @@ -282,9 +300,9 @@ int32_t HCameraService::CreateVideoOutput(const sptr& pro return CAMERA_OK; } -void HCameraService::OnCameraStatus(const std::string& cameraId, CameraStatus status) +void HCameraService::OnCameraStatus(const string& cameraId, CameraStatus status) { - std::lock_guard lock(cbMutex_); + lock_guard lock(cbMutex_); MEDIA_INFO_LOG("HCameraService::OnCameraStatus " "callbacks.size = %{public}zu, cameraId = %{public}s, status = %{public}d, pid = %{public}d", cameraServiceCallbacks_.size(), cameraId.c_str(), status, IPCSkeleton::GetCallingPid()); @@ -301,9 +319,9 @@ void HCameraService::OnCameraStatus(const std::string& cameraId, CameraStatus st } } -void HCameraService::OnFlashlightStatus(const std::string& cameraId, FlashStatus status) +void HCameraService::OnFlashlightStatus(const string& cameraId, FlashStatus status) { - std::lock_guard lock(cbMutex_); + lock_guard lock(cbMutex_); MEDIA_INFO_LOG("HCameraService::OnFlashlightStatus " "callbacks.size = %{public}zu, cameraId = %{public}s, status = %{public}d, pid = %{public}d", cameraServiceCallbacks_.size(), cameraId.c_str(), status, IPCSkeleton::GetCallingPid()); @@ -320,7 +338,7 @@ void HCameraService::OnFlashlightStatus(const std::string& cameraId, FlashStatus void HCameraService::OnTorchStatus(TorchStatus status) { - std::lock_guard lock(torchCbMutex_); + lock_guard lock(torchCbMutex_); MEDIA_INFO_LOG("HCameraService::OnTorchtStatus " "callbacks.size = %{public}zu, status = %{public}d, pid = %{public}d", torchServiceCallbacks_.size(), status, IPCSkeleton::GetCallingPid()); @@ -337,7 +355,7 @@ void HCameraService::OnTorchStatus(TorchStatus status) int32_t HCameraService::SetCallback(sptr& callback) { - std::lock_guard lock(cbMutex_); + lock_guard lock(cbMutex_); pid_t pid = IPCSkeleton::GetCallingPid(); MEDIA_INFO_LOG("HCameraService::SetCallback pid = %{public}d", pid); if (callback == nullptr) { @@ -349,7 +367,7 @@ int32_t HCameraService::SetCallback(sptr& callback) callbackItem->second = nullptr; (void)cameraServiceCallbacks_.erase(callbackItem); } - cameraServiceCallbacks_.insert(std::make_pair(pid, callback)); + cameraServiceCallbacks_.insert(make_pair(pid, callback)); return CAMERA_OK; } @@ -365,7 +383,7 @@ int32_t HCameraService::CloseCameraForDestory(pid_t pid) int32_t HCameraService::UnSetMuteCallback(pid_t pid) { - std::lock_guard lock(muteCbMutex_); + lock_guard lock(muteCbMutex_); MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback pid = %{public}d, size = %{public}zu", pid, cameraMuteServiceCallbacks_.size()); if (!cameraMuteServiceCallbacks_.empty()) { @@ -384,7 +402,7 @@ int32_t HCameraService::UnSetMuteCallback(pid_t pid) int32_t HCameraService::UnSetCallback(pid_t pid) { - std::lock_guard lock(cbMutex_); + lock_guard lock(cbMutex_); MEDIA_INFO_LOG( "HCameraService::UnSetCallback pid = %{public}d, size = %{public}zu", pid, cameraServiceCallbacks_.size()); if (!cameraServiceCallbacks_.empty()) { @@ -405,31 +423,31 @@ int32_t HCameraService::UnSetCallback(pid_t pid) int32_t HCameraService::SetMuteCallback(sptr& callback) { - std::lock_guard lock(muteCbMutex_); + lock_guard lock(muteCbMutex_); pid_t pid = IPCSkeleton::GetCallingPid(); if (callback == nullptr) { MEDIA_ERR_LOG("HCameraService::SetMuteCallback callback is null"); return CAMERA_INVALID_ARG; } - cameraMuteServiceCallbacks_.insert(std::make_pair(pid, callback)); + cameraMuteServiceCallbacks_.insert(make_pair(pid, callback)); return CAMERA_OK; } int32_t HCameraService::SetTorchCallback(sptr& callback) { - std::lock_guard lock(torchCbMutex_); + lock_guard lock(torchCbMutex_); pid_t pid = IPCSkeleton::GetCallingPid(); if (callback == nullptr) { MEDIA_ERR_LOG("HCameraService::SetTorchCallback callback is null"); return CAMERA_INVALID_ARG; } - torchServiceCallbacks_.insert(std::make_pair(pid, callback)); + torchServiceCallbacks_.insert(make_pair(pid, callback)); return CAMERA_OK; } int32_t HCameraService::UnSetTorchCallback(pid_t pid) { - std::lock_guard lock(torchCbMutex_); + lock_guard lock(torchCbMutex_); MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback pid = %{public}d, size = %{public}zu", pid, torchServiceCallbacks_.size()); if (!torchServiceCallbacks_.empty()) { @@ -446,10 +464,10 @@ int32_t HCameraService::UnSetTorchCallback(pid_t pid) return CAMERA_OK; } -bool HCameraService::IsCameraMuteSupported(std::string cameraId) +bool HCameraService::IsCameraMuteSupported(string cameraId) { bool isMuteSupported = false; - std::shared_ptr cameraAbility; + shared_ptr cameraAbility; int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility); if (ret != CAMERA_OK) { MEDIA_ERR_LOG("HCameraService::IsCameraMuted GetCameraAbility failed"); @@ -478,8 +496,8 @@ int32_t HCameraService::UpdateMuteSetting(sptr cameraDevice, bool { constexpr int32_t DEFAULT_ITEMS = 1; constexpr int32_t DEFAULT_DATA_LENGTH = 1; - std::shared_ptr changedMetadata = - std::make_shared(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH); + shared_ptr changedMetadata = + make_shared(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH); bool status = false; int32_t ret; int32_t count = 1; @@ -520,7 +538,7 @@ int32_t HCameraService::MuteCamera(bool muteMode) sptr deviceManager = HCameraDeviceManager::GetInstance(); pid_t activeClient = deviceManager->GetActiveClient(); if (activeClient == -1) { - std::lock_guard lock(muteCbMutex_); + lock_guard lock(muteCbMutex_); if (!cameraMuteServiceCallbacks_.empty()) { for (auto cb : cameraMuteServiceCallbacks_) { cb.second->OnCameraMute(muteMode); @@ -531,7 +549,7 @@ int32_t HCameraService::MuteCamera(bool muteMode) } sptr activeDevice = deviceManager->GetCameraByPid(activeClient); if (activeDevice != nullptr) { - std::string cameraId = activeDevice->GetCameraId(); + string cameraId = activeDevice->GetCameraId(); if (!IsCameraMuteSupported(cameraId)) { MEDIA_ERR_LOG("Not Supported Mute,cameraId: %{public}s", cameraId.c_str()); return CAMERA_UNSUPPORTED; @@ -544,7 +562,7 @@ int32_t HCameraService::MuteCamera(bool muteMode) muteMode_ = oldMuteMode; } } - std::lock_guard lock(muteCbMutex_); + lock_guard lock(muteCbMutex_); if (!cameraMuteServiceCallbacks_.empty() && ret == CAMERA_OK) { for (auto cb : cameraMuteServiceCallbacks_) { if (cb.second) { @@ -561,7 +579,7 @@ int32_t HCameraService::PrelaunchCamera() CAMERA_SYNC_TRACE; MEDIA_INFO_LOG("HCameraService::PrelaunchCamera"); if (preCameraId_.empty()) { - std::vector cameraIds_; + vector cameraIds_; cameraHostManager_->GetCameras(cameraIds_); if (cameraIds_.empty()) { return CAMERA_OK; @@ -577,11 +595,11 @@ int32_t HCameraService::PrelaunchCamera() return ret; } -int32_t HCameraService::SetPrelaunchConfig(std::string cameraId) +int32_t HCameraService::SetPrelaunchConfig(string cameraId) { CAMERA_SYNC_TRACE; OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - std::string permissionName = OHOS_PERMISSION_CAMERA; + string permissionName = OHOS_PERMISSION_CAMERA; int32_t ret = CheckPermission(permissionName, callerToken); if (ret != CAMERA_OK) { MEDIA_ERR_LOG("HCameraService::SetPrelaunchConfig failed permission is: %{public}s", permissionName.c_str()); @@ -589,7 +607,7 @@ int32_t HCameraService::SetPrelaunchConfig(std::string cameraId) } MEDIA_INFO_LOG("HCameraService::SetPrelaunchConfig"); - std::vector cameraIds_; + vector cameraIds_; cameraHostManager_->GetCameras(cameraIds_); if ((find(cameraIds_.begin(), cameraIds_.end(), cameraId) != cameraIds_.end()) && IsPrelaunchSupported(cameraId)) { preCameraId_ = cameraId; @@ -609,10 +627,10 @@ int32_t HCameraService::SetTorchLevel(float level) return ret; } -bool HCameraService::IsPrelaunchSupported(std::string cameraId) +bool HCameraService::IsPrelaunchSupported(string cameraId) { bool isPrelaunchSupported = false; - std::shared_ptr cameraAbility; + shared_ptr cameraAbility; int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility); if (ret != CAMERA_OK) { MEDIA_ERR_LOG("HCameraService::IsCameraMuted GetCameraAbility failed"); @@ -638,14 +656,14 @@ int32_t HCameraService::IsCameraMuted(bool& muteMode) return CAMERA_OK; } -void HCameraService::CameraSummary(std::vector cameraIds, std::string& dumpString) +void HCameraService::CameraSummary(vector cameraIds, string& dumpString) { - dumpString += "# Number of Cameras:[" + std::to_string(cameraIds.size()) + "]:\n"; - dumpString += "# Number of Active Cameras:[" + std::to_string(1) + "]:\n"; + dumpString += "# Number of Cameras:[" + to_string(cameraIds.size()) + "]:\n"; + dumpString += "# Number of Active Cameras:[" + to_string(1) + "]:\n"; HCaptureSession::CameraSessionSummary(dumpString); } -void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -653,7 +671,7 @@ void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_POSITION, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraPos.find(item.data.u8[0]); if (iter != g_cameraPos.end()) { dumpString += " Camera Position:[" @@ -664,7 +682,7 @@ void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_TYPE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraType.find(item.data.u8[0]); if (iter != g_cameraType.end()) { dumpString += "Camera Type:[" @@ -675,7 +693,7 @@ void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraConType.find(item.data.u8[0]); if (iter != g_cameraConType.end()) { dumpString += "Camera Connection Type:[" @@ -685,7 +703,7 @@ void HCameraService::CameraDumpAbility(common_metadata_header_t* metadataEntry, } } -void HCameraService::CameraDumpStreaminfo(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpStreaminfo(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -697,25 +715,25 @@ void HCameraService::CameraDumpStreaminfo(common_metadata_header_t* metadataEntr OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, &item); if (ret == CAM_META_SUCCESS) { dumpString += " Number Stream Info: " - + std::to_string(item.count/unitLen) + "\n"; + + to_string(item.count/unitLen) + "\n"; for (uint32_t index = 0; index < item.count; index += unitLen) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraFormat.find(item.data.i32[index]); if (iter != g_cameraFormat.end()) { dumpString += " Format:[" + iter->second + "]: "; dumpString += "Size:[Width:" - + std::to_string(item.data.i32[index + widthOffset]) + + to_string(item.data.i32[index + widthOffset]) + " Height:" - + std::to_string(item.data.i32[index + heightOffset]) + + to_string(item.data.i32[index + heightOffset]) + "]:\n"; } } } } -void HCameraService::CameraDumpZoom(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpZoom(common_metadata_header_t* metadataEntry, string& dumpString) { dumpString += " ## Zoom Related Info: \n"; camera_metadata_item_t item; @@ -726,36 +744,36 @@ void HCameraService::CameraDumpZoom(common_metadata_header_t* metadataEntry, std ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_CAP, &item); if ((ret == CAM_META_SUCCESS) && (item.count == zoomRangeCount)) { dumpString += " Available Zoom Capability:[" - + std::to_string(item.data.i32[minIndex]) + " " - + std::to_string(item.data.i32[maxIndex]) + + to_string(item.data.i32[minIndex]) + " " + + to_string(item.data.i32[maxIndex]) + "]:\n"; } ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_SCENE_ZOOM_CAP, &item); if ((ret == CAM_META_SUCCESS) && (item.count == zoomRangeCount)) { dumpString += " Available scene Zoom Capability:[" - + std::to_string(item.data.i32[minIndex]) + " " - + std::to_string(item.data.i32[maxIndex]) + + to_string(item.data.i32[minIndex]) + " " + + to_string(item.data.i32[maxIndex]) + "]:\n"; } ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_RATIO_RANGE, &item); if ((ret == CAM_META_SUCCESS) && (item.count == zoomRangeCount)) { dumpString += " Available Zoom Ratio Range:[" - + std::to_string(item.data.f[minIndex]) - + std::to_string(item.data.f[maxIndex]) + + to_string(item.data.f[minIndex]) + + to_string(item.data.f[maxIndex]) + "]:\n"; } ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_CONTROL_ZOOM_RATIO, &item); if (ret == CAM_META_SUCCESS) { dumpString += " Set Zoom Ratio:[" - + std::to_string(item.data.f[0]) + + to_string(item.data.f[0]) + "]:\n"; } } -void HCameraService::CameraDumpFlash(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpFlash(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -764,7 +782,7 @@ void HCameraService::CameraDumpFlash(common_metadata_header_t* metadataEntry, st ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FLASH_MODES, &item); if (ret == CAM_META_SUCCESS) { for (uint32_t i = 0; i < item.count; i++) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraFlashMode.find(item.data.u8[i]); if (iter != g_cameraFlashMode.end()) { dumpString += " " + iter->second; @@ -775,7 +793,7 @@ void HCameraService::CameraDumpFlash(common_metadata_header_t* metadataEntry, st ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_CONTROL_FLASH_MODE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraFlashMode.find(item.data.u8[0]); if (iter != g_cameraFlashMode.end()) { dumpString += " Set Flash Mode:[" @@ -785,7 +803,7 @@ void HCameraService::CameraDumpFlash(common_metadata_header_t* metadataEntry, st } } -void HCameraService::CameraDumpAF(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpAF(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -795,7 +813,7 @@ void HCameraService::CameraDumpAF(common_metadata_header_t* metadataEntry, std:: ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FOCUS_MODES, &item); if (ret == CAM_META_SUCCESS) { for (uint32_t i = 0; i < item.count; i++) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraFocusMode.find(item.data.u8[i]); if (iter != g_cameraFocusMode.end()) { dumpString += " " + iter->second; @@ -806,7 +824,7 @@ void HCameraService::CameraDumpAF(common_metadata_header_t* metadataEntry, std:: ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_CONTROL_FOCUS_MODE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraFocusMode.find(item.data.u8[0]); if (iter != g_cameraFocusMode.end()) { dumpString += " Set Focus Mode:[" @@ -816,7 +834,7 @@ void HCameraService::CameraDumpAF(common_metadata_header_t* metadataEntry, std:: } } -void HCameraService::CameraDumpAE(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpAE(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -826,7 +844,7 @@ void HCameraService::CameraDumpAE(common_metadata_header_t* metadataEntry, std:: ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_EXPOSURE_MODES, &item); if (ret == CAM_META_SUCCESS) { for (uint32_t i = 0; i < item.count; i++) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraExposureMode.find(item.data.u8[i]); if (iter != g_cameraExposureMode.end()) { dumpString += " " + iter->second; @@ -837,7 +855,7 @@ void HCameraService::CameraDumpAE(common_metadata_header_t* metadataEntry, std:: ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_CONTROL_EXPOSURE_MODE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraExposureMode.find(item.data.u8[0]); if (iter != g_cameraExposureMode.end()) { dumpString += " Set exposure Mode:[" @@ -847,7 +865,7 @@ void HCameraService::CameraDumpAE(common_metadata_header_t* metadataEntry, std:: } } -void HCameraService::CameraDumpSensorInfo(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpSensorInfo(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -859,15 +877,15 @@ void HCameraService::CameraDumpSensorInfo(common_metadata_header_t* metadataEntr ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &item); if (ret == CAM_META_SUCCESS) { dumpString += " Array:[" - + std::to_string(item.data.i32[leftIndex]) + " " - + std::to_string(item.data.i32[topIndex]) + " " - + std::to_string(item.data.i32[rightIndex]) + " " - + std::to_string(item.data.i32[bottomIndex]) + + to_string(item.data.i32[leftIndex]) + " " + + to_string(item.data.i32[topIndex]) + " " + + to_string(item.data.i32[rightIndex]) + " " + + to_string(item.data.i32[bottomIndex]) + "]:\n"; } } -void HCameraService::CameraDumpVideoStabilization(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpVideoStabilization(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; @@ -877,7 +895,7 @@ void HCameraService::CameraDumpVideoStabilization(common_metadata_header_t* meta ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &item); if (ret == CAM_META_SUCCESS) { for (uint32_t i = 0; i < item.count; i++) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraVideoStabilizationMode.find(item.data.u8[i]); if (iter != g_cameraVideoStabilizationMode.end()) { dumpString += " " + iter->second; @@ -888,7 +906,7 @@ void HCameraService::CameraDumpVideoStabilization(common_metadata_header_t* meta ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraVideoStabilizationMode.find(item.data.u8[0]); if (iter != g_cameraVideoStabilizationMode.end()) { dumpString += " Set Stabilization Mode:[" @@ -898,7 +916,7 @@ void HCameraService::CameraDumpVideoStabilization(common_metadata_header_t* meta } } -void HCameraService::CameraDumpVideoFrameRateRange(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpVideoFrameRateRange(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; const int32_t FRAME_RATE_RANGE_STEP = 2; @@ -909,21 +927,21 @@ void HCameraService::CameraDumpVideoFrameRateRange(common_metadata_header_t* met ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FPS_RANGES, &item); if (ret == CAM_META_SUCCESS) { for (uint32_t i = 0; i < (item.count - 1); i += FRAME_RATE_RANGE_STEP) { - dumpString += " [ " + std::to_string(item.data.i32[i]) + ", " + - std::to_string(item.data.i32[i+1]) + " ]\n"; + dumpString += " [ " + to_string(item.data.i32[i]) + ", " + + to_string(item.data.i32[i+1]) + " ]\n"; } dumpString += "\n"; } } -void HCameraService::CameraDumpPrelaunch(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpPrelaunch(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; dumpString += " ## Camera Prelaunch Related Info: \n"; ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_PRELAUNCH_AVAILABLE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraPrelaunchAvailable.find(item.data.u8[0]); if (iter != g_cameraPrelaunchAvailable.end()) { dumpString += " Available Prelaunch Info:[" @@ -933,14 +951,14 @@ void HCameraService::CameraDumpPrelaunch(common_metadata_header_t* metadataEntry } } -void HCameraService::CameraDumpThumbnail(common_metadata_header_t* metadataEntry, std::string& dumpString) +void HCameraService::CameraDumpThumbnail(common_metadata_header_t* metadataEntry, string& dumpString) { camera_metadata_item_t item; int ret; dumpString += " ## Camera Thumbnail Related Info: \n"; ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE, &item); if (ret == CAM_META_SUCCESS) { - std::map::const_iterator iter = + map::const_iterator iter = g_cameraQuickThumbnailAvailable.find(item.data.u8[0]); if (iter != g_cameraQuickThumbnailAvailable.end()) { dumpString += " Available Thumbnail Info:[" @@ -950,20 +968,20 @@ void HCameraService::CameraDumpThumbnail(common_metadata_header_t* metadataEntry } } -int32_t HCameraService::Dump(int fd, const std::vector& args) +int32_t HCameraService::Dump(int fd, const vector& args) { - std::unordered_set argSets; - std::u16string arg1(u"summary"); - std::u16string arg2(u"ability"); - std::u16string arg3(u"clientwiseinfo"); + unordered_set argSets; + u16string arg1(u"summary"); + u16string arg2(u"ability"); + u16string arg3(u"clientwiseinfo"); for (decltype(args.size()) index = 0; index < args.size(); ++index) { argSets.insert(args[index]); } - std::string dumpString; - std::vector cameraIds; - std::vector> cameraAbilityList; + string dumpString; + vector cameraIds; + vector> cameraAbilityList; int32_t capIdx = 0; - std::shared_ptr metadata; + shared_ptr metadata; int ret; ret = GetCameras(cameraIds, cameraAbilityList); -- Gitee