Explorar el Código

Z991239-1683 #comment other linux下增加视频回显功能

陈礼鹏80274480 hace 4 años
padre
commit
801049dee1

+ 207 - 101
Module/mod_sipphone/video_session.cpp

@@ -10,13 +10,13 @@
 
 #include "../../Other/rvcmediacommon/common_video/videocommon.h"
 #include "../../Other/libvideoframework/videoutil.h"
-#include "../../Other/libvideoframework/videoplayer.h"
-#include "../../Other/libvideoframework/videocap.h"
 #include "../../Other/libvideoframework/videortp.h"
 #include "../../Other/libvideoframework/videoclock.h"
 #include "fileutil.h"
 
 #ifdef RVC_OS_WIN
+#include "../../Other/libvideoframework/videoplayer.h"
+#include "../../Other/libvideoframework/videocap.h"
 #include <ipp.h>
 #include <io.h>
 #include <DbgHelp.h>
@@ -99,9 +99,7 @@ struct video_session_t
 	Clibvideoqueue *video_shm_q_preview; // preview queue
 	Clibvideoqueue *video_shm_q_remote; // preview queue
 	videoq_frame *video_error;
-	videoplayer_t *remote_player;
 	videortp_t *rtp;
-	videoplayer_t *local_player;
 	videoclock_t local_clock;
 	struct SwsContext *local_encode_sws_ctx_env;
 	struct SwsContext *local_encode_sws_ctx_opt;
@@ -111,6 +109,8 @@ struct video_session_t
 	IplImage*recordareamask;
 
 #ifdef RVC_OS_WIN
+	videoplayer_t* local_player;
+	videoplayer_t* remote_player;
 	HANDLE ui_thread;
 	HANDLE ui_event;
 	HWND local_hwnd; // preview window
@@ -188,10 +188,12 @@ static int calc_capture_mode(int width, int height, int *mode)
 	return Error_NotExist;
 }
 
+#ifdef RVC_OS_WIN
 static void __delete_frame(videoplayer_t *player, void *user_data, video_frame *frame)
 {
 	video_frame_delete(frame);
 }
+#endif
 
 static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int flags)
 {
@@ -215,6 +217,7 @@ static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int
 }
 static inline Clibvideoqueue *get_active_videoqueue(video_session_t *session)
 {
+	LOG_FUNCTION();
 	int agent_option = *session->conf.ref_camera_switch;
 	int facetracking_option = *session->conf.ref_active_camera;
 	int camera_state = *session->conf.ref_camera_state;
@@ -273,12 +276,16 @@ static inline Clibvideoqueue *get_active_videoqueue(video_session_t *session)
 			active = NULL;
 		}		
 	}
