Browse Source

Z991239-5745 #comment 优化音视频列表获取流程,使用cjson

80274480 1 year ago
parent
commit
b85c80cdf5

+ 1 - 0
Module/mod_mediacontroller/CMakeLists.txt

@@ -18,6 +18,7 @@ set(${MODULE_PREFIX}_SRCS
 	stdafx.cpp
 	capture.cpp
 	mod_mediacontroller.cpp
+	${ThirdPartyHeadRoot}/CJson/cJSON.c
 )
 
 set(MOD_VERSION_STRING "0.0.1-dev1")

+ 26 - 17
Module/mod_mediacontroller/capture.cpp

@@ -1886,7 +1886,9 @@ namespace MediaController {
 		int icamnum = 0;
 		CSimpleStringA strCamInfoJson("");
 		CSimpleStringA strCamListInfoJson("");
-		Json::Value rootReq;
+		cJSON* array = cJSON_CreateArray();
+		cJSON* root = cJSON_CreateObject();
+
 #ifdef RVC_OS_WIN
 		HRESULT hr = CoInitialize(NULL);
 		int rc;
@@ -1935,12 +1937,12 @@ namespace MediaController {
 				WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
 				videocap_get_device_instanceid(i, tmp2, ARRAYSIZE(tmp2));
 				WideCharToMultiByte(CP_ACP, 0, tmp2, -1, t2, sizeof(t2), 0, NULL);
-				
-				Json::Value item;
-				item["DevicePath"] = t1;
-				item["DeviceInstanceId"] = t2;
-				item["FriendlyName"] = t;
-				rootReq["CameraDevInfo"].append(item);
+
+				cJSON* pobject = cJSON_CreateObject();
+				cJSON_AddItemToObject(pobject, "DevicePath", cJSON_CreateString(t1));
+				cJSON_AddItemToObject(pobject, "DeviceInstanceId", cJSON_CreateString(t2));
+				cJSON_AddItemToObject(pobject, "FriendlyName", cJSON_CreateString(t));
+				cJSON_AddItemToArray(array, pobject);
 
 				{
 					unsigned char x[MD5_DIGESTSIZE] = {0};
@@ -1952,6 +1954,7 @@ namespace MediaController {
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s;%s", i, t, t1);
 				strCamInfoJson += CSimpleStringA::Format("\"%d\":\"%s;%s\",", i, t, t1);
 			}
+
 		}
 
 		{
@@ -1989,11 +1992,11 @@ namespace MediaController {
 					rvc_camera_info_t pcamerainfo;
 					memset(&pcamerainfo, 0, sizeof(rvc_camera_info_t));
 					if (0 == rvc_videocap_get_camera_infos(i, &pcamerainfo)) {
-						Json::Value item;
-						item["driver"] = pcamerainfo.strdriver;
-						item["card"] = pcamerainfo.strcard;
-						item["bus_info"] = pcamerainfo.strbus_info;
-						rootReq["CameraDevInfo"].append(item);
+						cJSON* pobject = cJSON_CreateObject();
+						cJSON_AddItemToObject(pobject, "driver", cJSON_CreateString(pcamerainfo.strdriver));
+						cJSON_AddItemToObject(pobject, "card", cJSON_CreateString(pcamerainfo.strcard));
+						cJSON_AddItemToObject(pobject, "bus_info", cJSON_CreateString(pcamerainfo.strbus_info));
+						cJSON_AddItemToArray(array, pobject);
 					}
 				}
 			}
@@ -2002,18 +2005,24 @@ namespace MediaController {
 
 		if (icamnum > 0) {
 			LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_CAMERA_COUNT, CSimpleStringA::Format("camera number is %d.", icamnum).GetData());
-
 			if (strCamInfoJson.GetLength() > 0) {
 				strCamInfoJson[strCamInfoJson.GetLength() - 1] = '\0';
 			}
 			LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_GETCAMERA_INFOS, CSimpleStringA::Format("[{%s}]", strCamInfoJson.GetData()).GetData());
+		
+			cJSON_AddItemToObject(root, "CameraDevInfo", array);
+			char* pjsonstr = cJSON_Print(root);
+			strCamListInfoJson = pjsonstr;
+			cJSON_free(pjsonstr);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V1").setAPI("RvcMedia_GetCameraDevInfo")(CSimpleStringA::Format("%s", strCamListInfoJson.GetData()).GetData());
+		}
+		else {
+			cJSON_Delete(array);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V1").setResultCode("RTA280A")("获取摄像头列表失败,找不到摄像头");
 		}
 
 		*ivideonum = icamnum;
-
-		Json::StyledWriter sw;
-		strCamListInfoJson = sw.write(rootReq).c_str();
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V1").setAPI("RvcMedia_GetCameraDevInfo")(CSimpleStringA::Format("%s", strCamListInfoJson.GetData()).GetData());
+		cJSON_Delete(root);
 
 		return Error_Succeed;
 	}

