From cbc1d53408b24bd4f9060f00c7aa2dcd5877547d Mon Sep 17 00:00:00 2001 From: chen0088 Date: Tue, 13 Aug 2024 17:33:57 +0800 Subject: [PATCH] modify Signed-off-by: chen0088 --- .../handler/include/dcamera_handler.h | 1 + .../handler/src/dcamera_handler.cpp | 63 +++++++++++-------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h index 3dcb9b8a..5cb0dcb0 100644 --- a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h +++ b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h @@ -63,6 +63,7 @@ private: std::vector& profileList); bool IsValid(const DCStreamType type, const CameraStandard::Size& size); int32_t CovertToDcameraFormat(CameraStandard::CameraFormat format); + int32_t CreateMeatdataStr(sptr& info, cJSON *root); sptr cameraManager_; std::shared_ptr pluginListener_; diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index e0c0aabf..00bf5fd1 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -238,28 +238,47 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D ConfigFormatvideo(CONTINUOUS_FRAME, root, previewProfiles); std::vector supportedModes = cameraManager_->GetSupportedModes(info); - cJSON *modeArray = cJSON_CreateArray(); - CHECK_AND_FREE_RETURN_RET_LOG(modeArray == nullptr, DCAMERA_BAD_VALUE, root, "Create modeArray object failed"); - cJSON_AddItemToObject(root, CAMERA_SUPPORT_MODE.c_str(), modeArray); - for (auto &mode : supportedModes) { - DHLOGI("The camera id: %{public}s, The supportedModes is : %{public}d", GetAnonyString(id).c_str(), mode); - cJSON_AddItemToArray(modeArray, cJSON_CreateNumber(mode)); - auto capability = cameraManager_->GetSupportedOutputCapability(info, mode); - CHECK_AND_FREE_RETURN_RET_LOG(capability == nullptr, DCAMERA_BAD_VALUE, root, "supported capability is null"); - cJSON *modeData = cJSON_CreateObject(); - CHECK_AND_FREE_RETURN_RET_LOG(modeData == nullptr, DCAMERA_BAD_VALUE, root, "Create cJSON object failed"); - std::vector photoProfiles = capability->GetPhotoProfiles(); - ConfigFormatphoto(SNAPSHOT_FRAME, modeData, photoProfiles); - - std::vector previewProfiles = capability->GetPreviewProfiles(); - ConfigFormatvideo(CONTINUOUS_FRAME, modeData, previewProfiles); - - cJSON_AddItemToObject(root, std::to_string(mode).c_str(), modeData); + if (!supportedModes.empty()) { + cJSON *modeArray = cJSON_CreateArray(); + CHECK_AND_FREE_RETURN_RET_LOG(modeArray == nullptr, DCAMERA_BAD_VALUE, root, "Create modeArray object failed"); + cJSON_AddItemToObject(root, CAMERA_SUPPORT_MODE.c_str(), modeArray); + for (auto &mode : supportedModes) { + DHLOGI("The camera id: %{public}s, The supportedModes is : %{public}d", GetAnonyString(id).c_str(), mode); + cJSON_AddItemToArray(modeArray, cJSON_CreateNumber(mode)); + auto capability = cameraManager_->GetSupportedOutputCapability(info, mode); + CHECK_AND_FREE_RETURN_RET_LOG( + capability == nullptr, DCAMERA_BAD_VALUE, root, "supported capability is null"); + cJSON *modeData = cJSON_CreateObject(); + CHECK_AND_FREE_RETURN_RET_LOG(modeData == nullptr, DCAMERA_BAD_VALUE, root, "Create cJSON object failed"); + std::vector photoProfiles = capability->GetPhotoProfiles(); + ConfigFormatphoto(SNAPSHOT_FRAME, modeData, photoProfiles); + + std::vector previewProfiles = capability->GetPreviewProfiles(); + ConfigFormatvideo(CONTINUOUS_FRAME, modeData, previewProfiles); + + cJSON_AddItemToObject(root, std::to_string(mode).c_str(), modeData); + } } + ret = CreateMeatdataStr(info, root); + CHECK_AND_FREE_RETURN_RET_LOG(ret != DCAMERA_OK, DCAMERA_BAD_VALUE, root, "CreateMeatdataStr failed"); + char *jsonstr = cJSON_Print(root); + CHECK_AND_FREE_RETURN_RET_LOG(jsonstr == nullptr, DCAMERA_BAD_VALUE, root, "jsonstr is null"); + + item.attrs = jsonstr; + cJSON_free(jsonstr); + cJSON_Delete(root); + return DCAMERA_OK; +} + +int32_t DCameraHandler::CreateMeatdataStr(sptr& info, cJSON *root) +{ sptr cameraInput = nullptr; - int rv = cameraManager_->CreateCameraInput(info, &cameraInput); - CHECK_AND_FREE_RETURN_RET_LOG(rv != DCAMERA_OK, DCAMERA_BAD_VALUE, root, "create cameraInput failed"); + int32_t rv = cameraManager_->CreateCameraInput(info, &cameraInput); + if (rv != DCAMERA_OK) { + DHLOGE("create cameraInput failed"); + return DCAMERA_BAD_VALUE; + } std::hash h; std::string abilityStr = cameraInput->GetCameraSettings(); @@ -268,13 +287,7 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D std::string encStr = Base64Encode(reinterpret_cast(abilityStr.c_str()), abilityStr.length()); DHLOGI("encodeString hash: %zu, length: %zu", h(encStr), encStr.length()); cJSON_AddStringToObject(root, CAMERA_METADATA_KEY.c_str(), encStr.c_str()); - char *jsonstr = cJSON_Print(root); - CHECK_AND_FREE_RETURN_RET_LOG(jsonstr == nullptr, DCAMERA_BAD_VALUE, root, "jsonstr is null"); - - item.attrs = jsonstr; CHECK_AND_LOG(cameraInput->Release() != DCAMERA_OK, "cameraInput Release failed"); - cJSON_free(jsonstr); - cJSON_Delete(root); return DCAMERA_OK; } -- Gitee