Преглед на файлове

Z991239-1621 #comment other 视频连线增加本地回显功能

陈礼鹏80274480 преди 4 години
родител
ревизия
7f3ff7e895

+ 15 - 5
Module/mod_sipphone/CMakeLists.txt

@@ -15,10 +15,21 @@ endif(RVC_DEBUG_MODE)
 
 if(MSVC)
     set(STDAFXCPP stdafx.cpp)
-	set(VOLUMEKEEPER_SRCS uuid.cpp volumekeeper.h volumekeeper.cpp)
 else()
 	set(STDAFXCPP )
-	set(VOLUMEKEEPER_SRCS )
+endif(MSVC)
+
+if(MSVC)
+	set(${SIPPHONE_PLATFORM}_SRCS
+	uuid.cpp 
+	volumekeeper.h 
+	volumekeeper.cpp
+	)
+else()
+	set(${SIPPHONE_PLATFORM}_SRCS 
+	videorenderobj.h
+	videorenderobj.cpp
+	)
 endif(MSVC)
 
 set(${MODULE_PREFIX}_SRCS
@@ -37,7 +48,7 @@ set(${MODULE_PREFIX}_SRCS
    
     mod_sipphone.cpp
     video_session.cpp
-	${VOLUMEKEEPER_SRCS}
+	${${SIPPHONE_PLATFORM}_SRCS}
 )
 
 set(MOD_VERSION_STRING "0.0.1-dev1")
@@ -120,14 +131,12 @@ target_include_directories(${MODULE_NAME} PRIVATE
 	${CONAN_INCLUDE_DIRS_APR}/apr-1
 	${CONAN_RVCFRAMEWORK_ROOT}/include
 	${CONAN_RVCFRAMEWORK_ROOT}/include/libtoolkit
-	#${CONAN_RVCFRAMEWORK_ROOT}/include/winpr
 	${CONAN_INCLUDE_DIRS_PORTAUDIO}
 	${CONAN_INCLUDE_DIRS_FFMPEG}
 	${CONAN_INCLUDE_DIRS_OPENCV}
     ${CONAN_INCLUDE_DIRS_OPENCV}/opencv
 	${RVC_TOOLKIT_INCLUDE_DIR}
 	${RVC_FRAMEWORK_INCLUDES_DIR}
-	#${RVC_FRAMEWORK_INCLUDES_DIR}/winpr
 	if(WIN32)
 	${CONAN_INCLUDE_DIRS_IPP}
 	${CONAN_INCLUDE_DIRS_APACHE-APR}/include
@@ -220,6 +229,7 @@ set(${MODULE_PREFIX}_LIBS  ${MODULE_BASE_LIBS}
 	${RVCCOMM_LIB}
 	${CONAN_PKG_LIBS_LIBKYSM}
 	${WINPR_LIB}
+	videorender
 )
 endif(WIN32)
 

+ 193 - 62
Module/mod_sipphone/video_session.cpp

@@ -22,13 +22,11 @@
 #include <DbgHelp.h>
 #pragma comment(lib, "dbghelp.lib")
 #else
-
+#include "videorenderobj.h"
+#include <signal.h>
 #endif // RVC_OS_WIN
 
 
-
-//#include "../../Other/libvideohorflip/videohorflip.h"
-
 #include "cv.h"
 #include "highgui.h"
 #include "y2k_time.h"
@@ -118,16 +116,15 @@ struct video_session_t
 	HWND local_hwnd; // preview window
 	HWND remote_hwnd; // remote window
 #else
-
+	VideoRenderObj* plocal_render;
+	VideoRenderObj* premote_render;
+	pthread_t ui_threadid;
 #endif // RVC_OS_WIN
 
-
 	picture_record_t* pic_record;
 };
 
 
-
-
 static void __dbg(void *user_data, const char *fmt, va_list arg)
 {
 	vDbg(fmt, arg);
@@ -489,6 +486,7 @@ 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;
@@ -938,6 +936,58 @@ static void	show_remote_agnet_picture(video_session_t *t_session)
 }
 
 
+static int start_video_rtpsession(video_session_t* session)
+{
+	int rc = -1;
+	videortp_config_t config = { 0 };
+	config.fps_den = REC_COMMON_VIDEO_FPS_DEN;
+	if (session->conf.eDeviceType == eMobilePadType)
+	{
+		config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE_AGENT;
+	}
+	else if ((session->conf.eDeviceType == ePadtype) || (session->conf.eDeviceType == eDesk2SType) || (session->conf.eDeviceType == eDesk1SType) || (session->conf.eDeviceType == eDesk2SIntegratedType))
+	{
+		config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE;
+	}
+	else if (session->conf.eDeviceType == eStand2sType)
+	{
+		config.fps_num = REC_COMMON_VIDEO_FPS_NUM;
+	}
+	config.capture_height = -1; // not use
+	config.capture_width = -1; // not use
+	config.dir = 3;
+	config.tx_width = REC_COMMON_VIDEO_RTP_WIDTH;
+	config.tx_height = REC_COMMON_VIDEO_RTP_HEIGHT;
+	config.rx_width = session->conf.remote_video_width;
+	config.rx_height = session->conf.remote_video_height;
+	config.local_ip = session->conf.local_rtp_ip;
+	config.local_pt = session->conf.local_pt;
+	config.remote_pt = session->conf.local_pt;
+	config.local_rtp_port = session->conf.local_rtp_port;
+	config.mtu = session->conf.mtu;
+	config.quant = session->conf.video_quant;
+	config.remote_ip = session->conf.remote_rtp_ip;
+	config.remote_rtp_port = session->conf.remote_rtp_port;
+	config.user_data = session;
+	config.bit_rate = session->conf.bit_rate;
+	config.on_rx_frame = &on_rx_frame;
+	config.dbg = &__dbg;
+	videortp_create(&config, &session->rtp);
+	rc = videortp_start(session->rtp);
+	if (rc != 0)
+	{
+		Dbg("start video rtp failed!");
+		videortp_destroy(session->rtp);
+		session->rtp = NULL;
+	}
+	else {
+		Dbg("videortp_start suc.");
+	}
+
+	return rc;
+}
+
+
 static int start_video(video_session_t *session)
 {
 	LOG_FUNCTION();
@@ -1187,51 +1237,54 @@ static int start_video(video_session_t *session)
 	{
 		if (0 != session->conf.remote_rtp_port)
 		{
-			videortp_config_t config = {0};
-			config.fps_den = REC_COMMON_VIDEO_FPS_DEN;
-			if (session->conf.eDeviceType == eMobilePadType)
-			{
-				config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE_AGENT;
-			} 
-			else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
-			{ 
-				config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE;
-			}
-			else if(session->conf.eDeviceType == eStand2sType)
-			{
-				config.fps_num = REC_COMMON_VIDEO_FPS_NUM;
-			}
-			config.capture_height = -1; // not use
-			config.capture_width = -1; // not use
-			config.dir = 3;
-			config.tx_width = REC_COMMON_VIDEO_RTP_WIDTH;
-			config.tx_height = REC_COMMON_VIDEO_RTP_HEIGHT;
-			config.rx_width = session->conf.remote_video_width;
-			config.rx_height = session->conf.remote_video_height;
-			config.local_ip = session->conf.local_rtp_ip;
-			config.local_pt = session->conf.local_pt;
-			config.remote_pt = session->conf.local_pt;
-			config.local_rtp_port = session->conf.local_rtp_port;
-			config.mtu = session->conf.mtu;
-			config.quant = session->conf.video_quant;
-			config.remote_ip = session->conf.remote_rtp_ip;
-			config.remote_rtp_port = session->conf.remote_rtp_port;
-			config.user_data = session;
-			config.bit_rate = session->conf.bit_rate;
-			config.on_rx_frame = &on_rx_frame;
-			config.dbg = &__dbg;
-			videortp_create(&config, &session->rtp);
-			rc = videortp_start(session->rtp);
-			if (rc != 0) 
-			{
-				Dbg("start video rtp failed!");
-				videortp_destroy(session->rtp);
-				session->rtp = NULL;
+			//videortp_config_t config = {0};
+			//config.fps_den = REC_COMMON_VIDEO_FPS_DEN;
+			//if (session->conf.eDeviceType == eMobilePadType)
+			//{
+			//	config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE_AGENT;
+			//} 
+			//else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
+			//{ 
+			//	config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE;
+			//}
+			//else if(session->conf.eDeviceType == eStand2sType)
+			//{
+			//	config.fps_num = REC_COMMON_VIDEO_FPS_NUM;
+			//}
+			//config.capture_height = -1; // not use
+			//config.capture_width = -1; // not use
+			//config.dir = 3;
+			//config.tx_width = REC_COMMON_VIDEO_RTP_WIDTH;
+			//config.tx_height = REC_COMMON_VIDEO_RTP_HEIGHT;
+			//config.rx_width = session->conf.remote_video_width;
+			//config.rx_height = session->conf.remote_video_height;
+			//config.local_ip = session->conf.local_rtp_ip;
+			//config.local_pt = session->conf.local_pt;
+			//config.remote_pt = session->conf.local_pt;
+			//config.local_rtp_port = session->conf.local_rtp_port;
+			//config.mtu = session->conf.mtu;
+			//config.quant = session->conf.video_quant;
+			//config.remote_ip = session->conf.remote_rtp_ip;
+			//config.remote_rtp_port = session->conf.remote_rtp_port;
+			//config.user_data = session;
+			//config.bit_rate = session->conf.bit_rate;
+			//config.on_rx_frame = &on_rx_frame;
+			//config.dbg = &__dbg;
+			//videortp_create(&config, &session->rtp);
+			//rc = videortp_start(session->rtp);
+			//if (rc != 0) 
+			//{
+			//	Dbg("start video rtp failed!");
+			//	videortp_destroy(session->rtp);
+			//	session->rtp = NULL;
+			//	goto on_error;
+			//}
+			//else{
+			//	Dbg("videortp_start suc.");
+			//}
+			if (0 != start_video_rtpsession(session)) {
 				goto on_error;
 			}
-			else{
-				Dbg("videortp_start suc.");
-			}
 
 			if (DOUBLERECORD_CALLTYPE == session->conf.nCallType){
 				if (NULL != pg_last_session){
@@ -1278,14 +1331,11 @@ static int start_video(video_session_t *session)
 			show_remote_agnet_picture(session);
 		}
 	}
-
 on_error:
-
+	return rc;
 #else
-
+	return start_video_rtpsession(session);
 #endif // RVC_OS_WIN
-	
-	return rc;
 }
 
 static void stop_video(video_session_t *session)
@@ -1337,7 +1387,15 @@ static void stop_video(video_session_t *session)
 		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");
+	}
 
 #endif // RVC_OS_WIN
 }
@@ -1585,14 +1643,12 @@ static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
 #endif // 
 
-
+#ifdef RVC_OS_WIN
 static unsigned int __stdcall ui_proc(void *arg)
 {
 	video_session_t *session = (video_session_t*)arg;
 	Dbg("ui_proc session addr is %0x", session);
 
-#ifdef RVC_OS_WIN
-
 	WNDCLASSA wc = {0};
 	ATOM a = 0;
 	HWND hWnd = NULL;
@@ -1731,13 +1787,58 @@ static unsigned int __stdcall ui_proc(void *arg)
 
 	CoUninitialize();
 
+	return 0;
+}
 #else
+void* videorender_func(void* arg)
+{
+	LOG_FUNCTION();
+	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);
+
+	if (NULL != session->premote_render)
+	{
+		start_video(session);
+	}
+
+	if (NULL != session->plocal_render){
+
+		videorender_param_t tparam = { 0 };
+		tparam.icx = 0;
+		tparam.icy = 0;
+		tparam.uwidth = REC_COMMON_VIDEO_PREVIEW_WIDTH;
+		tparam.uheight = REC_COMMON_VIDEO_PREVIEW_WIDTH;
+		tparam.uvideowidth = REC_COMMON_VIDEO_PREVIEW_WIDTH;
+		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)
+			{
+				video_frame_fill_black(frm);
+				video_frame* tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
+				videoq_frame frm;
+				frm.data = tmp_frame_preview->data[0];
+				BOOL result = session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
+				if (result){
+					session->plocal_render->RenderVideoFrame(tmp_frame_preview);
+				}
+				usleep(1000 * 20);
+			}
+			video_frame_delete(frm);
+		}
+	}
 