+ 1 - 1
Module/mod_mediacontroller/capture.h

@@ -5,7 +5,7 @@
 #include "libaudioqueue.h"
 #include "libvideoqueue.h"
 #include "rvc_media_common.h"
-#include "json/json.h"
+#include "cJSON.h"
 
 #ifdef RVC_OS_WIN
 #include <portaudio.h>

+ 7 - 3
Module/mod_mediacontroller/mod_mediacontroller.cpp

@@ -1180,17 +1180,21 @@ ErrorCodeEnum CMediaControllerEntity::LoadConfig(capture_config_t *conf)
 #endif // RVC_OS_WIN
 
 			Error = CheckConfigCameraName(conf, m_eDeviceType);
-			if (Error == Error_EnvCamera || Error == Error_AllCamera){
+			if (Error == Error_EnvCamera){
 				char strMessage[MAX_PATH*2] = {0};
-				get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoEnv ,"env camera start error,please check config file or device.");
+				get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoEnv ,"env camera config error,please check config file or device.");
 				LogWarn(Severity_Middle,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_ENVCAM_INITFAIL,strMessage);
 				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V2").setResultCode("RTA2801")("上摄像头配置错误,请检查摄像头配置");
 			} else if (Error == Error_OptCamera){
 				char strMessage[MAX_PATH*2] = {0};
-				get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoOpt, "operation camera start error,please check config file or device.");
+				get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoOpt, "operation camera config error,please check config file or device.");
 				LogWarn(Severity_Middle,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_OPTCAM_INITFAIL, strMessage);
 				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V2").setResultCode("RTA2802")("下摄像头配置错误,请检查摄像头配置");
 			}
+			else if (Error == Error_AllCamera) {
+				LogWarn(Severity_Middle, Error_Debug, ERROR_MOD_MEDIACONTROLLER_CONFIG_ALLERROR, "all config cameras error");
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V2").setResultCode("RTA280B")("上下摄像头配置都错误,请检查摄像头配置");
+			}
 			else {
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setLogCode("QLR0402208V2")("摄像头配置正确");
 			}

+ 1 - 0
Module/mod_sipphone/CMakeLists.txt

@@ -39,6 +39,7 @@ set(${MODULE_PREFIX}_SRCS
     mod_sipphone.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_PLAFORM_SUBDIR}/video_session.cpp
     ${${SIPPHONE_PLATFORM}_SRCS}
+	${ThirdPartyHeadRoot}/CJson/cJSON.c
 )
 
 set(MOD_VERSION_STRING "0.0.1-dev1")

+ 32 - 16
Module/mod_sipphone/audio_session.cpp

@@ -9,6 +9,7 @@
 #include "rvc_media_common.h"
 #include <string>
 #include "iaudionsinterface.h"
+#include "cJSON.h"
 
 #ifdef RVC_OS_WIN
 #include <portaudio.h>
@@ -947,18 +948,28 @@ CSimpleStringA audio_get_dev_infos(bool in_direction)
 	int cnt = Pa_GetDeviceCount();
 	
 	CSimpleStringA strAudioJson("");
