فهرست منبع

Z991239-5945 #comment 优化图像渲染功能

80274480 10 ماه پیش
والد
کامیت
d6ce8e8a88
1فایلهای تغییر یافته به همراه94 افزوده شده و 48 حذف شده
  1. 94 48
      Module/mod_sipphone/video_render.cpp

+ 94 - 48
Module/mod_sipphone/video_render.cpp

@@ -58,8 +58,7 @@ static int rvc_video_shm_enqueue(Clibvideoqueue* shm_queue, video_frame* frame,
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("caution: rvc render shm_queue video insert shm video failed!");
 		return Error_Unexpect;
 	}
-	else
-	{
+	else{
 		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video render shm_queue video insert shm video ok, and nowtime is %d, and frame id is %d.", nowtime, iframeid);
 		return Error_Succeed;
 	}
@@ -130,45 +129,84 @@ int rvc_remote_video_render(rvc_video_render_t* prender, void* videoframe)
 	return 0;
 }
 
-#ifdef RVC_OS_WIN
-static unsigned int __stdcall rvc_videorender_func(void* arg)
-#else
-static void* rvc_videorender_func(void* arg)
-#endif
+
+static int rvc_getrender_videoqueue(Clibvideoqueue** render_video_queue, int* render_width, int* render_height, RVC_RendererFlip* renderflip, rvc_video_render_t* param)
 {
-	rvc_video_render_t* param = (rvc_video_render_t*)arg;
-	int ilocal_video_fresh_time = param->render_param.ilocal_fresh_time;
-	bool bremote_video = false;
+	int iret = -1;
 
 	int irender_camera = CAMERA_TYPE_ENV;
 	if (param->render_param.ilocal_view_cx < param->render_param.ilocal_view_cy) {
 		irender_camera = CAMERA_TYPE_OPT;
 	}
 
-	Clibvideoqueue* local_video_queue = NULL;
-	RVC_RendererFlip renderflip = RVC_FLIP_VERTICAL;
-	int iwidth = 0;
-	int iheight = 0;
 	if (CAMERA_TYPE_ENV == irender_camera) {
 		if (ePreview_Queue == param->render_param.erender_queue) {
-			local_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE);
-			iwidth = REC_COMMON_VIDEO_PREVIEW_WIDTH;
-			iheight = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
+			*render_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE);
+			*render_width = REC_COMMON_VIDEO_PREVIEW_WIDTH;
+			*render_height = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
 		}
 		else {
-			local_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
-			iwidth = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
-			iheight = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
+			*render_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
+			*render_width = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
+			*render_height = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("use sanpshot queue.");
 		}
 	}
 	else {
-		local_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_PREVIEW_QUEUE);
-		iwidth = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
-		iheight = REC_COMMON_VIDEO_PREVIEW_WIDTH;
-		renderflip = RVC_FLIP_NONE;
+		if (ePreview_Queue == param->render_param.erender_queue) {
+			*render_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_PREVIEW_QUEUE);
+			*render_width = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
+			*render_height = REC_COMMON_VIDEO_PREVIEW_WIDTH;
+		}
+		else {
+			*render_video_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
+			*render_width = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
+			*render_height = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("use sanpshot queue.");
+		}
+		*renderflip = RVC_FLIP_NONE;
 	}
 
+	iret = 0;
+
+	return iret;
+}
+
+
+static int rvc_getrxkimage(IplImage** personimage, IplImage** personmask)
+{
+	int iret = -1;
+
+	char strPersonPath[MAX_PATH] = { 0 };
+	rvc_snprintf(strPersonPath, MAX_PATH, "./bin/rxk.jpg");
+
+	if (ExistsFile(strPersonPath)) {
+		*personimage = cvLoadImage(strPersonPath);
+		*personmask = cvLoadImage(strPersonPath, 0);
+		iret = 0;
+	}
+
+	return iret;
+}
+
+
+#ifdef RVC_OS_WIN
+static unsigned int __stdcall rvc_videorender_func(void* arg)
+#else
+static void* rvc_videorender_func(void* arg)
+#endif
+{
+	rvc_video_render_t* param = (rvc_video_render_t*)arg;
+	int ilocal_video_fresh_time = param->render_param.ilocal_fresh_time;
+	bool bremote_video = false;
+
+	Clibvideoqueue* local_video_queue = NULL;
+	RVC_RendererFlip renderflip = RVC_FLIP_VERTICAL;
+	int iwidth = 0;
+	int iheight = 0;
+
+	rvc_getrender_videoqueue(&local_video_queue, &iwidth, &iheight, &renderflip, param);
+
 	int ivideo_width = 0;
 	int ivideo_height = 0;
 	int isize = local_video_queue->GetFrameSize(ivideo_width, ivideo_height);
@@ -178,15 +216,9 @@ static void* rvc_videorender_func(void* arg)
 		iheight = ivideo_height;
 	}
 