-#endif // RVC_OS_WIN
 
 	return 0;
 }
 
+#endif // RVC_OS_WIN
+
 static int start_ui(video_session_t *session)
 {
 	LOG_FUNCTION();
@@ -1782,10 +1883,19 @@ static int start_ui(video_session_t *session)
 			return Error_Resource;
 		}
 	}
+	return 0;
 #else
 
+	int err = pthread_create(&session->ui_threadid, NULL, videorender_func, session);
+	if (0 == err) {
+		Dbg("create video render thread success, %lu.", session->ui_threadid);
+	}
+	else {
+		Dbg("create video render thread failed.");
+	}
+
+	return err;
 #endif // RVC_OS_WIN
-	return 0;
 }
 
 static void stop_ui(video_session_t *session)
@@ -1843,6 +1953,16 @@ static void stop_ui(video_session_t *session)
 	Dbg("set pg_last_session  to null.");
 
 #else
+	int kill_ret = pthread_kill(session->ui_threadid, 0);
+	if (ESRCH == kill_ret){
+		Dbg("pthread_kill failed for thread is not exsist or has stopped!");
+	}
+	else if (EINVAL == kill_ret) {
+		Dbg("pthread_kill failed for signal is not valid!");
+	}
+	else {
+		Dbg("pthread_kill success");
+	}
 
 #endif // RVC_OS_WIN
 }
