diff --git a/common/utils/camera_log.h b/common/utils/camera_log.h index 176e2265dce25e2631115a7f0c6a3742778e7fdf..54dc13ee7a3f35be9bfdce3c118b878d17819084 100644 --- a/common/utils/camera_log.h +++ b/common/utils/camera_log.h @@ -138,6 +138,200 @@ } \ } while (0) +#define CHECK_BREAK(cond) \ + if (1) { \ + if (cond) { \ + break; \ + } \ + } else \ + void(0) + +#define CHECK_CONTINUE(cond) \ + if (1) { \ + if (cond) { \ + continue; \ + } \ + } else \ + void(0) + +#define CHECK_RETURN(cond) \ + do { \ + if (cond) { \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_RET(cond, ret) \ + do { \ + if (cond) { \ + return ret; \ + } \ + } while (0) + +#define CHECK_PRINT_ELOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define CHECK_PRINT_WLOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define CHECK_PRINT_ILOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_INFO_LOG(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define CHECK_PRINT_DLOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_DEBUG_LOG(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define CHECK_RETURN_ELOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_WLOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_ILOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_INFO_LOG(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_DLOG(cond, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_DEBUG_LOG(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_RETURN_RET_ELOG(cond, ret, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ + return ret; \ + } \ + } while (0) + +#define CHECK_RETURN_RET_WLOG(cond, ret, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ + return ret; \ + } \ + } while (0) + +#define CHECK_RETURN_RET_ILOG(cond, ret, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_INFO_LOG(fmt, ##__VA_ARGS__); \ + return ret; \ + } \ + } while (0) + +#define CHECK_RETURN_RET_DLOG(cond, ret, fmt, ...) \ + do { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_DEBUG_LOG(fmt, ##__VA_ARGS__); \ + return ret; \ + } \ + } while (0) + +#define CHECK_BREAK_ELOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ + break; \ + } \ + } else \ + void(0) + +#define CHECK_BREAK_WLOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ + break; \ + } \ + } else \ + void(0) + +#define CHECK_BREAK_ILOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_INFO_LOG(fmt, ##__VA_ARGS__); \ + break; \ + } \ + } else \ + void(0) + +#define CHECK_BREAK_DLOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_DEBUG_LOG(fmt, ##__VA_ARGS__); \ + break; \ + } \ + } else \ + void(0) + +#define CHECK_CONTINUE_ELOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ + continue; \ + } \ + } else \ + void(0) + +#define CHECK_CONTINUE_WLOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ + continue; \ + } \ + } else \ + void(0) + +#define CHECK_CONTINUE_ILOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_INFO_LOG(fmt, ##__VA_ARGS__); \ + continue; \ + } \ + } else \ + void(0) + +#define CHECK_CONTINUE_DLOG(cond, fmt, ...) \ + if (1) { \ + if (CAMERA_UNLIKELY(cond)) { \ + MEDIA_DEBUG_LOG(fmt, ##__VA_ARGS__); \ + continue; \ + } \ + } else \ + void(0) + #define POINTER_MASK 0x00FFFFFF #define CAMERA_SYNC_TRACE HITRACE_METER_NAME(HITRACE_TAG_ZCAMERA, __PRETTY_FUNCTION__) diff --git a/frameworks/cj/camera/include/camera_utils.h b/frameworks/cj/camera/include/camera_utils.h index 9c5876b8819ab972b99fc6db894a915b92f4d6f3..807e9c2f95857e7260564fd605e200ddf9df9abe 100644 --- a/frameworks/cj/camera/include/camera_utils.h +++ b/frameworks/cj/camera/include/camera_utils.h @@ -168,7 +168,7 @@ struct CArrCJMetadataObject { int64_t size; }; -enum OutputType { METADATA_OUTPUT = 0, PHOTO_OUTPUT, PREVIEW_OUTPUT, VIDEO_OUTPUT }; +enum CJOutputType { METADATA_OUTPUT = 0, PHOTO_OUTPUT, PREVIEW_OUTPUT, VIDEO_OUTPUT }; CJMetadataObject MetadataObjectToCJMetadataObject(MetadataObject metaObject); diff --git a/frameworks/native/camera/src/output/metadata_output.cpp b/frameworks/native/camera/src/output/metadata_output.cpp index 707e5f4b6b5b9d475a7d9065f60417c071354079..006faed8d4a9fca0c80eec71b61cb62f0ae84a42 100644 --- a/frameworks/native/camera/src/output/metadata_output.cpp +++ b/frameworks/native/camera/src/output/metadata_output.cpp @@ -33,18 +33,6 @@ namespace CameraStandard { sptr MetadataObjectFactory::metaFactoryInstance_; std::mutex MetadataObjectFactory::instanceMutex_; -const std::unordered_map g_HALResultToFwCameraMetaDetect_ = { - {OHOS_STATISTICS_DETECT_HUMAN_FACE_INFOS, MetadataObjectType::FACE}, - {OHOS_STATISTICS_DETECT_HUMAN_BODY_INFOS, MetadataObjectType::HUMAN_BODY}, - {OHOS_STATISTICS_DETECT_CAT_FACE_INFOS, MetadataObjectType::CAT_FACE}, - {OHOS_STATISTICS_DETECT_CAT_BODY_INFOS, MetadataObjectType::CAT_BODY}, - {OHOS_STATISTICS_DETECT_DOG_FACE_INFOS, MetadataObjectType::DOG_FACE}, - {OHOS_STATISTICS_DETECT_DOG_BODY_INFOS, MetadataObjectType::DOG_BODY}, - {OHOS_STATISTICS_DETECT_SALIENT_INFOS, MetadataObjectType::SALIENT_DETECTION}, - {OHOS_STATISTICS_DETECT_BAR_CODE_INFOS, MetadataObjectType::BAR_CODE_DETECTION}, - {OHOS_STATISTICS_DETECT_BASE_FACE_INFO, MetadataObjectType::BASE_FACE_DETECTION}, -}; - MetadataObject::MetadataObject(const MetadataObjectType type, const int32_t timestamp, const Rect rect, const int32_t objectId, const int32_t confidence) : type_(type), @@ -357,7 +345,8 @@ void MetadataOutput::ProcessMetadata(const int32_t streamId, const std::shared_ptr &result, std::vector> &metaObjects, bool isNeedMirror, bool isNeedFlip) { - bool ret = MetadataCommonUtils::ProcessMetaObjects(streamId, result, metaObjects, isNeedMirror, isNeedFlip); + bool ret = MetadataCommonUtils::ProcessMetaObjects(streamId, result, metaObjects, isNeedMirror, + isNeedFlip, RectBoxType::RECT_CAMERA); if (ret) { reportFaceResults_ = true; return; diff --git a/frameworks/native/camera/src/session/mech_session.cpp b/frameworks/native/camera/src/session/mech_session.cpp index 48756a9f45a28d4b82d7d6497409b103c487ba7c..00d4bf078d044c0ce341417c52221474281ec11b 100644 --- a/frameworks/native/camera/src/session/mech_session.cpp +++ b/frameworks/native/camera/src/session/mech_session.cpp @@ -22,16 +22,18 @@ namespace OHOS { namespace CameraStandard { constexpr int32_t FOCUS_TRACKING_REGION_DATA_CNT = 4; +constexpr int32_t LOG_INTERVAL_FREQUENCY = 10; int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr& result) { MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; + CHECK_RETURN_RET(result == nullptr, ret); auto mechSession = mechSession_.promote(); - CHECK_ERROR_RETURN_RET(!mechSession, ret); + CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); - CHECK_ERROR_RETURN_RET(!appCallback, ret); + CHECK_RETURN_RET(!appCallback, ret); FocusTrackingMetaInfo info; FocusTrackingMode mode = FOCUS_TRACKING_MODE_AUTO; @@ -44,7 +46,8 @@ int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNe ProcessRectInfo(result, region); info.SetTrackingRegion(region); - MetadataCommonUtils::ProcessMetaObjects(streamId, result, metaObjects, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessMetaObjects(streamId, result, metaObjects, isNeedMirror, isNeedFlip, + RectBoxType::RECT_MECH); info.SetDetectedObjects(metaObjects); camera_metadata_item_t item; @@ -52,20 +55,53 @@ int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNe if (ret == CAM_META_SUCCESS && item.count > 0) { info.SetTrackingObjectId(item.data.i32[0]); } + PrintFocusTrackingInfo(info); appCallback->OnFocusTrackingInfo(info); return ret; } -int32_t MechSessionCallbackImpl::OnCameraAppInfo(const std::vector& cameraAppInfos) +int32_t MechSessionCallbackImpl::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; auto mechSession = mechSession_.promote(); - CHECK_ERROR_RETURN_RET(!mechSession, ret); + CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); - CHECK_ERROR_RETURN_RET(!appCallback, ret); + CHECK_RETURN_RET(!appCallback, ret); + PrintCaptureSessionInfo(captureSessionInfo); + appCallback->OnCaptureSessionConfiged(captureSessionInfo); + return CAMERA_OK; +} - appCallback->OnCameraAppInfo(cameraAppInfos); +int32_t MechSessionCallbackImpl::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) +{ + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); + int32_t ret = CAMERA_OK; + auto mechSession = mechSession_.promote(); + CHECK_RETURN_RET(!mechSession, ret); + auto appCallback = mechSession->GetCallback(); + CHECK_RETURN_RET(!appCallback, ret); + MEDIA_INFO_LOG("%{public}s sessionid:%{public}d, zoomValue:%{public}f," + "equivalentFocus:%{public}d, focusStatus:%{public}d," + "focusMode:%{public}d, videoStabilizationMode:%{public}d", + __FUNCTION__, sessionid, zoomInfo.zoomValue, + zoomInfo.equivalentFocus, zoomInfo.focusStatus, + zoomInfo.focusMode, zoomInfo.videoStabilizationMode); + appCallback->OnZoomInfoChange(sessionid, zoomInfo); + return CAMERA_OK; +} + +int32_t MechSessionCallbackImpl::OnSessionStatusChange(int32_t sessionid, bool status) +{ + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); + int32_t ret = CAMERA_OK; + auto mechSession = mechSession_.promote(); + CHECK_RETURN_RET(!mechSession, ret); + auto appCallback = mechSession->GetCallback(); + CHECK_RETURN_RET(!appCallback, ret); + MEDIA_INFO_LOG("%{public}s sessionid:%{public}d, status:%{public}d", + __FUNCTION__, sessionid, status); + appCallback->OnSessionStatusChange(sessionid, status); return CAMERA_OK; } @@ -76,8 +112,8 @@ bool MechSessionCallbackImpl::ProcessRectInfo(const std::shared_ptrget(), OHOS_ABILITY_FOCUS_TRACKING_REGION, &item); if (ret != CAM_META_SUCCESS || item.count < FOCUS_TRACKING_REGION_DATA_CNT) { @@ -98,13 +134,69 @@ bool MechSessionCallbackImpl::ProcessRectInfo(const std::shared_ptr(detectedObjects.size())); + for (size_t i = 0; i < detectedObjects.size(); i++) { + auto metadataObject = detectedObjects[i]; + auto type = metadataObject->GetType(); + auto box = metadataObject->GetBoundingBox(); + int32_t objectId = metadataObject->GetObjectId(); + int32_t confidence = metadataObject->GetConfidence(); + MEDIA_INFO_LOG("OnFocusTrackingInfo detectedObject type:%{public}d, " + "boundingBox:[%{public}f, %{public}f, %{public}f, %{public}f], " + "objectId:%{public}d, confidence:%{public}d", + type, box.topLeftX, box.topLeftY, + box.width, box.height, objectId, confidence); + } +} + +void MechSessionCallbackImpl::PrintCaptureSessionInfo(const CaptureSessionInfo& captureSessionInfo) +{ + MEDIA_INFO_LOG("OnCaptureSessionConfiged sessionId:%{public}d, " + "cameraId:%{public}s, position:%{public}d, sessionMode:%{public}d, " + "colorSpace:%{public}d, sessionStatus:%{public}d", + captureSessionInfo.sessionId, captureSessionInfo.cameraId.c_str(), + captureSessionInfo.position, captureSessionInfo.sessionMode, + captureSessionInfo.colorSpace, captureSessionInfo.sessionStatus); + + auto outputInfos = captureSessionInfo.outputInfos; + MEDIA_INFO_LOG("OnCaptureSessionConfiged outputInfos size:%{public}d", static_cast(outputInfos.size())); + for (size_t i = 0; i < outputInfos.size(); i++) { + auto outputInfo = outputInfos[i]; + MEDIA_INFO_LOG("OnCaptureSessionConfiged outputInfo type:%{public}d, " + "minfps:%{public}d, maxfps:%{public}d, width:%{public}d, " + "height:%{public}d", + outputInfo.type, outputInfo.minfps, outputInfo.minfps, + outputInfo.width, outputInfo.height); + } + + auto zoomInfo = captureSessionInfo.zoomInfo; + MEDIA_INFO_LOG("OnCaptureSessionConfiged zoomInfo zoomValue:%{public}f, " + "equivalentFocus:%{public}d, focusStatus:%{public}d, focusMode:%{public}d, " + "videoStabilizationMode:%{public}d", + zoomInfo.zoomValue, zoomInfo.equivalentFocus, zoomInfo.focusStatus, + zoomInfo.focusMode, zoomInfo.videoStabilizationMode); +} + MechSession::MechSession(sptr session) : remoteSession_(session) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); sptr object = remoteSession_->AsObject(); pid_t pid = 0; deathRecipient_ = new (std::nothrow) CameraDeathRecipient(pid); - CHECK_ERROR_RETURN_LOG(deathRecipient_ == nullptr, "failed to new CameraDeathRecipient."); + CHECK_RETURN_ELOG(deathRecipient_ == nullptr, "failed to new CameraDeathRecipient."); deathRecipient_->SetNotifyCb([this](pid_t pid) { CameraServerDied(pid); }); bool result = object->AddDeathRecipient(deathRecipient_); @@ -116,7 +208,7 @@ MechSession::MechSession(sptr session) : remoteSession_(session) MechSession::~MechSession() { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); RemoveDeathRecipient(); } @@ -124,24 +216,24 @@ int32_t MechSession::EnableMechDelivery(bool isEnableMech) { MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); auto remoteSession = GetRemoteSession(); - CHECK_ERROR_RETURN_RET_LOG(remoteSession == nullptr, CameraErrorCode::INVALID_ARGUMENT, + CHECK_RETURN_RET_ELOG(remoteSession == nullptr, CameraErrorCode::INVALID_ARGUMENT, "MechSession::EnableMechDelivery mechSession is nullptr"); int32_t retCode = remoteSession->EnableMechDelivery(isEnableMech); - CHECK_ERROR_RETURN_RET_LOG(retCode != CAMERA_OK, retCode, + CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, retCode, "Failed to EnableMechDelivery!, %{public}d", retCode); return CameraErrorCode::SUCCESS; } void MechSession::SetCallback(std::shared_ptr callback) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); std::lock_guard lock(callbackMutex_); auto remoteSession = GetRemoteSession(); - CHECK_ERROR_RETURN_LOG(remoteSession == nullptr, + CHECK_RETURN_ELOG(remoteSession == nullptr, "MechSession::SetCallback mechSession is null"); sptr remoteCallback = new(std::nothrow) MechSessionCallbackImpl(this); - CHECK_ERROR_RETURN_LOG(remoteCallback == nullptr, + CHECK_RETURN_ELOG(remoteCallback == nullptr, "MechSession::SetCallback failed to new MechSessionCallbackImpl!"); remoteSession->SetCallback(remoteCallback); @@ -156,12 +248,12 @@ std::shared_ptr MechSession::GetCallback() int32_t MechSession::Release() { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); auto remoteSession = GetRemoteSession(); - CHECK_ERROR_RETURN_RET_LOG(remoteSession == nullptr, CameraErrorCode::INVALID_ARGUMENT, + CHECK_RETURN_RET_ELOG(remoteSession == nullptr, CameraErrorCode::INVALID_ARGUMENT, "MechSession::Release remoteSession is nullptr"); int32_t retCode = remoteSession->Release(); - CHECK_ERROR_RETURN_RET_LOG(retCode != CAMERA_OK, retCode, + CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, retCode, "Failed to Release!, %{public}d", retCode); return CameraErrorCode::SUCCESS; } diff --git a/frameworks/native/camera/src/utils/metadata_common_utils.cpp b/frameworks/native/camera/src/utils/metadata_common_utils.cpp index a32f36405473654036b5d06b58f2a72a30d8b524..07294a22ad67400e496fe6f6ce4b25a43593f20f 100644 --- a/frameworks/native/camera/src/utils/metadata_common_utils.cpp +++ b/frameworks/native/camera/src/utils/metadata_common_utils.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace CameraStandard { namespace { -const std::unordered_map g_HALResultToFwCameraMetaDetect_copy = { +const std::unordered_map g_HALResultToFwCameraMetaDetect_ = { {OHOS_STATISTICS_DETECT_HUMAN_FACE_INFOS, MetadataObjectType::FACE}, {OHOS_STATISTICS_DETECT_HUMAN_BODY_INFOS, MetadataObjectType::HUMAN_BODY}, {OHOS_STATISTICS_DETECT_CAT_FACE_INFOS, MetadataObjectType::CAT_FACE}, @@ -37,7 +37,7 @@ const std::unordered_map g_HALResultToFwCameraMeta {OHOS_STATISTICS_DETECT_BASE_FACE_INFO, MetadataObjectType::BASE_FACE_DETECTION}, }; -std::vector typesOfMetadata_copy = { +std::vector g_typesOfMetadata = { OHOS_STATISTICS_DETECT_HUMAN_FACE_INFOS, OHOS_STATISTICS_DETECT_HUMAN_BODY_INFOS, OHOS_STATISTICS_DETECT_CAT_FACE_INFOS, @@ -51,6 +51,7 @@ std::vector typesOfMetadata_copy = { void FillSizeListFromStreamInfo( vector& sizeList, const StreamInfo& streamInfo, const camera_format_t targetFormat) { + // LCOV_EXCL_START for (const auto &detail : streamInfo.detailInfos) { camera_format_t hdi_format = static_cast(detail.format); if (hdi_format != targetFormat) { @@ -59,11 +60,13 @@ void FillSizeListFromStreamInfo( Size size { .width = detail.width, .height = detail.height }; sizeList.emplace_back(size); } + // LCOV_EXCL_STOP } void FillSizeListFromStreamInfo( vector& sizeList, const StreamRelatedInfo& streamInfo, const camera_format_t targetFormat) { + // LCOV_EXCL_START for (const auto &detail : streamInfo.detailInfo) { camera_format_t hdi_format = static_cast(detail.format); if (hdi_format != targetFormat) { @@ -72,15 +75,17 @@ void FillSizeListFromStreamInfo( Size size{.width = detail.width, .height = detail.height}; sizeList.emplace_back(size); } + // LCOV_EXCL_STOP } std::shared_ptr> GetSupportedPreviewSizeRangeFromProfileLevel( const int32_t modeName, camera_format_t targetFormat, const std::shared_ptr metadata) { - CHECK_ERROR_RETURN_RET(metadata == nullptr, nullptr); + // LCOV_EXCL_START + CHECK_RETURN_RET(metadata == nullptr, nullptr); camera_metadata_item_t item; int32_t retCode = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_AVAILABLE_PROFILE_LEVEL, &item); - CHECK_ERROR_RETURN_RET(retCode != CAM_META_SUCCESS || item.count == 0, nullptr); + CHECK_RETURN_RET(retCode != CAM_META_SUCCESS || item.count == 0, nullptr); std::shared_ptr> sizeList = std::make_shared>(); std::vector specInfos; ProfileLevelInfo modeInfo = {}; @@ -95,13 +100,15 @@ std::shared_ptr> GetSupportedPreviewSizeRangeFromProfileLevel( MEDIA_INFO_LOG("MetadataCommonUtils::GetSupportedPreviewSizeRangeFromProfileLevel listSize: %{public}d", static_cast(sizeList->size())); return sizeList; + // LCOV_EXCL_STOP } std::shared_ptr> GetSupportedPreviewSizeRangeFromExtendConfig( const int32_t modeName, camera_format_t targetFormat, const std::shared_ptr metadata) { + // LCOV_EXCL_START auto item = MetadataCommonUtils::GetCapabilityEntry(metadata, OHOS_ABILITY_STREAM_AVAILABLE_EXTEND_CONFIGURATIONS); - CHECK_ERROR_RETURN_RET(item == nullptr, nullptr); + CHECK_RETURN_RET(item == nullptr, nullptr); std::shared_ptr> sizeList = std::make_shared>(); ExtendInfo extendInfo = {}; @@ -129,13 +136,15 @@ std::shared_ptr> GetSupportedPreviewSizeRangeFromExtendConfig( MEDIA_INFO_LOG("MetadataCommonUtils::GetSupportedPreviewSizeRangeFromExtendConfig listSize: %{public}d", static_cast(sizeList->size())); return sizeList; + // LCOV_EXCL_STOP } std::shared_ptr> GetSupportedPreviewSizeRangeFromBasicConfig( camera_format_t targetFormat, const std::shared_ptr metadata) { + // LCOV_EXCL_START auto item = MetadataCommonUtils::GetCapabilityEntry(metadata, OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS); - CHECK_ERROR_RETURN_RET(item == nullptr, nullptr); + CHECK_RETURN_RET(item == nullptr, nullptr); std::shared_ptr> sizeList = std::make_shared>(); const uint32_t widthOffset = 1; @@ -155,22 +164,24 @@ std::shared_ptr> GetSupportedPreviewSizeRangeFromBasicConfig( MEDIA_INFO_LOG("MetadataCommonUtils::GetSupportedPreviewSizeRangeFromBasicConfig listSize: %{public}d", static_cast(sizeList->size())); return sizeList; + // LCOV_EXCL_STOP } } // namespace std::shared_ptr MetadataCommonUtils::GetCapabilityEntry( const std::shared_ptr metadata, uint32_t metadataTag) { - CHECK_ERROR_RETURN_RET(metadata == nullptr, nullptr); + CHECK_RETURN_RET(metadata == nullptr, nullptr); std::shared_ptr item = std::make_shared(); int32_t retCode = Camera::FindCameraMetadataItem(metadata->get(), metadataTag, item.get()); - CHECK_ERROR_RETURN_RET(retCode != CAM_META_SUCCESS || item->count == 0, nullptr); + CHECK_RETURN_RET(retCode != CAM_META_SUCCESS || item->count == 0, nullptr); return item; } std::shared_ptr> MetadataCommonUtils::GetSupportedPreviewSizeRange( const int32_t modeName, camera_format_t targetFormat, const std::shared_ptr metadata) { + // LCOV_EXCL_START MEDIA_DEBUG_LOG("MetadataCommonUtils::GetSupportedPreviewSizeRange modeName: %{public}d, targetFormat:%{public}d", modeName, targetFormat); std::shared_ptr> sizeList = std::make_shared>(); @@ -209,6 +220,7 @@ std::shared_ptr> MetadataCommonUtils::GetSupportedPreviewSizeRange( sizeList->insert(sizeList->end(), basicList->begin(), basicList->end()); } return sizeList; + // LCOV_EXCL_STOP } std::shared_ptr MetadataCommonUtils::CopyMetadata( @@ -220,7 +232,8 @@ std::shared_ptr MetadataCommonUtils::CopyMetadata( bool MetadataCommonUtils::ProcessFocusTrackingModeInfo(const std::shared_ptr& metadata, FocusTrackingMode& mode) { - CHECK_ERROR_RETURN_RET_LOG(metadata == nullptr, false, "metadata is nullptr"); + // LCOV_EXCL_START + CHECK_RETURN_RET_ELOG(metadata == nullptr, false, "metadata is nullptr"); camera_metadata_item_t item; int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_TRACKING_MODE, &item); if (ret != CAM_META_SUCCESS || item.count == 0) { @@ -229,14 +242,16 @@ bool MetadataCommonUtils::ProcessFocusTrackingModeInfo(const std::shared_ptr(item.data.u8[0]); return true; + // LCOV_EXCL_STOP } bool MetadataCommonUtils::ProcessMetaObjects(const int32_t streamId, const std::shared_ptr& result, - std::vector> &metaObjects, bool isNeedMirror, bool isNeedFlip) + std::vector> &metaObjects, bool isNeedMirror, bool isNeedFlip, RectBoxType type) { - CHECK_ERROR_RETURN_RET(result == nullptr, false); + CHECK_RETURN_RET(result == nullptr, false); // camera_metadata_item_t metadataItem; + // LCOV_EXCL_START common_metadata_header_t *metadata = result->get(); std::vector metadataResults; std::vector metadataTypes; @@ -246,16 +261,19 @@ bool MetadataCommonUtils::ProcessMetaObjects(const int32_t streamId, MEDIA_ERR_LOG("Camera not ProcessFaceRectangles"); return false; } - int32_t ret = ProcessMetaObjects(streamId, metaObjects, metadataResults, metadataTypes, isNeedMirror, isNeedFlip); - CHECK_ERROR_RETURN_RET_LOG(ret != CameraErrorCode::SUCCESS, false, + int32_t ret = ProcessMetaObjects(streamId, metaObjects, metadataResults, metadataTypes, + isNeedMirror, isNeedFlip, type); + CHECK_RETURN_RET_ELOG(ret != CameraErrorCode::SUCCESS, false, "MetadataCommonUtils::ProcessFaceRectangles() is failed."); return true; + // LCOV_EXCL_STOP } void MetadataCommonUtils::GetMetadataResults(const common_metadata_header_t *metadata, std::vector& metadataResults, std::vector& metadataTypes) { - for (auto itr : typesOfMetadata_copy) { + // LCOV_EXCL_START + for (auto itr : g_typesOfMetadata) { camera_metadata_item_t item; int ret = Camera::FindCameraMetadataItem(metadata, itr, &item); if (ret == CAM_META_SUCCESS) { @@ -263,49 +281,54 @@ void MetadataCommonUtils::GetMetadataResults(const common_metadata_header_t *met metadataTypes.emplace_back(itr); } } + // LCOV_EXCL_STOP } int32_t MetadataCommonUtils::ProcessMetaObjects(const int32_t streamId, std::vector>& metaObjects, const std::vector& metadataItem, const std::vector& metadataTypes, - bool isNeedMirror, bool isNeedFlip) + bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START for (size_t i = 0; i < metadataItem.size(); ++i) { - auto itr = g_HALResultToFwCameraMetaDetect_copy.find(metadataTypes[i]); - if (itr != g_HALResultToFwCameraMetaDetect_copy.end()) { - GenerateObjects(metadataItem[i], itr->second, metaObjects, isNeedMirror, isNeedFlip); + auto itr = g_HALResultToFwCameraMetaDetect_.find(metadataTypes[i]); + if (itr != g_HALResultToFwCameraMetaDetect_.end()) { + GenerateObjects(metadataItem[i], itr->second, metaObjects, isNeedMirror, isNeedFlip, type); } else { MEDIA_ERR_LOG("MetadataOutput::ProcessMetaObjects() unsupported type: %{public}d", metadataTypes[i]); } } return CameraErrorCode::SUCCESS; + // LCOV_EXCL_STOP } -void MetadataCommonUtils::GenerateObjects(const camera_metadata_item_t &metadataItem, MetadataObjectType type, +void MetadataCommonUtils::GenerateObjects(const camera_metadata_item_t &metadataItem, MetadataObjectType metadataType, std::vector> &metaObjects, - bool isNeedMirror, - bool isNeedFlip) + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType) { int32_t index = 0; int32_t countOfObject = 0; - auto iteratorOfLengthMap = mapLengthOfType.find(type); + auto iteratorOfLengthMap = mapLengthOfType.find(metadataType); if (iteratorOfLengthMap != mapLengthOfType.end()) { countOfObject = metadataItem.count / iteratorOfLengthMap->second; } + // LCOV_EXCL_START for (int32_t itr = 0; itr < countOfObject; ++itr) { sptr objectFactoryPtr = MetadataObjectFactory::GetInstance(); MetadataObjectType typeFromHal = static_cast(metadataItem.data.i32[index]); index++; - ProcessBaseInfo(objectFactoryPtr, metadataItem, index, typeFromHal, isNeedMirror, isNeedFlip); - ProcessExternInfo(objectFactoryPtr, metadataItem, index, typeFromHal, isNeedMirror, isNeedFlip); - metaObjects.push_back(objectFactoryPtr->createMetadataObject(type)); + ProcessBaseInfo(objectFactoryPtr, metadataItem, index, typeFromHal, isNeedMirror, isNeedFlip, rectBoxType); + ProcessExternInfo(objectFactoryPtr, metadataItem, index, typeFromHal, isNeedMirror, isNeedFlip, rectBoxType); + metaObjects.push_back(objectFactoryPtr->createMetadataObject(metadataType)); } + // LCOV_EXCL_STOP } void MetadataCommonUtils::ProcessBaseInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, MetadataObjectType typeFromHal, - bool isNeedMirror, bool isNeedFlip) + bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START const int32_t rectLength = 4; const int32_t offsetOne = 1; const int32_t offsetTwo = 2; @@ -317,7 +340,7 @@ void MetadataCommonUtils::ProcessBaseInfo(sptr factoryPtr index++; factoryPtr->SetBox(ProcessRectBox(metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; factoryPtr->SetConfidence(metadataItem.data.i32[index]); index++; @@ -325,11 +348,13 @@ void MetadataCommonUtils::ProcessBaseInfo(sptr factoryPtr index++; MEDIA_DEBUG_LOG("MetadataOutput::GenerateObjects, type: %{public}d, externalLength: %{public}d", typeFromHal, externalLength); + // LCOV_EXCL_STOP } void MetadataCommonUtils::ProcessHumanFaceDetectInfo(sptr factoryPtr, - const camera_metadata_item_t &metadataItem, int32_t &index, bool isNeedMirror, bool isNeedFlip) + const camera_metadata_item_t &metadataItem, int32_t &index, bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START int32_t version = metadataItem.data.i32[index++]; MEDIA_DEBUG_LOG("isNeedMirror: %{public}d, isNeedFlip: %{public}d, version: %{public}d", isNeedMirror, isNeedFlip, version); @@ -340,12 +365,12 @@ void MetadataCommonUtils::ProcessHumanFaceDetectInfo(sptr factoryPtr->SetLeftEyeBoundingBox(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; factoryPtr->SetRightEyeBoundingBoxd(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; factoryPtr->SetEmotion(static_cast(metadataItem.data.i32[index])); index++; @@ -357,31 +382,35 @@ void MetadataCommonUtils::ProcessHumanFaceDetectInfo(sptr index++; factoryPtr->SetRollAngle(metadataItem.data.i32[index]); index++; + // LCOV_EXCL_STOP } void MetadataCommonUtils::ProcessExternInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - MetadataObjectType typeFromHal, bool isNeedMirror, bool isNeedFlip) + MetadataObjectType typeFromHal, bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START switch (typeFromHal) { case MetadataObjectType::FACE: - ProcessHumanFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip); + ProcessHumanFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip, type); break; case MetadataObjectType::CAT_FACE: - ProcessCatFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip); + ProcessCatFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip, type); break; case MetadataObjectType::DOG_FACE: - ProcessDogFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip); + ProcessDogFaceDetectInfo(factoryPtr, metadataItem, index, isNeedMirror, isNeedFlip, type); break; default: break; } + // LCOV_EXCL_STOP } void MetadataCommonUtils::ProcessCatFaceDetectInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - bool isNeedMirror, bool isNeedFlip) + bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START int32_t version = metadataItem.data.i32[index++]; MEDIA_DEBUG_LOG("isNeedMirror: %{public}d, isNeedFlip: %{public}d, version: %{public}d", isNeedMirror, isNeedFlip, version); @@ -392,19 +421,21 @@ void MetadataCommonUtils::ProcessCatFaceDetectInfo(sptr f factoryPtr->SetLeftEyeBoundingBox(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; factoryPtr->SetRightEyeBoundingBoxd(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; + // LCOV_EXCL_STOP } void MetadataCommonUtils::ProcessDogFaceDetectInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - bool isNeedMirror, bool isNeedFlip) + bool isNeedMirror, bool isNeedFlip, RectBoxType type) { + // LCOV_EXCL_START int32_t version = metadataItem.data.i32[index++]; MEDIA_DEBUG_LOG("isNeedMirror: %{public}d, isNeedFlip: %{public}d, version: %{public}d", isNeedMirror, isNeedFlip, version); @@ -415,16 +446,27 @@ void MetadataCommonUtils::ProcessDogFaceDetectInfo(sptr f factoryPtr->SetLeftEyeBoundingBox(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; factoryPtr->SetRightEyeBoundingBoxd(ProcessRectBox( metadataItem.data.i32[index], metadataItem.data.i32[index + offsetOne], metadataItem.data.i32[index + offsetTwo], - metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip)); + metadataItem.data.i32[index + offsetThree], isNeedMirror, isNeedFlip, type)); index += rectLength; + // LCOV_EXCL_STOP } Rect MetadataCommonUtils::ProcessRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, + int32_t offsetBottomRightX, int32_t offsetBottomRightY, bool isNeedMirror, bool isNeedFlip, RectBoxType type) +{ + if (type == RectBoxType::RECT_MECH) { + return ProcessMechRectBox(offsetTopLeftX, offsetTopLeftY, offsetBottomRightX, offsetBottomRightY); + } + return ProcessCameraRectBox(offsetTopLeftX, offsetTopLeftY, offsetBottomRightX, offsetBottomRightY, + isNeedMirror, isNeedFlip); +} + +Rect MetadataCommonUtils::ProcessCameraRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, int32_t offsetBottomRightX, int32_t offsetBottomRightY, bool isNeedMirror, bool isNeedFlip) { constexpr int32_t scale = 1000000; @@ -456,6 +498,18 @@ Rect MetadataCommonUtils::ProcessRectBox(int32_t offsetTopLeftX, int32_t offsetT return (Rect){ topLeftX / scale, topLeftY / scale, width / scale, height / scale}; } +Rect MetadataCommonUtils::ProcessMechRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, + int32_t offsetBottomRightX, int32_t offsetBottomRightY) +{ + constexpr int32_t scale = 1000000; + double topLeftX = static_cast(offsetTopLeftX); + double topLeftY = static_cast(offsetTopLeftY); + double width = static_cast(offsetBottomRightX); + double height = static_cast(offsetBottomRightY); + + return (Rect){ topLeftX / scale, topLeftY / scale, width / scale, height / scale}; +} + std::vector ParsePhysicalApertureRangeByMode(const camera_metadata_item_t &item, const int32_t modeName) { const float factor = 20.0; @@ -485,11 +539,11 @@ std::vector ParsePhysicalApertureRangeByMode(const camera_metadata_item_t [currentMode](auto value) -> bool { return currentMode == value[0]; }); - CHECK_ERROR_RETURN_RET_LOG(it == modeRanges.end(), {}, + CHECK_RETURN_RET_ELOG(it == modeRanges.end(), {}, "ParsePhysicalApertureRangeByMode Failed meta not support mode:%{public}d", modeName); return *it; } } // namespace CameraStandard -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/test/unittest/framework_native/output/src/metadata_output_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/output/src/metadata_output_unittest.cpp index e122e89423689fc6a434fc27e42d3549e994d719..54c536507abe96c95453d3ae2a6405f24067db30 100644 --- a/frameworks/native/camera/test/unittest/framework_native/output/src/metadata_output_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/output/src/metadata_output_unittest.cpp @@ -533,10 +533,12 @@ HWTEST_F(CameraMetadataOutputUnit, metadata_output_unittest_013, TestSize.Level1 bool isNeedMirror = true; bool isNeedFlip = false; metadatOutput->reportFaceResults_ = true; - MetadataCommonUtils::GenerateObjects(metadataItem, type, metaObjects, isNeedMirror, isNeedFlip); + MetadataCommonUtils::GenerateObjects(metadataItem, type, metaObjects, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_EQ(metaObjects.size(), 0); - Rect ret = MetadataCommonUtils::ProcessRectBox(1, 1, 1, 1, isNeedMirror, isNeedFlip); + Rect ret = MetadataCommonUtils::ProcessRectBox(1, 1, 1, 1, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_EQ(ret.topLeftX, 0.999999); EXPECT_EQ(ret.topLeftY, 0.999999); EXPECT_EQ(ret.width, 0); @@ -544,7 +546,8 @@ HWTEST_F(CameraMetadataOutputUnit, metadata_output_unittest_013, TestSize.Level1 isNeedMirror = false; isNeedFlip = true; - ret = MetadataCommonUtils::ProcessRectBox(1, 1, 1, 1, isNeedMirror, isNeedFlip); + ret = MetadataCommonUtils::ProcessRectBox(1, 1, 1, 1, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_EQ(ret.topLeftX, 0.000001); EXPECT_EQ(ret.topLeftY, 0.000001); EXPECT_EQ(ret.width, 0); @@ -595,19 +598,23 @@ HWTEST_F(CameraMetadataOutputUnit, metadata_output_unittest_014, TestSize.Level1 MetadataObjectType type = MetadataObjectType::FACE; bool isNeedMirror = true; bool isNeedFlip = false; - MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_NE(factoryPtr, nullptr); type = MetadataObjectType::CAT_FACE; - MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_NE(factoryPtr, nullptr); type = MetadataObjectType::DOG_FACE; - MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_NE(factoryPtr, nullptr); type = static_cast(64); - MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); EXPECT_NE(factoryPtr, nullptr); input->Close(); diff --git a/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h b/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h index e00b11ee50a40d0ffadf7ea248e995e861ec6cbe..8d74fd50a75e1d6b5a093364568e29d3ebabee90 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h +++ b/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h @@ -33,15 +33,13 @@ public: void SetUp(void); /* TearDown:Execute after each test case */ void TearDown(void); - - void NativeAuthorization(void); private: void CommitConfig(); void StartSession(); void StopSession(); + void SetFocusPoint(float x, float y); void ReleaseSession(); - uint64_t tokenId_ = 0; int32_t uid_ = 0; int32_t userId_ = 0; sptr cameraManager_ = nullptr; @@ -53,36 +51,50 @@ class AppMechSessionCallback : public MechSessionCallback { public: void OnFocusTrackingInfo(FocusTrackingMetaInfo info) override { - MEDIA_INFO_LOG("CallbackListener::OnFocusTrackingInfo "); return; } - void OnCameraAppInfo(const std::vector& cameraAppInfos) override + void OnCaptureSessionConfiged(CaptureSessionInfo captureSessionInfo) override { - cameraAppInfos_ = cameraAppInfos; - for (int i = 0; i < cameraAppInfos.size(); i++) { - auto appInfo = cameraAppInfos[i]; - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo tokenId:%{public}d", appInfo.tokenId); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo cameraId:%{public}s", appInfo.cameraId.c_str()); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo opmode:%{public}d", appInfo.opmode); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo zoomValue:%{public}f", appInfo.zoomValue); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo equivalentFocus:%{public}d", - appInfo.equivalentFocus); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo width:%{public}d", appInfo.width); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo height:%{public}d", appInfo.height); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo videoStatus:%{public}d", appInfo.videoStatus); - } - return; + captureSessionInfo_ = captureSessionInfo; + } + + void OnZoomInfoChange(int sessionid, ZoomInfo zoomInfo) override + { + zoomInfo_ = zoomInfo; + } + + void OnSessionStatusChange(int sessionid, bool status) override + { + sessionStatus_ = status; + } + + CaptureSessionInfo GetSessionInfo() + { + return captureSessionInfo_; + } + + ZoomInfo GetZoomInfo() + { + return zoomInfo_; + } + + bool GetSessionStatus() + { + return sessionStatus_; } - std::vector GetCameraAppInfos() + bool GetFocusStatus() { - return cameraAppInfos_; + return focusStatus_; } private: - std::vector cameraAppInfos_; + CaptureSessionInfo captureSessionInfo_; + ZoomInfo zoomInfo_; + bool sessionStatus_ = false; + bool focusStatus_ = false; }; } } -#endif +#endif \ No newline at end of file diff --git a/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp index 6acb13f9387190381c7377d9430ac13c8c71e649..b8aa15904b8574dc04eb453dc5b30e4a3c5bbf1f 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp @@ -15,23 +15,16 @@ #include "mech_session_unittest.h" #include "gtest/gtest.h" +#include #include +#include #include -#include "access_token.h" -#include "accesstoken_kit.h" + #include "camera_util.h" -#include "hap_token_info.h" -#include "ipc_skeleton.h" -#include "metadata_utils.h" -#include "nativetoken_kit.h" #include "surface.h" #include "test_common.h" -#include "token_setproc.h" -#include "os_account_manager.h" -#include "sketch_wrapper.h" #include "hcapture_session.h" -#include "hcamera_service.h" -#include "session/video_session.h" +#include "test_token.h" using namespace testing::ext; namespace OHOS { @@ -39,13 +32,15 @@ namespace CameraStandard { using namespace OHOS::HDI::Camera::V1_1; static const int32_t PREVIEW_WIDTH = 1920; static const int32_t PREVIEW_HEIGHT = 1080; -void MechSessionUnitTest::SetUpTestCase(void) {} +void MechSessionUnitTest::SetUpTestCase(void) +{ + ASSERT_TRUE(TestToken().GetAllCameraPermission()); +} void MechSessionUnitTest::TearDownTestCase(void) {} void MechSessionUnitTest::SetUp() { - NativeAuthorization(); cameraManager_ = CameraManager::GetInstance(); ASSERT_NE(cameraManager_, nullptr); } @@ -58,29 +53,6 @@ void MechSessionUnitTest::TearDown() MEDIA_DEBUG_LOG("MechSessionUnitTest TearDown"); } -void MechSessionUnitTest::NativeAuthorization() -{ - const char *perms[2]; - perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; - perms[1] = "ohos.permission.CAMERA"; - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = NULL, - .perms = perms, - .acls = NULL, - .processName = "native_camera_tdd", - .aplStr = "system_basic", - }; - tokenId_ = GetAccessTokenId(&infoInstance); - uid_ = IPCSkeleton::GetCallingUid(); - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); - MEDIA_DEBUG_LOG("MechSessionUnitTest::NativeAuthorization uid_:%{public}d, userId_:%{public}d", uid_, userId_); - SetSelfTokenID(tokenId_); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); -} - void MechSessionUnitTest::CommitConfig() { std::vector> cameras = cameraManager_->GetSupportedCameras(); @@ -129,6 +101,15 @@ void MechSessionUnitTest::StopSession() captureSession_->Stop(); } +void MechSessionUnitTest::SetFocusPoint(float x, float y) +{ + ASSERT_NE(captureSession_, nullptr); + Point point; + point.x = x; + point.y = y; + captureSession_->SetFocusPoint(point); +} + void MechSessionUnitTest::ReleaseSession() { if (captureSession_ != nullptr) { @@ -280,38 +261,48 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_007, TestSize.Level0) /* * Feature: Framework - * Function: Test MechSession SetCallback + * Function: Test OnCaptureSessionConfiged when session start * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession SetCallback + * CaseDescription: Test OnCaptureSessionConfiged when session start */ HWTEST_F(MechSessionUnitTest, mech_session_unittest_008, TestSize.Level0) { - CommitConfig(); - StartSession(); - sptr mechSession = cameraManager_->CreateMechSession(userId_); ASSERT_NE(mechSession, nullptr); int32_t retCode = mechSession->EnableMechDelivery(true); EXPECT_EQ(retCode, 0); + auto mechSessionCallback = std::make_shared(); mechSession->SetCallback(mechSessionCallback); + CommitConfig(); + StartSession(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + CaptureSessionInfo sessionInfo = mechSessionCallback->GetSessionInfo(); + auto outputInfos = sessionInfo.outputInfos; + int size = outputInfos.size(); + EXPECT_NE(size, 0); + for (int i = 0; i < size; i++) { + auto outputInfo = outputInfos[i]; + EXPECT_EQ(outputInfo.width, PREVIEW_WIDTH); + EXPECT_EQ(outputInfo.height, PREVIEW_HEIGHT); + } + StopSession(); ReleaseSession(); - retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); } /* * Feature: Framework - * Function: Test MechSession callback when session start + * Function: Test OnSessionStatusChange when session start * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession callback when session star + * CaseDescription: Test MechSession OnSessionStatusChange when session start */ HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level0) { @@ -325,16 +316,8 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level0) CommitConfig(); StartSession(); - - std::vector cameraAppInfos = mechSessionCallback->GetCameraAppInfos(); - int size = cameraAppInfos.size(); - EXPECT_NE(size, 0); - for (int i = 0; i < size; i++) { - auto appInfo = cameraAppInfos[i]; - EXPECT_EQ(appInfo.width, PREVIEW_WIDTH); - EXPECT_EQ(appInfo.height, PREVIEW_HEIGHT); - EXPECT_EQ(appInfo.videoStatus, true); - } + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + EXPECT_EQ(mechSessionCallback->GetSessionStatus(), true); retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); @@ -344,11 +327,11 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level0) /* * Feature: Framework - * Function: Test MechSession callback when session stop + * Function: Test OnSessionStatusChange when session stop * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession callback when session stop + * CaseDescription: Test MechSession OnSessionStatusChange when session stop */ HWTEST_F(MechSessionUnitTest, mech_session_unittest_010, TestSize.Level0) { @@ -357,60 +340,19 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_010, TestSize.Level0) int32_t retCode = mechSession->EnableMechDelivery(true); EXPECT_EQ(retCode, 0); - CommitConfig(); - StartSession(); - auto mechSessionCallback = std::make_shared(); mechSession->SetCallback(mechSessionCallback); - StopSession(); - std::vector cameraAppInfos = mechSessionCallback->GetCameraAppInfos(); - int size = cameraAppInfos.size(); - EXPECT_NE(size, 0); - for (int i = 0; i < size; i++) { - auto appInfo = cameraAppInfos[i]; - EXPECT_EQ(appInfo.width, PREVIEW_WIDTH); - EXPECT_EQ(appInfo.height, PREVIEW_HEIGHT); - EXPECT_EQ(appInfo.videoStatus, false); - } - ReleaseSession(); - retCode = mechSession->Release(); - EXPECT_EQ(retCode, 0); -} -/* - * Feature: Framework - * Function: Test MechSession SetCallback when session setZoomRatio - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test MechSession SetCallback when session setZoomRatio - */ -HWTEST_F(MechSessionUnitTest, mech_session_unittest_011, TestSize.Level0) -{ - sptr mechSession = cameraManager_->CreateMechSession(userId_); - ASSERT_NE(mechSession, nullptr); - int32_t retCode = mechSession->EnableMechDelivery(true); - auto mechSessionCallback = std::make_shared(); - mechSession->SetCallback(mechSessionCallback); - EXPECT_EQ(retCode, 0); CommitConfig(); StartSession(); - std::vector zoomRatioRange = captureSession_->GetZoomRatioRange(); - if (!zoomRatioRange.empty()) { - for (int i = 0; i < zoomRatioRange.size(); i++) { - float zoomRatio = zoomRatioRange[i]; - captureSession_->LockForControl(); - captureSession_->SetZoomRatio(zoomRatio); - captureSession_->UnlockForControl(); - } - } - - void StopSession(); - void ReleaseSession(); + StopSession(); + ReleaseSession(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + EXPECT_EQ(mechSessionCallback->GetSessionStatus(), false); retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); } } -} +} \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/output/metadata_output.h b/interfaces/inner_api/native/camera/include/output/metadata_output.h index c2c00c47f888f78d96826b9ef0ca76cb4ddff163..018b8903008381fa0eb5ef479c85eb525f8cfb2e 100644 --- a/interfaces/inner_api/native/camera/include/output/metadata_output.h +++ b/interfaces/inner_api/native/camera/include/output/metadata_output.h @@ -455,16 +455,6 @@ private: std::shared_ptr appObjectCallback_; std::shared_ptr appStateCallback_; sptr cameraMetadataCallback_; - std::vector typesOfMetadata_ = { - OHOS_STATISTICS_DETECT_HUMAN_FACE_INFOS, - OHOS_STATISTICS_DETECT_HUMAN_BODY_INFOS, - OHOS_STATISTICS_DETECT_CAT_FACE_INFOS, - OHOS_STATISTICS_DETECT_CAT_BODY_INFOS, - OHOS_STATISTICS_DETECT_DOG_FACE_INFOS, - OHOS_STATISTICS_DETECT_DOG_BODY_INFOS, - OHOS_STATISTICS_DETECT_SALIENT_INFOS, - OHOS_STATISTICS_DETECT_BAR_CODE_INFOS, - OHOS_STATISTICS_DETECT_BASE_FACE_INFO}; }; class MetadataObjectListener : public IBufferConsumerListener { diff --git a/interfaces/inner_api/native/camera/include/session/mech_session.h b/interfaces/inner_api/native/camera/include/session/mech_session.h index 6c40b4c17ce59e02a5103975fae7f23eb38285cb..8f7edd9bff3852f962f2e301b6693b44bff5f5bd 100644 --- a/interfaces/inner_api/native/camera/include/session/mech_session.h +++ b/interfaces/inner_api/native/camera/include/session/mech_session.h @@ -31,7 +31,9 @@ public: MechSessionCallback() = default; virtual ~MechSessionCallback() = default; virtual void OnFocusTrackingInfo(FocusTrackingMetaInfo info) = 0; - virtual void OnCameraAppInfo(const std::vector& cameraAppInfos) = 0; + virtual void OnCaptureSessionConfiged(CaptureSessionInfo captureSessionInfo); + virtual void OnZoomInfoChange(int sessionid, ZoomInfo zoomInfo); + virtual void OnSessionStatusChange(int sessionid, bool status); }; class MechSession : public RefBase { @@ -91,12 +93,17 @@ public: ErrCode OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr& result) override; - ErrCode OnCameraAppInfo(const std::vector& cameraAppInfos) override; + ErrCode OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) override; + ErrCode OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) override; + ErrCode OnSessionStatusChange(int32_t sessionid, bool status) override; private: bool ProcessRectInfo(const std::shared_ptr& metadata, Rect& rect); + void PrintFocusTrackingInfo(FocusTrackingMetaInfo& info); + void PrintCaptureSessionInfo(const CaptureSessionInfo& captureSessionInfo); wptr mechSession_; + uint32_t logCount_ = 0; }; } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/utils/metadata_common_utils.h b/interfaces/inner_api/native/camera/include/utils/metadata_common_utils.h index 74c76beadfe6285c5b07f8ae1137687e900894fb..4c4cd40f1e1790510af7b3f195e5b597db3bedef 100644 --- a/interfaces/inner_api/native/camera/include/utils/metadata_common_utils.h +++ b/interfaces/inner_api/native/camera/include/utils/metadata_common_utils.h @@ -26,6 +26,10 @@ namespace OHOS { namespace CameraStandard { +enum RectBoxType { + RECT_CAMERA = 0, + RECT_MECH +}; class MetadataCommonUtils { private: explicit MetadataCommonUtils() = default; @@ -36,34 +40,42 @@ private: static int32_t ProcessMetaObjects(const int32_t streamId, std::vector>& metaObjects, const std::vector& metadataItem, const std::vector& metadataTypes, - bool isNeedMirror, bool isNeedFlip); + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); - static void GenerateObjects(const camera_metadata_item_t &metadataItem, MetadataObjectType type, - std::vector> &metaObjects, - bool isNeedMirror, bool isNeedFlip); + static void GenerateObjects(const camera_metadata_item_t &metadataItem, MetadataObjectType metadataType, + std::vector> &metaObjects, + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); static void ProcessBaseInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, MetadataObjectType typeFromHal, bool isNeedMirror, - bool isNeedFlip); + bool isNeedFlip, RectBoxType rectBoxType); static void ProcessExternInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - MetadataObjectType typeFromHal, bool isNeedMirror, bool isNeedFlip); + MetadataObjectType typeFromHal, bool isNeedMirror, bool isNeedFlip, + RectBoxType rectBoxType); static void ProcessHumanFaceDetectInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - bool isNeedMirror, bool isNeedFlip); + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); static void ProcessCatFaceDetectInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - bool isNeedMirror, bool isNeedFlip); + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); static void ProcessDogFaceDetectInfo(sptr factoryPtr, const camera_metadata_item_t &metadataItem, int32_t &index, - bool isNeedMirror, bool isNeedFlip); + bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); static Rect ProcessRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, + int32_t offsetBottomRightX, int32_t offsetBottomRightY, bool isNeedMirror, bool isNeedFlip, + RectBoxType rectBoxType); + + static Rect ProcessCameraRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, int32_t offsetBottomRightX, int32_t offsetBottomRightY, bool isNeedMirror, bool isNeedFlip); + + static Rect ProcessMechRectBox(int32_t offsetTopLeftX, int32_t offsetTopLeftY, + int32_t offsetBottomRightX, int32_t offsetBottomRightY); public: static std::shared_ptr GetCapabilityEntry( const std::shared_ptr metadata, uint32_t metadataTag); @@ -78,7 +90,7 @@ public: FocusTrackingMode& mode); static bool ProcessMetaObjects(const int32_t streamId, const std::shared_ptr& result, - std::vector> &metaObjects, bool isNeedMirror, bool isNeedFlip); + std::vector> &metaObjects, bool isNeedMirror, bool isNeedFlip, RectBoxType rectBoxType); }; std::vector ParsePhysicalApertureRangeByMode(const camera_metadata_item_t &item, const int32_t modeName); diff --git a/services/camera_service/idls/CameraTypes.idl b/services/camera_service/idls/CameraTypes.idl index 63aa94ab4fc47c6dca4ac6bc988831dde56ba500..51c3311260fc155ab742736717874fcf759fd4e0 100644 --- a/services/camera_service/idls/CameraTypes.idl +++ b/services/camera_service/idls/CameraTypes.idl @@ -52,7 +52,7 @@ enum MetadataObjectType { SALIENT_DETECTION = 6, BAR_CODE_DETECTION = 7, BASE_FACE_DETECTION = 8, - HUMAN_HEAD = 9, + BASE_TRACKING_REGION = 9, }; enum SketchStatus { @@ -109,14 +109,37 @@ enum PressureStatus { SYSTEM_PRESSURE_SHUTDOWN }; -struct CameraAppInfo { - int tokenId; - String cameraId; - int opmode; - float zoomValue; - int equivalentFocus; +enum OutputType { + PREVIEW = 0, + PHOTO = 1, + VIDEO = 2, + MOVING_PHOTO = 3, +}; + +struct OutputInfo { + OutputType type; + int minfps; + int maxfps; int width; int height; - boolean videoStatus; +}; + +struct ZoomInfo { + float zoomValue; + int equivalentFocus; + boolean focusStatus; + int focusMode; + int videoStabilizationMode; +}; + +struct CaptureSessionInfo { + int sessionId; + int callerTokenId; + String cameraId; int position; + int sessionMode; + OutputInfo[] outputInfos; + int colorSpace; + ZoomInfo zoomInfo; + boolean sessionStatus; }; \ No newline at end of file diff --git a/services/camera_service/idls/IMechSessionCallback.idl b/services/camera_service/idls/IMechSessionCallback.idl index 8083e30a7a5f2ac9c8a1dbc81cae2909975b6f86..8010b42e832e0a7193501a9686f4e82dcb7e19e8 100644 --- a/services/camera_service/idls/IMechSessionCallback.idl +++ b/services/camera_service/idls/IMechSessionCallback.idl @@ -19,5 +19,7 @@ sequenceable CameraMetadataInfo..OHOS.Camera.CameraMetadata; interface IMechSessionCallback{ [ipccode 0, oneway] void OnFocusTrackingInfo([in] int streamId, [in] boolean isNeedMirror, [in] boolean isNeedFlip, [in] sharedptr results); - [ipccode 1, oneway] void OnCameraAppInfo([in] CameraAppInfo[] cameraAppInfos); -} \ No newline at end of file + [ipccode 1, oneway] void OnCaptureSessionConfiged([in] CaptureSessionInfo captureSessionInfo); + [ipccode 2, oneway] void OnZoomInfoChange([in] int sessionid, [in] ZoomInfo zoomInfo); + [ipccode 3, oneway] void OnSessionStatusChange([in] int sessionid, [in] boolean status); +} diff --git a/services/camera_service/include/hcamera_device.h b/services/camera_service/include/hcamera_device.h index ffc64478f85425194fbbf8332606c22d2119332a..2e0263642b1812445611160435ea042832ceca82 100644 --- a/services/camera_service/include/hcamera_device.h +++ b/services/camera_service/include/hcamera_device.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "camera_privacy.h" #include "camera_sensor_plugin.h" @@ -106,6 +107,8 @@ public: uint8_t GetUsedAsPosition(); bool GetDeviceMuteMode(); float GetZoomRatio(); + int32_t GetFocusMode(); + int32_t GetVideoStabilizationMode(); void EnableMovingPhoto(bool isMovingPhotoEnabled); static void DeviceEjectCallBack(); static void DeviceFaultCallBack(); @@ -154,7 +157,7 @@ public: void SetMovingPhotoEndTimeCallback(std::function callback); - void SetZoomInfoCallback(std::function callback); + void SetZoomInfoCallback(std::function callback); inline void SetCameraConcurrentType(int32_t cameraConcurrentTypenum) { @@ -251,6 +254,8 @@ private: bool CanOpenCamera(); void ResetZoomTimer(); void CheckZoomChange(const std::shared_ptr& settings); + void CheckFocusChange(const std::shared_ptr& settings); + void CheckVideoStabilizationChange(const std::shared_ptr& settings); void UnPrepareZoom(); int32_t OpenDevice(bool isEnableSecCam = false); void ConfigQosParam(const char *bundleName, int32_t qosLevel, @@ -295,9 +300,13 @@ private: std::mutex cameraRotateStrategyInfosLock_; std::vector cameraRotateStrategyInfos_; std::string bundleName_ = ""; - std::mutex zoomInfoCallbackLock_; - std::function zoomInfoCallback_; + std::shared_mutex mechCallbackLock_; + std::shared_mutex zoomInfoCallbackLock_; + std::function zoomInfoCallback_; float zoomRatio_ = 1.0f; + int32_t focusMode_ = -1; + bool focusStatus_ = false; + int32_t videoStabilizationMode_ = 0; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/include/hcapture_session.h b/services/camera_service/include/hcapture_session.h index 3baef046b1d044357d039874c7c99287bc3f4717..d50a948dda31e48d99b9e84c66273e4b23a75131 100644 --- a/services/camera_service/include/hcapture_session.h +++ b/services/camera_service/include/hcapture_session.h @@ -206,9 +206,7 @@ public: int32_t GetUserId(); int32_t EnableMechDelivery(bool isEnableMech); void SetMechDeliveryState(MechDeliveryState state); - bool GetCameraAppInfo(CameraAppInfo& appInfo); - uint32_t GetEquivalentFocus(); - void OnCameraAppInfo(); + bool GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo); private: int32_t CommitConfigWithValidation(); @@ -253,9 +251,9 @@ private: int32_t SetHasFitedRotation(bool isHasFitedRotation) override; void InitialHStreamOperator(); void UpdateSettingForSpecialBundle(); - MechDeliveryState GetMechDeliveryState(); int32_t UpdateSettingForFocusTrackingMech(bool isEnableMech); void UpdateSettingForFocusTrackingMechBeforeStart(std::shared_ptr &settings); + void SetDeviceMechCallback(); void ClearMovingPhotoRepeatStream(); StateMachine stateMachine_; sptr innerPressureCallback_; @@ -274,6 +272,12 @@ private: int32_t AddOutputInner(StreamType streamType, const sptr& stream); int32_t RemoveOutputInner(StreamType streamType, const sptr& stream); + uint32_t GetEquivalentFocus(); + std::vector GetOutputInfos(); + void OnCaptureSessionConfiged(); + void OnZoomInfoChange(const ZoomInfo& zoomInfo); + void OnSessionStatusChange(bool status); + std::mutex cbMutex_; // Make sure device thread safe,set device by {SetCameraDevice}, get device by {GetCameraDevice} diff --git a/services/camera_service/include/hmech_session.h b/services/camera_service/include/hmech_session.h index 9285d93f929d4297cddf768c5146a7d102b17c4e..bce528931bfad7cb175dfc24ff9ff6477d92a85b 100644 --- a/services/camera_service/include/hmech_session.h +++ b/services/camera_service/include/hmech_session.h @@ -16,8 +16,8 @@ #ifndef OHOS_CAMERA_H_MECH_SESSION_H #define OHOS_CAMERA_H_MECH_SESSION_H -#include #include +#include #include "mech_session_callback_stub.h" #include "mech_session_stub.h" @@ -36,17 +36,19 @@ public: int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; int32_t OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr &result); - int32_t OnCameraAppInfo(const std::vector& cameraAppInfos); + int32_t OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo); + int32_t OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo); + int32_t OnSessionStatusChange(int32_t sessionid, bool status); sptr GetCallback(); bool IsEnableMech(); private: - void HandleCameraAppInfo(const sptr& callback); + void HanldeOnCaptureSessionConfiged(const sptr& callback); int32_t userId_; bool isEnableMech_ = false; sptr callback_; std::mutex enableLock_; - std::mutex callbackLock_; + std::shared_mutex callbackLock_; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/include/hstream_metadata.h b/services/camera_service/include/hstream_metadata.h index 6558aa405e718dd5089d74457cbb47c0820b2cdc..33f3897684b081a42a4ab16d18bcc2b29dd49c80 100644 --- a/services/camera_service/include/hstream_metadata.h +++ b/services/camera_service/include/hstream_metadata.h @@ -28,6 +28,18 @@ namespace OHOS { namespace CameraStandard { +static const std::unordered_map g_FwkToHALResultCameraMetaDetect_ = { + {MetadataObjectType::FACE, 0}, + {MetadataObjectType::HUMAN_BODY, 1}, + {MetadataObjectType::CAT_FACE, 2}, + {MetadataObjectType::CAT_BODY, 3}, + {MetadataObjectType::DOG_FACE, 4}, + {MetadataObjectType::DOG_BODY, 5}, + {MetadataObjectType::SALIENT_DETECTION, 6}, + {MetadataObjectType::BAR_CODE_DETECTION, 7}, + {MetadataObjectType::BASE_FACE_DETECTION, 8}, + {MetadataObjectType::BASE_TRACKING_REGION, 9} +}; class EXPORT_API HStreamMetadata : public StreamMetadataStub, public HStreamCommon, public ICameraIpcChecker { public: HStreamMetadata(sptr producer, int32_t format, std::vector metadataTypes); @@ -46,12 +58,10 @@ public: int32_t DisableMetadataType(const std::vector& metadataTypes) override; void DumpStreamInfo(CameraInfoDumper& infoDumper) override; int32_t OperatePermissionCheck(uint32_t interfaceCode) override; - int32_t OnMetaResult(int32_t streamId, const std::vector& result); + int32_t OnMetaResult(int32_t streamId, std::shared_ptr result); int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; - void SetUserId(int32_t userId); - void SetMechCallback(std::function&, uint32_t)> callback); + std::vector GetMetadataObjectTypes(); private: int32_t EnableOrDisableMetadataType(const std::vector& metadataTypes, const bool enable); @@ -63,9 +73,6 @@ private: std::mutex callbackLock_; uint32_t majorVer_ = 0; uint32_t minorVer_ = 0; - std::mutex mechCallbackLock_; - std::function&, uint32_t)> mechCallback_; - int32_t userId_; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/include/hstream_operator.h b/services/camera_service/include/hstream_operator.h index 630d6ee87d48612191cfd987202e99b231d411a8..d0f7f45124238950355a5b39038a80058a21e671 100644 --- a/services/camera_service/include/hstream_operator.h +++ b/services/camera_service/include/hstream_operator.h @@ -285,6 +285,11 @@ public: void UpdateOrientationBaseGravity(int32_t rotationValue, int32_t sensorOrientation, int32_t cameraPosition, int32_t& rotation); + void SetMechCallback(std::function&)> callback); + std::mutex mechCallbackLock_; + std::function&)> mechCallback_; + private: int32_t Initialize(const uint32_t callerToken, int32_t opMode); void RegisterDisplayListener(sptr repeat); diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index e896095594e2c6a014aea189049c56baacf79a8f..fc8c25e973368f47e5313332bd9785cb6783bd78 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -251,6 +251,16 @@ float HCameraDevice::GetZoomRatio() return zoomRatio_; } +int32_t HCameraDevice::GetFocusMode() +{ + return focusMode_; +} + +int32_t HCameraDevice::GetVideoStabilizationMode() +{ + return videoStabilizationMode_; +} + void HCameraDevice::EnableMovingPhoto(bool isMovingPhotoEnabled) { isMovingPhotoEnabled_ = isMovingPhotoEnabled; @@ -890,6 +900,55 @@ void HCameraDevice::CheckZoomChange(const std::shared_ptr& settings) +{ + std::unique_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); + int32_t ret; + camera_metadata_item_t item; + ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_AF_REGIONS, &item); + bool focusStatus = (ret == CAM_META_SUCCESS); + + int32_t focusMode = focusMode_; + ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FOCUS_MODE, &item); + if (ret == CAM_META_SUCCESS && item.count != 0) { + focusMode = static_cast(item.data.u8[0]); + } + + if (focusMode_!= focusMode || focusStatus_ != focusStatus) { + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio_; + zoomInfo.focusStatus = focusStatus; + zoomInfo.focusMode = focusMode; + zoomInfo.videoStabilizationMode = videoStabilizationMode_; + zoomInfoCallback_(zoomInfo); + } + + focusMode_ = focusMode; + focusStatus_ = focusStatus; +} + +void HCameraDevice::CheckVideoStabilizationChange(const std::shared_ptr& settings) +{ + std::shared_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); + camera_metadata_item_t item; + + int32_t ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item); + CHECK_RETURN(ret != CAM_META_SUCCESS || item.count == 0); + int32_t videoStabilizationMode = static_cast(item.data.u8[0]); + + if (videoStabilizationMode_ != videoStabilizationMode) { + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio_; + zoomInfo.focusStatus = focusStatus_; + zoomInfo.focusMode = focusMode_; + zoomInfo.videoStabilizationMode = videoStabilizationMode; + zoomInfoCallback_(zoomInfo); + } + videoStabilizationMode_ = videoStabilizationMode; +} + bool HCameraDevice::CheckMovingPhotoSupported(int32_t mode) { std::shared_ptr cameraAbility; @@ -993,7 +1052,8 @@ int32_t HCameraDevice::UpdateSetting(const std::shared_ptrget()); CHECK_ERROR_RETURN_RET_LOG(!count, CAMERA_OK, "HCameraDevice::UpdateSetting Nothing to update"); @@ -1495,28 +1555,29 @@ void HCameraDevice::SetMovingPhotoEndTimeCallback(std::function cameraResult) { - std::lock_guard lock(zoomInfoCallbackLock_); - if (!zoomInfoCallback_) { - return; - } + std::shared_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); float zoomRatio = 1.0; camera_metadata_item_t item; int ret = OHOS::Camera::FindCameraMetadataItem(cameraResult->get(), OHOS_CONTROL_ZOOM_RATIO, &item); - if (ret != CAM_META_SUCCESS || item.count == 0) { - return; - } + CHECK_RETURN(ret != CAM_META_SUCCESS || item.count == 0); zoomRatio = item.data.f[0]; MEDIA_DEBUG_LOG("ReportZoomInfos zoomRatio: %{public}f", zoomRatio); if (zoomRatio != zoomRatio_) { - zoomRatio_ = zoomRatio; - zoomInfoCallback_(); + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio; + zoomInfo.focusStatus = focusStatus_; + zoomInfo.focusMode = focusMode_; + zoomInfo.videoStabilizationMode = videoStabilizationMode_; + zoomInfoCallback_(zoomInfo); } + zoomRatio_ = zoomRatio; } -void HCameraDevice::SetZoomInfoCallback(std::function callback) +void HCameraDevice::SetZoomInfoCallback(std::function callback) { MEDIA_DEBUG_LOG("HCameraDevice::SetZoomInfoCallback enter."); - std::lock_guard lock(zoomInfoCallbackLock_); + std::unique_lock lock(zoomInfoCallbackLock_); zoomInfoCallback_ = callback; } diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index efc21b7186b72d382f81ef7185a504f1258c247e..241caef3abd90028e32cd675a699a92fcc3e7361 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -585,7 +585,7 @@ int32_t HCameraService::CreateCaptureSession(sptr& session, int int32_t uid = IPCSkeleton::GetCallingUid(); int32_t userId; AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - MEDIA_DEBUG_LOG("HCameraService::CreateCaptureSession userId= %{public}d", userId); + MEDIA_INFO_LOG("HCameraService::CreateCaptureSession userId= %{public}d", userId); captureSession->SetUserId(userId); auto &sessionManager = HCameraSessionManager::GetInstance(); @@ -805,33 +805,6 @@ int32_t HCameraService::CreateMetadataOutput(const sptr& CHECK_ERROR_RETURN_RET_LOG(streamMetadata == nullptr, CAMERA_ALLOC_ERROR, "HCameraService::CreateMetadataOutput HStreamMetadata allocation failed"); - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId; - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - MEDIA_DEBUG_LOG("HCameraService::CreateMetadataOutput userId= %{public}d", userId); - streamMetadata->SetUserId(userId); - streamMetadata->SetMechCallback([](int32_t streamId, const std::shared_ptr &result, - int32_t userId) { - auto &sessionManager = HCameraSessionManager::GetInstance(); - auto mechSession = sessionManager.GetMechSession(userId); - if (mechSession == nullptr) { - return; - } - bool isNeedMirror = false; - bool isNeedFlip = false; - sptr deviceManager = HCameraDeviceManager::GetInstance(); - std::vector> deviceHolderVector = deviceManager->GetActiveCameraHolders(); - for (sptr activeDeviceHolder : deviceHolderVector) { - sptr activeDevice = activeDeviceHolder->GetDevice(); - if (activeDevice != nullptr && activeDevice->IsOpenedCameraDevice()) { - int32_t position = activeDevice->GetCameraPosition(); - isNeedMirror = (position == static_cast(OHOS_CAMERA_POSITION_FRONT)); - int32_t usedAsPosition = activeDevice->GetUsedAsPosition(); - isNeedFlip = (usedAsPosition == static_cast(OHOS_CAMERA_POSITION_FRONT)); - } - } - mechSession->OnFocusTrackingInfo(streamId, isNeedMirror, isNeedFlip, result); - }); metadataOutput = streamMetadata; MEDIA_INFO_LOG("HCameraService::CreateMetadataOutput execute success"); return CAMERA_OK; diff --git a/services/camera_service/src/hcamera_session_manager.cpp b/services/camera_service/src/hcamera_session_manager.cpp index 5c9a48da6e10192fae039f308e729a456c04d627..9d89dc96904011aac339e455078ecc00d9f6f6f4 100644 --- a/services/camera_service/src/hcamera_session_manager.cpp +++ b/services/camera_service/src/hcamera_session_manager.cpp @@ -31,6 +31,8 @@ namespace OHOS { namespace CameraStandard { static const int32_t GROUP_SIZE_MIN_LIMIT = 1; // Default session min size is 1 static const int32_t GROUP_SIZE_MAX_LIMIT = 10; // Default session max size is 10 +static const int32_t MAX_SUPER_USER_ID = 100; +static int32_t g_mechLastUserid = 0; static size_t GetGroupSizeLimit(pid_t pid) { @@ -111,9 +113,10 @@ sptr HCameraSessionManager::GetMechSession(int32_t userId) { std::lock_guard lock(mechMapMutex_); auto mapIt = mechSessionMap_.find(userId); - if (mapIt == mechSessionMap_.end()) { - return nullptr; + if (mapIt == mechSessionMap_.end() && userId < MAX_SUPER_USER_ID) { + mapIt = mechSessionMap_.find(g_mechLastUserid); } + CHECK_RETURN_RET(mapIt == mechSessionMap_.end(), nullptr); return mapIt->second; } @@ -136,6 +139,7 @@ CamServiceError HCameraSessionManager::AddMechSession(int32_t userId, } std::lock_guard lock(mechMapMutex_); mechSessionMap_.insert(std::make_pair(userId, mechSession)); + g_mechLastUserid = userId; return CAMERA_OK; } diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index bb1447293d685519340f868e8dbdadd61d76cc8f..426853fb7adfcd7d0e7a57a1930013f67eda233c 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -327,13 +327,7 @@ int32_t HCaptureSession::AddInput(const sptr& cameraDevice MEDIA_INFO_LOG("HCaptureSession::AddInput device:%{public}s", hCameraDevice->GetCameraId().c_str()); SetCameraDevice(hCameraDevice); hCameraDevice->DispatchDefaultSettingToHdi(); - auto thisPtr = wptr(this); - hCameraDevice->SetZoomInfoCallback([thisPtr]() { - auto ptr = thisPtr.promote(); - if (ptr != nullptr) { - ptr->OnCameraAppInfo(); - } - }); + SetDeviceMechCallback(); }); if (errorCode == CAMERA_OK) { CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddInput, sessionID: %d", GetSessionId())); @@ -412,11 +406,31 @@ int32_t HCaptureSession::SetPreviewRotation(const std::string &deviceClass) void HCaptureSession::InitialHStreamOperator() { auto hStreamOperatorTemp = GetStreamOperator(); - if (hStreamOperatorTemp == nullptr) { - sptr hStreamOperator = HStreamOperator::NewInstance(callerToken_, opMode_); - SetStreamOperator(hStreamOperator); - HStreamOperatorManager::GetInstance()->AddStreamOperator(hStreamOperator); // 鍗曚緥绠$悊streamoperator 寰呮壘鍞竴key + CHECK_RETURN(hStreamOperatorTemp != nullptr); + sptr hStreamOperator = HStreamOperator::NewInstance(callerToken_, opMode_); + if (hStreamOperator != nullptr) { + auto thisPtr = wptr(this); + hStreamOperator->SetMechCallback([thisPtr](int32_t streamId, + const std::shared_ptr &result) { + auto sessionPtr = thisPtr.promote(); + CHECK_RETURN(!sessionPtr); + auto &sessionManager = HCameraSessionManager::GetInstance(); + auto mechSession = sessionManager.GetMechSession(sessionPtr->userId_); + CHECK_RETURN(!mechSession); + bool isNeedMirror = false; + bool isNeedFlip = false; + auto currentDevice = thisPtr->GetCameraDevice(); + if (currentDevice != nullptr) { + int32_t position = currentDevice->GetCameraPosition(); + isNeedMirror = (position == static_cast(OHOS_CAMERA_POSITION_FRONT)); + int32_t usedAsPosition = currentDevice->GetUsedAsPosition(); + isNeedFlip = (usedAsPosition == static_cast(OHOS_CAMERA_POSITION_FRONT)); + } + mechSession->OnFocusTrackingInfo(streamId, isNeedMirror, isNeedFlip, result); + }); } + SetStreamOperator(hStreamOperator); + HStreamOperatorManager::GetInstance()->AddStreamOperator(hStreamOperator); // 单例管理streamoperator 待找唯一key } int32_t HCaptureSession::AddOutput(StreamType streamType, const sptr& remoteObj) @@ -1190,7 +1204,8 @@ int32_t HCaptureSession::Start() mechDeliveryState_ = MechDeliveryState::ENABLED; } } - OnCameraAppInfo(); + OnSessionStatusChange(true); + OnCaptureSessionConfiged(); }); MEDIA_INFO_LOG("HCaptureSession::Start execute success, sessionID: %{public}d", GetSessionId()); MEDIA_INFO_LOG("%{public}s", GetConcurrentCameraIds(pid_).c_str()); @@ -1258,7 +1273,7 @@ int32_t HCaptureSession::Stop() isSessionStarted_ = false; } stateMachine_.Transfer(CaptureSessionState::SESSION_CONFIG_COMMITTED); - OnCameraAppInfo(); + OnSessionStatusChange(false); }); MEDIA_INFO_LOG("HCaptureSession::Stop execute success, sessionID: %{public}d", GetSessionId()); return errorCode; @@ -1717,19 +1732,13 @@ void HCaptureSession::SetMechDeliveryState(MechDeliveryState state) mechDeliveryState_ = state; } -MechDeliveryState HCaptureSession::GetMechDeliveryState() -{ - std::lock_guard lock(mechDeliveryStateLock_); - return mechDeliveryState_; -} - void HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart(std::shared_ptr& settings) { - MEDIA_DEBUG_LOG("HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart is called"); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); std::lock_guard lock(mechDeliveryStateLock_); if (mechDeliveryState_ == MechDeliveryState::NEED_ENABLE) { - MEDIA_DEBUG_LOG("start EnableMechDelivery"); + MEDIA_INFO_LOG("%{public}s start EnableMechDelivery", __FUNCTION__); int32_t count = 1; uint8_t value = OHOS_CAMERA_MECH_MODE_ON; settings->addEntry(OHOS_CONTROL_FOCUS_TRACKING_MECH, &value, count); @@ -1738,8 +1747,7 @@ void HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart(std::shared_p int32_t HCaptureSession::UpdateSettingForFocusTrackingMech(bool isEnableMech) { - MEDIA_DEBUG_LOG("HCaptureSession::UpdateSettingForFocusTrackingMech is called, isEnableMech: %{public}d", - isEnableMech); + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); auto cameraDevice = GetCameraDevice(); CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, CAMERA_INVALID_SESSION_CFG, "HCaptureSession::UpdateSettingForFocusTrackingMech device is null"); @@ -1766,52 +1774,69 @@ int32_t HCaptureSession::UpdateSettingForFocusTrackingMech(bool isEnableMech) return CAMERA_OK; } -bool HCaptureSession::GetCameraAppInfo(CameraAppInfo& appInfo) +void HCaptureSession::SetDeviceMechCallback() { - appInfo.zoomValue = 1.0f; // default zoom - appInfo.cameraId = ""; - appInfo.position = -1; - appInfo.width = 0; - appInfo.height = 0; + CHECK_RETURN(!cameraDevice_); + auto thisPtr = wptr(this); + cameraDevice_->SetZoomInfoCallback([thisPtr](ZoomInfo zoomInfo) { + auto ptr = thisPtr.promote(); + CHECK_RETURN(!ptr); + zoomInfo.equivalentFocus = ptr->GetEquivalentFocus(); + ptr->OnZoomInfoChange(zoomInfo); + }); +} + +bool HCaptureSession::GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo) +{ + sessionInfo.cameraId = ""; + sessionInfo.position = -1; + ZoomInfo zoomInfo; + zoomInfo.zoomValue = 1.0f; + zoomInfo.equivalentFocus = GetEquivalentFocus(); if (cameraDevice_ != nullptr) { - appInfo.cameraId = cameraDevice_->GetCameraId(); - appInfo.zoomValue = cameraDevice_->GetZoomRatio(); - appInfo.position = cameraDevice_->GetCameraPosition(); - } - appInfo.tokenId = static_cast(callerToken_); - appInfo.opmode = opMode_; - appInfo.equivalentFocus = static_cast(GetEquivalentFocus()); - auto hStreamOperatorSptr = GetStreamOperator(); - if (hStreamOperatorSptr != nullptr) { - auto streams = hStreamOperatorSptr->GetAllStreams(); - for (auto& stream : streams) { - if (stream->GetStreamType() == StreamType::REPEAT) { - auto curStreamRepeat = CastStream(stream); - appInfo.width = curStreamRepeat->width_; - appInfo.height = curStreamRepeat->height_; - } - } - } - auto currentState = stateMachine_.GetCurrentState(); - appInfo.videoStatus = (currentState == CaptureSessionState::SESSION_STARTED); + sessionInfo.cameraId = cameraDevice_->GetCameraId(); + sessionInfo.position = cameraDevice_->GetCameraPosition(); + zoomInfo.zoomValue = cameraDevice_->GetZoomRatio(); + zoomInfo.focusMode = cameraDevice_->GetFocusMode(); + zoomInfo.videoStabilizationMode = cameraDevice_->GetVideoStabilizationMode(); + } + sessionInfo.zoomInfo = zoomInfo; + sessionInfo.callerTokenId = static_cast(callerToken_); + sessionInfo.sessionId = GetSessionId(); + sessionInfo.sessionMode = GetopMode(); + int32_t curColorSpace = 0; + GetActiveColorSpace(curColorSpace); + sessionInfo.colorSpace = curColorSpace; + std::vector outputInfos = GetOutputInfos(); + sessionInfo.outputInfos = outputInfos; + sessionInfo.sessionStatus = stateMachine_.IsStateNoLock(CaptureSessionState::SESSION_STARTED); return true; } -void HCaptureSession::OnCameraAppInfo() +void HCaptureSession::OnCaptureSessionConfiged() { auto &sessionManager = HCameraSessionManager::GetInstance(); auto mechSession = sessionManager.GetMechSession(userId_); - if (mechSession == nullptr) { - return; - } - CameraAppInfo appInfo; - if (!GetCameraAppInfo(appInfo)) { - MEDIA_INFO_LOG("HCaptureSession::OnCameraAppInfo GetCameraAppInfo failed"); - return; - } - std::vector cameraAppInfos = {}; - cameraAppInfos.emplace_back(appInfo); - mechSession->OnCameraAppInfo(cameraAppInfos); + CHECK_RETURN(mechSession == nullptr); + CaptureSessionInfo sessionInfo; + CHECK_RETURN_ILOG(!GetCaptureSessionInfo(sessionInfo), + "HCaptureSession::OnCaptureSessionConfiged GetCaptureSessionInfo failed"); + mechSession->OnCaptureSessionConfiged(sessionInfo); +} + +void HCaptureSession::OnZoomInfoChange(const ZoomInfo& zoomInfo) +{ + auto &sessionManager = HCameraSessionManager::GetInstance(); + auto mechSession = sessionManager.GetMechSession(userId_); + CHECK_RETURN(mechSession == nullptr); +} + +void HCaptureSession::OnSessionStatusChange(bool status) +{ + auto &sessionManager = HCameraSessionManager::GetInstance(); + auto mechSession = sessionManager.GetMechSession(userId_); + CHECK_RETURN(mechSession == nullptr); + mechSession->OnSessionStatusChange(GetSessionId(), status); } uint32_t HCaptureSession::GetEquivalentFocus() @@ -1841,8 +1866,50 @@ uint32_t HCaptureSession::GetEquivalentFocus() return equivalentFocus; } +std::vector HCaptureSession::GetOutputInfos() +{ + std::vector outputInfos = {}; + auto hStreamOperatorSptr = GetStreamOperator(); + CHECK_RETURN_RET(!hStreamOperatorSptr, outputInfos); + auto streams = hStreamOperatorSptr->GetAllStreams(); + for (auto& stream : streams) { + if (stream->GetStreamType() == StreamType::CAPTURE) { + OutputInfo info; + info.type = OutputType::PHOTO; + info.width = stream->width_; + info.height = stream->height_; + outputInfos.emplace_back(info); + } else if (stream->GetStreamType() == StreamType::REPEAT) { + auto curStreamRepeat = CastStream(stream); + if (curStreamRepeat == nullptr) { + continue; + } + OutputInfo info; + auto streamType = curStreamRepeat->GetRepeatStreamType(); + if (streamType == RepeatStreamType::PREVIEW) { + info.type = OutputType::PREVIEW; + } else if (streamType == RepeatStreamType::VIDEO) { + info.type = OutputType::VIDEO; + } else if (streamType == RepeatStreamType::LIVEPHOTO) { + info.type = OutputType::MOVING_PHOTO; + } + info.width = stream->width_; + info.height = stream->height_; + std::vector frameRateRange = curStreamRepeat->GetFrameRateRange(); + constexpr int32_t fpsSize = 2; + if (frameRateRange.size() == fpsSize) { + info.minfps = frameRateRange[0]; + info.maxfps = frameRateRange[1]; + } + outputInfos.emplace_back(info); + } + } + return outputInfos; +} + int32_t HCaptureSession::EnableMechDelivery(bool isEnableMech) { + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); std::lock_guard lock(mechDeliveryStateLock_); auto currentState = stateMachine_.GetCurrentState(); switch (currentState) { diff --git a/services/camera_service/src/hmech_session.cpp b/services/camera_service/src/hmech_session.cpp index 8fa488ac1284189500fa24477bd06b047aab0101..ac5be36e91c1ee0dbebfda90fe714b41233ead9e 100644 --- a/services/camera_service/src/hmech_session.cpp +++ b/services/camera_service/src/hmech_session.cpp @@ -25,17 +25,17 @@ namespace CameraStandard { HMechSession::HMechSession(int32_t userId) : userId_(userId) { - MEDIA_INFO_LOG("HMechSession::HMechSession enter, userId:%{public}d", userId); + MEDIA_INFO_LOG("%{public}s is called, userId:%{public}d", __FUNCTION__, userId); } HMechSession::~HMechSession() { - MEDIA_INFO_LOG("HMechSession::~HMechSession enter"); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); } int32_t HMechSession::EnableMechDelivery(bool isEnableMech) { - MEDIA_INFO_LOG("HMechSession::EnableMechDelivery enter, isEnableMech:%{public}d", isEnableMech); + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); std::lock_guard lock(enableLock_); this->isEnableMech_ = isEnableMech; auto &sessionManager = HCameraSessionManager::GetInstance(); @@ -49,10 +49,10 @@ int32_t HMechSession::EnableMechDelivery(bool isEnableMech) int32_t HMechSession::SetCallback(const sptr& callback) { - MEDIA_INFO_LOG("HMechSession::SetCallback enter"); - std::lock_guard lock(callbackLock_); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); + std::unique_lock lock(callbackLock_); callback_ = callback; - HandleCameraAppInfo(callback); + HanldeOnCaptureSessionConfiged(callback); return CAMERA_OK; } @@ -70,7 +70,7 @@ int32_t HMechSession::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unuse int32_t HMechSession::Release() { - MEDIA_INFO_LOG("HMechSession::Release enter"); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); sptr emptyCallback = nullptr; SetCallback(emptyCallback); EnableMechDelivery(false); @@ -79,53 +79,67 @@ int32_t HMechSession::Release() return CAMERA_OK; } +sptr HMechSession::GetCallback() +{ + std::shared_lock lock(callbackLock_); + return callback_; +} + +bool HMechSession::IsEnableMech() +{ + std::lock_guard lock(enableLock_); + return isEnableMech_; +} + int32_t HMechSession::OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr &result) { - std::lock_guard lock(callbackLock_); + std::shared_lock lock(callbackLock_); if (callback_ != nullptr) { callback_->OnFocusTrackingInfo(streamId, isNeedMirror, isNeedFlip, result); } return CAMERA_OK; } -int32_t HMechSession::OnCameraAppInfo(const std::vector& cameraAppInfos) +int32_t HMechSession::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) { - std::lock_guard lock(callbackLock_); + std::shared_lock lock(callbackLock_); if (callback_ != nullptr) { - callback_->OnCameraAppInfo(cameraAppInfos); + callback_->OnCaptureSessionConfiged(captureSessionInfo); } return CAMERA_OK; } -sptr HMechSession::GetCallback() +int32_t HMechSession::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) { - std::lock_guard lock(callbackLock_); - return callback_; + std::shared_lock lock(callbackLock_); + if (callback_ != nullptr) { + callback_->OnZoomInfoChange(sessionid, zoomInfo); + } + return CAMERA_OK; } -bool HMechSession::IsEnableMech() +int32_t HMechSession::OnSessionStatusChange(int32_t sessionid, bool status) { - std::lock_guard lock(enableLock_); - return isEnableMech_; + std::shared_lock lock(callbackLock_); + if (callback_ != nullptr) { + callback_->OnSessionStatusChange(sessionid, status); + } + return CAMERA_OK; } -void HMechSession::HandleCameraAppInfo(const sptr& callback) +void HMechSession::HanldeOnCaptureSessionConfiged(const sptr& callback) { - if (callback == nullptr) { - return; - } + CHECK_RETURN(callback == nullptr); auto &sessionManager = HCameraSessionManager::GetInstance(); std::vector> userSessions = sessionManager.GetUserSessions(userId_); - std::vector cameraAppInfos = {}; for (size_t i = 0; i < userSessions.size(); i++) { sptr captureSession = userSessions[i]; - CameraAppInfo appInfo; - if (captureSession->GetCameraAppInfo(appInfo)) { - cameraAppInfos.emplace_back(appInfo); + CaptureSessionInfo sessionInfo; + if (captureSession->GetCaptureSessionInfo(sessionInfo)) { + callback->OnCaptureSessionConfiged(sessionInfo); } } - callback->OnCameraAppInfo(cameraAppInfos); } } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/src/hstream_metadata.cpp b/services/camera_service/src/hstream_metadata.cpp index 9885cb8027f9945a99003d4981a5f6ead894ca14..7fca48da738e92dea42cd4e28d19da8c60269a72 100644 --- a/services/camera_service/src/hstream_metadata.cpp +++ b/services/camera_service/src/hstream_metadata.cpp @@ -28,24 +28,12 @@ namespace OHOS { namespace CameraStandard { constexpr int32_t DEFAULT_ITEMS = 1; constexpr int32_t DEFAULT_DATA_LENGTH = 10; -static const std::unordered_map g_FwkToHALResultCameraMetaDetect_ = { - {MetadataObjectType::FACE, 0}, - {MetadataObjectType::HUMAN_BODY, 1}, - {MetadataObjectType::CAT_FACE, 2}, - {MetadataObjectType::CAT_BODY, 3}, - {MetadataObjectType::DOG_FACE, 4}, - {MetadataObjectType::DOG_BODY, 5}, - {MetadataObjectType::SALIENT_DETECTION, 6}, - {MetadataObjectType::BAR_CODE_DETECTION, 7}, - {MetadataObjectType::BASE_FACE_DETECTION, 8}, - {MetadataObjectType::HUMAN_HEAD, 9} -}; using namespace OHOS::HDI::Camera::V1_0; HStreamMetadata::HStreamMetadata(sptr producer, int32_t format, std::vector metadataTypes) : HStreamCommon(StreamType::METADATA, producer, format, producer->GetDefaultWidth(), producer->GetDefaultHeight()), - metadataObjectTypes_(metadataTypes), userId_(0) + metadataObjectTypes_(metadataTypes) {} HStreamMetadata::~HStreamMetadata() @@ -150,21 +138,13 @@ int32_t HStreamMetadata::DisableMetadataType(const std::vector& metadat return rc; } -int32_t HStreamMetadata::OnMetaResult(int32_t streamId, const std::vector& result) +int32_t HStreamMetadata::OnMetaResult(int32_t streamId, std::shared_ptr result) { - CHECK_ERROR_RETURN_RET_LOG(result.size() == 0, CAMERA_INVALID_ARG, "onResult get null meta from HAL"); - std::lock_guard lock(callbackLock_); - std::shared_ptr cameraResult = nullptr; - OHOS::Camera::MetadataUtils::ConvertVecToMetadata(result, cameraResult); - if (cameraResult == nullptr) { - cameraResult = std::make_shared(0, 0); + if (result == nullptr) { + result = std::make_shared(0, 0); } CHECK_EXECUTE(streamMetadataCallback_ != nullptr, - streamMetadataCallback_->OnMetadataResult(streamId, cameraResult)); - { - std::lock_guard mechLock(mechCallbackLock_); - CHECK_EXECUTE(mechCallback_ != nullptr, mechCallback_(streamId, cameraResult, userId_)); - } + streamMetadataCallback_->OnMetadataResult(streamId, result)); return CAMERA_OK; } @@ -183,18 +163,6 @@ int32_t HStreamMetadata::UnSetCallback() return CAMERA_OK; } -void HStreamMetadata::SetUserId(int32_t userId) -{ - userId_ = userId; -} - -void HStreamMetadata::SetMechCallback(std::function&, - uint32_t)> callback) -{ - std::lock_guard lock(mechCallbackLock_); - mechCallback_ = callback; -} - int32_t HStreamMetadata::EnableOrDisableMetadataType(const std::vector& metadataTypes, const bool enable) { MEDIA_DEBUG_LOG("HStreamMetadata::EnableOrDisableMetadataType enable: %{public}d, metadataTypes size: %{public}zu", @@ -251,5 +219,10 @@ void HStreamMetadata::removeMetadataType(const std::vector& metaRes, st [&set](const int32_t &element) { return set.find(element) != set.end(); }), metaTarget.end()); } + +std::vector HStreamMetadata::GetMetadataObjectTypes() +{ + return metadataObjectTypes_; +} } // namespace Standard } // namespace OHOS diff --git a/services/camera_service/src/hstream_operator.cpp b/services/camera_service/src/hstream_operator.cpp index f7c106f1f08e1786a0ffe0b879c4e317d0fbbd7d..81d6a27104b49d51da4aefe88369fe51289a56cf 100644 --- a/services/camera_service/src/hstream_operator.cpp +++ b/services/camera_service/src/hstream_operator.cpp @@ -98,6 +98,7 @@ constexpr int32_t ROTATION_360_DEGREES = 360; #endif static GravityData gravityData = {0.0, 0.0, 0.0}; static int32_t sensorRotation = 0; +static bool g_isNeedFilterMetadata = false; } // namespace sptr HStreamOperator::NewInstance(const uint32_t callerToken, int32_t opMode) @@ -857,17 +858,51 @@ int32_t HStreamOperator::StartPreviewStream(const std::shared_ptrGetStreamType(); - if (repeatType != StreamType::METADATA) { + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); + std::lock_guard mechLock(mechCallbackLock_); + CHECK_RETURN_RET(!streamOperator_, CAMERA_INVALID_STATE); + uint32_t majorVer = 0; + uint32_t minorVer = 0; + streamOperator_->GetVersion(majorVer, minorVer); + CHECK_RETURN_RET(majorVer < HDI_VERSION_1 || minorVer < HDI_VERSION_3, CAMERA_OK); + sptr streamOperatorV1_3 = + OHOS::HDI::Camera::V1_3::IStreamOperator::CastFrom(streamOperator_); + CHECK_RETURN_RET(!streamOperatorV1_3, CAMERA_UNKNOWN_ERROR); + const int32_t DEFAULT_ITEMS = 1; + const int32_t DEFAULT_DATA_LENGTH = 10; + std::shared_ptr metadata4Types = + std::make_shared(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH); + bool needAddMetadataType = true; + auto allStream = streamContainer_.GetAllStreams(); + for (auto& stream : allStream) { + if (stream->GetStreamType() != StreamType::METADATA) { continue; } - auto curStreamRepeat = CastStream(item); - std::vector metadataTypes; - metadataTypes.push_back(static_cast(MetadataObjectType::HUMAN_HEAD)); - isEnableMech ? curStreamRepeat->EnableMetadataType(metadataTypes) : - curStreamRepeat->DisableMetadataType(metadataTypes); + auto streamMetadata = CastStream(stream); + auto types = streamMetadata->GetMetadataObjectTypes(); + if (std::find(types.begin(), types.end(), static_cast(MetadataObjectType::FACE)) != types.end()) { + needAddMetadataType = false; + break; + } + } + g_isNeedFilterMetadata = needAddMetadataType; + std::vector typeTagToHal; + typeTagToHal.emplace_back(static_cast(MetadataObjectType::BASE_TRACKING_REGION)); + if (needAddMetadataType) { + typeTagToHal.emplace_back(static_cast(MetadataObjectType::FACE)); + } + uint32_t count = typeTagToHal.size(); + uint8_t* typesToEnable = typeTagToHal.data(); + bool status = metadata4Types->addEntry(OHOS_CONTROL_STATISTICS_DETECT_SETTING, typesToEnable, count); + CHECK_RETURN_RET_ELOG(!status, CAMERA_UNKNOWN_ERROR, "set_camera_metadata failed!"); + std::vector settings; + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(metadata4Types, settings); + if (isEnableMech) { + MEDIA_INFO_LOG("%{public}s EnableResult start!", __FUNCTION__); + streamOperatorV1_3->EnableResult(-1, settings); + } else { + MEDIA_INFO_LOG("%{public}s DisableResult start!", __FUNCTION__); + streamOperatorV1_3->DisableResult(-1, settings); } return CAMERA_OK; } @@ -1849,6 +1884,17 @@ int32_t HStreamOperator::OnCaptureReady( int32_t HStreamOperator::OnResult(int32_t streamId, const std::vector& result) { MEDIA_DEBUG_LOG("HStreamOperator::OnResult"); + CHECK_RETURN_RET(result.size() == 0, CAMERA_OK); + std::shared_ptr cameraResult = nullptr; + OHOS::Camera::MetadataUtils::ConvertVecToMetadata(result, cameraResult); + { + std::lock_guard mechLock(mechCallbackLock_); + CHECK_EXECUTE(mechCallback_ != nullptr && cameraResult!= nullptr, mechCallback_(streamId, cameraResult)); + if (g_isNeedFilterMetadata) { + OHOS::Camera::DeleteCameraMetadataItem(cameraResult->get(), OHOS_STATISTICS_DETECT_HUMAN_FACE_INFOS); + } + } + sptr curStream; const int32_t metaStreamId = -1; if (streamId == metaStreamId) { @@ -1857,7 +1903,7 @@ int32_t HStreamOperator::OnResult(int32_t streamId, const std::vector& curStream = GetHdiStreamByStreamID(streamId); } if ((curStream != nullptr) && (curStream->GetStreamType() == StreamType::METADATA)) { - CastStream(curStream)->OnMetaResult(streamId, result); + CastStream(curStream)->OnMetaResult(streamId, cameraResult); } else { MEDIA_ERR_LOG("HStreamOperator::OnResult StreamId: %{public}d is null or not Not adapted", streamId); return CAMERA_INVALID_ARG; @@ -2160,5 +2206,11 @@ void HStreamOperator::DisplayRotationListener::RemoveHstreamRepeatForListener(sp std::remove(repeatStreamList_.begin(), repeatStreamList_.end(), repeatStream), repeatStreamList_.end()); } +void HStreamOperator::SetMechCallback(std::function&)> callback) +{ + std::lock_guard lock(mechCallbackLock_); + mechCallback_ = callback; +} } // namespace CameraStandard } // namespace OHOS diff --git a/test/fuzztest/metadataoutput_fuzzer/metadata_output_fuzzer.cpp b/test/fuzztest/metadataoutput_fuzzer/metadata_output_fuzzer.cpp index 685bf7c87279a61dc35e916b128635a1c78b4c64..81cdb5d8455e28c4220f90b4d04e699cabf5fad3 100644 --- a/test/fuzztest/metadataoutput_fuzzer/metadata_output_fuzzer.cpp +++ b/test/fuzztest/metadataoutput_fuzzer/metadata_output_fuzzer.cpp @@ -116,11 +116,14 @@ void MetadataOutputFuzzer::MetadataOutputFuzzTest1(FuzzedDataProvider& fdp) fuzz_->ProcessMetadata(streamId, result, metaObjects, isNeedMirror, isNeedFlip); camera_metadata_item_t metadataItem; fuzz_->reportFaceResults_ = fdp.ConsumeBool(); - MetadataCommonUtils::GenerateObjects(metadataItem, type, metaObjects, isNeedMirror, isNeedFlip); + MetadataCommonUtils::GenerateObjects(metadataItem, type, metaObjects, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); MetadataCommonUtils::ProcessRectBox(fdp.ConsumeIntegral(), fdp.ConsumeIntegral(), - fdp.ConsumeIntegral(), fdp.ConsumeIntegral(), isNeedMirror, isNeedFlip); + fdp.ConsumeIntegral(), fdp.ConsumeIntegral(), isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); int32_t index = fdp.ConsumeIntegral(); - MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip); + MetadataCommonUtils::ProcessExternInfo(factoryPtr, metadataItem, index, type, isNeedMirror, isNeedFlip, + RectBoxType::RECT_CAMERA); fuzz_->GetSurface(); fuzz_->surface_ = nullptr; fuzz_->ReleaseSurface();