From 4a319467c98820dc31c1a2898634127cc04f351a Mon Sep 17 00:00:00 2001 From: w30042960 Date: Wed, 21 Feb 2024 19:48:40 +0800 Subject: [PATCH] modify cjson Signed-off-by: w30042960 --- .../sinkservicechannelneg_fuzzer/BUILD.gn | 1 - .../sinkserviceclosechannel_fuzzer/BUILD.gn | 1 - .../sinkservicegetcamerainfo_fuzzer/BUILD.gn | 1 - .../sinkserviceinitsink_fuzzer/BUILD.gn | 2 +- .../sinkserviceopenchannel_fuzzer/BUILD.gn | 1 - .../sinkservicereleasesink_fuzzer/BUILD.gn | 1 - .../sinkservicestopcapture_fuzzer/BUILD.gn | 1 - .../BUILD.gn | 1 - .../BUILD.gn | 1 - .../BUILD.gn | 2 - .../sourceserviceinitsource_fuzzer/BUILD.gn | 2 - .../BUILD.gn | 2 - .../BUILD.gn | 2 - .../BUILD.gn | 2 - .../base/include/dcamera_capture_info_cmd.h | 5 +- .../base/src/dcamera_capture_info_cmd.cpp | 178 +++++++++++------- .../base/src/dcamera_sink_frame_info.cpp | 81 +++++--- .../base/test/unittest/common/base/BUILD.gn | 1 - .../cameraoperator/client/BUILD.gn | 8 +- .../client/test/sample/BUILD.gn | 2 - .../unittest/common/cameraoperator/BUILD.gn | 2 - .../unittest/common/dcamerahandler/BUILD.gn | 1 - services/cameraservice/sinkservice/BUILD.gn | 2 - .../dcamera_sink_controller.cpp | 19 +- .../common/distributedcamera/BUILD.gn | 2 - .../common/distributedcameramgr/BUILD.gn | 1 - services/cameraservice/sourceservice/BUILD.gn | 2 - .../dcamera_source_dev.cpp | 33 ++-- .../dcamera_source_controller.cpp | 17 +- .../common/distributedcamera/BUILD.gn | 2 - .../common/distributedcameramgr/BUILD.gn | 2 - services/channel/BUILD.gn | 6 +- services/channel/src/dcamera_low_latency.cpp | 40 ++-- .../test/unittest/common/channel/BUILD.gn | 2 - services/data_process/BUILD.gn | 7 +- test/distributedcameraclienttest/BUILD.gn | 2 - 36 files changed, 242 insertions(+), 193 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn index ab69cdcc..7fb6b12b 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceChannelNegFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn index f785f5f8..d4392436 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceCloseChannelFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn index f175e8c6..eb97b3f2 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceGetCameraInfoFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn index 9ea16914..6431223f 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn @@ -43,7 +43,7 @@ ohos_fuzztest("SinkServiceInitSinkFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", + ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn index 7a9f73c5..d7df969a 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceOpenChannelFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn index 3076be19..3ed662c5 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceReleaseSinkFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn index ce006f09..d18f31dc 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceStopCaptureFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn index 8399b17c..a1a4eeec 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn @@ -43,7 +43,6 @@ ohos_fuzztest("SinkServiceSubscribeLocalHardwareFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn index 66166720..8dfee9f4 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn @@ -44,7 +44,6 @@ ohos_fuzztest("SinkServiceUnsubscribeLocalHardwareFuzzTest") { "${fwk_utils_path}/include/eventbus", "${feeding_smoother_path}/base", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn index b05febd1..9027802c 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn @@ -47,7 +47,6 @@ ohos_fuzztest("SourceServiceDCameraNotifyFuzzTest") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ @@ -62,7 +61,6 @@ ohos_fuzztest("SourceServiceDCameraNotifyFuzzTest") { deps = [ "${common_path}:distributed_camera_utils", "${services_path}/cameraservice/sourceservice:distributed_camera_source", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/BUILD.gn index b65940f1..0b086927 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -47,7 +47,6 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ @@ -63,7 +62,6 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { "${common_path}:distributed_camera_utils", "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", "${services_path}/cameraservice/sourceservice:distributed_camera_source", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn index 82c6cc10..a5c7357e 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -48,7 +48,6 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ @@ -63,7 +62,6 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { deps = [ "${common_path}:distributed_camera_utils", "${services_path}/cameraservice/sourceservice:distributed_camera_source", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/BUILD.gn index 2eb7e9bf..196d2f02 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -47,7 +47,6 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ @@ -62,7 +61,6 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { deps = [ "${common_path}:distributed_camera_utils", "${services_path}/cameraservice/sourceservice:distributed_camera_source", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn index c490e958..292a5a00 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -48,7 +48,6 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] cflags = [ @@ -63,7 +62,6 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { deps = [ "${common_path}:distributed_camera_utils", "${services_path}/cameraservice/sourceservice:distributed_camera_source", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/services/cameraservice/base/include/dcamera_capture_info_cmd.h b/services/cameraservice/base/include/dcamera_capture_info_cmd.h index 99b0158f..3588b42e 100644 --- a/services/cameraservice/base/include/dcamera_capture_info_cmd.h +++ b/services/cameraservice/base/include/dcamera_capture_info_cmd.h @@ -17,6 +17,7 @@ #define OHOS_DCAMERA_CAPTURE_INFO_H #include "distributed_camera_constants.h" +#include "cJSON.h" #include "json/json.h" #include "v1_0/dcamera_types.h" @@ -47,8 +48,8 @@ public: int32_t Unmarshal(const std::string& jsonStr); private: - int32_t UmarshalValue(Json::Value& rootValue); - int32_t UmarshalSettings(Json::Value& valueJson, std::shared_ptr& captureInfo); + int32_t UmarshalValue(cJSON* rootValue); + int32_t UmarshalSettings(cJSON* valueJson, std::shared_ptr& captureInfo); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp b/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp index a85ff75f..0f92ce45 100644 --- a/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp @@ -23,123 +23,159 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraCaptureInfoCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); - Json::Value captureInfos; + cJSON *rootValue = cJSON_CreateObject(); + if (rootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); + + cJSON *captureInfos = cJSON_CreateArray(); + if (captureInfos == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } for (auto iter = value_.begin(); iter != value_.end(); iter++) { - Json::Value captureInfo; + cJSON *captureInfo = cJSON_CreateObject(); + if (captureInfo == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } std::shared_ptr capture = *iter; - captureInfo["Width"] = Json::Value(capture->width_); - captureInfo["Height"] = Json::Value(capture->height_); - captureInfo["Format"] = Json::Value(capture->format_); - captureInfo["DataSpace"] = Json::Value(capture->dataspace_); - captureInfo["IsCapture"] = Json::Value(capture->isCapture_); - captureInfo["EncodeType"] = Json::Value(capture->encodeType_); - captureInfo["StreamType"] = Json::Value(capture->streamType_); - - Json::Value captureSettings; + cJSON_AddNumberToObject(captureInfo, "Width", capture->width_); + cJSON_AddNumberToObject(captureInfo, "Height", capture->height_); + cJSON_AddNumberToObject(captureInfo, "Format", capture->format_); + cJSON_AddNumberToObject(captureInfo, "DataSpace", capture->dataspace_); + cJSON_AddNumberToObject(captureInfo, "IsCapture", capture->isCapture_); + cJSON_AddNumberToObject(captureInfo, "EncodeType", capture->encodeType_); + cJSON_AddNumberToObject(captureInfo, "StreamType", capture->streamType_); + cJSON *captureSettings = cJSON_CreateArray(); + if (captureSettings == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } for (auto settingIter = capture->captureSettings_.begin(); settingIter != capture->captureSettings_.end(); settingIter++) { - Json::Value captureSetting; - captureSetting["SettingType"] = Json::Value((*settingIter)->type_); - captureSetting["SettingValue"] = Json::Value((*settingIter)->value_); - captureSettings.append(captureSetting); + cJSON *captureSetting = cJSON_CreateObject(); + if (captureSetting == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + cJSON_AddNumberToObject(captureSetting, "SettingType", (*settingIter)->type_); + cJSON_AddStringToObject(captureSetting, "SettingValue", (*settingIter)->value_.c_str()); + cJSON_AddItemToArray(captureSettings, captureSetting); } - - captureInfo["CaptureSettings"] = captureSettings; - captureInfos.append(captureInfo); + cJSON_AddItemToObject(captureInfo, "CaptureSettings", captureSettings); + cJSON_AddItemToArray(captureInfos, captureInfo); } - rootValue["Value"] = captureInfos; - jsonStr = rootValue.toStyledString(); + cJSON_AddItemToObject(rootValue, "Value", captureInfos); + char *jsonstr = cJSON_Print(rootValue); + if (jsonstr == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + jsonStr = jsonstr; + cJSON_Delete(rootValue); + cJSON_free(jsonstr); return DCAMERA_OK; } int32_t DCameraCaptureInfoCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { - return DCAMERA_BAD_VALUE; - } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == nullptr) { return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (type == nullptr || !cJSON_IsString(type) || (type->valuestring == nullptr)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); + type_ = type->valuestring; - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (dhId == nullptr || !cJSON_IsString(dhId) || (dhId->valuestring == nullptr)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); + dhId_ = dhId->valuestring; - if (!rootValue.isMember("Value") || !rootValue["Value"].isArray()) { + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (command == nullptr || !cJSON_IsString(command) || (command->valuestring == nullptr)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } + command_ = command->valuestring; int32_t ret = UmarshalValue(rootValue); if (ret != DCAMERA_OK) { + cJSON_Delete(rootValue); return ret; } + cJSON_Delete(rootValue); return DCAMERA_OK; } -int32_t DCameraCaptureInfoCmd::UmarshalValue(Json::Value& rootValue) +int32_t DCameraCaptureInfoCmd::UmarshalValue(cJSON *rootValue) { - for (Json::ArrayIndex i = 0; i < rootValue["Value"].size(); i++) { - Json::Value valueJson = rootValue["Value"][i]; + cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (valueJson == nullptr || !cJSON_IsObject(valueJson)) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + cJSON *capInfo = nullptr; + cJSON_ArrayForEach(capInfo, valueJson) { std::shared_ptr captureInfo = std::make_shared(); - if (!valueJson.isMember("Width") || !valueJson["Width"].isInt()) { + cJSON *width = cJSON_GetObjectItemCaseSensitive(capInfo, "Width"); + if (width == nullptr || !cJSON_IsNumber(width)) { return DCAMERA_BAD_VALUE; } - captureInfo->width_ = valueJson["Width"].asInt(); - - if (!valueJson.isMember("Height") || !valueJson["Height"].isInt()) { + captureInfo->width_ = width->valueint; + + cJSON *height = cJSON_GetObjectItemCaseSensitive(capInfo, "Height"); + if (height == nullptr || !cJSON_IsNumber(height)) { return DCAMERA_BAD_VALUE; } - captureInfo->height_ = valueJson["Height"].asInt(); + captureInfo->height_ = height->valueint; - if (!valueJson.isMember("Format") || !valueJson["Format"].isInt()) { + cJSON *format = cJSON_GetObjectItemCaseSensitive(capInfo, "Format"); + if (format == nullptr || !cJSON_IsNumber(format)) { return DCAMERA_BAD_VALUE; } - captureInfo->format_ = valueJson["Format"].asInt(); + captureInfo->format_ = format->valueint; - if (!valueJson.isMember("DataSpace") || !valueJson["DataSpace"].isInt()) { + cJSON *dataSpace = cJSON_GetObjectItemCaseSensitive(capInfo, "DataSpace"); + if (dataSpace == nullptr || !cJSON_IsNumber(dataSpace)) { return DCAMERA_BAD_VALUE; } - captureInfo->dataspace_ = valueJson["DataSpace"].asInt(); + captureInfo->dataspace_ = dataSpace->valueint; - if (!valueJson.isMember("IsCapture") || !valueJson["IsCapture"].isBool()) { + cJSON *isCapture = cJSON_GetObjectItemCaseSensitive(capInfo, "IsCapture"); + if (isCapture == nullptr || !cJSON_IsNumber(isCapture)) { return DCAMERA_BAD_VALUE; } - captureInfo->isCapture_ = valueJson["IsCapture"].asBool(); + captureInfo->isCapture_ = static_cast(isCapture->valueint); - if (!valueJson.isMember("EncodeType") || !valueJson["EncodeType"].isInt()) { + cJSON *encodeType = cJSON_GetObjectItemCaseSensitive(capInfo, "EncodeType"); + if (encodeType == nullptr || !cJSON_IsNumber(encodeType)) { return DCAMERA_BAD_VALUE; } - captureInfo->encodeType_ = (DCEncodeType)valueJson["EncodeType"].asInt(); + captureInfo->encodeType_ = static_cast(encodeType->valueint); - if (!valueJson.isMember("StreamType") || !valueJson["StreamType"].isInt()) { + cJSON *streamType = cJSON_GetObjectItemCaseSensitive(capInfo, "StreamType"); + if (streamType == nullptr || !cJSON_IsNumber(streamType)) { return DCAMERA_BAD_VALUE; } - captureInfo->streamType_ = (DCStreamType)valueJson["StreamType"].asInt(); + captureInfo->streamType_ = static_cast(streamType->valueint); - if (!valueJson.isMember("CaptureSettings") || !valueJson["CaptureSettings"].isArray()) { + cJSON *captureSettings = cJSON_GetObjectItemCaseSensitive(capInfo, "CaptureSettings"); + if (captureSettings == nullptr || !cJSON_IsArray(captureSettings)) { return DCAMERA_BAD_VALUE; } - int32_t ret = UmarshalSettings(valueJson, captureInfo); + int32_t ret = UmarshalSettings(captureSettings, captureInfo); if (ret != DCAMERA_OK) { return ret; } @@ -148,20 +184,24 @@ int32_t DCameraCaptureInfoCmd::UmarshalValue(Json::Value& rootValue) return DCAMERA_OK; } -int32_t DCameraCaptureInfoCmd::UmarshalSettings(Json::Value& valueJson, +int32_t DCameraCaptureInfoCmd::UmarshalSettings(cJSON *valueJson, std::shared_ptr& captureInfo) { - for (Json::ArrayIndex j = 0; j < valueJson["CaptureSettings"].size(); j++) { - Json::Value settingJson = valueJson["CaptureSettings"][j]; - if (!settingJson.isMember("SettingType") || !settingJson["SettingType"].isInt()) { + cJSON *captureSetting = nullptr; + cJSON_ArrayForEach(captureSetting, valueJson) { + cJSON *settingType = cJSON_GetObjectItemCaseSensitive(captureSetting, "SettingType"); + if (settingType == nullptr || !cJSON_IsNumber(settingType)) { return DCAMERA_BAD_VALUE; } - if (!settingJson.isMember("SettingValue") || !settingJson["SettingValue"].isString()) { + + cJSON *settingValue = cJSON_GetObjectItemCaseSensitive(captureSetting, "SettingValue"); + if (settingValue == nullptr || !cJSON_IsString(settingValue) || + (settingValue->valuestring == nullptr)) { return DCAMERA_BAD_VALUE; } std::shared_ptr setting = std::make_shared(); - setting->type_ = static_cast(settingJson["SettingType"].asInt()); - setting->value_ = settingJson["SettingValue"].asString(); + setting->type_ = static_cast(settingType->valueint); + setting->value_ = settingValue->valuestring; captureInfo->captureSettings_.push_back(setting); } return DCAMERA_OK; diff --git a/services/cameraservice/base/src/dcamera_sink_frame_info.cpp b/services/cameraservice/base/src/dcamera_sink_frame_info.cpp index f2148627..bcee661b 100644 --- a/services/cameraservice/base/src/dcamera_sink_frame_info.cpp +++ b/services/cameraservice/base/src/dcamera_sink_frame_info.cpp @@ -14,68 +14,91 @@ */ #include "dcamera_sink_frame_info.h" -#include "nlohmann/json.hpp" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" -using json = nlohmann::json; +#include "cJSON.h" namespace OHOS { namespace DistributedHardware { void DCameraSinkFrameInfo::Marshal(std::string& jsonStr) { - json frameInfo; - frameInfo[FRAME_INFO_TYPE] = type_; - frameInfo[FRAME_INFO_INDEX] = index_; - frameInfo[FRAME_INFO_PTS] = pts_; - frameInfo[FRAME_INFO_START_ENCODE] = startEncodeT_; - frameInfo[FRAME_INFO_FINISH_ENCODE] = finishEncodeT_; - frameInfo[FRAME_INFO_SENDT] = sendT_; - frameInfo[FRAME_INFO_VERSION] = ver_; - jsonStr = frameInfo.dump(); + cJSON *frameInfo = cJSON_CreateObject(); + if (frameInfo == nullptr) { + return; + } + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_TYPE.c_str(), type_); + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_INDEX.c_str(), index_); + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_PTS.c_str(), pts_); + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_START_ENCODE.c_str(), startEncodeT_); + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_FINISH_ENCODE.c_str(), finishEncodeT_); + cJSON_AddNumberToObject(frameInfo, FRAME_INFO_SENDT.c_str(), sendT_); + cJSON_AddStringToObject(frameInfo, FRAME_INFO_VERSION.c_str(), ver_.c_str()); + + char *jsonstr = cJSON_Print(frameInfo); + if (jsonstr == nullptr) { + cJSON_Delete(frameInfo); + return; + } + jsonStr = jsonstr; + cJSON_Delete(frameInfo); + cJSON_free(jsonstr); } int32_t DCameraSinkFrameInfo::Unmarshal(const std::string& jsonStr) { - json frameInfo = json::parse(jsonStr, nullptr, false); - if (frameInfo.is_discarded()) { - DHLOGE("FrameInfo json::parse error."); + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == nullptr) { + DHLOGE("FrameInfo parse error."); return DCAMERA_BAD_VALUE; } - - if (!frameInfo.contains(FRAME_INFO_TYPE) || !frameInfo[FRAME_INFO_TYPE].is_number_integer()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_TYPE.c_str()); + if (type == nullptr || !cJSON_IsNumber(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = frameInfo[FRAME_INFO_TYPE].get(); + type_ = static_cast(type->valueint); - if (!frameInfo.contains(FRAME_INFO_INDEX) || !frameInfo[FRAME_INFO_INDEX].is_number_integer()) { + cJSON *index = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_INDEX.c_str()); + if (index == nullptr || !cJSON_IsNumber(index)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - index_ = frameInfo[FRAME_INFO_INDEX].get(); + index_ = static_cast(index->valueint); - if (!frameInfo.contains(FRAME_INFO_PTS) || !frameInfo[FRAME_INFO_PTS].is_number_integer()) { + cJSON *pts = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_PTS.c_str()); + if (pts == nullptr || !cJSON_IsNumber(pts)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - pts_ = frameInfo[FRAME_INFO_PTS].get(); + pts_ = static_cast(pts->valueint); - if (!frameInfo.contains(FRAME_INFO_START_ENCODE) || !frameInfo[FRAME_INFO_START_ENCODE].is_number_integer()) { + cJSON *startEncode = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_START_ENCODE.c_str()); + if (startEncode == nullptr || !cJSON_IsNumber(startEncode)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - startEncodeT_ = frameInfo[FRAME_INFO_START_ENCODE].get(); + startEncodeT_ = static_cast(startEncode->valueint); - if (!frameInfo.contains(FRAME_INFO_FINISH_ENCODE) || !frameInfo[FRAME_INFO_FINISH_ENCODE].is_number_integer()) { + cJSON *finishEncode = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_FINISH_ENCODE.c_str()); + if (finishEncode == nullptr || !cJSON_IsNumber(finishEncode)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - finishEncodeT_ = frameInfo[FRAME_INFO_FINISH_ENCODE].get(); + finishEncodeT_ = static_cast(finishEncode->valueint); - if (!frameInfo.contains(FRAME_INFO_SENDT) || !frameInfo[FRAME_INFO_SENDT].is_number_integer()) { + cJSON *sendT = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_SENDT.c_str()); + if (sendT == nullptr || !cJSON_IsNumber(sendT)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - sendT_ = frameInfo[FRAME_INFO_SENDT].get(); + sendT_ = static_cast(sendT->valueint); - if (!frameInfo.contains(FRAME_INFO_VERSION) || !frameInfo[FRAME_INFO_VERSION].is_string()) { + cJSON *ver = cJSON_GetObjectItemCaseSensitive(rootValue, FRAME_INFO_VERSION.c_str()); + if (ver == nullptr || !cJSON_IsString(ver)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - ver_ = frameInfo[FRAME_INFO_VERSION].get(); + ver_ = std::string(ver->valuestring); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/base/test/unittest/common/base/BUILD.gn b/services/cameraservice/base/test/unittest/common/base/BUILD.gn index ab1b661e..1d4141dd 100755 --- a/services/cameraservice/base/test/unittest/common/base/BUILD.gn +++ b/services/cameraservice/base/test/unittest/common/base/BUILD.gn @@ -60,7 +60,6 @@ ohos_unittest("DCameraServicesBaseTest") { "${services_path}/channel:distributed_camera_channel", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/cameraoperator/client/BUILD.gn b/services/cameraservice/cameraoperator/client/BUILD.gn index 6323675f..21d62bcb 100644 --- a/services/cameraservice/cameraoperator/client/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("distributed_camera_client") { "${camerastandard_path}/services/camera_service/binder/client/include", "${camerastandard_path}/services/camera_service/binder/server/include", "${camerastandard_path}/services/camera_service/include", + "//third_party/cJSON", ] include_dirs += [ @@ -51,8 +52,6 @@ ohos_shared_library("distributed_camera_client") { "${feeding_smoother_path}/utils", ] - configs = [ "//third_party/jsoncpp:jsoncpp_public_config" ] - sources = [ "src/callback/dcamera_input_callback.cpp", "src/callback/dcamera_manager_callback.cpp", @@ -65,7 +64,10 @@ ohos_shared_library("distributed_camera_client") { sources += [ "src/dcamera_client.cpp" ] - deps = [ "${common_path}:distributed_camera_utils" ] + deps = [ + "${common_path}:distributed_camera_utils", + "//third_party/cJSON:cjson", + ] defines = [ "HI_LOG_ENABLE", diff --git a/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn b/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn index ee6dae1d..6d33405d 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn @@ -19,7 +19,6 @@ import( config("module_private_config") { include_dirs = [ "//third_party/cJSON", - "//third_party/jsoncpp/include", "${graphicsurface_path}/surface/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include/input", @@ -75,7 +74,6 @@ ohos_executable("dcamera_client_demo") { "${services_path}/cameraservice/cameraoperator/client:distributed_camera_client", "${services_path}/cameraservice/sinkservice:distributed_camera_sink", "//third_party/cJSON:cjson", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn index 44baacc6..ac0b32a1 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn @@ -21,7 +21,6 @@ config("module_private_config") { visibility = [ ":*" ] include_dirs = [ "//third_party/cJSON", - "//third_party/jsoncpp/include", "${graphicsurface_path}/surface/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include/input", @@ -69,7 +68,6 @@ ohos_unittest("DCameraClientTest") { "${services_path}/cameraservice/sinkservice:distributed_camera_sink", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/BUILD.gn b/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/BUILD.gn index 94ad5ffe..0b631f98 100644 --- a/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/BUILD.gn +++ b/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/BUILD.gn @@ -55,7 +55,6 @@ ohos_unittest("DCameraHandlerTest") { "${services_path}/cameraservice/cameraoperator/handler:distributed_camera_handler", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index af190f2d..30e14304 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -41,7 +41,6 @@ ohos_shared_library("distributed_camera_sink") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] include_dirs += [ @@ -110,7 +109,6 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index 97211e5d..5c56455e 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -527,23 +527,17 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& d DHLOGI("DCameraSinkController::HandleReceivedData dhId: %s", GetAnonyString(dhId_).c_str()); uint8_t *data = dataBuffer->Data(); std::string jsonStr(reinterpret_cast(data), dataBuffer->Capacity()); - - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value root; - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if ((!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &root, &errs)) || - (!root.isObject())) { - DHLOGE("parse json string failed"); + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == nullptr) { return DCAMERA_BAD_VALUE; } - - if ((!root.isMember("Command")) || (!root["Command"].isString())) { + cJSON *comvalue = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (comvalue == nullptr || !cJSON_IsString(comvalue) || (comvalue->valuestring == nullptr)) { + cJSON_Delete(rootValue); DHLOGE("parse command failed"); return DCAMERA_BAD_VALUE; } - - std::string command = root["Command"].asString(); + std::string command = std::string(comvalue->valuestring); if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { DCameraCaptureInfoCmd captureInfoCmd; int ret = captureInfoCmd.Unmarshal(jsonStr); @@ -562,6 +556,7 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& d } return UpdateSettings(metadataSettingCmd.value_); } + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn index 50a09490..bf9a8d18 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn @@ -21,7 +21,6 @@ config("module_private_config") { visibility = [ ":*" ] include_dirs = [ "//third_party/cJSON", - "//third_party/jsoncpp/include", "${graphicsurface_path}/surface/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include", "${camerastandard_path}/interfaces/inner_api/native/camera/include/input", @@ -77,7 +76,6 @@ ohos_unittest("DistributedCameraSinkServiceTest") { "${services_path}/cameraservice/sinkservice:distributed_camera_sink", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn index ca7711f2..37795545 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -86,7 +86,6 @@ ohos_unittest("DCameraSinkMgrTest") { "${services_path}/cameraservice/sinkservice:distributed_camera_sink", "${services_path}/channel:distributed_camera_channel", "//third_party/cJSON:cjson", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index d221ef14..06cb0d71 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -32,7 +32,6 @@ ohos_shared_library("distributed_camera_source") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", "//third_party/cJSON", - "//third_party/jsoncpp/include", ] include_dirs += [ @@ -110,7 +109,6 @@ ohos_shared_library("distributed_camera_source") { "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", - "//third_party/jsoncpp:jsoncpp", ] defines = [ diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index 6299221b..da100b0f 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -273,27 +273,32 @@ int32_t DCameraSourceDev::Register(std::shared_ptr& param) int32_t DCameraSourceDev::ParseEnableParam(std::shared_ptr& param, std::string& ability) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value sinkRootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(param->sinkParam_.c_str(), param->sinkParam_.c_str() + param->sinkParam_.length(), - &sinkRootValue, &errs) || !sinkRootValue.isObject()) { + cJSON *sinkRootValue = cJSON_Parse(param->sinkParam_.c_str()); + if (sinkRootValue == nullptr) { DHLOGE("Input sink ablity info is not json object."); return DCAMERA_INIT_ERR; } - Json::Value srcRootValue; - if (!jsonReader->parse(param->srcParam_.c_str(), param->srcParam_.c_str() + param->srcParam_.length(), - &srcRootValue, &errs) || !srcRootValue.isObject()) { + cJSON *srcRootValue = cJSON_Parse(param->srcParam_.c_str()); + if (srcRootValue == nullptr) { DHLOGE("Input source ablity info is not json object."); return DCAMERA_INIT_ERR; } - Json::Value abilityRootValue; - abilityRootValue["SinkAbility"] = sinkRootValue; - abilityRootValue["SourceAbility"] = srcRootValue; - ability = abilityRootValue.toStyledString(); + + cJSON *abilityRootValue = cJSON_CreateObject(); + if (abilityRootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddItemToObject(abilityRootValue, "SinkAbility", sinkRootValue); + cJSON_AddItemToObject(abilityRootValue, "SourceAbility", srcRootValue); + char *jsonstr = cJSON_Print(abilityRootValue); + if (jsonstr == nullptr) { + cJSON_Delete(abilityRootValue); + return DCAMERA_BAD_VALUE; + } + ability = jsonstr; + cJSON_Delete(abilityRootValue); + cJSON_free(jsonstr); return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 270c1ec3..97bd3d2c 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -445,23 +445,20 @@ void DCameraSourceController::OnDataReceived(std::vector buffer = *(buffers.begin()); std::string jsonStr(reinterpret_cast(buffer->Data())); - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == nullptr) { return; } - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + cJSON *comvalue = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (comvalue == nullptr || !cJSON_IsString(comvalue) || (comvalue->valuestring == nullptr)) { + cJSON_Delete(rootValue); return; } - std::string command = rootValue["Command"].asString(); + std::string command = std::string(comvalue->valuestring); if (command == DCAMERA_PROTOCOL_CMD_METADATA_RESULT) { HandleMetaDataResult(jsonStr); } + cJSON_Delete(rootValue); return; } diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn index f2ede19f..07417663 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn @@ -45,7 +45,6 @@ config("module_private_config") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", "//drivers/peripheral/base/", "${graphicsurface_path}/surface/include", ] @@ -76,7 +75,6 @@ ohos_unittest("DCameraSourceTest") { "${services_path}/channel:distributed_camera_channel", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index 001197a5..62a681ea 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -46,7 +46,6 @@ config("module_private_config") { "${fwk_utils_path}/include/eventbus", "${fwk_common_path}/utils/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", "//drivers/peripheral/base/", "${graphicsurface_path}/surface/include", "${feeding_smoother_path}", @@ -88,7 +87,6 @@ ohos_unittest("DCameraSourceMgrTest") { "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/channel/BUILD.gn b/services/channel/BUILD.gn index 3e232bc3..3146d4ff 100644 --- a/services/channel/BUILD.gn +++ b/services/channel/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("distributed_camera_channel") { "${av_transport_path}/common/include", "${fwk_common_path}/utils/include", "${services_path}/cameraservice/base/include", + "//third_party/cJSON", ] include_dirs += [ @@ -54,7 +55,10 @@ ohos_shared_library("distributed_camera_channel") { "src/dcamera_softbus_session.cpp", ] - deps = [ "${common_path}:distributed_camera_utils" ] + deps = [ + "${common_path}:distributed_camera_utils", + "//third_party/cJSON:cjson", + ] defines = [ "HI_LOG_ENABLE", diff --git a/services/channel/src/dcamera_low_latency.cpp b/services/channel/src/dcamera_low_latency.cpp index 8a356556..f62a0cf9 100644 --- a/services/channel/src/dcamera_low_latency.cpp +++ b/services/channel/src/dcamera_low_latency.cpp @@ -19,7 +19,7 @@ #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" #include "ipublisher_listener.h" -#include "nlohmann/json.hpp" +#include "cJSON.h" namespace OHOS { namespace DistributedHardware { @@ -38,13 +38,22 @@ int32_t DCameraLowLatency::EnableLowLatency() DHLOGE("Get dHFwkKit is null when enable low latency."); return DCAMERA_BAD_VALUE; } - nlohmann::json enable = { - {DH_TYPE, DHType::CAMERA}, - {LOW_LATENCY_ENABLE, true}, - }; - dHFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, enable.dump()); + cJSON *rootValue = cJSON_CreateObject(); + if (rootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddItemToObject(rootValue, DH_TYPE.c_str(), cJSON_CreateNumber(static_cast(DHType::CAMERA))); + cJSON_AddItemToObject(rootValue, LOW_LATENCY_ENABLE.c_str(), cJSON_CreateBool(true)); + char *jsonstr = cJSON_Print(rootValue); + if (jsonstr == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + dHFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, std::string(jsonstr)); refCount_++; DHLOGD("Enable low latency success and now refCount is: %d", refCount_.load()); + cJSON_Delete(rootValue); + cJSON_free(jsonstr); return DCAMERA_OK; } @@ -65,13 +74,22 @@ int32_t DCameraLowLatency::DisableLowLatency() DHLOGE("Get dHFwkKit is null when disable low latency."); return DCAMERA_BAD_VALUE; } - nlohmann::json disable = { - {DH_TYPE, DHType::CAMERA}, - {LOW_LATENCY_ENABLE, false}, - }; - dHFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, disable.dump()); + cJSON *rootValue = cJSON_CreateObject(); + if (rootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddItemToObject(rootValue, DH_TYPE.c_str(), cJSON_CreateNumber(static_cast(DHType::CAMERA))); + cJSON_AddItemToObject(rootValue, LOW_LATENCY_ENABLE.c_str(), cJSON_CreateBool(false)); + char *jsonstr = cJSON_Print(rootValue); + if (jsonstr == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + dHFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, std::string(jsonstr)); refCount_--; DHLOGD("Disable low latency success."); + cJSON_Delete(rootValue); + cJSON_free(jsonstr); return DCAMERA_OK; } diff --git a/services/channel/test/unittest/common/channel/BUILD.gn b/services/channel/test/unittest/common/channel/BUILD.gn index 17b6fdba..33d38b73 100644 --- a/services/channel/test/unittest/common/channel/BUILD.gn +++ b/services/channel/test/unittest/common/channel/BUILD.gn @@ -49,7 +49,6 @@ config("module_private_config") { "${innerkits_path}/native_cpp/camera_source/include/callback", "${graphicsurface_path}/surface/include", "//third_party/cJSON", - "//third_party/jsoncpp/include", "${feeding_smoother_path}/base", ] } @@ -81,7 +80,6 @@ ohos_unittest("DCameraChannelTest") { "${services_path}/cameraservice/sourceservice:distributed_camera_source", "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index f34d4ed0..e847def3 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("distributed_camera_data_process") { "${fwk_utils_path}/include/eventbus", "${graphicsurface_path}/surface/include", "${services_path}/cameraservice/base/include", + "//third_party/cJSON", ] include_dirs += [ @@ -43,7 +44,6 @@ ohos_shared_library("distributed_camera_data_process") { "include/pipeline_node/multimedia_codec/encoder", "include/pipeline_node/fpscontroller", "include/pipeline_node/scale_conversion", - "//third_party/json/include", "${common_path}/include/constants", "${common_path}/include/utils", "${feeding_smoother_path}/base", @@ -66,7 +66,10 @@ ohos_shared_library("distributed_camera_data_process") { "src/utils/property_carrier.cpp", ] - deps = [ "${common_path}:distributed_camera_utils" ] + deps = [ + "${common_path}:distributed_camera_utils", + "//third_party/cJSON:cjson", + ] if (!distributed_camera_common) { sources += [ diff --git a/test/distributedcameraclienttest/BUILD.gn b/test/distributedcameraclienttest/BUILD.gn index 4ebfb31a..dad88a87 100644 --- a/test/distributedcameraclienttest/BUILD.gn +++ b/test/distributedcameraclienttest/BUILD.gn @@ -30,7 +30,6 @@ ohos_moduletest_suite("SubDctsdisCameraClientTest") { "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include", "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/callback", "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/listener", - "$base_root/third_party/jsoncpp/include", ] sources = [ @@ -51,7 +50,6 @@ ohos_moduletest_suite("SubDctsdisCameraClientTest") { "$base_root/foundation/distributedhardware/distributed_camera/common:distributed_camera_utils", "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client:distributed_camera_client", "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/sinkservice:distributed_camera_sink", - "$base_root/third_party/jsoncpp:jsoncpp", ] external_deps = [ -- Gitee