@@ -1980,6 +2100,11 @@ int Local_video_session_create(const video_session_conf_t *conf, video_session_t
 				Dbg("load record area picture failed.");
 			}
 		}
+
+#ifdef RVC_OS_WIN
+#else
+		session->plocal_render = new VideoRenderObj();
+#endif
 		*p_session = session;
 	}
 	return 0;
@@ -2113,6 +2238,12 @@ int video_session_create(const video_session_conf_t *conf, video_session_t **p_s
 			session->video_shm_q_opt = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
 		}
 
+#ifdef RVC_OS_WIN
+#else
+		session->plocal_render = new VideoRenderObj();
+		session->premote_render = new VideoRenderObj();
+
+#endif
 		*p_session = session;
 	}
 	return 0;

+ 75 - 0
Module/mod_sipphone/videorenderobj.cpp

@@ -0,0 +1,75 @@
+#include"videorenderobj.h"
+#include<stdlib.h>
+#include<string.h>
+#include<stdarg.h>
+#include <time.h>
+#include <stdio.h>
+#include "SpBase.h"
+
+VideoRenderObj::VideoRenderObj()
+{
+	m_pVideoRender = CreateVideoRenderObj(this);
+}
+
+VideoRenderObj::~VideoRenderObj()
+{
+	if (NULL != m_pVideoRender){
+		DestroyVideoRenderObj(m_pVideoRender);
+	}
+}
+
+
+void VideoRenderObj::Debug(const char* fmt, ...)
+{
+	va_list arg;
+	va_start(arg, fmt);
+	vDbg(fmt, arg);
+	va_end(arg);
+}
+
+void VideoRenderObj::OnRenderFailed()
+{
+
+}
+
+void VideoRenderObj::OnVideoRenderExcption()
+{
+
+}
+
+int VideoRenderObj::ShowVideoWindow()
+{
+	int iRet = -1;
+	if (NULL == m_pVideoRender) {
+		return iRet;
+	}
+	return m_pVideoRender->ShowVideoWindow();
+}
+
+int VideoRenderObj::HideVideoWindow()
+{
+	int iRet = -1;
+	if (NULL == m_pVideoRender) {
+		return iRet;
+	}
+	return m_pVideoRender->HideVideoWindow();
+}
+
+int VideoRenderObj::RenderVideoFrame(video_frame* pframe)
+{
+	int iRet = -1;
+	if (NULL == m_pVideoRender) {
+		return iRet;
+	}
+	return m_pVideoRender->RenderVideoFrame(pframe);
+}
+
+
+int VideoRenderObj::SetVideoRenderParam(videorender_param_t* param)
+{
+	int iRet = -1;
+	if (NULL == m_pVideoRender){
+		return iRet;
+	}
+	return m_pVideoRender->VideoRenderSetParam(param);
+}