-	Json::Value rootReq;
+	cJSON* array = cJSON_CreateArray();
+	cJSON* root = cJSON_CreateObject();
+
+	char* strkey = NULL;
+	if (in_direction) {
+		strkey = "MicrophoneInfo";
+	}
+	else {
+		strkey = "SpeakerInfo";
+	}
+
 	for (int i = 0; i < cnt; ++i) {
 		const PaDeviceInfo* pinfo = Pa_GetDeviceInfo(i);
-		Json::Value item;
 		if (in_direction) {
 			if (pinfo->maxInputChannels > 0) {
-				item["name"] = pinfo->name;
-				item["samprate"] = CSimpleStringA::Format("%d", (int)pinfo->defaultSampleRate).GetData();
-				item["channels"] = CSimpleStringA::Format("%d", pinfo->maxInputChannels).GetData();
-				item["low_latency"] = CSimpleStringA::Format("%.2f", pinfo->defaultLowInputLatency).GetData();
-				item["high_latency"] = CSimpleStringA::Format("%.2f", pinfo->defaultHighInputLatency).GetData();
-				rootReq["MicrophoneInfo"].append(item);
+				cJSON* pobject = cJSON_CreateObject();
+				cJSON_AddItemToObject(pobject, "name", cJSON_CreateString(pinfo->name));
+				cJSON_AddItemToObject(pobject, "samprate", cJSON_CreateString(CSimpleStringA::Format("%d", (int)pinfo->defaultSampleRate).GetData()));
+				cJSON_AddItemToObject(pobject, "channels", cJSON_CreateString(CSimpleStringA::Format("%d", pinfo->maxInputChannels).GetData()));
+				cJSON_AddItemToObject(pobject, "low_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", pinfo->defaultLowInputLatency).GetData()));
+				cJSON_AddItemToObject(pobject, "high_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", pinfo->defaultHighInputLatency).GetData()));
+				cJSON_AddItemToArray(array, pobject);
 			}
 			else {
 				continue;
@@ -966,21 +977,26 @@ CSimpleStringA audio_get_dev_infos(bool in_direction)
 		}
 		else {
 			if (pinfo->maxOutputChannels > 0) {
-				item["name"] = pinfo->name;
-				item["samprate"] = CSimpleStringA::Format("%d", (int)pinfo->defaultSampleRate).GetData();
-				item["channels"] = CSimpleStringA::Format("%d", pinfo->maxOutputChannels).GetData();
-				item["low_latency"] = CSimpleStringA::Format("%.2f", pinfo->defaultLowOutputLatency).GetData();
-				item["high_latency"] = CSimpleStringA::Format("%.2f", pinfo->defaultHighOutputLatency).GetData();
-				rootReq["SpeakerInfo"].append(item);
+				cJSON* pobject = cJSON_CreateObject();
+				cJSON_AddItemToObject(pobject, "name", cJSON_CreateString(pinfo->name));
+				cJSON_AddItemToObject(pobject, "samprate", cJSON_CreateString(CSimpleStringA::Format("%d", (int)pinfo->defaultSampleRate).GetData()));
+				cJSON_AddItemToObject(pobject, "channels", cJSON_CreateString(CSimpleStringA::Format("%d", pinfo->maxOutputChannels).GetData()));
+				cJSON_AddItemToObject(pobject, "low_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", pinfo->defaultLowOutputLatency).GetData()));
+				cJSON_AddItemToObject(pobject, "high_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", pinfo->defaultHighOutputLatency).GetData()));
+				cJSON_AddItemToArray(array, pobject);
 			}
 			else {
 				continue;
 			}
 		}
 	}
+	cJSON_AddItemToObject(root, strkey, array);
+
+	char* pjsonstr = cJSON_Print(root);
+	strAudioJson = pjsonstr;
 
-	Json::StyledWriter sw;
-	strAudioJson = sw.write(rootReq).c_str();
+	cJSON_free(pjsonstr);
+	cJSON_Delete(root);
 
 	return strAudioJson;
 }

+ 0 - 1
Module/mod_sipphone/audio_session.h

