diff --git a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h index 3dcb9b8a726a16640586deefb225b1f23f62572c..5cb0dcb007a2cbd0933962ac208921d3d7a228fd 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 e0c0aabf2b3988ec175d066498b7687815806e63..00bf5fd1e236ca7eda9428128aecd758675bcf11 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; }