+ 23 - 0
Module/mod_sipphone/videorenderobj.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "../../Other/libvideorender/ivideorenderinterface.h"
+
+
+class VideoRenderObj : public IRenderCallback
+{
+public:
+	VideoRenderObj();
+	virtual ~VideoRenderObj();
+
+	void Debug(const char* fmt, ...);
+	void OnRenderFailed();
+	void OnVideoRenderExcption();
+	
+	int SetVideoRenderParam(videorender_param_t* param);
+	int ShowVideoWindow();
+	int HideVideoWindow();
+	int RenderVideoFrame(video_frame* pframe);
+
+private:
+	IVideoRender* m_pVideoRender;
+};

+ 1 - 0
Other/libvideocapture/libvideocapture.h

@@ -4,6 +4,7 @@
 #include "../libvideoframework/videoutil.h"
 #include "../rvcmediacommon/common_video/videocommon.h"
 #include "videocapturedefines.h"
+#include <pthread.h>
 
 static const int mode_width[VIDEOCAP_MAX_MODE] = {
 	VIDEOCAP_SQCIF_WIDTH,VIDEOCAP_QQVGA_WIDTH,

+ 7 - 10
Other/libvideoframework/videoplayer.c

@@ -52,7 +52,6 @@ struct winthunk_t
 struct videoplayer_t
 {
 	struct winthunk_t thunk;
-	HWND hWndVideo;
 	int x;
 	int y;
 	int cx;
@@ -61,22 +60,15 @@ struct videoplayer_t
 	int fps_den;
 	int width;
 	int height;
-	WNDPROC oldWndProc;
-
 	int flags;
 
 	eVideoSizeMode esizemode; // double size mode
-
 	struct SwsContext *double_size_sws_context;
 	LPVOID double_size_data;
 
 	struct SwsContext *zoomout_size_sws_context;
 	LPVOID zoomout_size_data;
-
 	frame_entry current_frame;
-
-	CRITICAL_SECTION q_lock;
-
 	frame_entry frames[FRAME_QUEUE_LEGNTH];
 	int q_head;
 	int q_tail;
@@ -87,8 +79,7 @@ struct videoplayer_t
 	struct SwsContext *sws_context;
 
 	DWORD dwPlayTimer;
-	HDRAWDIB hdib;
-
+	
 	int min_cache_size;
 	int max_cache_size;
 
@@ -97,6 +88,12 @@ struct videoplayer_t
 	void *user_data;
 
 	char name[16];
+#ifdef _WIN32
+	HWND hWndVideo;
+	WNDPROC oldWndProc;
+	CRITICAL_SECTION q_lock;
+	HDRAWDIB hdib;
+#endif
 };
 
 

+ 55 - 146
Other/libvideoframework/videortp.c

@@ -7,7 +7,7 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #else
-
+#include <semaphore.h>
 #endif // RVC_OS_WIN
 
 #include <assert.h>
@@ -114,10 +114,13 @@ struct videortp_t
 	//ÓµÈû¿ØÖÆ
 	int send_cc_feedback;
 	
+#ifdef _WIN32
 	HANDLE recv_thread;
 	HANDLE evt;
-
-
+#else
+	pthread_t recv_threadid;
+	sem_t sem_evt;
+#endif
 	/******************************·¢ËÍ¶Ë */
 	VideoEncoderApi *encoder;
 	x264_t* enc_params;
@@ -1129,8 +1132,17 @@ static unsigned int __stdcall recv_proc(void *arg)
 
 
 	for (;;) {
+#ifdef _WIN32
 		DWORD dwRet = WaitForSingleObject(vrtp->evt, 10);
-		if (dwRet == WAIT_TIMEOUT) {
+		if (dwRet == WAIT_TIMEOUT)
+#else
+		struct timespec ts;
+		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))
+#endif
+		{
 			int n;
 			{
 				unsigned rtcp_flags = 0;
@@ -2126,8 +2138,19 @@ int videortp_start(videortp_t *vrtp)
 	video_jbuffer_api_start(vrtp->jbuffer);
 
 	if (vrtp->config.dir & DIR_RX) {
+#ifdef _WIN32
 		vrtp->evt = CreateEventA(NULL, FALSE, FALSE, NULL);
 		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);
+		if (0 == err) {
+			Dbg("create vrtp recv thread success, %lu.", vrtp->recv_threadid);
+		}
+		else {
+			Dbg("create vrtp recv thread failed.");
+		}
+#endif
 	}
 	Dbg("videortp_start.");
 
@@ -2155,10 +2178,11 @@ int videortp_start(videortp_t *vrtp)
 	return 0;
 }
 
-void videortp_stop(videortp_t *vrtp)
+void videortp_stop(videortp_t* vrtp)
 {
 	int64_t now = TimeInMilliseconds();
 	Dbg("start call videortp_stop.");
+#ifdef _WIN32
 	if (vrtp->evt) {
 		SetEvent(vrtp->evt);
 		if (vrtp->recv_thread) {
@@ -2169,6 +2193,17 @@ void videortp_stop(videortp_t *vrtp)
 		CloseHandle(vrtp->evt);
 		vrtp->evt = NULL;
 	}
+#else
+	if (&vrtp->sem_evt) {
+		sem_post(&vrtp->sem_evt);
+		if (0 != vrtp->recv_threadid) {
+			pthread_join(vrtp->recv_threadid, NULL);
+			vrtp->recv_threadid = 0;
+		}
+		sem_destroy(&vrtp->sem_evt);
+	}
+#endif
+
 	Dbg("stop rtp recv thread.");
 
 	video_stats_receiver_on_stopped(now);
@@ -2242,148 +2277,10 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
 }
 
 
-
-int videortp_convert_bgrtoyuvframe(MSPicture* ppic, const video_frame *vframe)
-{
-	uint8_t *src_data[4] = {0};
-	int src_linesize[4] = {0};
-
-	uint8_t *dst_data[4] = {0};
-	int dst_linesize[4] = {0};
-
-	int src_w = vframe->width;
-	int src_h = vframe->height;
-	int src_bpp=av_get_bits_per_pixel(av_pix_fmt_desc_get(AV_PIX_FMT_BGR24));
-	const int dst_w=SEND_WIDTH,dst_h=SEND_HEIGHT;
-	int dst_bpp=av_get_bits_per_pixel(av_pix_fmt_desc_get(AV_PIX_FMT_YUV420P));
-
-	//Init Method 2
-	int ret=0;
-	int rescale_method=SWS_BICUBIC;
-	struct SwsContext *img_convert_ctx = sws_getContext(src_w, src_h,AV_PIX_FMT_BGR24, dst_w, dst_h, AV_PIX_FMT_YUV420P, 
-		rescale_method, NULL, NULL, NULL); 
-
-	ret= av_image_alloc(src_data, src_linesize,src_w, src_h, AV_PIX_FMT_BGR24, 1);
-	if (ret< 0) {
-		return -1;
-	}
-
-	memcpy(src_data[0],vframe->data[0],src_w*src_h*3);
-
-	sws_scale(img_convert_ctx, src_data, src_linesize, 0, src_h, ppic->planes, ppic->strides);
-
-	ppic->strides[3] = 0;
-	ppic->planes[3] = 0;
-
-	sws_freeContext(img_convert_ctx);
-
-	av_freep(&src_data[0]);
-
-	return 0;
-}
-
 int videortp_send_yuvframe(videortp_t *vrtp, const video_frame *vframe)
 {
 	videortp_send_frame(vrtp, vframe);
 
-#if 0
-	MSPicture pic={0};
-	static int icount = 0;
-	x264_picture_t xpic;
-	x264_picture_t oxpic;
-	x264_nal_t *xnals = NULL;
-	int num_nals = 0;
-	static int framenum = 0;
-	int ret = 0;
-	unsigned __int64 now;
-	x264_param_t params_reconfig;
-	x264_param_t params_print;
-
-	if (NULL==vrtp || NULL==vframe){
-		return ret;
-	}
-
-	if(DEBUG_TX){
-	Dbg("%s:%d: videortp_send_yuvframe width: %d height: %d format: %d.", __FILE__, __LINE__, vframe->width, vframe->height, vframe->format);
-	}
-	
-	memset(&xpic, 0, sizeof(xpic));
-	memset(&oxpic, 0, sizeof(oxpic));
-
-	if (VIDEO_FORMAT_RGB24 == vframe->format)
-	{
-		const int dst_w=SEND_WIDTH,dst_h=SEND_HEIGHT;
-		ret = av_image_alloc(pic.planes, pic.strides,dst_w, dst_h, AV_PIX_FMT_YUV420P, 1);
-		if (ret< 0) {
-			return -1;
-		}
-		if (videortp_convert_bgrtoyuvframe(&pic, vframe)){
-			return -1;
-		}
-		xpic.img.i_stride[0]=pic.strides[0];
-		xpic.img.i_stride[1]=pic.strides[1];
-		xpic.img.i_stride[2]=pic.strides[2];
-		xpic.img.i_stride[3]=0;
-		xpic.img.plane[0]=pic.planes[0];
-		xpic.img.plane[1]=pic.planes[1];
-		xpic.img.plane[2]=pic.planes[2];
-		xpic.img.plane[3]=0;
-	}
-	else{
-		xpic.img.i_stride[0]=vframe->linesize[0];
-		xpic.img.i_stride[1]=vframe->linesize[1];
-		xpic.img.i_stride[2]=vframe->linesize[2];
-		xpic.img.i_stride[3]=0;
-		xpic.img.plane[0]=vframe->data[0];
-		xpic.img.plane[1]=vframe->data[1];
-		xpic.img.plane[2]=vframe->data[2];
-		xpic.img.plane[3]=0;
-
-		{	
-			unsigned char *video_debug_buf;
-		    int length = vrtp->config.capture_width*vrtp->config.capture_width*3/2;
-			video_debug_buf = (unsigned char *)malloc(length);
-			yuv_buffers_combine_to_one(vframe, video_debug_buf);
-			video_debug_write_record_file(VIDEO_CAPTURE_OUT, video_debug_buf, length);
-			free(video_debug_buf);
-		}
-	}
-
-	/*send I frame 2 seconds and 4 seconds after the beginning */
-	if (0 == icount++%IDR_INTERVAL){
-		xpic.i_type = X264_TYPE_IDR;
-		if(DEBUG_TX){
-		Dbg("%s:%d: videortp_send_yuvframe icount: %d force_key_frames.", __FILE__, __LINE__, icount);
-		}
-	}
-	else{
-		xpic.i_type = X264_TYPE_AUTO;
-	}
-	xpic.i_qpplus1=0;
-	xpic.i_pts = vrtp->framenum;
-	xpic.param=NULL;
-	xpic.img.i_csp=X264_CSP_I420;
-	xpic.img.i_plane=3;
-
-	ret = x264_encoder_encode(vrtp->enc_params,&xnals,&num_nals,&xpic,&oxpic);
-	if (ret >= 0){
-		if (ret == 0){
-			ret = x264_encoder_encode(vrtp->enc_params,&xnals,&num_nals,NULL,&oxpic);
-		}
-		if (ret > 0){
-			vrtp->delta_ts += VIDEO_CLOCK * vrtp->config.fps_den / vrtp->config.fps_num;
-			sender_standard_h264_packetize_x264_nals(vrtp, vrtp->config.local_pt, xnals,num_nals);
-			vrtp->framenum++;
-		}
-	}
-
-	if (VIDEO_FORMAT_RGB24 == vframe->format){
-		av_freep(&pic.planes[0]);
-	}
-
-#endif
-
-
 	return 0;
 }
 
@@ -2394,14 +2291,26 @@ int videortp_reconfig_local_pt(videortp_t *vrtp, unsigned int local_pt){
 }
 
 
+bool videortp_thread_valid(videortp_t* vrtp) 
+{
+	bool bret = true;
+#ifdef _WIN32
+	bret = vrtp->recv_thread != NULL ? true : false;
+#else
+	bret = vrtp->recv_threadid != 0 ? true : false;
+#endif
+	return bret;
+}
 
 int videortp_force_key_frame(videortp_t *vrtp)
 {
-	if (vrtp->recv_thread) {
+	int iret = -1;
+	if (videortp_thread_valid(vrtp))
+	{
 		receiver_force_key_frame(vrtp);
-		return 0;
+		iret = 0;
 	}
-	return -1;
+	return iret;
 }
 
 /******************************¶ÔÍâapi end***************************/

+ 0 - 2
Other/rvcmediacommon/common_video/videocommon.h

@@ -1,6 +1,4 @@
 #pragma once
-#include <string>
-
 
 // Supported video types.
 enum VideoType {