Parcourir la source

Z991239-1621 #comment other 图像采集增加一路i420格式

陈礼鹏80274480 il y a 4 ans
Parent
commit
0c2639d0b2
1 fichiers modifiés avec 99 ajouts et 26 suppressions
  1. 99 26
      Module/mod_mediacontroller/capture.cpp

+ 99 - 26
Module/mod_mediacontroller/capture.cpp

@@ -425,8 +425,15 @@ static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int
 {
 	videoq_frame tmp_frm;
 	tmp_frm.data = frame->data[0];
-	tmp_frm.framesize = frame->width * frame->height * 3;
-	tmp_frm.format = VIDEOQ_FORMAT_RGB24;
+	if (VIDEO_FORMAT_RGB24 == frame->format){
+		tmp_frm.framesize = frame->width * frame->height * 3;
+		tmp_frm.format = VIDEOQ_FORMAT_RGB24;
+	}
+	else {
+		tmp_frm.framesize = frame->width * frame->height * 3/2;
+		tmp_frm.format = VIDEOQ_FORMAT_I420;
+	}
+
 	tmp_frm.width = frame->width;
 	tmp_frm.height = frame->height;
 	unsigned int nowtime = y2k_time_now();
@@ -439,6 +446,22 @@ static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int
 	}
 }
 