-	char strPersonPath[MAX_PATH] = { 0 };
-	rvc_snprintf(strPersonPath, MAX_PATH, "./bin/rxk.jpg");
 	IplImage* personimage = NULL;
 	IplImage* personmask = NULL;
-
-	if (ExistsFile(strPersonPath)){
-		personimage = cvLoadImage(strPersonPath);
-		personmask = cvLoadImage(strPersonPath, 0);
-	}
+	rvc_getrxkimage(&personimage, &personmask);
 
 	if (NULL != param->plocal_render) {
 		videorender_param_t tparam = { 0 };
@@ -292,26 +324,20 @@ static void* rvc_videorender_func(void* arg)
 	return 0;
 }
 
-#ifdef RVC_OS_WIN
-static unsigned int __stdcall rvc_remote_videorender_func(void* arg)
-#else
-static void* rvc_remote_videorender_func(void* arg)
-#endif
+
+static int rvc_get_remote_videoframe(video_frame** remote_frame)
 {
-	rvc_video_render_t* param = (rvc_video_render_t*)arg;
-	int iremote_video_fresh_time = param->render_param.iremote_fresh_time;
+	int iret = -1;
+
 	char strImgPath[MAX_PATH] = { 0 };
+	rvc_snprintf(strImgPath, MAX_PATH, "%s", "./bin/agent.jpg");
 	int irecord_video_frame_width = REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_WIDTH;
 	int irecord_video_frame_heigt = REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_HEIGHT;
 
-	Clibvideoqueue* video_shm_q_remote = new Clibvideoqueue(REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE);
-	
-	rvc_snprintf(strImgPath, MAX_PATH, "%s", "./bin/agent.jpg");
+	*remote_frame = video_frame_new(irecord_video_frame_width, irecord_video_frame_heigt, VIDEO_FORMAT_RGB24);
+	video_frame_fill_black(*remote_frame);
 
-	video_frame* remote_frame = video_frame_new(irecord_video_frame_width, irecord_video_frame_heigt, VIDEO_FORMAT_RGB24);
-	video_frame_fill_black(remote_frame);
-
-	if (ExistsFile(strImgPath)){
+	if (ExistsFileA(strImgPath)) {
 		IplImage* img = cvLoadImage(strImgPath, 1);
 		videoq_frame* vframe = new videoq_frame;
 
@@ -332,9 +358,9 @@ static void* rvc_remote_videorender_func(void* arg)
 			SWS_POINT, NULL, NULL, NULL);
 
 		uint8_t* src_data[4] = { (unsigned char*)vframe->data + (vframe->height - 1) * vframe->width * 3, NULL, NULL, NULL };
-		int src_linesize[4] = { -vframe->width * 3, 0, 0, 0};
-		unsigned char* dst[4] = { remote_frame->data[0],NULL,NULL,NULL };
-		int dst_linesize[4] = { remote_frame->linesize[0], 0, 0, 0};
+		int src_linesize[4] = { -vframe->width * 3, 0, 0, 0 };
+		unsigned char* dst[4] = { (*remote_frame)->data[0],NULL,NULL,NULL };
+		int dst_linesize[4] = { (*remote_frame)->linesize[0], 0, 0, 0 };
 		sws_scale(sws, src_data, src_linesize, 0, vframe->height, dst, dst_linesize);
 		sws_freeContext(sws);
 
@@ -343,8 +369,28 @@ static void* rvc_remote_videorender_func(void* arg)
 			delete vframe;
 			vframe = NULL;
 		}
+
+		iret = 0;
 	}
 
+	return iret;
+}
+
+
+#ifdef RVC_OS_WIN
+static unsigned int __stdcall rvc_remote_videorender_func(void* arg)
+#else
+static void* rvc_remote_videorender_func(void* arg)
+#endif
+{
+	rvc_video_render_t* param = (rvc_video_render_t*)arg;
+	int iremote_video_fresh_time = param->render_param.iremote_fresh_time;
+
+	Clibvideoqueue* video_shm_q_remote = new Clibvideoqueue(REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE);
+
+	video_frame* remote_frame = NULL;
+	rvc_get_remote_videoframe(&remote_frame);
+
 	video_frame* showframe = NULL;
 	if (-1 == translate_image_resolution(&showframe, param->render_param.iremote_view_cx, param->render_param.iremote_view_cy, remote_frame)) {
 		showframe = video_frame_new(param->render_param.iremote_view_cx, param->render_param.iremote_view_cy, VIDEO_FORMAT_RGB24);