+
+	active = session->video_shm_q_env;
+
 	return active;
 }
 
 
 static void local_get_frame(void *user_data, video_frame *frame)
 {
+	LOG_FUNCTION();
 	video_session_t *session = (video_session_t*)user_data;
 	Clibvideoqueue *q = get_active_videoqueue(session);
 
@@ -315,22 +322,27 @@ static void local_get_frame(void *user_data, video_frame *frame)
 
 static void local_put_frame(void *user_data, video_frame *frame)
 {
+	LOG_FUNCTION();
 	video_session_t *session = (video_session_t*)user_data;
 	video_frame *tmp_frame_encode = NULL;
-	int rc;
 
 	// send out
 	{
 		tmp_frame_encode = video_frame_new(REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_I420);
 		video_frame_fill_black(tmp_frame_encode);
 		if (frame->width == REC_COMMON_VIDEO_RTP_ENV_WIDTH && frame->height == REC_COMMON_VIDEO_RTP_ENV_HEIGHT) { // env
+			Dbg("send env %s:%d", __FUNCTION__, __LINE__);
 			int offset = (REC_COMMON_VIDEO_RTP_HEIGHT - REC_COMMON_VIDEO_RTP_ENV_HEIGHT) / 2;
 			unsigned char *dst_data[4] = {tmp_frame_encode->data[0], tmp_frame_encode->data[1], tmp_frame_encode->data[2], NULL};
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			dst_data[0] += offset * tmp_frame_encode->linesize[0];
 			dst_data[1] += offset / 2 * tmp_frame_encode->linesize[1];
 			dst_data[2] += offset / 2 * tmp_frame_encode->linesize[2];
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			sws_scale(session->local_encode_sws_ctx_env, frame->data, frame->linesize, 0, frame->height, dst_data, tmp_frame_encode->linesize);
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 		} else if (frame->width == REC_COMMON_VIDEO_RTP_OPT_WIDTH && frame->height == REC_COMMON_VIDEO_RTP_OPT_HEIGHT) { // opt
+			Dbg("send opt %s:%d", __FUNCTION__, __LINE__);
 			video_frame tt;
 			video_frame_alloc(REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, &tt);
 			video_frame_fill_black(&tt);
@@ -349,28 +361,33 @@ static void local_put_frame(void *user_data, video_frame *frame)
 
 
 			}
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			sws_scale(session->local_encode_sws_ctx_opt, tt.data, tt.linesize, 0, tt.height, tmp_frame_encode->data, tmp_frame_encode->linesize);
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			video_frame_free(&tt);
 		}
-
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		if (session->conf.local_pt == REC_COMMON_VIDEO_PT)
 		{
+			Dbg("%s:%d videortp send frame", __FUNCTION__, __LINE__);
 			videortp_send_frame(session->rtp, tmp_frame_encode);
 		}
 		else
 		{
+			Dbg("%s:%d videortp send yuvframe session->rtp = 0x%0x, tmp_frame_encode = 0x%0x", __FUNCTION__, __LINE__, session->rtp, tmp_frame_encode);
 			videortp_send_yuvframe(session->rtp, tmp_frame_encode);
 		}
 	}
 
-on_error:
 	if (tmp_frame_encode) {
+		Dbg("%s:%d video frame delete", __FUNCTION__, __LINE__);
 		video_frame_delete(tmp_frame_encode);
 	}
 }
 
 static int on_rx_frame(video_frame *frame, void *user_data)
 {
+	LOG_FUNCTION();
 	video_session_t *session = (video_session_t *)user_data;
 	////计算当前接收到的视频帧频,用于移动版
 	//DWORD nCurFrameTime = GetTickCount();
@@ -397,42 +414,56 @@ static int on_rx_frame(video_frame *frame, void *user_data)
 	//	nRecvFrameNum = 0;
 	//	g_nLastRecFrameTime = GetTickCount();
 	//}
-	int used = 0;
-	if (session->remote_player) 
-	{
-		if (session->conf.nCallType == MOBILETOPAD_CALLTYPE){
-			int rc = video_shm_enqueue(session->video_shm_q_remote, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
-			if (rc != Error_Succeed) {
-				Dbg("mobile mod insert remote video to queue");
-			}
-			//Dbg("remote video queue get video lens:%d.", session->video_shm_q_remote->GetVideoLens());
-		}
-		else if(DOUBLERECORD_CALLTYPE == session->conf.nCallType){
-			if (eStand2sType == session->conf.eDeviceType){
-				//大机对远端视频进行缩放匹配
-				video_frame* recordframe = NULL;
-				if(0 == translate_image_resolution(&recordframe,/*REC_COMMON_VIDEO_SSM_AGENT_WIDTH*/REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_WIDTH,/*REC_COMMON_VIDEO_SSM_AGENT_HEIGHT*/REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_HEIGHT,frame)){
-					int rc = video_shm_enqueue(session->video_shm_q_remote, recordframe, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
-					if (rc != Error_Succeed) {
-						Dbg("eStand2sType record call mod insert remote video to queue");
-					}
-					video_frame_delete(recordframe);
-				}
-				recordframe = NULL;
-			}
-			else{
-				int rc = video_shm_enqueue(session->video_shm_q_remote, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
+
+	if (session->conf.nCallType == MOBILETOPAD_CALLTYPE) {
+		int rc = video_shm_enqueue(session->video_shm_q_remote, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
+		if (rc != Error_Succeed) {
+			Dbg("mobile mod insert remote video to queue");
+		}
+		//Dbg("remote video queue get video lens:%d.", session->video_shm_q_remote->GetVideoLens());
+	}
+	else if (DOUBLERECORD_CALLTYPE == session->conf.nCallType) {
+		if (eStand2sType == session->conf.eDeviceType) {
+			//大机对远端视频进行缩放匹配
+			video_frame* recordframe = NULL;
+			if (0 == translate_image_resolution(&recordframe,/*REC_COMMON_VIDEO_SSM_AGENT_WIDTH*/REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_WIDTH,/*REC_COMMON_VIDEO_SSM_AGENT_HEIGHT*/REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_HEIGHT, frame)) {
+				int rc = video_shm_enqueue(session->video_shm_q_remote, recordframe, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
 				if (rc != Error_Succeed) {
-					Dbg("not eStand2sType record call mod insert remote video to queue.");
+					Dbg("eStand2sType record call mod insert remote video to queue");
 				}
+				video_frame_delete(recordframe);
+			}
+			recordframe = NULL;
+		}
+		else {
+			int rc = video_shm_enqueue(session->video_shm_q_remote, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
+			if (rc != Error_Succeed) {
+				Dbg("not eStand2sType record call mod insert remote video to queue.");
 			}
 		}
+	}
 
+	int used = 0;
+#ifdef RVC_OS_WIN
+	if (session->remote_player)
+	{
 		int rc = videoplayer_queue_frame(session->remote_player, frame, &__delete_frame, NULL);
 		if (rc == 0) {
-			used = TRUE;
+			used = 1;
 		}
 	}
+#else
+	static int icount = 0;
+	if (icount == 0){
+		video_frame_save_bmpfile("test.bmp", frame);
+		icount++;
+	}
+	if (NULL != session->premote_render){
+		Dbg("session plocal_render RenderVideoFrame");
+		session->premote_render->RenderVideoFrame(frame);
+	}
+
+#endif
 	return used;
 }
 
@@ -464,7 +495,7 @@ int GetCurrentRunPath(char* pPath)
 	strncpy_s(pPath, MAX_PATH_SIZE, pBuf, len - lenDel);
 	delete[]pBuf;   return strnlen_s(pPath, MAX_PATH_SIZE);
 }
-#endif // RVC_OS_WIN
+
 
 
 //远端视频窗口状态回调
@@ -485,8 +516,9 @@ static int on_remoteWinstate(videoplayer_t *player, void *user_data, video_frame
 	//}
 	return *session->conf.ref_window_state ;
 }
-//本地回显回调
 
+
+//本地回显回调
 static int on_pull(videoplayer_t *player, void *user_data, video_frame **frame)
 {
 	video_session_t *session = (video_session_t*)user_data;
@@ -673,11 +705,15 @@ static int on_pull(videoplayer_t *player, void *user_data, video_frame **frame)
 	return *session->conf.ref_window_state;
 }
 
+
 static void free_frame(videoplayer_t *player, void *user_data, video_frame *frame)
 {
 	video_frame_delete(frame);
 }
 
+#endif // RVC_OS_WIN
+
+
 int show_agent_picture_proc(void *arg)
 {
 	LOG_FUNCTION();
@@ -925,7 +961,6 @@ static void	show_remote_agnet_picture(video_session_t *t_session)
 		video_frame_copy(showframe, remote_frame);
 	}
 	
-	
 	t_session->pic_record = new picture_record_t();
 	t_session->pic_record->record_frame = remote_frame;
 	t_session->pic_record->show_frame = showframe;
@@ -988,12 +1023,52 @@ static int start_video_rtpsession(video_session_t* session)
 }
 
 
+static int start_local_video_clock(video_session_t* session)
+{
+	int rc = -1;
+	Dbg("%s:%d.", __FUNCTION__, __LINE__);
+	if (session->conf.eDeviceType == eMobilePadType){
+		rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN,
+			REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
+			&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps, &__dbg);
+	}
+	else if ((session->conf.eDeviceType == ePadtype) || (session->conf.eDeviceType == eDesk2SType) || (session->conf.eDeviceType == eDesk1SType) || (session->conf.eDeviceType == eDesk2SIntegratedType))
+	{
+		rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN,
+			REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
+			&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps, &__dbg);
+	}
+	else if (session->conf.eDeviceType == eStand2sType)
+	{
+		rc = videoclock_create(REC_COMMON_VIDEO_FPS_NUM, REC_COMMON_VIDEO_FPS_DEN,
+			REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
+			&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps, &__dbg);
+	}
+
+	Dbg("create session->local_clock addr is %0x", session->local_clock);
+
+	if (0 == rc) {
+		rc = videoclock_start(session->local_clock);
+		if (rc != 0) {
+			Dbg("start video clock failed!");
+			videoclock_destroy(session->local_clock);
+			session->local_clock = NULL;
+		}
+		else {
+			Dbg("videoclock start success!");
+		}
+	}
+	else {
+		Dbg("create video clock failed!");
+	}
+	return rc;
+}
+
 static int start_video(video_session_t *session)
 {
 	LOG_FUNCTION();
 	int rc = -1;
 
-#ifdef RVC_OS_WIN
 	if (session->video_shm_q_env) 
 	{
 		session->local_encode_sws_ctx_env = sws_getContext(
@@ -1026,7 +1101,7 @@ static int start_video(video_session_t *session)
 		Dbg("session->video_shm_q_opt is NULL.");
 	}
 
-
+#ifdef RVC_OS_WIN
 	Dbg("session nCallType is %d, remote_video_view_cx = %d,remote_video_view_cy = %d,remote_video_width = %d,remote_video_height = %d.", session->conf.nCallType,session->conf.remote_video_view_cx,session->conf.remote_video_view_cy,session->conf.remote_video_width,session->conf.remote_video_height);
 	if (DOUBLERECORD_CALLTYPE != session->conf.nCallType){
 		Dbg("create new remote video player");
@@ -1292,36 +1367,40 @@ static int start_video(video_session_t *session)
 				}
 			}
 
-			if (session->conf.eDeviceType == eMobilePadType)
-			{
-				rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN, 
-					REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
-					&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
-			} 
-			else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
-			{
-				rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN, 
-					REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
-					&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
-			}
-			else if(session->conf.eDeviceType == eStand2sType)
-			{
-				rc = videoclock_create(REC_COMMON_VIDEO_FPS_NUM, REC_COMMON_VIDEO_FPS_DEN, 
-					REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
-					&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
-			}
+			//if (session->conf.eDeviceType == eMobilePadType)
+			//{
+			//	rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN, 
+			//		REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
+			//		&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
+			//} 
+			//else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
+			//{
+			//	rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN, 
+			//		REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
+			//		&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
+			//}
+			//else if(session->conf.eDeviceType == eStand2sType)
+			//{
+			//	rc = videoclock_create(REC_COMMON_VIDEO_FPS_NUM, REC_COMMON_VIDEO_FPS_DEN, 
+			//		REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, 
+			//		&local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
+			//}
 
-			Dbg("create session->local_clock addr is %0x", session->local_clock);
-			
-			if (rc != 0) {
-				Dbg("create video clock failed!");
-				goto on_error;
-			}
-			rc = videoclock_start(session->local_clock);
-			if (rc != 0) {
-				Dbg("start video clock failed!");
-				videoclock_destroy(session->local_clock);
-				session->local_clock = NULL;
+			//Dbg("create session->local_clock addr is %0x", session->local_clock);
+			//
+			//if (rc != 0) {
+			//	Dbg("create video clock failed!");
+			//	goto on_error;
+			//}
+			//rc = videoclock_start(session->local_clock);
+			//if (rc != 0) {
+			//	Dbg("start video clock failed!");
+			//	videoclock_destroy(session->local_clock);
+			//	session->local_clock = NULL;
+			//	goto on_error;
+			//}
+
+			if (0 != start_local_video_clock(session)) {
 				goto on_error;
 			}
 		}
@@ -1331,30 +1410,36 @@ static int start_video(video_session_t *session)
 			show_remote_agnet_picture(session);
 		}
 	}
-on_error:
-	return rc;
 #else
-	return start_video_rtpsession(session);
+	if (0 != start_video_rtpsession(session)) {
+		goto on_error;
+	}
+
+	Dbg("%s:%d.",__FUNCTION__, __LINE__);
+	if (0 != start_local_video_clock(session)) {
+		goto on_error;
+	}
+	Dbg("%s:%d.", __FUNCTION__, __LINE__);
 #endif // RVC_OS_WIN
+
+on_error:
+	return rc;
 }
 
 static void stop_video(video_session_t *session)
 {
 	LOG_FUNCTION();
 
-#ifdef RVC_OS_WIN
-	Dbg("stop_video param video_session %0x, session->local_clock is %0x, session->remote_hwnd is %0x.", session, session->local_clock, session->remote_hwnd);
-	if (session->local_clock && session->remote_hwnd)
-	{
-		Dbg("videoclock_stop local_clock addr is %0x", session->local_clock);
-		videoclock_stop(session->local_clock);
-		videoclock_destroy(session->local_clock);
-		session->local_clock = NULL;
-		pg_remote_hwnd = NULL;
-		pg_local_hwnd = NULL;
+	if (session->local_encode_sws_ctx_env) {
+		sws_freeContext(session->local_encode_sws_ctx_env);
+		session->local_encode_sws_ctx_env = NULL;
+	}
+	if (session->local_encode_sws_ctx_opt) {
+		sws_freeContext(session->local_encode_sws_ctx_opt);
+		session->local_encode_sws_ctx_opt = NULL;
 	}
 
-	if (session->rtp/*&&session->remote_hwnd*/)
+	if (session->rtp)
 	{
 		Dbg("begin stop video rtp.");
 		videortp_stop(session->rtp);
@@ -1365,6 +1450,18 @@ static void stop_video(video_session_t *session)
 		Dbg("session->rtp == null");
 	}
 
+#ifdef RVC_OS_WIN
+	Dbg("stop_video param video_session %0x, session->local_clock is %0x, session->remote_hwnd is %0x.", session, session->local_clock, session->remote_hwnd);
+	if (session->local_clock && session->remote_hwnd)
+	{
+		Dbg("videoclock_stop local_clock addr is %0x", session->local_clock);
+		videoclock_stop(session->local_clock);
+		videoclock_destroy(session->local_clock);
+		session->local_clock = NULL;
+		pg_remote_hwnd = NULL;
+		pg_local_hwnd = NULL;
+	}
+
 	if (session->local_player) {
 		videoplayer_destroy(session->local_player);
 		session->local_player = NULL;
@@ -1378,25 +1475,17 @@ static void stop_video(video_session_t *session)
 		Dbg("remote video player destroy.");
 	}
 
-	if (session->local_encode_sws_ctx_env) {
-		sws_freeContext(session->local_encode_sws_ctx_env);
-		session->local_encode_sws_ctx_env = NULL;
-	}
-	if (session->local_encode_sws_ctx_opt) {
-		sws_freeContext(session->local_encode_sws_ctx_opt);
-		session->local_encode_sws_ctx_opt = NULL;
-	}
 #else
-	if (session->rtp){
-		Dbg("begin stop video rtp.");
-		videortp_stop(session->rtp);
-		videortp_destroy(session->rtp);
-		session->rtp = NULL;
-	}
-	else {
-		Dbg("session->rtp == null");
+
+	if (session->local_clock)
+	{
+		Dbg("videoclock_stop local_clock addr is %0x", session->local_clock);
+		videoclock_stop(session->local_clock);
+		videoclock_destroy(session->local_clock);
+		session->local_clock = NULL;
 	}
 
+
 #endif // RVC_OS_WIN
 }
 
@@ -1796,8 +1885,24 @@ void* videorender_func(void* arg)
 	video_session_t* session = (video_session_t*)arg;
 	Dbg("%s:%d session addr is 0x%0x, session->plocal_render = 0x%0x", __FUNCTION__, __LINE__, session, session->plocal_render);
 
+	Dbg("videorender_func local_pt: %d local_ip: %d local_rtp_port: %d.", session->conf.local_pt, session->conf.local_rtp_ip, session->conf.local_rtp_port);
+	Dbg("videorender_func remote_pt: %d remote_ip: %d remote_rtp_port: %d.", session->conf.remote_pt, session->conf.remote_rtp_ip, session->conf.remote_rtp_port);
+	Dbg("videorender_func rx_width: %d rx_height: %d.", session->conf.remote_video_width, session->conf.remote_video_height);
+
 	if (NULL != session->premote_render)
 	{
+		videorender_param_t tparam_remote = { 0 };
+		tparam_remote.icx = 0;
+		tparam_remote.icy = REC_COMMON_VIDEO_PREVIEW_WIDTH+50;
+		tparam_remote.uwidth = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
+		tparam_remote.uheight = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
+		tparam_remote.uvideowidth = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
+		tparam_remote.uvideoheight = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
+		tparam_remote.ivideoformat = VIDEO_FORMAT_RGB24;
+		if (0 == session->premote_render->SetVideoRenderParam(&tparam_remote)) {
+			session->premote_render->ShowVideoWindow();
+		}
+
 		start_video(session);
 	}
 
@@ -1812,9 +1917,7 @@ void* videorender_func(void* arg)
 		tparam.uvideoheight = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
 		tparam.ivideoformat = VIDEO_FORMAT_RGB24;
 		if (0 == session->plocal_render->SetVideoRenderParam(&tparam)){
-			usleep(1000 * 1000 * 2);
 			session->plocal_render->ShowVideoWindow();
-
 			video_frame* frm = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
 
 			while (true)
@@ -2382,7 +2485,7 @@ void video_session_destroy(video_session_t *session)
 
 void av_log_cb(void*ptr, int level, const char*fmt, va_list list)
 {
-	//vDbg(fmt, list);
+	vDbg(fmt, list);
 }
 
 int video_lib_init()
@@ -2410,6 +2513,9 @@ int video_lib_init()
 	
 #else
 	videoframework_init();
+	av_log_set_callback(&av_log_cb);
+	av_log_set_level(AV_LOG_TRACE);
+	//av_log_set_level(AV_LOG_QUIET);
 #endif // RVC_OS_WIN
 	return 0;
 }

+ 3 - 5
Other/libvideoframework/CMakeLists.txt

@@ -23,12 +23,10 @@ endif(MSVC)
 if(MSVC)
 	set(${VIDEOPLATFORM}_SRCS
 	   videocap.h
-       videoclock.h
        videoplayer.h
        #videorender.h
        #videoview.h
 	   videocap.c
-	   videoclock.c
 	   videoplayer.c
        #videorender.c
 	   #videoview.c
@@ -95,10 +93,10 @@ set(${MODULE_PREFIX}_SRCS
    rtp_header_extension/rtp_header_extension_packet.h
    rtp_header_extension/rtp_header_extension_parser.h
 #   videocap.h
-#   videoclock.h
+   videoclock.h
    videocommon.h
    videoframework.h
-#   videoplayer.h
+   videoplayer.h
 #   videorender.h
    videortp.h
    videoutil.h
@@ -175,7 +173,7 @@ set(${MODULE_PREFIX}_SRCS
     rtp_header_extension/rtp_header_extension_packet.cpp
     rtp_header_extension/rtp_header_extension_parser.cpp
 #    videocap.c
-#    videoclock.c
+    videoclock.c
 #    videoplayer.c
 #    videorender.c
     videortp.c

+ 1 - 5
Other/libvideoframework/adaptive_jitter_buffer/video_jbuff_log.c

@@ -1,11 +1,7 @@
 
 #include "video_jbuff_log.h"
 #include "video_jbuff_defines.h"
-#ifdef _WIN32
-#include "stdarg.h "
-#else
-
-#endif // RVC_OS_WIN
+#include "stdarg.h"
 
 static VideoJBufferLogCallBack g_log_func = {0};
 

+ 1 - 0
Other/libvideoframework/congestion_control/cc/razor_log.c

@@ -2,6 +2,7 @@
 #include "razor_log.h"
 #include "razor_api.h"
 #include "../common/cf_platform.h"
+#include <stdarg.h>
 
 static razor_log_func g_log_cb = NULL;
 static void *g_log_user_data = NULL;

+ 1 - 0
Other/libvideoframework/congestion_control/sim_transport/sim_internal.h

@@ -7,6 +7,7 @@
 #include "../cc/razor_api.h"			/*razor的引用头文件*/
 #include "../estimator/rate_stat.h"
 #include "sim_external.h"
+#include "stdarg.h"
 
 struct __sim_session;
 typedef struct __sim_session			sim_session_t;

+ 1 - 1
Other/libvideoframework/congestion_control/sim_transport/sim_sender.c

@@ -7,7 +7,7 @@
 static void sim_bitrate_change(void* trigger, uint32_t bitrate, uint8_t fraction_loss, uint32_t rtt)
 {
 	sim_session_t* s = (sim_session_t*)trigger;
-	sim_sender_t* sender = s->sender;
+	//sim_sender_t* sender = s->sender;
 
 	uint32_t overhead_bitrate, per_packets_second, payload_bitrate, video_bitrate_kbps;
 	double loss;

+ 12 - 1
Other/libvideoframework/precompile.h

@@ -31,6 +31,8 @@
 #include <locale.h>
 #include <time.h>
 
+
+#ifdef RVC_OS_WIN
 #ifdef SPBASE_EXPORTS
 #ifndef SPBASE_API
 #define SPBASE_API __declspec(dllexport)
@@ -39,4 +41,13 @@
 #ifndef SPBASE_API
 #define SPBASE_API __declspec(dllimport)
 #endif
-#endif
+#endif
+# elif ( defined(__GNUC__) &&  __GNUC__ >= 4 )
+#ifndef SPBASE_API
+#define SPBASE_API __attribute__((visibility("default")))
+#endif
+#else // RVC_OS_WIN
+#ifndef SPBASE_API
+#define SPBASE_API
+#endif // !SPBASE_API
+#endif // RVC_OS_WIN

+ 1 - 0
Other/libvideoframework/video_common/videocommon.c

@@ -25,6 +25,7 @@ int videoframework_init()
 	avcodec_register_all();
 	WSAStartup(0x0202, &wsaData);
 #else
+	av_register_all();
 	avcodec_register_all();
 #endif // _WIN32
 	return 0;

+ 1 - 0
Other/libvideoframework/video_statics/video_stats.c

@@ -3,6 +3,7 @@
 
 #include "video_stats.h"
 #include "../videoutil.h"
+#include "stdarg.h"
 
 #define BW_GAMMA 0.5f
 

+ 138 - 12
Other/libvideoframework/videoclock.c

@@ -1,12 +1,19 @@
 #include "precompile.h"
 #include "videoclock.h"
 
+#ifdef RVC_OS_WIN
+#else
+#include <pthread.h>
+#include <semaphore.h>
+#endif
+
 #define TIMER_RESOLUTION 1
 
 struct videoclock
 {
     get_frame_cb get_frame;
     put_frame_cb put_frame;
+	clockdbg_cb dbglog;
 
     int fps_num;
     int fps_den;
@@ -21,11 +28,35 @@ struct videoclock
     HANDLE exit_evt;
     HANDLE thread_run;
 #else
+	sem_t exit_sem;
+	pthread_t thread_id;
 
 #endif
 	volatile int *nVideoSendFreq;
 };
 
+
+static void	clockDbg(videoclock_t clock, const char* fmt, ...)
+{
+	int n;
+	va_list arg;
+	va_start(arg, fmt);
+	if (clock->dbglog) {
+		(clock->dbglog)(clock, fmt, arg);
+	}
+	else {
+		n = _vscprintf(fmt, arg);
+		if (n > 0) {
+			char* buf = (char*)malloc((size_t)(n + 3));
+			vsprintf(buf, fmt, arg);
+			strcat(buf, "\r\n");
+			printf(buf);
+		}
+	}
+	va_end(arg);
+}
+
+#ifdef RVC_OS_WIN
 static __inline void GetTick(LARGE_INTEGER *last, LARGE_INTEGER *lt)
 {
 	DWORD dwNow = GetTickCount();
@@ -108,6 +139,63 @@ on_error:
     _endthreadex(0);
     return 0;
 }
+#else
+void* local_video_sendfunc(void* param)
+{
+	struct videoclock* clock = (struct videoclock*)param;
+	video_frame frame;
+	//LARGE_INTEGER start_tick;
+	int dwTimeout = 50;/*
+	LARGE_INTEGER seq = { 0 };
+	LARGE_INTEGER tick = { 0 };*/
+
+
+	if (video_frame_alloc(clock->frame_width, clock->frame_height, clock->frame_format, &frame) != 0)
+		goto on_error;
+
+	//start_tick.LowPart = GetTickCount();
+	//start_tick.HighPart = 0;
+	//seq.LowPart = 1;
+
+	for (;;) {
+		struct timespec ts;
+		int ivalue = -1;
+		clock_gettime(CLOCK_REALTIME, &ts);
+		ts.tv_nsec += 1000 * 1000 * dwTimeout;
+		sem_getvalue(&clock->exit_sem, &ivalue);
+		clockDbg(clock, "%s:%d sem value is %d", __FUNCTION__, __LINE__, ivalue);
+		if (0 != sem_timedwait(&clock->exit_sem, &ts) /*&& (ETIMEDOUT == errno)*/)
+		{
+			clockDbg(clock, "%s:%d last errno = %d for %s", __FUNCTION__, __LINE__, errno, strerror(errno));
+			clock->get_frame(clock->get_user_data, &frame);
+			clock->put_frame(clock->put_user_data, &frame);
+			//seq.LowPart++;
+			//if (seq.LowPart == 0) {
+			//	seq.HighPart++;
+			//}
+			//GetTick(&tick, &tick);
+
+			//if (seq.QuadPart * clock->fps_den * 1000 / clock->fps_num < tick.QuadPart - start_tick.QuadPart) {
+			//	dwTimeout = 0;
+			//}
+			//else {
+			//	dwTimeout = (DWORD)(seq.QuadPart * clock->fps_den * 1000 / clock->fps_num - (tick.QuadPart - start_tick.QuadPart));
+			//}
+		}
+		else {
+			break;
+		}
+	}
+
+	video_frame_free(&frame);
+
+on_error:
+	return 0;
+}
+
+
+#endif
+
 
 int videoclock_create(int fps_num, 
                       int fps_den, 
@@ -119,7 +207,8 @@ int videoclock_create(int fps_num,
                       get_frame_cb get,
                       void *get_user_data,
                       videoclock_t *p_clock,
-					  volatile int*nFps)
+					  volatile int*nFps,
+					  clockdbg_cb dbgfunc)
 {
     struct videoclock *clock;
 
@@ -132,14 +221,25 @@ int videoclock_create(int fps_num,
         frame_format != VIDEO_FORMAT_RGB24)
         return -1;
 
+	if (NULL == dbgfunc) {
+		return -1;
+	}
+
     clock = malloc(sizeof(struct videoclock));
     if (!clock)
         return -1;
 
     memset(clock, 0, sizeof(struct videoclock));
-    clock->exit_evt = CreateEvent(NULL, FALSE, FALSE, NULL);
-    if (!clock->exit_evt)
-        goto on_error;
+#ifdef RVC_OS_WIN
+	clock->exit_evt = CreateEvent(NULL, FALSE, FALSE, NULL);
+	if (!clock->exit_evt)
+		goto on_error;
+#else
+	if (0 != sem_init(&clock->exit_sem, 0, 0)){
+		goto on_error;
+	}
+#endif
+
     clock->fps_num = fps_num;
 	clock->nVideoSendFreq = fps_num;
     clock->fps_den = fps_den;
@@ -151,13 +251,14 @@ int videoclock_create(int fps_num,
     clock->put_frame = put;
     clock->put_user_data = put_user_data;
 	clock->nVideoSendFreq = nFps;
+	clock->dbglog = dbgfunc;
     *p_clock = clock;
-    
+	
+	clockDbg(clock,"%s:%d videoclock_create success.", __FUNCTION__, __LINE__);
     return 0;
 
 on_error:
-    if (clock->exit_evt)
-        CloseHandle(clock->exit_evt);
+	clockDbg(clock,"%s:%d videoclock_create failed.", __FUNCTION__, __LINE__);
     free(clock);
     return -1;
 }
@@ -165,7 +266,11 @@ on_error:
 void videoclock_destroy(videoclock_t vc)
 {
     if (vc) {
-        CloseHandle(vc->exit_evt);
+#ifdef RVC_OS_WIN
+		CloseHandle(vc->exit_evt);
+#else
+		sem_destroy(&vc->exit_sem);
+#endif
         free(vc);
     }
 }
@@ -174,13 +279,28 @@ int videoclock_start(videoclock_t vc)
 {
 	if (!vc)
 		return -1;
-
+#ifdef RVC_OS_WIN
 	ResetEvent(vc->exit_evt);
-
 	vc->thread_run = (HANDLE)_beginthreadex(NULL, 0, &worker_thread_proc, vc, 0, NULL);
 	if (!vc->thread_run)
 		return -1;
-	
+#else
+	pthread_attr_t attr;
+	pthread_attr_init(&attr);
+	struct sched_param param;
+	param.sched_priority = sched_get_priority_max(SCHED_RR);
+	pthread_attr_setschedpolicy(&attr, SCHED_RR);
+	pthread_attr_setschedparam(&attr, &param);
+	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+	int err = pthread_create(&vc->thread_id, &attr, local_video_sendfunc, vc);
+	if (0 == err) {
+		clockDbg(vc,"%s:%d pthread create success, and thread id is %lu.", __FUNCTION__, __LINE__, vc->thread_id);
+	}
+	else {
+		clockDbg(vc,"%s:%d pthread create failed.", __FUNCTION__, __LINE__);
+		return -1;
+	}
+#endif
 	return 0;
 }
 
@@ -188,7 +308,7 @@ int videoclock_stop(videoclock_t vc)
 {
 	if (!vc)
 		return -1;
-
+#ifdef RVC_OS_WIN
 	if (vc->exit_evt) {
 		SetEvent(vc->exit_evt);
 	}
@@ -197,6 +317,12 @@ int videoclock_stop(videoclock_t vc)
 		CloseHandle(vc->thread_run);
 		vc->thread_run = NULL;
 	}
+#else
+	sem_post(&vc->exit_sem);
+	if (vc->thread_id > 0){
+		pthread_join(vc->thread_id, NULL);
+	}
 
+#endif
 	return 0;
 }

+ 6 - 5
Other/libvideoframework/videoclock.h

@@ -1,11 +1,11 @@
-#ifndef VIDEOCLOCK_H
-#define VIDEOCLOCK_H
+#pragma once
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #include "videoutil.h"
+#include <stdarg.h>
 
 /**
  * video clock engine handler
@@ -14,6 +14,7 @@ typedef struct videoclock* videoclock_t;
 
 typedef void (*get_frame_cb)(void *get_user_data, video_frame *frame);
 typedef void (*put_frame_cb)(void *put_user_data, video_frame *frame);
+typedef void (*clockdbg_cb)(void* user_data, const char* fmt, va_list arg);
 
 /**
  * create a clock engine
@@ -28,6 +29,7 @@ typedef void (*put_frame_cb)(void *put_user_data, video_frame *frame);
  * @param get_usre_data user specify data pass to get_user_data
  * @param p_clock return the created clock engine
  */
+
 int videoclock_create(int fps_num, 
                       int fps_den, 
                       int video_width,
@@ -38,7 +40,8 @@ int videoclock_create(int fps_num,
                       get_frame_cb get,
                       void *get_user_data,
                       videoclock_t *p_clock,
-					  volatile int*nFps);
+					  volatile int*nFps,
+					  clockdbg_cb dbgfunc);
 
 /**
  * destroy the clock 
@@ -58,5 +61,3 @@ int videoclock_stop(videoclock_t vc);
 #ifdef __cplusplus
 }//extern "C" {
 #endif
-
-#endif // VIDEOCLOCK_H

+ 164 - 123
Other/libvideoframework/videortp.c

@@ -147,25 +147,27 @@ typedef struct _MSPicture {
 	int strides[4];					// with ffmpeg's swscale.h
 }MSPicture;
 
-//static void __Dbg(videortp_t *rtp, const char *fmt, ...)
-//{
-//	int n;
-//	va_list arg;
-//	va_start(arg, fmt);
-//	if (rtp->config.dbg) {
-//		(*rtp->config.dbg)(rtp->config.user_data, fmt, arg);
-//	} else {
-//		n = _vscprintf(fmt, arg);
-//		if (n > 0) {
-//			char *buf = (char*)_alloca((size_t)(n+3));
-//			vsprintf(buf, fmt, arg);
-//			strcat(buf, "\r\n");
-//			OutputDebugStringA((LPCSTR)buf);
-//			printf(buf);
-//		}
-//	}
-//	va_end(arg);
-//}
+static void	rtpDbg(videortp_t *rtp, const char *fmt, ...)
+{
+	int n;
+	va_list arg;
+	va_start(arg, fmt);
+	if (rtp->config.dbg) {
+		(*rtp->config.dbg)(rtp->config.user_data, fmt, arg);
+	} else {
+		n = _vscprintf(fmt, arg);
+		if (n > 0) {
+			char *buf = (char*)_alloca((size_t)(n+3));
+			vsprintf(buf, fmt, arg);
+			strcat(buf, "\r\n");
+#ifdef _WIN32
+			OutputDebugStringA((LPCSTR)buf);
+#endif
+			printf(buf);
+		}
+	}
+	va_end(arg);
+}
 
 
 
@@ -298,7 +300,7 @@ static __inline void receiver_notify_peer_fast_update(videortp_t *vrtp)
 	DWORD dwNow = GetTickCount();
 	if (dwNow - vrtp->last_peer_update_tick >= PEER_UPDATE_INTERVAL) {
 
-		Dbg("%I64d receiver_notify_peer_fast_update!", TimeInMilliseconds());
+		rtpDbg(vrtp,"%I64d receiver_notify_peer_fast_update!", TimeInMilliseconds());
 		rtp_session_send_rtcp_h261_fir(vrtp->rtp_sess);
 		vrtp->last_peer_update_tick = dwNow;
 	}
@@ -308,15 +310,23 @@ static __inline void receiver_notify_peer_fast_update_now(videortp_t *vrtp)
 {
 	DWORD dwNow = GetTickCount();
 
-	Dbg("%I64d receiver_notify_peer_fast_update_now!", TimeInMilliseconds());
+	rtpDbg(vrtp,"%I64d receiver_notify_peer_fast_update_now!", TimeInMilliseconds());
 	rtp_session_send_rtcp_h261_fir(vrtp->rtp_sess);
 	vrtp->last_peer_update_tick = dwNow;
 }
 
 static __inline void receiver_force_key_frame(videortp_t *vrtp)
 {
-	Dbg("%I64d receiver_force_key_frame!", TimeInMilliseconds());
+	rtpDbg(vrtp,"%I64d receiver_force_key_frame!", TimeInMilliseconds());
+#ifdef _WIN32
 	InterlockedCompareExchange(&vrtp->force_key_frames, 1, 0);
+#else
+	LONG* plTemp = &vrtp->force_key_frames;
+	if (0 == *plTemp){
+		*plTemp = 1;
+		rtpDbg(vrtp,"%s:%d force_key_frames = %lu", __FUNCTION__, __LINE__, vrtp->force_key_frames);
+	}
+#endif // _WIN32
 }
 
 static void receiver_clear_window(videortp_t *vrtp)
@@ -347,7 +357,7 @@ int video_coding_on_log(void *userdata, int level, const char* file, int line, c
 	if ((DEBUG_ENCODER || DEBUG_DECODER) && n > 0 && vrtp && level >= VIDEO_CODING_DEBUG_INFO) {
 		char *buf = (char*)_alloca((size_t)(n+3));
 		vsprintf(buf, fmt, vl);
-		Dbg("%s.", buf);
+		rtpDbg(vrtp,"%s.", buf);
 	}
 
 	return 0;
@@ -366,18 +376,18 @@ static int decoder_process(videortp_t *vrtp, uint8_t *input_buf, int input_len){
 		video_debug_write_play_file(AUDIO_DEC_IN, input_buf, input_len);
 
 		if(DEBUG_DECODER){
-		Dbg("%s:%d: receiver_do_decode before decode data_len:%d.", __FILE__, __LINE__, input_len);
+		rtpDbg(vrtp,"%s:%d: receiver_do_decode before decode data_len:%d.", __FILE__, __LINE__, input_len);
 		}
 		before_decode_ms = TimeInMilliseconds();
 		
 		decodered_frame = video_decoder_process(vrtp->decoder, input_buf, input_len, &input_len, &key_frame);
 
 		if(DEBUG_DECODER){
-		Dbg("%s:%d: receiver_do_decode after decode data_len:%d.", __FILE__, __LINE__, input_len);
+		rtpDbg(vrtp,"%s:%d: receiver_do_decode after decode data_len:%d.", __FILE__, __LINE__, input_len);
 		}
 		after_decode_ms = TimeInMilliseconds();
 		if (decodered_frame == NULL){
-			Dbg("receiver_do_decode decode failed.");
+			rtpDbg(vrtp,"receiver_do_decode decode failed.");
 			video_stats_receiver_on_decoded_frame(after_decode_ms, after_decode_ms - before_decode_ms, 0);
 			return 0;
 		}
@@ -388,14 +398,21 @@ static int decoder_process(videortp_t *vrtp, uint8_t *input_buf, int input_len){
 		if (vrtp->config.rx_height)
 		{ 
 			if (VIDEO_FORMAT_RGB24 != decodered_frame->format)
-			{	
-				unsigned char *video_debug_buf;
-				int length = vrtp->config.rx_height*vrtp->config.rx_width*3/2;
-				video_debug_buf = (unsigned char *)malloc(length);
+			{
+				unsigned char* video_debug_buf;
+				int length = vrtp->config.rx_height * vrtp->config.rx_width * 3 / 2;
+				video_debug_buf = (unsigned char*)malloc(length);
 				yuv_buffers_combine_to_one(decodered_frame, video_debug_buf);
 				video_debug_write_play_file(VIDEO_RENDER_IN, video_debug_buf, length);
 				free(video_debug_buf);
 			}
+
+			rtpDbg(vrtp, "%s:%d: decodered_frame->format = %d", __FILE__, __LINE__, decodered_frame->format);
+			static int icount = 0;
+			if (icount == 0) {
+				video_frame_save_bmpfile("formattest.bmp", decodered_frame);
+				icount++;
+			}
 		}
 
 		//notify render
@@ -424,7 +441,7 @@ void decoder_create(videortp_t *vrtp, const videortp_config_t *config){
 	log_func.userdata = vrtp;
 	vrtp->decoder = video_decoder_open(&decoder_config, &log_func);
 
-	Dbg("decoder_create color_space: %d decode_id: %d width: %d height: %d.", 
+	rtpDbg(vrtp,"decoder_create color_space: %d decode_id: %d width: %d height: %d.", 
 		decoder_config.color_space, decoder_config.decode_id, decoder_config.width, decoder_config.height);
 }
 
@@ -432,7 +449,7 @@ void decoder_destroy(videortp_t *vrtp){
 	if (vrtp->decoder != NULL) {
 		video_decoder_close(vrtp->decoder);
 	}
-	Dbg("decoder_destroy.");
+	rtpDbg(vrtp,"decoder_destroy.");
 }
 
 
@@ -674,12 +691,12 @@ static int receiver_h264_on_receive_encoded_image(EncodedImage *encoded_image,
 		int decoded;
 
 	    if(DEBUG_RX){
-		Dbg("%s:%d: receiver_h264_on_receive_encoded_image timestamp:%u first_seq:%u last_seq:%u key: %d len: %d.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: receiver_h264_on_receive_encoded_image timestamp:%u first_seq:%u last_seq:%u key: %d len: %d.", __FILE__, __LINE__, 
 			timestamp, first_seq, last_seq, encoded_image->key_frame, encoded_image->size_);
-		Dbg("%s:%d: receiver_h264_on_receive_encoded_image fragmentationSize: %d.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: receiver_h264_on_receive_encoded_image fragmentationSize: %d.", __FILE__, __LINE__, 
 				encoded_image->fragmentation_header_.fragmentationVectorSize);
 		for (i = 0;i < encoded_image->fragmentation_header_.fragmentationVectorSize;++i){
-		Dbg("%s:%d: receiver_h264_on_receive_encoded_image index: %d fragmentationLength: %d fragmentationOffset: %d.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: receiver_h264_on_receive_encoded_image index: %d fragmentationLength: %d fragmentationOffset: %d.", __FILE__, __LINE__, 
 				i, encoded_image->fragmentation_header_.fragmentationLength[i], encoded_image->fragmentation_header_.fragmentationOffset[i]);
 
 		}
@@ -718,7 +735,7 @@ static int receiver_h264_on_receive_encoded_image(EncodedImage *encoded_image,
 				}
 			}
 			if(DEBUG_RX){
-			Dbg("%s:%d: receiver_h264_on_receive_encoded_image encoded_size:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, 
+			rtpDbg(vrtp,"%s:%d: receiver_h264_on_receive_encoded_image encoded_size:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, 
 				encoded_image->size_, input_len, TimeInMilliseconds());
 			}
 			
@@ -728,7 +745,7 @@ static int receiver_h264_on_receive_encoded_image(EncodedImage *encoded_image,
 				vrtp->prev_dec_seq = last_seq;
 				vrtp->prev_dec_ts = timestamp;
 			} else {
-				Dbg("receiver_h264_on_receive_encoded_image decode_frame failed!");
+				rtpDbg(vrtp,"receiver_h264_on_receive_encoded_image decode_frame failed!");
 			}
 		} 
 	}
@@ -754,7 +771,7 @@ static int receiver_standard_h264_decode(videortp_t *vrtp, rtpframe_t *frame)
 		input_len = receiver_standard_h264_add_startcode(vrtp, frame, input_buf, &need_reinit);
 		}
 		if(DEBUG_RX){
-		Dbg("%s:%d: receiver_standard_h264_decode frame_used:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, frame->used, input_len, TimeInMilliseconds());
+		rtpDbg(vrtp,"%s:%d: receiver_standard_h264_decode frame_used:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, frame->used, input_len, TimeInMilliseconds());
 		}
 		
 		//decode
@@ -789,7 +806,7 @@ rtpframe_t *receiver_standard_h264_assemble(videortp_t *vrtp,
 	part_data->mark = mark;
 	part_data->seq = seq;
 	if(DEBUG_RX){
-	Dbg("%s:%d: receiver_standard_h264_assemble actual_len:%d seq:%d key:%d.", __FILE__, __LINE__, len, seq, key);
+	rtpDbg(vrtp,"%s:%d: receiver_standard_h264_assemble actual_len:%d seq:%d key:%d.", __FILE__, __LINE__, len, seq, key);
 	}
 	
 	iret = receiver_standard_h264_find_frame(vrtp, part_data, mark, ts, key);
@@ -829,7 +846,7 @@ static int receiver_process_standard_h264_packet(
 	packet_info.pt = pt;
 
 	if(DEBUG_RX){
-	Dbg("%s:%d: receiver_process_standard_h264_packet len:%d seq:%d mark:%d ts:%d nalu_type:%u offset:%d actual_len:%d.", __FILE__, __LINE__, 
+	rtpDbg(vrtp,"%s:%d: receiver_process_standard_h264_packet len:%d seq:%d mark:%d ts:%d nalu_type:%u offset:%d actual_len:%d.", __FILE__, __LINE__, 
 		len, seq, mark, ts, nalu_type, offset, actual_len);
 	}
 	
@@ -851,12 +868,12 @@ static int receiver_process_standard_h264_packet(
 				//Dbg("decode_frame ok!");
 				if (vrtp->frame_duration==0 && vrtp->prev_dec_seq+1 == rtpframe_get_first_seq(frame)) {
 					vrtp->frame_duration = frame->ts - vrtp->prev_dec_ts;
-					Dbg("decode frame duration: %d", vrtp->frame_duration);
+					rtpDbg(vrtp,"decode frame duration: %d", vrtp->frame_duration);
 				}
 				vrtp->prev_dec_seq = rtpframe_get_last_seq(frame);
 				vrtp->prev_dec_ts = frame->ts;
 			} else {
-				Dbg("decode_frame failed!");
+				rtpDbg(vrtp,"decode_frame failed!");
 			}
 		} 
 		
@@ -974,7 +991,7 @@ static int receiver_custom_h264_decode(videortp_t *vrtp, rtpframe_t *frame)
 		}
 		memset(input_buf+input_len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 		if(DEBUG_RX){
-		Dbg("%s:%d: receiver_custom_h264_decode frame_used:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, frame->used, input_len, TimeInMilliseconds());
+		rtpDbg(vrtp,"%s:%d: receiver_custom_h264_decode frame_used:%d frame_len:%d now:%I64d.", __FILE__, __LINE__, frame->used, input_len, TimeInMilliseconds());
 		}
 		//decode
 		return decoder_process(vrtp, input_buf, input_len);
@@ -996,7 +1013,7 @@ rtpframe_t *receiver_custom_h264_assemble(videortp_t *vrtp,
 	int sno = hdr->id;
 	int end = hdr->end;
 	if(DEBUG_RX){
-	Dbg("%s:%d: receiver_custom_h264_assemble actual_len:%d seq:%d key:%d sno:%d end: %d.", __FILE__, __LINE__, actual_len, seq, !!key, sno, end);
+	rtpDbg(vrtp,"%s:%d: receiver_custom_h264_assemble actual_len:%d seq:%d key:%d sno:%d end: %d.", __FILE__, __LINE__, actual_len, seq, !!key, sno, end);
 	}
 	part_data->actual_len = actual_len;
 	part_data->offset = sizeof(h26x_hdr)-2;
@@ -1046,7 +1063,7 @@ static int receiver_process_custom_h264_packet(videortp_t *vrtp,
 	packet_info.pt = pt;
 
 	if(DEBUG_RX){
-	Dbg("%s:%d: receiver_process_custom_h264_packet len:%d seq:%d mark:%d ts:%d pt:%u key:%d sno:%d end:%d offset:%d actual_len:%d.", __FILE__, __LINE__, 
+	rtpDbg(vrtp,"%s:%d: receiver_process_custom_h264_packet len:%d seq:%d mark:%d ts:%d pt:%u key:%d sno:%d end:%d offset:%d actual_len:%d.", __FILE__, __LINE__, 
 		len, seq, mark, ts, pt, key, sno, end, offset, actual_len);
 	}
 	
@@ -1057,7 +1074,7 @@ static int receiver_process_custom_h264_packet(videortp_t *vrtp,
 	rtpframe_t *frame = NULL;
 
 	if(DEBUG_RX){
-	Dbg("%s:%d: receiver_process_custom_h264_packet len:%d seq:%d mark:%d ts:%d.", __FILE__, __LINE__, len, seq, mark, ts);
+	rtpDbg(vrtp,"%s:%d: receiver_process_custom_h264_packet len:%d seq:%d mark:%d ts:%d.", __FILE__, __LINE__, len, seq, mark, ts);
 	}
 	
 	frame = receiver_custom_h264_assemble(vrtp, part_data, len, seq, mark, ts);
@@ -1070,12 +1087,12 @@ static int receiver_process_custom_h264_packet(videortp_t *vrtp,
 				if (decoded) {
 					if (vrtp->frame_duration==0 && vrtp->prev_dec_seq+1 == rtpframe_get_first_seq(frame)) {
 						vrtp->frame_duration = frame->ts - vrtp->prev_dec_ts;
-						Dbg("%s:%d: receiver_process_custom_h264_packet decode frame duration: %d.", __FILE__, __LINE__, vrtp->frame_duration);
+						rtpDbg(vrtp,"%s:%d: receiver_process_custom_h264_packet decode frame duration: %d.", __FILE__, __LINE__, vrtp->frame_duration);
 					}
 					vrtp->prev_dec_seq = rtpframe_get_last_seq(frame);
 					vrtp->prev_dec_ts = frame->ts;
 				} else {
-					Dbg("%s:%d: receiver_process_custom_h264_packet decode_frame failed!", __FILE__, __LINE__);
+					rtpDbg(vrtp,"%s:%d: receiver_process_custom_h264_packet decode_frame failed!", __FILE__, __LINE__);
 				}
 				rtpframe_clear(vrtp, frame);
 				vrtp->frame_win_ptr = (frame->id+1) % FRAME_WIN_SIZE;
@@ -1118,28 +1135,39 @@ static void receiver_process_rtcp_packet(videortp_t *vrtp, unsigned rtcp_flags){
 	}
 }
 
-static unsigned int __stdcall recv_proc(void *arg)
+#ifdef _WIN32
+static unsigned int __stdcall recv_proc(void* arg)
+#else
+void* recv_proc(void* arg)
+#endif
 {
 	videortp_t *vrtp = (videortp_t*)arg;
 	int rtp_timeout_cnt = 0;
 	int64_t pre_500_ms = TimeInMilliseconds();
 
-	Dbg("recv_proc.");
-
+	rtpDbg(vrtp,"recv_proc.");
+#ifdef _WIN32
 	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+#else
+	struct sched_param param;
+	int policy;
+	pthread_getschedparam(pthread_self(), &policy, &param);
+	rtpDbg(vrtp,"%s:%d current thread policy is %d, priority is %d.", __FUNCTION__, __LINE__, policy, param.sched_priority);
+#endif
 	receiver_notify_peer_fast_update_now(vrtp);
 
-
 	for (;;) {
 #ifdef _WIN32
 		DWORD dwRet = WaitForSingleObject(vrtp->evt, 10);
 		if (dwRet == WAIT_TIMEOUT)
 #else
 		struct timespec ts;
+		int ivalue = -1;
 		clock_gettime(CLOCK_REALTIME, &ts);
 		ts.tv_nsec += 1000 * 1000 * 10;
-		//sem_getvalue(&m_semt, &ivalue);
-		if (-1 == sem_timedwait(&vrtp->sem_evt, &ts) && (ETIMEDOUT == errno))
+		sem_getvalue(&vrtp->sem_evt, &ivalue);
+		rtpDbg(vrtp,"%s:%d sem value is %d", __FUNCTION__, __LINE__, ivalue);
+		if (0 != sem_timedwait(&vrtp->sem_evt, &ts) /*&& (ETIMEDOUT == errno)*/)
 #endif
 		{
 			int n;
@@ -1147,7 +1175,7 @@ static unsigned int __stdcall recv_proc(void *arg)
 				unsigned rtcp_flags = 0;
 				int result = rtp_session_recv_rtcp(vrtp->rtp_sess, &rtcp_flags);
 				if (result >= 0) {
-					receiver_process_rtcp_packet(vrtp, rtcp_flags);
+					//receiver_process_rtcp_packet(vrtp, rtcp_flags);
 				}
 			}
 			do {
@@ -1175,7 +1203,7 @@ static unsigned int __stdcall recv_proc(void *arg)
 #if 0 // for testing
 #define PACKET_LOSS_RATIO	30 
 				if (n > 0 && rand()%1000 >= PACKET_LOSS_RATIO) {
-					Dbg("rtp_session_recv_hook pt = %u, mark = %u, ts = %u, seq = %u, size = %d", pt, mark, ts, seq, n);
+					rtpDbg(vrtp,"%s:%d rtp_session_recv_hook2 pt = %u, mark = %u, ts = %u, seq = %u, size = %d", __FUNCTION__, __LINE__, pt, mark, ts, seq, n);
 #else
 				if (n > 0) {
 #endif				
@@ -1188,7 +1216,7 @@ static unsigned int __stdcall recv_proc(void *arg)
 						part_data->actual_len = n - extension_length;
 						part_data->offset = extension_length;
 						if(DEBUG_RX){
-							Dbg("%s:%d: recv_proc rtp_header_extension send_time:%u length:%d actual_len:%d offset:%d.", 
+							rtpDbg(vrtp,"%s:%d: recv_proc rtp_header_extension send_time:%u length:%d actual_len:%d offset:%d.", 
 								__FILE__, __LINE__, send_time, extension_length, 
 								part_data->actual_len, part_data->offset);
 						}
@@ -1198,14 +1226,16 @@ static unsigned int __stdcall recv_proc(void *arg)
 					}
 
 					//huchen add for video cc
-					{
-						sim_segment_t seg = {0};
-						seg.transport_seq = seq;
-						//注意,cc中的ts是以真实时间毫秒为单位,rtp的时间戳是90000为1秒,这里需要转换
-						seg.timestamp = (send_time==0 ? (ts/(VIDEO_CLOCK/1000)) : send_time);
-						seg.data_size = n;
-						sim_recv_video(&seg);
-					}
+					//{
+					//	sim_segment_t seg = {0};
+					//	seg.transport_seq = seq;
+					//	//注意,cc中的ts是以真实时间毫秒为单位,rtp的时间戳是90000为1秒,这里需要转换
+					//	seg.timestamp = (send_time==0 ? (ts/(VIDEO_CLOCK/1000)) : send_time);
+					//	seg.data_size = n;
+					//	rtpDbg(vrtp,"%s:%d ", __FUNCTION__, __LINE__);
+					//	sim_recv_video(&seg);
+					//	rtpDbg(vrtp,"%s:%d ", __FUNCTION__, __LINE__);
+					//}
 					}
 					video_stats_bandwidth_update_recv_rtp_bytes(n);
 					video_stats_receiver_on_incoming_packet(TimeInMilliseconds());
@@ -1226,7 +1256,7 @@ static unsigned int __stdcall recv_proc(void *arg)
 			    //1s没有解码到视频数据,请求I帧
 				int64_t now_ms = TimeInMilliseconds();
 				if (now_ms - vrtp->prev_dec_ms >= 1000){
-					Dbg("recv_proc now:%I64d > prev_dec_ms:%I64d 1s.", TimeInMilliseconds(), vrtp->prev_dec_ms);
+					rtpDbg(vrtp,"recv_proc now:%I64d > prev_dec_ms:%I64d 1s.", TimeInMilliseconds(), vrtp->prev_dec_ms);
 					receiver_notify_peer_fast_update_now(vrtp);
 					vrtp->prev_dec_ms = now_ms;
 				}
@@ -1248,9 +1278,6 @@ static unsigned int __stdcall recv_proc(void *arg)
 	return 0;
 }
 
-#if 0
-#endif
-
 /******************************custom_h264发送处理 start***************************/
 
 
@@ -1264,7 +1291,7 @@ static void sender_custom_h264_packetize_and_send(videortp_t *vrtp, int key, uns
 	mtu = mtu-20-8-12-sizeof(h26x_hdr)+2; // ip hdr: 20, udp hdr: 8, rtp hdr: 12
 
 	if(DEBUG_TX){
-	Dbg("%s:%d: sender_custom_h264_packetize_and_send key: %d len: %d delta_ts: %d now: %I64d.", 
+	rtpDbg(vrtp,"%s:%d: sender_custom_h264_packetize_and_send key: %d len: %d delta_ts: %d now: %I64d.", 
 		__FILE__, __LINE__, key, n, delta_ts, TimeInMilliseconds());
 	}
 	video_debug_write_record_file(VIDEO_ENC_OUT, buf, n);
@@ -1281,7 +1308,7 @@ static void sender_custom_h264_packetize_and_send(videortp_t *vrtp, int key, uns
 		hdr->id = id++;
 		memcpy((void *)(&tx_buf[0]+sizeof(h26x_hdr)-2), (const void *)ptr, (size_t)tn);
 		if (DEBUG_TX) {
-			Dbg("end = %d, id = %d, tn = %d", hdr->end, hdr->id, tn);
+			rtpDbg(vrtp,"end = %d, id = %d, tn = %d", hdr->end, hdr->id, tn);
 		}
 		rc = rtp_session_send_hook(vrtp->rtp_sess, &rtcp_flag, pt, mark, delta_ts, tx_buf, tn+sizeof(h26x_hdr)-2, vrtp->config.on_tx_udp, vrtp->config.user_data);
 		if (rc == 0) {
@@ -1315,7 +1342,7 @@ static void sender_custom_h264_send_fragment(videortp_t *vrtp, int index, int ke
 		unsigned int delta_ts = vrtp->delta_ts;
 
 		if(DEBUG_TX){
-		Dbg("%s:%d: sender_custom_h264_send_fragment mark: %d length: %d delta_ts: %d now: %I64d.", 
+		rtpDbg(vrtp,"%s:%d: sender_custom_h264_send_fragment mark: %d length: %d delta_ts: %d now: %I64d.", 
 			__FILE__, __LINE__, mark, length, delta_ts, TimeInMilliseconds());
 		}
 
@@ -1327,7 +1354,7 @@ static void sender_custom_h264_send_fragment(videortp_t *vrtp, int index, int ke
 			memcpy((void *)(&tx_buf[0]), (const void *)rtp_header_extension_buf, (size_t)rtp_header_extension_length);
 			rtp_extension = 1;
 			if(DEBUG_TX){
-				Dbg("%s:%d: sender_custom_h264_send_fragment rtp_header_extension interval_ms:%u length:%d.", __FILE__, __LINE__, interval_ms, rtp_header_extension_length);
+				rtpDbg(vrtp,"%s:%d: sender_custom_h264_send_fragment rtp_header_extension interval_ms:%u length:%d.", __FILE__, __LINE__, interval_ms, rtp_header_extension_length);
 			}
 		}
 		//custom header
@@ -1372,7 +1399,7 @@ static int sender_standard_h264_send_packet(videortp_t *vrtp, unsigned mark, uns
 		unsigned int delta_ts = vrtp->delta_ts;
 		
 		if(DEBUG_TX){
-		Dbg("%s:%d: sender_standard_h264_send_packet mark: %d length: %d delta_ts: %d now: %I64d.", 
+		rtpDbg(vrtp,"%s:%d: sender_standard_h264_send_packet mark: %d length: %d delta_ts: %d now: %I64d.", 
 			__FILE__, __LINE__, mark, length, delta_ts, TimeInMilliseconds());
 		}
 		
@@ -1384,7 +1411,7 @@ static int sender_standard_h264_send_packet(videortp_t *vrtp, unsigned mark, uns
 			memcpy(&tx_buf[0], rtp_header_extension_buf, rtp_header_extension_length);
 			rtp_extension = 1;
 			if(DEBUG_TX){
-				Dbg("%s:%d: sender_standard_h264_send_packet rtp_header_extension interval_ms:%u length:%d.", __FILE__, __LINE__, interval_ms, rtp_header_extension_length);
+				rtpDbg(vrtp,"%s:%d: sender_standard_h264_send_packet rtp_header_extension interval_ms:%u length:%d.", __FILE__, __LINE__, interval_ms, rtp_header_extension_length);
 			}
 		}
 		//playload
@@ -1435,7 +1462,7 @@ static int sender_standard_h264_send_nal(videortp_t *vrtp, unsigned mark, unsign
 			}
 
 			if(DEBUG_TX){
-			Dbg("%s:%d: sender_standard_h264_send_nal mark: %d processed: %u payload_len: %d.", 
+			rtpDbg(vrtp,"%s:%d: sender_standard_h264_send_nal mark: %d processed: %u payload_len: %d.", 
 				__FILE__, __LINE__, mark, processed, payload_len);
 			}
 			//input mark =1, means last nal, rtp mark = 1, we need last nal 's last packet.
@@ -1482,7 +1509,7 @@ static void sender_standard_h264_packetize_x264_nals(videortp_t *vrtp, unsigned
 	int i;
 
 	if(DEBUG_TX){
-	Dbg("%s:%d: sender_standard_h264_packetize_x264_nals num_nals: %d.", __FILE__, __LINE__, num_nals);
+	rtpDbg(vrtp,"%s:%d: sender_standard_h264_packetize_x264_nals num_nals: %d.", __FILE__, __LINE__, num_nals);
 	}
 	
 	for (i = 0;i < num_nals;++i){
@@ -1490,22 +1517,22 @@ static void sender_standard_h264_packetize_x264_nals(videortp_t *vrtp, unsigned
 		x264_nal_t* nal = &xnals[i];
 		if (xnals[i].i_type == NAL_SPS) {
 			if (DEBUG_TX) {
-				Dbg("A SPS is being sent.");
+				rtpDbg(vrtp,"A SPS is being sent.");
 			}
 		}else if (xnals[i].i_type == NAL_PPS) {
 			if (DEBUG_TX) {
-				Dbg("A PPS is being sent.");
+				rtpDbg(vrtp,"A PPS is being sent.");
 			}
 		}else if (xnals[i].i_type == NAL_SLICE_IDR) {
 			if (DEBUG_TX) {
-				Dbg("A IDR is being sent.");
+				rtpDbg(vrtp,"A IDR is being sent.");
 			}
 		}
 
 		if (i == num_nals -1){
 			mark = 1;
 			if (DEBUG_TX) {
-				Dbg("A frame end.");
+				rtpDbg(vrtp,"A frame end.");
 			}
 		}
 		sender_standard_h264_send_nal(vrtp, mark , pt, nal->p_payload, nal->i_payload);
@@ -1518,14 +1545,14 @@ void sender_h264_packetize_nal(videortp_t *vrtp, int index, int total, int key_f
 	unsigned mark = 0;
 
 	if(DEBUG_TX){
-	Dbg("%s:%d: sender_h264_packetize_nal index: %d total: %d key_frame: %d data_size: %d.", __FILE__, __LINE__, 
+	rtpDbg(vrtp,"%s:%d: sender_h264_packetize_nal index: %d total: %d key_frame: %d data_size: %d.", __FILE__, __LINE__, 
 		index, total, key_frame, data_size);
 	}
 	
 	if (index == total -1){
 		mark = 1;
 		if(DEBUG_TX){
-		Dbg("A frame end.");
+		rtpDbg(vrtp,"A frame end.");
 		}
 	}
 
@@ -1567,7 +1594,7 @@ int congestion_control_on_log(void *userdata, int level, const char* file, int l
 	if (DEBUG_CC && n > 0 && level >= 1 && vrtp) {
 		char *buf = (char*)_alloca((size_t)(n+3));
 		vsprintf(buf, fmt, vl);
-		Dbg("%s.", buf);
+		rtpDbg(vrtp,"%s.", buf);
 	}
 }
 
@@ -1578,7 +1605,7 @@ void congestion_control_sender_on_send_fragment(sim_segment_t* seg, void *userda
 	videortp_t *vrtp = (videortp_t *)userdata;
 	
 	if(DEBUG_TX){
-	Dbg("%s:%d: congestion_control_sender_on_send_fragment.", __FILE__, __LINE__);
+	rtpDbg(vrtp,"%s:%d: congestion_control_sender_on_send_fragment.", __FILE__, __LINE__);
 	}
 
 	sender_h264_packetize_nal(vrtp, seg->index, seg->total, seg->key_frame, seg->payload_type, seg->data, seg->data_size);
@@ -1592,7 +1619,7 @@ void congestion_control_sender_on_change_bitrate(uint32_t bw, int lost, void *us
 	videortp_t *vrtp = (videortp_t *)userdata;
 
 	if(DEBUG_CC){
-	Dbg("%s:%d: congestion_control_sender_on_change_bitrate bw: %d lost: %d.", __FILE__, __LINE__, bw, lost);
+	rtpDbg(vrtp,"%s:%d: congestion_control_sender_on_change_bitrate bw: %d lost: %d.", __FILE__, __LINE__, bw, lost);
 	}
 	
 	//回调时编码器可能未创建
@@ -1606,7 +1633,7 @@ void congestion_control_receiver_on_send_bitrate_feedback(uint32_t estimate_bitr
 	videortp_t *vrtp = (videortp_t *)userdata;
 
 	if(DEBUG_CC){
-	Dbg("%s:%d: congestion_control_receiver_on_send_bitrate_feedback estimate_bitrate: %d.", __FILE__, __LINE__, estimate_bitrate);
+	rtpDbg(vrtp,"%s:%d: congestion_control_receiver_on_send_bitrate_feedback estimate_bitrate: %d.", __FILE__, __LINE__, estimate_bitrate);
 	}
 	video_stats_receiver_on_report_cc_bitrate(estimate_bitrate);
 	
@@ -1615,6 +1642,7 @@ void congestion_control_receiver_on_send_bitrate_feedback(uint32_t estimate_bitr
 }
 
 
+
 void congestion_control_create(videortp_t *vrtp, const videortp_config_t *config){
 	int max_bitrate, target_bitrate, min_bitrate;
 
@@ -1629,14 +1657,14 @@ void congestion_control_create(videortp_t *vrtp, const videortp_config_t *config
 	sim_init(gcc_transport, 0, min_bitrate, target_bitrate, max_bitrate, &callback);
 	}
 
-	Dbg("congestion_control_create min_bitrate: %d target_bitrate: %d max_bitrate: %d.", min_bitrate, target_bitrate, max_bitrate);
+	rtpDbg(vrtp,"congestion_control_create min_bitrate: %d target_bitrate: %d max_bitrate: %d.", min_bitrate, target_bitrate, max_bitrate);
 }
 
 
 void congestion_control_destroy(videortp_t *vrtp){
 	sim_destroy();
 
-	Dbg("congestion_control_destroy.");
+	rtpDbg(vrtp,"congestion_control_destroy.");
 }
 
 
@@ -1794,9 +1822,9 @@ void x264_encoder_create(videortp_t *vrtp, const videortp_config_t *config){
 	x264_encoder_set_param_t(&params);
 	vrtp->enc_params = x264_encoder_open(&params);
 	x264_encoder_parameters(vrtp->enc_params, &params_print);
-	Dbg("x264_encoder_create bit_rate: %d kb/s, i_rc_method: %d ", params_print.rc.i_bitrate, params_print.rc.i_rc_method);
-	Dbg("x264_encoder_create i_vbv_max_bitrate: %d kb/s, i_vbv_buffer_size: %d ", params_print.rc.i_vbv_max_bitrate, params_print.rc.i_vbv_buffer_size);
-	Dbg("x264_encoder_create keyint_max: %d, i_keyint_min: %d ", params_print.i_keyint_max, params_print.i_keyint_min);
+	rtpDbg(vrtp,"x264_encoder_create bit_rate: %d kb/s, i_rc_method: %d ", params_print.rc.i_bitrate, params_print.rc.i_rc_method);
+	rtpDbg(vrtp,"x264_encoder_create i_vbv_max_bitrate: %d kb/s, i_vbv_buffer_size: %d ", params_print.rc.i_vbv_max_bitrate, params_print.rc.i_vbv_buffer_size);
+	rtpDbg(vrtp,"x264_encoder_create keyint_max: %d, i_keyint_min: %d ", params_print.i_keyint_max, params_print.i_keyint_min);
 
 }
 
@@ -1804,7 +1832,7 @@ void x264_encoder_destroy(videortp_t *vrtp){
 	if (vrtp->enc_params){
 		x264_encoder_close(vrtp->enc_params);
 	}
-	Dbg("x264_encoder_destroy.");
+	rtpDbg(vrtp,"x264_encoder_destroy.");
 }
 
 
@@ -1822,15 +1850,15 @@ void ffmpeg_encoder_on_encoder_encoded_image(const EncodedImage *encoded_image,
 	if (encoded_image != NULL && vrtp != NULL) {
 
 	    if(DEBUG_TX){
-		Dbg("%s:%d: ffmpeg_encoder_on_encoder_encoded_image key: %d len: %d qp: %d, PT:%u.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: ffmpeg_encoder_on_encoder_encoded_image key: %d len: %d qp: %d, PT:%u.", __FILE__, __LINE__, 
 			encoded_image->key_frame, encoded_image->size_, encoded_image->qp_, encoded_image->pt_);
-		Dbg("%s:%d: ffmpeg_encoder_on_encoder_encoded_image encode_start_ms: %I64d encode_finish_ms: %I64d fragmentationSize: %d.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: ffmpeg_encoder_on_encoder_encoded_image encode_start_ms: %I64d encode_finish_ms: %I64d fragmentationSize: %d.", __FILE__, __LINE__, 
 				encoded_image->encode_start_ms, encoded_image->encode_finish_ms, encoded_image->fragmentation_header_.fragmentationVectorSize);
 		
 		}
 		if(DEBUG_TX){
 		for (i = 0;i < encoded_image->fragmentation_header_.fragmentationVectorSize;++i){
-		Dbg("%s:%d: ffmpeg_encoder_on_encoder_encoded_image index: %d fragmentationLength: %d.", __FILE__, __LINE__, 
+		rtpDbg(vrtp,"%s:%d: ffmpeg_encoder_on_encoder_encoded_image index: %d fragmentationLength: %d.", __FILE__, __LINE__, 
 				i, encoded_image->fragmentation_header_.fragmentationLength[i]);
 
 		}
@@ -1908,11 +1936,11 @@ void ffmpeg_encoder_create(videortp_t *vrtp, const videortp_config_t *config){
 	encoder_config.min_qp = 10;
 	video_encoder_api_configure_encoder(vrtp->encoder, &encoder_config, get_mtu(config->mtu) - 5/*padding*/ - ((sizeof(h26x_hdr)-2 + 32/*rtp_header_extension_length*/)));
 
-	Dbg("ffmpeg_encoder_create color_space: %d encode_id: %d width: %d height: %d.", 
+	rtpDbg(vrtp,"ffmpeg_encoder_create color_space: %d encode_id: %d width: %d height: %d.", 
 		encoder_config.color_space, encoder_config.encode_id, encoder_config.width, encoder_config.height);
-	Dbg("ffmpeg_encoder_create max_bitrate: %d min_bitrate: %d target_bitrate: %d.", 
+	rtpDbg(vrtp,"ffmpeg_encoder_create max_bitrate: %d min_bitrate: %d target_bitrate: %d.", 
 		max_bitrate, min_bitrate, target_bitrate);
-	Dbg("ffmpeg_encoder_create min_framerate: %d key_frame_interval: %d target_qp: %d.", 
+	rtpDbg(vrtp,"ffmpeg_encoder_create min_framerate: %d key_frame_interval: %d target_qp: %d.", 
 		encoder_config.min_framerate, encoder_config.key_frame_interval, encoder_config.target_qp);
 
 }
@@ -1923,7 +1951,7 @@ void ffmpeg_encoder_destory(videortp_t *vrtp){
 		video_encoder_api_stop(vrtp->encoder);
 		video_encoder_api_destroy(vrtp->encoder);
 	}
-	Dbg("ffmpeg_encoder_destory.");
+	rtpDbg(vrtp,"ffmpeg_encoder_destory.");
 }
 
 
@@ -1944,7 +1972,7 @@ int jitter_buffer_on_log(void *userdata, int level, const char* file, int line,
 	if (DEBUG_RX && n > 0 && vrtp && level >= VIDEO_JBUFFER_DEBUG_TRACE) {
 		char *buf = (char*)_alloca((size_t)(n+3));
 		vsprintf(buf, fmt, vl);
-		Dbg("%s.", buf);
+		rtpDbg(vrtp,"%s.", buf);
 	}
 }
 
@@ -1960,7 +1988,7 @@ void jitter_buffer_create(videortp_t *vrtp, const videortp_config_t *config){
 	log_func.userdata = vrtp;
 	vrtp->jbuffer = video_jbuffer_api_new(&video_jbuffer_observer, &log_func);
 	
-	Dbg("jitter_buffer_create.");
+	rtpDbg(vrtp,"jitter_buffer_create.");
 }
 
 
@@ -1968,7 +1996,7 @@ void jitter_buffer_destory(videortp_t *vrtp){
 	if (vrtp->jbuffer != NULL) {
 		video_jbuffer_api_destroy(vrtp->jbuffer);
 	}
-	Dbg("jitter_buffer_destory.");
+	rtpDbg(vrtp,"jitter_buffer_destory.");
 }
 
 
@@ -2010,7 +2038,7 @@ int video_stats_on_log(void *userdata, int level, const char* file, int line, co
 	if (n > 0 && vrtp) {
 		char *buf = (char*)_alloca((size_t)(n+3));
 		vsprintf(buf, fmt, vl);
-		Dbg("%s.", buf);
+		rtpDbg(vrtp,"%s.", buf);
 	}
 }
 
@@ -2029,12 +2057,12 @@ int videortp_create(const videortp_config_t *config, videortp_t **p_rtp)
 	vrtp->remote_support_cc = 0;
 	memcpy((void *)(&vrtp->config), (const void *)config, sizeof(videortp_config_t));
 
-	Dbg("videortp_create local_pt: %d local_ip: %d local_rtp_port: %d.", config->local_pt, config->local_ip, config->local_rtp_port);
-	Dbg("videortp_create remote_pt: %d remote_ip: %d remote_rtp_port: %d.", config->remote_pt, config->remote_ip, config->remote_rtp_port);
-	Dbg("videortp_create tx_width: %d tx_height: %d.", config->tx_width, config->tx_height);
-	Dbg("videortp_create rx_width: %d rx_height: %d.", config->rx_width, config->rx_height);
-	Dbg("videortp_create capture_width: %d capture_height: %d.", config->capture_width, config->capture_height);
-	Dbg("videortp_create fps_num: %d bit_rate: %d dir: %d.", config->fps_num, config->bit_rate, config->dir);
+	rtpDbg(vrtp,"videortp_create local_pt: %d local_ip: %d local_rtp_port: %d.", config->local_pt, config->local_ip, config->local_rtp_port);
+	rtpDbg(vrtp,"videortp_create remote_pt: %d remote_ip: %d remote_rtp_port: %d.", config->remote_pt, config->remote_ip, config->remote_rtp_port);
+	rtpDbg(vrtp,"videortp_create tx_width: %d tx_height: %d.", config->tx_width, config->tx_height);
+	rtpDbg(vrtp,"videortp_create rx_width: %d rx_height: %d.", config->rx_width, config->rx_height);
+	rtpDbg(vrtp,"videortp_create capture_width: %d capture_height: %d.", config->capture_width, config->capture_height);
+	rtpDbg(vrtp,"videortp_create fps_num: %d bit_rate: %d dir: %d.", config->fps_num, config->bit_rate, config->dir);
 
 	INIT_LIST_HEAD(&vrtp->free_part_list);
 	for (i = 0; i < FRAME_WIN_SIZE; ++i) {
@@ -2095,7 +2123,7 @@ void videortp_destroy(videortp_t *vrtp)
 	}
 	config = &vrtp->config;
 
-	Dbg("videortp_destroy.");
+	rtpDbg(vrtp,"videortp_destroy.");
 
 	receiver_clear_window(vrtp);
 	while (!list_empty(&vrtp->free_part_list)) {
@@ -2142,16 +2170,23 @@ int videortp_start(videortp_t *vrtp)
 		vrtp->recv_thread = (HANDLE)_beginthreadex(NULL, 0, &recv_proc, vrtp, 0, NULL);
 #else
 		sem_init(&vrtp->sem_evt, 0, 0);
-		int err = pthread_create(&vrtp->recv_threadid, NULL, recv_proc, vrtp);
+		pthread_attr_t attr;
+		pthread_attr_init(&attr);
+		struct sched_param param;
+		param.sched_priority = sched_get_priority_max(SCHED_RR);
+		pthread_attr_setschedpolicy(&attr, SCHED_RR);
+		pthread_attr_setschedparam(&attr, &param);
+		pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+		int err = pthread_create(&vrtp->recv_threadid, &attr, recv_proc, vrtp);
 		if (0 == err) {
-			Dbg("create vrtp recv thread success, %lu.", vrtp->recv_threadid);
+			rtpDbg(vrtp,"create vrtp recv thread success, %lu.", vrtp->recv_threadid);
 		}
 		else {
-			Dbg("create vrtp recv thread failed.");
+			rtpDbg(vrtp,"create vrtp recv thread failed.");
 		}
 #endif
 	}
-	Dbg("videortp_start.");
+	rtpDbg(vrtp,"videortp_start.");
 
 	receiver_config_stats.remote_pt = vrtp->config.remote_pt;
 	receiver_config_stats.local_ip = vrtp->config.local_ip;
@@ -2180,7 +2215,7 @@ int videortp_start(videortp_t *vrtp)
 void videortp_stop(videortp_t* vrtp)
 {
 	int64_t now = TimeInMilliseconds();
-	Dbg("start call videortp_stop.");
+	rtpDbg(vrtp,"start call videortp_stop.");
 #ifdef _WIN32
 	if (vrtp->evt) {
 		SetEvent(vrtp->evt);
@@ -2203,13 +2238,13 @@ void videortp_stop(videortp_t* vrtp)
 	}
 #endif
 
-	Dbg("stop rtp recv thread.");
+	rtpDbg(vrtp,"stop rtp recv thread.");
 
 	video_stats_receiver_on_stopped(now);
 	video_stats_sender_on_stopped(now);
 	
 	video_jbuffer_api_stop(vrtp->jbuffer);
-	Dbg("videortp_stop func end.");
+	rtpDbg(vrtp,"videortp_stop func end.");
 }
 
 int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
@@ -2218,7 +2253,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
 		int64_t now;
 
 		if(DEBUG_TX){
-		Dbg("%s:%d: videortp_send_frame width: %d height: %d format: %d.", __FILE__, __LINE__, frame->width, frame->height, frame->format);
+		rtpDbg(vrtp,"%s:%d: videortp_send_frame width: %d height: %d format: %d.", __FILE__, __LINE__, frame->width, frame->height, frame->format);
 		}
 		
 		if (VIDEO_FORMAT_RGB24 != frame->format)
@@ -2236,7 +2271,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
 			vrtp->force_key_frames = 0;
 
 			if(DEBUG_TX){
-			Dbg("%s:%d: videortp_send_frame force_key_frames.", __FILE__, __LINE__);
+			rtpDbg(vrtp,"%s:%d: videortp_send_frame force_key_frames.", __FILE__, __LINE__);
 
 			}
 		}
@@ -2250,7 +2285,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
 				if (vrtp->framenum % start_key_interval == 0) {
 					video_encoder_api_send_key_frame(vrtp->encoder);
 					if(DEBUG_TX){
-					Dbg("%s:%d: videortp_send_frame framenum: %d force_key_frames.", __FILE__, __LINE__, vrtp->framenum);
+					rtpDbg(vrtp,"%s:%d: videortp_send_frame framenum: %d force_key_frames.", __FILE__, __LINE__, vrtp->framenum);
 					}
 				}
 			}
@@ -2263,7 +2298,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
 		//从未收到cc_feedback估计带宽,远端不支持流量控制,将码率设为配置值
 		now = TimeInMilliseconds();
 		if ((vrtp->recv_cc_feedback == FALSE) && (now-vrtp->recv_cc_feedback_ms >= 10*1000)){		
-			Dbg("videortp_send_frame, never receive cc feedback, remote don't support .");
+			rtpDbg(vrtp,"videortp_send_frame, never receive cc feedback, remote don't support .");
 
 			sim_recv_bitrate_feedback(vrtp->config.bit_rate/*bps*/);
 			vrtp->recv_cc_feedback = TRUE;
@@ -2280,11 +2315,17 @@ int videortp_send_yuvframe(videortp_t *vrtp, const video_frame *vframe)
 {
 	videortp_send_frame(vrtp, vframe);
 
+	static int itest = 0;
+	if (itest == 0) {
+		video_frame_save_bmpfile("videortp_send_yuvframe.bmp", vframe);
+		itest++;
+	}
+
 	return 0;
 }
 
 int videortp_reconfig_local_pt(videortp_t *vrtp, unsigned int local_pt){
-	Dbg("videortp_reconfig_local_pt:%u .", local_pt);
+	rtpDbg(vrtp,"videortp_reconfig_local_pt:%u .", local_pt);
 
 	vrtp->config.local_pt = local_pt;
 }

+ 1 - 1
Other/libvideorender/libvideorender.cpp

@@ -45,7 +45,7 @@ int VideoRenderImpl::SetWindowProperty(videorender_param_t* tparam)
 		return iRet;
 	}
 
-	m_cx = tparam->icy;
+	m_cx = tparam->icx;
 	m_cy = tparam->icy;
 	m_width = tparam->uwidth;
 	m_height = tparam->uheight;