+static int env_cap_on_frame_i420(void* user_data, video_frame* frame)
+{
+	video_capture_t* video_cap = (video_capture_t*)user_data;
+	capture_t* cap = video_cap->parent;
+	return video_shm_enqueue(video_cap->render_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
+}
+
+
+static int opt_cap_on_frame_i420(void* user_data, video_frame* frame)
+{
+	video_capture_t* video_cap = (video_capture_t*)user_data;
+	capture_t* cap = video_cap->parent;
+	return video_shm_enqueue(video_cap->opt_render_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
+}
+
+
 static void env_cap_on_frame(void *user_data, video_frame *frame)
 {
 	video_capture_t *video_cap = (video_capture_t *)user_data;
@@ -449,18 +472,27 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 	//Dbg("env cap on frame");
 
 	//Dbg("start env on frame, id=%d, tick=%d", video_cap->frame_id, GetTickCount());;
-	//IplImage*img = NULL;
-	//img = cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
+	//IplImage* img = NULL;
+	//img = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
 	//img->imageData = (char*)frame->data[0];
-	//cvSaveImage("d:\\env.jpg", img,0);
+	//cvSaveImage("./env.jpg", img, 0);
 	//cvReleaseImageHeader(&img);
 
 	rc = video_shm_enqueue(video_cap->snapshot_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
 
+	static int isnapshot_shm_queue = 0;
+	if (isnapshot_shm_queue == 0) {
+		video_frame_save_bmpfile("snapshot_shm_queue.bmp", frame);
+		isnapshot_shm_queue++;
+	}
+
 	if (rc != Error_Succeed) 
 	{
-		Dbg("env snapshot queue enqueue shm failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
+		Dbg("env snapshot queue enqueue failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
 	}
+	//else {
+	//	Dbg("env snapshot queue enqueue success! camera_type=%d", video_cap->camera_type);
+	//}
 	// snapshot
 	if (rc==Error_Succeed)
 	{
@@ -494,8 +526,20 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 		video_frame_alloc(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24, &preview_frame);
 		uint8_t *src_data[4] = {frame->data[0] + 80*3, 0, 0, 0};
 		sws_scale(video_cap->preview_sws_ctx, src_data, frame->linesize, 0, frame->height, preview_frame.data, preview_frame.linesize);
-		video_shm_enqueue(video_cap->preview_shm_queue, &preview_frame, 0);
+		rc= video_shm_enqueue(video_cap->preview_shm_queue, &preview_frame, 0);
+		if (rc != Error_Succeed){
+			Dbg("preview_shm_queue enqueue failed! Error = %d", rc);
+		}
+		//else {
+		//	Dbg("preview_shm_queue enqueue success!");
+		//}
 		video_frame_free(&preview_frame);
+
+		static int ipreview_shm_queue = 0;
+		if (ipreview_shm_queue == 0) {
+			video_frame_save_bmpfile("preview_shm_queue.bmp", frame);
+			ipreview_shm_queue++;
+		}
 	}
 	// rtp
 	{
@@ -504,19 +548,33 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 		uint8_t *src_data[4] = {frame->data[0] + (frame->height-1) * frame->linesize[0], 0, 0, 0};
 		int src_linesize[4] = {-frame->linesize[0], 0, 0, 0};
 		sws_scale(video_cap->rtp_sws_ctx, src_data, src_linesize, 0, frame->height, rtp_frame.data, rtp_frame.linesize);
-		video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
+		rc = video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
+		if (rc != Error_Succeed) {
+			Dbg("rtp_shm_queue enqueue failed! Error = %d", rc);
+		}
+		//else {
+		//	Dbg("rtp_shm_queue enqueue success!");
+		//}
+
+		static int irtp_frame = 0;
+		if (irtp_frame == 0){
+			video_frame_save_bmpfile("rtp_shm_queue.bmp", &rtp_frame);
+			irtp_frame++;
+		}
+		
 #if 0
 		static int i = 0;
-		if (i == 0 && 0) {
+		if (i == 0) {
 			video_frame tmp_frame;
-			video_frame_alloc(320, 180, VIDEO_FORMAT_RGB24, &tmp_frame);
+			video_frame_alloc(REC_COMMON_VIDEO_RTP_ENV_WIDTH, REC_COMMON_VIDEO_RTP_ENV_HEIGHT, VIDEO_FORMAT_RGB24, &tmp_frame);
 			video_frame_fill_black(&tmp_frame);
 			videoq_frame frm;
 			frm.data = tmp_frame.data[0];
 			video_cap->rtp_shm_queue->GetVideo(&frm, 0);
-			video_frame_save_bmpfile("d:\\abc.bmp", &tmp_frame);
+			video_frame_save_bmpfile("rtp_videoqueue_abc.bmp", &tmp_frame);
 			video_frame_free(&tmp_frame);
 			//video_frame_save_bmpfile("d:\\ab.bmp", &rtp_frame);
+			i++;
 		}
 #endif
 		video_frame_free(&rtp_frame);
@@ -590,6 +648,9 @@ static void opt_cap_on_frame(void *user_data, video_frame *frame)
 	{
 		Dbg("opt snapshot queue enqueue shm failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
 	}
+	//else {
+	//	Dbg("opt snapshot queue enqueue success!" );
+	//}
 	// snapshot
 	if (rc==Error_Succeed)
 	{
@@ -613,7 +674,14 @@ static void opt_cap_on_frame(void *user_data, video_frame *frame)
 		video_frame rtp_frame = {0};
 		video_frame_alloc(REC_COMMON_VIDEO_RTP_OPT_WIDTH, REC_COMMON_VIDEO_RTP_OPT_HEIGHT, VIDEO_FORMAT_RGB24, &rtp_frame);
 		sws_scale(video_cap->rtp_sws_ctx, rframe.data, rframe.linesize, 0, rframe.height, rtp_frame.data, rtp_frame.linesize);
-		video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
+		rc = video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
+		if (rc != Error_Succeed)
+		{
+			Dbg("rtp_shm_queue enqueue shm failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
+		}
+		//else {
+		//	Dbg("rtp_shm_queue enqueue success!");
+		//}
 		video_frame_free(&rtp_frame);
 	}
 
@@ -627,7 +695,10 @@ static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
 		video_cap->parent = cap;
 		video_cap->camera_type = camera_type;
 		video_cap->frame_id = 0;
+		
 		if (camera_type == CAMERA_TYPE_ENV) {
+			video_cap->render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RENDER_QUEUE);
+			video_cap->opt_render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RENDER_QUEUE);
 			video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
 			video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
 			video_cap->rtp_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, 
@@ -646,6 +717,8 @@ static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
 				AV_PIX_FMT_BGR24,
 				SWS_FAST_BILINEAR, NULL, NULL, NULL);
 		} else {
+			video_cap->render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RENDER_QUEUE);
+			video_cap->opt_render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RENDER_QUEUE);
 			video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
 			video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
 			video_cap->rtp_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, 
@@ -685,6 +758,14 @@ static void video_capture_destroy(video_capture_t *video_cap)
 			delete video_cap->preview_shm_queue;
 			video_cap->preview_shm_queue = NULL;
 		}
+		if (video_cap->render_shm_queue) {
+			delete video_cap->render_shm_queue;
+			video_cap->render_shm_queue = NULL;
+		}
+		if (video_cap->opt_render_shm_queue) {
+			delete video_cap->opt_render_shm_queue;
+			video_cap->opt_render_shm_queue = NULL;
+		}
 		free(video_cap);
 	}
 }
@@ -693,7 +774,7 @@ static void video_capture_destroy(video_capture_t *video_cap)
 static int get_video_capture_fps()
 {
 	int ifps = REC_COMMON_VIDEO_PADRAW_FPS;
-//#ifdef RVC_OS_WIN
+#ifdef RVC_OS_WIN
 	if ((ePadtype == g_eDeviceType) || (eMobilePadType == g_eDeviceType) || (eDesk2SType == g_eDeviceType) 
 	|| (eDesk1SType == g_eDeviceType) || (eDesk2SIntegratedType == g_eDeviceType)){
 		ifps = REC_COMMON_VIDEO_PADRAW_FPS;
@@ -701,9 +782,9 @@ static int get_video_capture_fps()
 	else{
 		ifps = REC_COMMON_VIDEO_RAW_FPS;
 	}
-//#else
-//	ifps = REC_COMMON_VIDEO_PADRAW_FPS;
-//#endif // RVC_OS_WIN
+#else
+	ifps = REC_COMMON_VIDEO_PADRAW_FPS;
+#endif // RVC_OS_WIN
 
 	return ifps;
 }
@@ -818,8 +899,10 @@ static int video_capture_start_linux(video_capture_t* video_cap)
 	t_param.fps = get_video_capture_fps();
 
 	t_param.on_frame = (video_cap->camera_type == CAMERA_TYPE_ENV ? &env_cap_on_frame : &opt_cap_on_frame);
+	t_param.on_frame_i420 = (video_cap->camera_type == CAMERA_TYPE_ENV ? &env_cap_on_frame_i420 : &opt_cap_on_frame_i420);
 	t_param.user_data = video_cap;
 	t_param.option = 0;
+	
 
 	video_cap->pVideoCap = new VideoCapObj();
 	if (NULL != video_cap->pVideoCap){
@@ -924,22 +1007,17 @@ namespace MediaController {
 
 	int capture_create(const capture_config_t *config, capture_t **p_cap)
 	{
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		capture_t *cap = ZALLOC_T(capture_t);
 		cap->audio = NULL;
 		cap->env_video = NULL;
 		cap->opt_video = NULL;
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		memcpy(&cap->config, config, sizeof(capture_config_t));
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		cap->audio = audio_capture_create(cap);
 		if (!cap->audio) {
 			Dbg("create audio capture object failed!");
 			return Error_Unexpect;
 		}
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		int dev_id_env = capture_get_video_device_id(config->strVideoEnv);
-		Dbg("%s:%d %d", __FUNCTION__, __LINE__, dev_id_env);
 		if (dev_id_env != -1) 
 		{
 			cap->env_video = video_capture_create(cap, CAMERA_TYPE_ENV);
@@ -948,13 +1026,11 @@ namespace MediaController {
 				return Error_Unexpect;
 			}
 		}
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		int dev_id_opt = -1;
 		if (eStand2sType == g_eDeviceType)
 		{
 			dev_id_opt = capture_get_video_device_id(config->strVideoOpt);
 		}
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		if (dev_id_opt != -1) 
 		{
 			cap->opt_video = video_capture_create(cap, CAMERA_TYPE_OPT);
@@ -964,7 +1040,6 @@ namespace MediaController {
 				return Error_Unexpect;
 			}
 		}
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		if((dev_id_env == -1)&&(dev_id_opt == -1))
 		{
 			Dbg("all camera device id error!");
@@ -974,7 +1049,6 @@ namespace MediaController {
 		else
 		{
 			*p_cap = cap;
-			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			return 0;
 		}
 	}
@@ -1454,7 +1528,6 @@ namespace MediaController {
 		}
 		return -1; // not found
 #else
-		Dbg("%s:%d, %s", __FUNCTION__, __LINE__, dev_name);
 		return rvc_videocap_get_video_device_id(dev_name);
 #endif // RVC_OS_WIN