From 3523f811131772e02451738570491ab146b1d92b Mon Sep 17 00:00:00 2001 From: cold Date: Fri, 12 Apr 2024 14:54:40 +0800 Subject: [PATCH 1/5] add auto high quality photo Signed-off-by: cold --- .../native/camera/src/output/photo_output.cpp | 54 +++++++++++++++++++ .../camera/src/session/capture_session.cpp | 31 +++++++++++ .../camera/include/output/photo_output.h | 14 +++++ .../camera/include/session/capture_session.h | 3 ++ 4 files changed, 102 insertions(+) diff --git a/frameworks/native/camera/src/output/photo_output.cpp b/frameworks/native/camera/src/output/photo_output.cpp index 89ebf9a3f..99cfa56e0 100644 --- a/frameworks/native/camera/src/output/photo_output.cpp +++ b/frameworks/native/camera/src/output/photo_output.cpp @@ -19,6 +19,7 @@ #include "camera_log.h" #include "camera_util.h" +#include "capture_scene_const.h" #include "hstream_capture_callback_stub.h" #include "input/camera_device.h" #include "session/capture_session.h" @@ -593,6 +594,59 @@ int32_t PhotoOutput::IsDeferredImageDeliveryEnabled(DeferredDeliveryImageType ty return isEnabled; } +int32_t PhotoOutput::IsAutoHighQualityPhotoSupported() +{ + int32_t isAutoHighQualityPhotoSupported = -1; + camera_metadata_item_t item; + sptr cameraObj; + auto captureSession = GetSession(); + if ((captureSession == nullptr) || (captureSession->inputDevice_ == nullptr)) { + MEDIA_ERR_LOG("PhotoOutput IsAutoHighQualityPhotoSupported error!, captureSession or inputDevice_ is nullptr"); + return SESSION_NOT_RUNNING; + } + cameraObj = captureSession->inputDevice_->GetCameraDeviceInfo(); + if (cameraObj == nullptr) { + MEDIA_ERR_LOG("PhotoOutput IsAutoHighQualityPhotoSupported error!, cameraObj is nullptr"); + return SESSION_NOT_RUNNING; + } + std::shared_ptr metadata = cameraObj->GetMetadata(); + if (metadata == nullptr) { + return SESSION_NOT_RUNNING; + } + int32_t ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_HIGH_QUALITY_SUPPORT, &item); + if (ret == CAM_META_SUCCESS) { + isAutoHighQualityPhotoSupported = (item.data.u8[1] == 1) ? 0 : -1; // default mode + } + + int headLenPerMode = 2; + SceneMode currentSceneMode = captureSession->GetMode(); + for (int i = 0; i < static_cast(item.count); i += headLenPerMode) { + if (currentSceneMode == static_cast(item.data.u8[i])) { + isAutoHighQualityPhotoSupported = (item.data.u8[i + 1] == 1) ? 0 : -1; + } + } + MEDIA_INFO_LOG("PhotoOutput IsAutoHighQualityPhotoSupported curMode:%{public}d, modeSupportType:%{public}d", + currentSceneMode, isAutoHighQualityPhotoSupported); + return isAutoHighQualityPhotoSupported; +} + +int32_t PhotoOutput::EnableAutoHighQualityPhoto(bool enabled) +{ + MEDIA_DEBUG_LOG("CaptureSession::EnableAutoHighQualityPhoto"); + auto captureSession = GetSession(); + if ((captureSession == nullptr) || (captureSession->inputDevice_ == nullptr)) { + MEDIA_ERR_LOG("PhotoOutput IsAutoHighQualityPhotoSupported error!, captureSession or inputDevice_ is nullptr"); + return SESSION_NOT_RUNNING; + } + if ((!IsAutoHighQualityPhotoSupported()) { + MEDIA_ERR_LOG("CaptureSession::EnableAutoHighQualityPhoto not supported"); + return INVALID_ARGUMENT; + } + + int32_t res = captureSession->EnableAutoHighQualityPhoto(enabled); + return res; +} + void PhotoOutput::ProcessSnapshotDurationUpdates(int32_t snapshotDuration) { if (GetApplicationCallback() != nullptr) { diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 22e601f58..24cced6d1 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -3565,5 +3565,36 @@ void CaptureSession::SetUserId() MEDIA_DEBUG_LOG("CaptureSession::SetUserId Failed"); } } + +int32_t CaptureSession::EnableAutoHighQualityPhoto(bool enabled) +{ + MEDIA_INFO_LOG("CaptureSession::EnableAutoHighQualityPhoto enabled:%{public}d", enabled); + + this->LockForControl(); + if (changedMetadata_ == nullptr) { + MEDIA_ERR_LOG("CaptureSession::EnableAutoHighQualityPhoto changedMetadata_ is NULL"); + return INVALID_ARGUMENT; + } + + int32_t res = CameraErrorCode::SUCCESS; + bool status = false; + camera_metadata_item_t item; + uint8_t hightQualityEnable = static_cast(enabled); + int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_HIGH_QUALITY_MODE, &item); + if (ret == CAM_META_ITEM_NOT_FOUND) { + status = changedMetadata_->addEntry(OHOS_CONTROL_HIGH_QUALITY_MODE, &hightQualityEnable, 1); + } else if (ret == CAM_META_SUCCESS) { + status = changedMetadata_->updateEntry(OHOS_CONTROL_HIGH_QUALITY_MODE, &hightQualityEnable, 1); + } + if (!status) { + MEDIA_ERR_LOG("CaptureSession::EnableAutoHighQualityPhoto Failed to set type!"); + res = INVALID_ARGUMENT + } + res = this->UnlockForControl(); + if (errCode != CameraErrorCode::SUCCESS) { + MEDIA_DEBUG_LOG("CaptureSession::EnableAutoHighQualityPhoto Failed"); + } + return res; +} } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/output/photo_output.h b/interfaces/inner_api/native/camera/include/output/photo_output.h index 7f6daf2ac..bc499ba7b 100644 --- a/interfaces/inner_api/native/camera/include/output/photo_output.h +++ b/interfaces/inner_api/native/camera/include/output/photo_output.h @@ -323,6 +323,20 @@ public: int32_t IsDeferredImageDeliveryEnabled(DeferredDeliveryImageType type); void ProcessSnapshotDurationUpdates(int32_t snapshotDuration); + + /** + * @brief To check the auto high quality photo is supported or not. + * + * @return Returns true/false if the auto high quality photo is supported/not-supported respectively. + */ + int32_t IsAutoHighQualityPhotoSupported(); + + /** + * @brief To enable the auto high quality photo. + * + * @return Returns the result of the auto high quality photo enable. + */ + int32_t EnableAutoHighQualityPhoto(bool enabled); /** * @brief Get default photo capture setting. 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 f2c0f606f..339894a32 100644 --- a/interfaces/inner_api/native/camera/include/session/capture_session.h +++ b/interfaces/inner_api/native/camera/include/session/capture_session.h @@ -988,6 +988,9 @@ public: void EnableDeferredType(DeferredDeliveryImageType deferredType); void SetUserId(); bool IsImageDeferred(); + + int32_t EnableAutoHighQualityPhoto(bool enabled); + protected: std::shared_ptr changedMetadata_; Profile photoProfile_; -- Gitee From 85f0f49de10847852eb27f935a19679b3955cb97 Mon Sep 17 00:00:00 2001 From: cold Date: Mon, 15 Apr 2024 22:18:12 +0800 Subject: [PATCH 2/5] auto high quality Signed-off-by: cold --- .../src/output/photo_output_napi.cpp | 64 ++++++++++++++++++- .../native/camera/src/output/photo_output.cpp | 22 +++++-- .../camera/include/output/photo_output.h | 2 +- .../include/output/photo_output_napi.h | 2 + 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp index 9ff5b4a60..7fa3f85dd 100644 --- a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp @@ -20,6 +20,7 @@ #include "camera_napi_security_utils.h" #include "camera_napi_template_utils.h" #include "camera_napi_utils.h" +#include "camera_napi_param_parser.h" #include "image_napi.h" #include "image_receiver.h" #include "pixel_map_napi.h" @@ -903,7 +904,9 @@ napi_value PhotoOutputNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("deferImageDelivery", DeferImageDeliveryFor), DECLARE_NAPI_FUNCTION("deferImageDeliveryFor", DeferImageDeliveryFor), DECLARE_NAPI_FUNCTION("isDeferredImageDeliverySupported", IsDeferredImageDeliverySupported), - DECLARE_NAPI_FUNCTION("isDeferredImageDeliveryEnabled", IsDeferredImageDeliveryEnabled) + DECLARE_NAPI_FUNCTION("isDeferredImageDeliveryEnabled", IsDeferredImageDeliveryEnabled), + DECLARE_NAPI_FUNCTION("isAutoHighQualityPhotoSupported", IsAutoHighQualityPhotoSupported), + DECLARE_NAPI_FUNCTION("enableAutoHighQualityPhoto", EnableAutoHighQualityPhoto) }; status = napi_define_class(env, CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, PhotoOutputNapiConstructor, @@ -1977,5 +1980,64 @@ napi_value PhotoOutputNapi::Off(napi_env env, napi_callback_info info) { return ListenerTemplate::Off(env, info); } + +napi_value PhotoOutputNapi::IsAutoHighQualityPhotoSupported(napi_env env, napi_callback_info info) +{ + auto result = CameraNapiUtils::GetUndefinedValue(env); + if (!CameraNapiSecurity::CheckSystemApp(env)) { + MEDIA_ERR_LOG("SystemApi IsAutoHighQualityPhotoSupported is called!"); + return result; + } + MEDIA_DEBUG_LOG("PhotoOutputNapi::IsAutoHighQualityPhotoSupported is called"); + PhotoOutputNapi* photoOutputNapi = nullptr; + CameraNapiParamParser jsParamParser(env, info, photoOutputNapi); + if (!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error")) { + MEDIA_ERR_LOG("PhotoOutputNapi::IsAutoHighQualityPhotoSupported parse parameter occur error"); + return result; + } + if (photoOutputNapi->photoOutput_ == nullptr) { + MEDIA_ERR_LOG("PhotoOutputNapi::IsAutoHighQualityPhotoSupported get native object fail"); + CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail"); + return result; + } + + int32_t isAutoHighQualityPhotoSupported; + int32_t retCode = photoOutputNapi->photoOutput_->IsAutoHighQualityPhotoSupported(isAutoHighQualityPhotoSupported); + if (retCode == 0 && isAutoHighQualityPhotoSupported != -1) { + napi_get_boolean(env, true, &result); + return result; + } + MEDIA_ERR_LOG("PhotoOutputNapi::IsAutoHighQualityPhotoSupported is not supported"); + napi_get_boolean(env, false, &result); + return result; +} + +napi_value PhotoOutputNapi::EnableAutoHighQualityPhoto(napi_env env, napi_callback_info info) +{ + auto result = CameraNapiUtils::GetUndefinedValue(env); + if (!CameraNapiSecurity::CheckSystemApp(env)) { + MEDIA_ERR_LOG("SystemApi EnableAutoHighQualityPhoto is called!"); + return result; + } + MEDIA_DEBUG_LOG("PhotoOutputNapi::EnableAutoHighQualityPhoto is called"); + PhotoOutputNapi* photoOutputNapi = nullptr; + bool isEnable; + CameraNapiParamParser jsParamParser(env, info, photoOutputNapi, isEnable); + if (!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error")) { + MEDIA_ERR_LOG("PhotoOutputNapi::EnableAutoHighQualityPhoto parse parameter occur error"); + return result; + } + if (photoOutputNapi->photoOutput_ == nullptr) { + MEDIA_ERR_LOG("PhotoOutputNapi::EnableAutoHighQualityPhoto get native object fail"); + CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail"); + return result; + } + + int32_t retCode = photoOutputNapi->photoOutput_->EnableAutoHighQualityPhoto(isEnable); + if (CameraNapiUtils::CheckError(env, retCode)) { + MEDIA_ERR_LOG("PhotoOutputNapi::EnableAutoHighQualityPhoto fail %{public}d", retCode); + } + return result; +} } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/src/output/photo_output.cpp b/frameworks/native/camera/src/output/photo_output.cpp index 99cfa56e0..234ad5211 100644 --- a/frameworks/native/camera/src/output/photo_output.cpp +++ b/frameworks/native/camera/src/output/photo_output.cpp @@ -594,9 +594,10 @@ int32_t PhotoOutput::IsDeferredImageDeliveryEnabled(DeferredDeliveryImageType ty return isEnabled; } -int32_t PhotoOutput::IsAutoHighQualityPhotoSupported() +int32_t PhotoOutput::IsAutoHighQualityPhotoSupported(int32_t &isAutoHighQualityPhotoSupported) { - int32_t isAutoHighQualityPhotoSupported = -1; + MEDIA_INFO_LOG("PhotoOutput IsAutoHighQualityPhotoSupported is called"); + isAutoHighQualityPhotoSupported = -1; camera_metadata_item_t item; sptr cameraObj; auto captureSession = GetSession(); @@ -627,21 +628,28 @@ int32_t PhotoOutput::IsAutoHighQualityPhotoSupported() } MEDIA_INFO_LOG("PhotoOutput IsAutoHighQualityPhotoSupported curMode:%{public}d, modeSupportType:%{public}d", currentSceneMode, isAutoHighQualityPhotoSupported); - return isAutoHighQualityPhotoSupported; + return CAMERA_OK; } int32_t PhotoOutput::EnableAutoHighQualityPhoto(bool enabled) { - MEDIA_DEBUG_LOG("CaptureSession::EnableAutoHighQualityPhoto"); + MEDIA_DEBUG_LOG("PhotoOutput EnableAutoHighQualityPhoto"); auto captureSession = GetSession(); if ((captureSession == nullptr) || (captureSession->inputDevice_ == nullptr)) { MEDIA_ERR_LOG("PhotoOutput IsAutoHighQualityPhotoSupported error!, captureSession or inputDevice_ is nullptr"); return SESSION_NOT_RUNNING; } - if ((!IsAutoHighQualityPhotoSupported()) { - MEDIA_ERR_LOG("CaptureSession::EnableAutoHighQualityPhoto not supported"); - return INVALID_ARGUMENT; + int32_t isAutoHighQualityPhotoSupported; + int32_t ret = IsAutoHighQualityPhotoSupported(isAutoHighQualityPhotoSupported); + if (ret != CAMERA_OK) { + MEDIA_ERR_LOG("PhotoOutput EnableAutoHighQualityPhoto error"); + return OPERATION_NOT_ALLOWED; } + + if (isAutoHighQualityPhotoSupported == -1) { + MEDIA_ERR_LOG("PhotoOutput EnableAutoHighQualityPhoto not supported"); + return INVALID_ARGUMENT; + } int32_t res = captureSession->EnableAutoHighQualityPhoto(enabled); return res; diff --git a/interfaces/inner_api/native/camera/include/output/photo_output.h b/interfaces/inner_api/native/camera/include/output/photo_output.h index bc499ba7b..804c36eea 100644 --- a/interfaces/inner_api/native/camera/include/output/photo_output.h +++ b/interfaces/inner_api/native/camera/include/output/photo_output.h @@ -329,7 +329,7 @@ public: * * @return Returns true/false if the auto high quality photo is supported/not-supported respectively. */ - int32_t IsAutoHighQualityPhotoSupported(); + int32_t IsAutoHighQualityPhotoSupported(int32_t &isAutoHighQualityPhotoSupported); /** * @brief To enable the auto high quality photo. diff --git a/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h b/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h index f4b3a5a98..72c0dd942 100644 --- a/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h +++ b/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h @@ -219,6 +219,8 @@ public: 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 Off(napi_env env, napi_callback_info info); + static napi_value IsAutoHighQualityPhotoSupported(napi_env env, napi_callback_info info); + static napi_value EnableAutoHighQualityPhoto(napi_env env, napi_callback_info info); static int32_t MapQualityLevelFromJs(int32_t jsQuality, PhotoCaptureSetting::QualityLevel& nativeQuality); static int32_t MapImageRotationFromJs(int32_t jsRotation, PhotoCaptureSetting::RotationConfig& nativeRotation); -- Gitee From e7bb1e2a403a4cd47dab00454ce4fe79130fc5e9 Mon Sep 17 00:00:00 2001 From: cold Date: Sun, 28 Apr 2024 10:38:54 +0000 Subject: [PATCH 3/5] update frameworks/native/camera/src/session/capture_session.cpp. fix Signed-off-by: cold --- frameworks/native/camera/src/session/capture_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index d44e32aa6..0a64e93b7 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -3803,4 +3803,4 @@ std::shared_ptr CaptureSession::GetMetadata() return inputDevice_->GetCameraDeviceInfo()->GetMetadata(); } } // CameraStandard -} // OHOS +} // OHOS \ No newline at end of file -- Gitee From 00a11cdcd02c98a609fbb710bfe33b909fc3f7e6 Mon Sep 17 00:00:00 2001 From: cold Date: Sun, 28 Apr 2024 12:05:47 +0000 Subject: [PATCH 4/5] update frameworks/native/camera/src/session/capture_session.cpp. fix bug Signed-off-by: cold --- frameworks/native/camera/src/session/capture_session.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 0a64e93b7..6b4a18cbd 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -3773,10 +3773,10 @@ int32_t CaptureSession::EnableAutoHighQualityPhoto(bool enabled) } if (!status) { MEDIA_ERR_LOG("CaptureSession::EnableAutoHighQualityPhoto Failed to set type!"); - res = INVALID_ARGUMENT + res = INVALID_ARGUMENT; } res = this->UnlockForControl(); - if (errCode != CameraErrorCode::SUCCESS) { + if (res != CameraErrorCode::SUCCESS) { MEDIA_DEBUG_LOG("CaptureSession::EnableAutoHighQualityPhoto Failed"); } return res; -- Gitee From 16b4fec927aa6b3b947539a5d40f14783636d37d Mon Sep 17 00:00:00 2001 From: cold Date: Sun, 28 Apr 2024 12:08:35 +0000 Subject: [PATCH 5/5] update frameworks/native/camera/src/output/photo_output.cpp. fix codex Signed-off-by: cold --- frameworks/native/camera/src/output/photo_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/camera/src/output/photo_output.cpp b/frameworks/native/camera/src/output/photo_output.cpp index 4b240a601..d54ed95d2 100644 --- a/frameworks/native/camera/src/output/photo_output.cpp +++ b/frameworks/native/camera/src/output/photo_output.cpp @@ -679,7 +679,7 @@ int32_t PhotoOutput::EnableAutoHighQualityPhoto(bool enabled) if (isAutoHighQualityPhotoSupported == -1) { MEDIA_ERR_LOG("PhotoOutput EnableAutoHighQualityPhoto not supported"); return INVALID_ARGUMENT; - } + } int32_t res = captureSession->EnableAutoHighQualityPhoto(enabled); return res; -- Gitee