@@ -6,7 +6,6 @@
 #include "../mod_counterconnector/CallType.h"
 #include "EventCode.h"
 #include "Event.h"
-#include "json/json.h"
 
 enum e_dev_type
 {

+ 16 - 13
Module/mod_sipphone/mod_sipphone.cpp

@@ -2377,7 +2377,8 @@ void CSIPEntity::ShowBothVideo()
 CSimpleStringA CSIPEntity::GetAudioDeviceJsonInfos(bool bmicro)
 {
 	CSimpleStringA strAudioDevJson("");
-	Json::Value rootReq;
+	cJSON* array = cJSON_CreateArray();
+	cJSON* root = cJSON_CreateObject();
 	if (NULL != m_pAudioMgr) {
 		char* strkey = NULL;
 		if (bmicro) {
@@ -2391,21 +2392,23 @@ CSimpleStringA CSIPEntity::GetAudioDeviceJsonInfos(bool bmicro)
 		for (int i = 0; i < iaudiocount; i++) {
 			rvc_audio_device_t* audio_dev = m_pAudioMgr->audio_get_device_infos(bmicro, i);
 
-			Json::Value item;
-			item["name"] = audio_dev->name;
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("item[\"name\"] = %s.", item["name"].asCString());
-			item["description"] = audio_dev->description;
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("item[\"description\"] = %s.", item["description"].asCString());
-			item["samprate"] = CSimpleStringA::Format("%d", audio_dev->samprate).GetData();
-			item["channels"] = CSimpleStringA::Format("%d", audio_dev->channels).GetData();
-			item["low_latency"] = CSimpleStringA::Format("%.2f", audio_dev->low_latency).GetData();
-			item["high_latency"] = CSimpleStringA::Format("%.2f", audio_dev->high_latency).GetData();
-			rootReq[strkey].append(item);
+			cJSON* pobject = cJSON_CreateObject();
+			cJSON_AddItemToObject(pobject, "name", cJSON_CreateString(audio_dev->name));
+			cJSON_AddItemToObject(pobject, "description", cJSON_CreateString(audio_dev->description));
+			cJSON_AddItemToObject(pobject, "samprate", cJSON_CreateString(CSimpleStringA::Format("%d", audio_dev->samprate).GetData()));
+			cJSON_AddItemToObject(pobject, "channels", cJSON_CreateString(CSimpleStringA::Format("%d", audio_dev->channels).GetData()));
+			cJSON_AddItemToObject(pobject, "low_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", audio_dev->low_latency).GetData()));
+			cJSON_AddItemToObject(pobject, "high_latency", cJSON_CreateString(CSimpleStringA::Format("%.2f", audio_dev->high_latency).GetData()));
+			cJSON_AddItemToArray(array, pobject);
 		}
+		cJSON_AddItemToObject(root, strkey, array);
 	}
+	
+	char* pjsonstr = cJSON_Print(root);
+	strAudioDevJson = pjsonstr;
 
-	Json::StyledWriter sw;
-	strAudioDevJson = sw.write(rootReq).c_str();
+	cJSON_free(pjsonstr);
+	cJSON_Delete(root);
 
 	return strAudioDevJson;
 }

+ 5 - 2
Other/libfilecryption/fileanalysis.cpp

@@ -240,8 +240,9 @@ int get_file_json_infos_from_rvc_header(char** pstrjson, uint32_t* ujsonlen, cha
 		memcpy(*pstrjson, pret, ulen);
 		*ujsonlen = ulen;
 		iret = 0;
-		free(pret);
+		cJSON_free(pret);
 	}
+	cJSON_Delete(root);
 	return iret;
 }
 
@@ -285,8 +286,10 @@ int get_file_json_infos_from_file(char** pstrjson, uint32_t* ujsonlen, const cha
 		memcpy(*pstrjson, pret, ulen);
 		*ujsonlen = ulen;
 		iret = 0;
-		free(pret);
+		cJSON_free(pret);
 	}
+	cJSON_Delete(root);
+
 	return iret;
 }