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 481d992a5dbf97ddb6eb2da03a285bb214c0bab4..5ecbb5b1924adeb7c967eba80740967d3d9768dd 100644 --- a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp @@ -21,6 +21,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 "camera_output_capability.h" #include "image_napi.h" #include "image_receiver.h" @@ -1053,7 +1054,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, @@ -2160,5 +2163,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 063765816ba567c2ebecabe1c1a69cfcfc3b2e32..d54ed95d28d649162ed7b419a95615abf393caaf 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" @@ -623,6 +624,67 @@ int32_t PhotoOutput::IsDeferredImageDeliveryEnabled(DeferredDeliveryImageType ty return isEnabled; } +int32_t PhotoOutput::IsAutoHighQualityPhotoSupported(int32_t &isAutoHighQualityPhotoSupported) +{ + MEDIA_INFO_LOG("PhotoOutput IsAutoHighQualityPhotoSupported is called"); + 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 CAMERA_OK; +} + +int32_t PhotoOutput::EnableAutoHighQualityPhoto(bool enabled) +{ + 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; + } + 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; +} + 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 2b36db039ba058055523e8b01e0dd9649b91e04f..6b4a18cbdcdb83d7aedd0718ee11b08bfc04ba42 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -3751,6 +3751,37 @@ void CaptureSession::SetUserId() } } +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 (res != CameraErrorCode::SUCCESS) { + MEDIA_DEBUG_LOG("CaptureSession::EnableAutoHighQualityPhoto Failed"); + } + return res; +} + void CaptureSession::ExecuteAbilityChangeCallback() { std::lock_guard lock(sessionCallbackMutex_); 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 884bf976b643762d97d1e3fe3c29cc3b254e2d29..23c480d1ee2f652db208f1f7e831936a8d9f5f97 100644 --- a/interfaces/inner_api/native/camera/include/output/photo_output.h +++ b/interfaces/inner_api/native/camera/include/output/photo_output.h @@ -330,6 +330,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(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 ddd65d2e23c9297b11cced01fd12e20df985edb7..faf7443fe73191184025390800efe7f71f11fc0c 100644 --- a/interfaces/inner_api/native/camera/include/session/capture_session.h +++ b/interfaces/inner_api/native/camera/include/session/capture_session.h @@ -1049,6 +1049,9 @@ public: void EnableDeferredType(DeferredDeliveryImageType deferredType); void SetUserId(); bool IsImageDeferred(); + + int32_t EnableAutoHighQualityPhoto(bool enabled); + protected: std::shared_ptr changedMetadata_; Profile photoProfile_; 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 bad433eb6f457af2a07bf751f615e2420e6a4797..337305b54d4167484f66f3a40093d01ab01345f7 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 @@ -250,6 +250,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);