浏览代码

Z991239-1781 #comment other 解决座席端主动挂断,终端sipphone实体出现异常问题

陈礼鹏80274480 4 年之前
父节点
当前提交
6b858b3b3a

+ 10 - 8
Module/mod_mediacontroller/capture.cpp

@@ -323,6 +323,7 @@ static int audio_capture_start(audio_capture_t *audio_cap)
 	inParam.hostApiSpecificStreamInfo = NULL;
 	audio_cap->dev_samplespersec = in_info->defaultSampleRate;
 	double inSampleRate = in_info->defaultSampleRate;
+	Dbg("audio input device name is %s.", in_info->name);
 	paError = Pa_IsFormatSupported(&inParam, NULL, inSampleRate);
 	if (paNoError != paError) {
 		Dbg("[%d] in dev %s audio capture create error[%d], cannot open audio input device", in_dev_id, in_info->name, paError);
@@ -355,7 +356,7 @@ static int audio_capture_start(audio_capture_t *audio_cap)
 	outParam.suggestedLatency = out_info->defaultLowOutputLatency;
 	outParam.sampleFormat = paInt16;
 	outParam.hostApiSpecificStreamInfo = NULL;
-
+	Dbg("audio output device name is %s.", in_info->name);
 	if (Pa_IsFormatSupported(NULL, &outParam, out_info->defaultSampleRate) != paNoError) {
 		Dbg("audio capture create error, cannot open output audio device.");
 		return Error_AudioOut;
@@ -560,7 +561,6 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 	int rc;
 
 	video_cap->frame_id++;
-	//Dbg("env cap on frame");
 
 	//Dbg("start env on frame, id=%d, tick=%d", video_cap->frame_id, GetTickCount());;
 	//IplImage* img = NULL;
@@ -571,7 +571,7 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 
 	rc = video_shm_enqueue(video_cap->snapshot_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
 
-	/*static*/ int isnapshot_shm_queue = 0;
+	static int isnapshot_shm_queue = 0;
 	if (isnapshot_shm_queue == 0) {
 		video_frame_save_bmpfile("snapshot_shm_queue_1.bmp", frame);
 		isnapshot_shm_queue++;
@@ -614,19 +614,21 @@ static void env_cap_on_frame(void *user_data, video_frame *frame)
 	// preview
 	{
 		video_frame preview_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);
 		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);
+			Dbg("preview_shm_queue enqueue failed, error = %d", rc);
+		}
+		else {
+			//Dbg("preview_shm_queue enqueue[%d] success, and current video queue len is %d.", video_cap->frame_id, video_cap->preview_shm_queue->GetVideoLens());
 		}
-		//else {
-		//	Dbg("preview_shm_queue enqueue success!");
-		//}
 		video_frame_free(&preview_frame);
 
-		/*static*/ int ipreview_shm_queue = 0;
+		static int ipreview_shm_queue = 0;
 		if (ipreview_shm_queue == 0) {
 			video_frame_save_bmpfile("preview_shm_queue_1.bmp", frame);
 			ipreview_shm_queue++;

+ 45 - 153
Module/mod_sipphone/endpoint.cpp

@@ -355,7 +355,7 @@ static void endpoint_media_update_video(endpoint_call_t *call, media_desc_t *vid
 			return;
 		}
 		else{
-			Dbg("make remote call session addr is %0x.",call->video);
+			Dbg("make remote call session addr is 0x%0x.",call->video);
 		}
 		rc = video_session_start(call->video);
 		if (rc != 0) {
@@ -365,7 +365,7 @@ static void endpoint_media_update_video(endpoint_call_t *call, media_desc_t *vid
 			return;
 		}
 		else{
-			Dbg("endpoint media update video, video session start suc, and session is %0x.", call->video);
+			Dbg("endpoint media update video, video session start suc, and session is 0x%0x.", call->video);
 		}
 	}
 }
@@ -378,7 +378,9 @@ static void endpoint_media_update_audio(endpoint_call_t *call, media_desc_t *aud
 		if (call->audio) {
 			LOG_TRACE("stop audio...");
 			audio_session_stop(call->audio);
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			audio_session_destroy(call->audio);
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			call->audio = NULL;
 			LOG_TRACE("stop audio ok!");
 		}
@@ -1054,7 +1056,6 @@ static void endpoint_callback(nua_event_t   event,
 						 sip_t const  *sip,
 						 tagi_t        tags[])
 {
-	LOG_FUNCTION();
 	switch (event) 
 	{
 		if (!g_IsExternalTerminalted)
@@ -1159,7 +1160,6 @@ void* __event_thread(void* arg)
 		ep, 
 		NUTAG_URL(ep->conf.uri),
 		TAG_END());
-	Dbg("%s:%d", __FUNCTION__, __LINE__);
 
 	nua_set_params(ep->nua,
 		SIPTAG_ALLOW_STR("INVITE,CANCEL,BYE,ACK,INFO,OPTIONS"),
@@ -1172,9 +1172,10 @@ void* __event_thread(void* arg)
 		NTATAG_SIP_T1X64(8000),
 		TAG_NULL());
 
-	Dbg("%s:%d", __FUNCTION__, __LINE__);
+	Dbg("%s:%d thread self id is %u.", __FUNCTION__, __LINE__, pthread_self());
 	su_root_run(ep->root);
 	Dbg("%s:%d", __FUNCTION__, __LINE__);
+
 	nua_shutdown(ep->nua);
 	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	ep->nua = NULL;
@@ -1186,17 +1187,19 @@ void* __event_thread(void* arg)
 
 #ifdef RVC_OS_WIN
 	CoUninitialize();
+	return 0;
 #else
-
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
+	pthread_exit(NULL);
 #endif // RVC_OS_WIN
-	
-	return 0;
 }
 
 static int __endpoint_break(void *arg)
 {
+	LOG_FUNCTION();
 	endpoint_t *ep = (endpoint_t *)arg;
-
+	Dbg("%s:%d ep = 0x%x. su_root_break called.", __FUNCTION__, __LINE__, ep);
 	//.....nua_shutdown
 	su_root_break(ep->root);
 
@@ -1233,8 +1236,9 @@ static endpoint_t *__endpoint_create(CEntityBase *pEntity, const endpoint_conf_t
 	return ep;
 }
 
-static void __endpoint_destroy(endpoint_t *ep)\
+static void __endpoint_destroy(endpoint_t *ep)
 {
+	LOG_FUNCTION();
 	su_root_destroy(ep->root);
 	su_home_deinit(ep->home);
 	free(ep);
@@ -1261,19 +1265,32 @@ static int __endpoint_start(endpoint_t *ep)
 	}
 	return ep->event_thread ? 0 : -1;
 #else
-	int err = pthread_create(&ep->ievent_threadid, NULL, __event_thread, ep);
+	pthread_attr_t attr;
+	pthread_attr_init(&attr);
+	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+	int err = pthread_create(&ep->ievent_threadid, &attr, __event_thread, ep);
+	pthread_attr_destroy(&attr);
 	if (0 == err) {
-		Dbg("create event thread success, %lu.", ep->ievent_threadid);
-		struct timespec ts;
-		Dbg("before circle ep->root = 0x%0x", ep->root);
+		Dbg("create event thread success, event_threadid is %u.", ep->ievent_threadid);
+		//Dbg("before circle ep->root = 0x%0x", ep->root);
 		while (!ep->root) {
+			struct timespec ts; 
 			clock_gettime(CLOCK_REALTIME, &ts);
-			ts.tv_nsec += 1000 * 1000;
+			Dbg("%s:%d tv_nsec = %lu.", __FUNCTION__, __LINE__, ts.tv_nsec);
+			long unsec = ts.tv_nsec + (1000 * 1000);
+			ts.tv_sec += (unsec / 1000000000);
+			ts.tv_nsec = (unsec % 1000000000);
+			Dbg("%s:%d ", __FUNCTION__, __LINE__);
 			if (0 == pthread_timedjoin_np(ep->ievent_threadid, NULL, &ts)) {
+				Dbg("%s:%d ts", __FUNCTION__, __LINE__);
 				ep->ievent_threadid = 0;
 				Dbg("__event_thread exit break");
 				break;
 			}
+			else
+			{
+				Dbg("%s:%d ts and tv_nsec = %lu.", __FUNCTION__, __LINE__, ts.tv_nsec);
+			}
 		}
 		Dbg("break circle ep->root = 0x%0x", ep->root);
 	}
@@ -1287,6 +1304,7 @@ static int __endpoint_start(endpoint_t *ep)
 
 static void __endpoint_stop(endpoint_t *ep)
 {
+	LOG_FUNCTION();
 #ifdef RVC_OS_WIN
 	if (ep->event_thread)
 	{
@@ -1297,12 +1315,19 @@ static void __endpoint_stop(endpoint_t *ep)
 		ep->event_thread = NULL;
 	}
 #else
+	Dbg("%s:%d ievent_threadid is %u.", __FUNCTION__, __LINE__, ep->ievent_threadid);
 	if (ep->ievent_threadid > 0)
 	{
 		int rc;
 		su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
-		pthread_join(ep->ievent_threadid, NULL);
-		ep->ievent_threadid = 0;
+		Dbg("%s:%d ep address is 0x%0x, event_threadid is %u.", __FUNCTION__, __LINE__, ep, ep->ievent_threadid);
+		//if (0 == pthread_join(ep->ievent_threadid, NULL)) {
+		//	Dbg("pthread join success.");
+		//	ep->ievent_threadid = 0;
+		//}
+		//else {
+		//	Dbg("pthread join error for %s", strerror(errno));
+		//}
 	}
 #endif
 
@@ -1342,8 +1367,11 @@ void endpoint_destroy(endpoint_t *ep)
 	LOG_FUNCTION();
 	if (ep) 
 	{
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		__endpoint_stop(ep);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		__endpoint_destroy(ep);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 	}
 }
 
@@ -1463,142 +1491,6 @@ int endpoint_call_hangup(endpoint_call_t *call)
 }
 
 
-int set_switch_distribute_req_buffer(char* pbuffer, size_t ulen, endpoint_distribute_call_info_t *tinfo)
-{
-	int ret = 0;
-	if (!tinfo){
-		return ret;
-	}
-
-	int ilen = sizeof(unsigned int);
-	char* pindex = pbuffer + ilen;
-
-	memcpy(pindex, &tinfo->etype, ilen);
-	pindex += ilen;
-
-	if (tinfo->call_name){
-		unsigned int callname_len = strlen(tinfo->call_name);
-		memcpy(pindex, &callname_len, ilen);
-		pindex += ilen;
-		memcpy(pindex, tinfo->call_name, callname_len);
-		pindex += callname_len;
-	}
-
-	int actlen = pindex - pbuffer;
-	if (actlen < ulen)
-	{
-		memcpy(pbuffer, &actlen, ilen);
-		ret = actlen;
-	}
-
-	return ret;
-}
-
-#ifndef BUFFER_SIZE
-#define BUFFER_SIZE 256
-#endif
-
-//int endpoint_pad_switch_interactive(endpoint_distribute_call_info_t *tinfo)
-//{
-//	int ret = -1;
-//	SOCKET conn = INVALID_SOCKET;
-//	struct sockaddr_in addr = {0};
-//	int rc = -1;
-//	BOOL opt = TRUE;
-//	int saccept = -1;
-//	BOOL bconnect = FALSE;
-//	// try connect to switch server
-//	if (NULL== tinfo){
-//		return ret;
-//	}
-//
-//	addr.sin_family = AF_INET;
-//	addr.sin_port = htons(tinfo->server_port);
-//	addr.sin_addr.s_addr = inet_addr(tinfo->server_ip);//strtoul(config->switch_server, NULL, 10);
-//
-//	conn = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-//	if (INVALID_SOCKET == conn){
-//		return ret;
-//	}
-//	rc = setsockopt(conn, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(opt));
-//	opt = TRUE;
-//	if (rc == 0){
-//		rc = setsockopt(conn, SOL_SOCKET, SO_DONTLINGER, (char*)&opt, sizeof(opt));
-//	}
-//
-//	if (0 != rc){
-//		return ret;
-//	}
-//
-//	int nRet = 0;
-//	u_long lRet = 1;
-//	nRet = ioctlsocket(conn, FIONBIO, &lRet);
-//	if (SOCKET_ERROR == nRet){
-//		closesocket(conn);
-//		return ret;
-//	}    
-//
-//	saccept = connect(conn, (struct sockaddr*)&addr, sizeof(addr));
-//	if (SOCKET_ERROR == saccept){
-//		fd_set fdWrite;
-//		FD_ZERO(&fdWrite);
-//		FD_SET(conn, &fdWrite);
-//		timeval time;
-//		time.tv_sec = 5;
-//		time.tv_usec = 0;
-//
-//		int nret = select(0, NULL, &fdWrite, NULL, &time);
-//		if (SOCKET_ERROR == nret){
-//			closesocket(conn);
-//			return ret;
-//		}
-//
-//		if (!FD_ISSET(conn, &fdWrite)){
-//			closesocket(conn);
-//			return ret;
-//		}
-//		else{
-//			bconnect = TRUE;
-//		}
-//	}
-//	else{
-//		bconnect = TRUE;
-//	}
-//
-//	if (bconnect){
-//		lRet = 0;
-//		nRet = ioctlsocket(conn, FIONBIO, &lRet);
-//		if (SOCKET_ERROR == nRet){
-//			closesocket(conn);
-//			return ret;
-//		}   
-//
-//		char req_buffer[BUFFER_SIZE] = {0};
-//		int idatalen = set_switch_distribute_req_buffer(req_buffer, BUFFER_SIZE, tinfo);
-//		int n = send(conn, req_buffer, idatalen, 0);
-//		if (n == idatalen){
-//			ret = 0;
-//		}
-//	}
-//	closesocket(conn);
-//
-//	return ret;
-//}
-
-int endpoint_distribute_hangup(endpoint_distribute_call_info_t *tinfo)
-{
-	int ret = -1;
-	if (NULL == tinfo){
-		return ret;
-	}
-
-	//ret = endpoint_pad_switch_interactive(tinfo);
-	Dbg("endpoint_distribute_hangup call_name=%s,server_ip=%s,server_port=%d.", tinfo->call_name,tinfo->server_ip,tinfo->server_port);
-
-	return ret;
-}
-
-
 int endpoint_call_start_video(endpoint_call_t *call, unsigned long remote_ip, int remote_video_rtp, 
 	unsigned long local_ip, int local_video_rtp, 
 	int remote_width, int remote_height,

+ 0 - 1
Module/mod_sipphone/endpoint.h

@@ -127,7 +127,6 @@ int local_play_stop_video(endpoint_call_t *call);
 int local_remote_show_video(endpoint_call_t *call,int local_view_x, int local_view_y, int local_view_cx, int local_view_cy,int remote_view_x, int remote_view_y, int remote_view_cx, int remote_view_cy, int local_move, int remote_move, video_session_callback_t* cb);
 
 void Terminatedcall(endpoint_call_t *call);
-int endpoint_distribute_hangup(endpoint_distribute_call_info_t *tinfo);
 int translate_ipaddr_from_int(char* strdst, unsigned ulen, unsigned long uip);
 
 #endif // ENDPOINT_H

+ 52 - 71
Module/mod_sipphone/mod_sipphone.cpp

@@ -838,7 +838,7 @@ public:
 				return Error_Unexpect;
 			}
 			else{
-				Dbg("__OnStart call uri is %s, endpoint_create m_pEndpoint addr is %0x.",conf.uri, m_pEndpoint);
+				Dbg("%s:%d call uri is %s, endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, conf.uri, m_pEndpoint);
 			}
 		} 
 		else 
@@ -1491,6 +1491,7 @@ public:
 
 	ErrorCodeEnum InitEndpoint() 
 	{	
+		LOG_FUNCTION();
 		ErrorCodeEnum eCode = Error_Param;
 		CSmartPointer<IEntityFunction> Func = GetFunction();
 		Func->GetSystemStaticInfo(staticInfo);
@@ -1507,7 +1508,7 @@ public:
 				eCode = Error_Unexpect;
 			}
 			else{
-				Dbg("__OnStart endpoint_create m_pEndpoint addr is %0x.", m_pEndpoint);
+				Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEndpoint);
 				eCode = Error_Succeed;
 			}
 		} 
@@ -1964,43 +1965,49 @@ void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Re
 	cmd->pSIPPhoneSession = this;
 	cmd->strUri = ctx->Req.call_uri;
 	///////////重新初始化sip话机,防止断网导致IP改变//////////////////
-	if (m_pEntity->m_pEndpoint)
+	if (m_pEntity->m_eDeviceType == eMobilePadType)
 	{
-		Dbg("Handle_MakeCall endpoint_destroy m_pEndpoint addr is %0x.",m_pEntity->m_pEndpoint);
-		endpoint_destroy(m_pEntity->m_pEndpoint);
-		m_pEntity->m_pEndpoint = NULL;
-	}
+		if (m_pEntity->m_pEndpoint)
+		{
+			Dbg("Handle_MakeCall endpoint_destroy m_pEndpoint addr is 0x%0x.", m_pEntity->m_pEndpoint);
+			endpoint_destroy(m_pEntity->m_pEndpoint);
+			m_pEntity->m_pEndpoint = NULL;
+		}
 
-	CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
-	if (strUri.GetLength() > 0) 
-	{
-		strcpy(m_pEntity->conf.uri, strUri);
-		m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
-		m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
-		m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf,m_pEntity->m_iPickupPhoneState);
-		if (!m_pEntity->m_pEndpoint)
+		CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
+		if (strUri.GetLength() > 0)
 		{
-			LOG_TRACE("create endpoint failed!");
+			strcpy(m_pEntity->conf.uri, strUri);
+			m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
+			m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
+			m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf, m_pEntity->m_iPickupPhoneState);
+			if (!m_pEntity->m_pEndpoint)
+			{
+				LOG_TRACE("create endpoint failed!");
+			}
+			else {
+				Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
+			}
 		}
-		else{
-			Dbg("Handle_MakeCall endpoint_create m_pEndpoint addr is %0x.", m_pEntity->m_pEndpoint);
+		else
+		{
+			LOG_TRACE("strUri length equals zero!");
+		}
+		ErrorCodeEnum  Error = m_pEntity->GetLocalIP();
+		if (Error != 0)
+		{
+			LOG_TRACE("get local ip failed!");
+		}
+		if (m_pEntity->m_eDeviceType == eMobilePadType)
+		{
+			m_pEntity->m_stVideoParam.nUpDynamicFps = 3;
 		}
-	} 
-	else 
-	{
-		LOG_TRACE("strUri length equals zero!");
-	}
-	ErrorCodeEnum  Error = m_pEntity->GetLocalIP();
-	if (Error != 0) 
-	{
-		LOG_TRACE("get local ip failed!");
-	}
-	if (m_pEntity->m_eDeviceType == eMobilePadType)
-	{
-		m_pEntity->m_stVideoParam.nUpDynamicFps = 3;	
 	}
+
 	///////////重新初始化sip话机,防止断网导致IP改变//////////////////
-	endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
+	if (m_pEntity->GetEndpoint()) {
+		endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
+	}
 	ctx->Answer((ErrorCodeEnum)rc);
 }
 
@@ -2027,9 +2034,12 @@ void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext<PhoneService_ReleaseC
 	int rc = Error_Succeed;
 	g_IsExternalTerminalted = TRUE;
 	endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc);
-	Dbg("Handle_ReleaseCall endpoint_destroy m_pEndpoint addr is %0x.",m_pEntity->m_pEndpoint);
-	endpoint_destroy(m_pEntity->m_pEndpoint);
-	m_pEntity->m_pEndpoint = NULL;
+	Dbg("%s:%d endpoint_destroy m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
+	if (NULL != m_pEntity->m_pEndpoint){
+		endpoint_destroy(m_pEntity->m_pEndpoint);
+		m_pEntity->m_pEndpoint = NULL;
+	}
+	
 	ctx->Answer((ErrorCodeEnum)rc);
 }
 
@@ -2145,35 +2155,6 @@ void CSIPPhoneSession::hangup_call(HangupCallCommand* cmd)
 		Dbg("normal hangup.");
 		endpoint_call_hangup(m_pCall);
 	}
-	else
-	{  
-		if (m_pEntity && m_pEntity->m_nCallType == MOBILETOPAD_CALLTYPE){
-			//分布式呼叫主动挂断场景
-			Dbg("distribute hangup, without pickup");
-			if (cmd){
-				const char* pserver = cmd->strBranch_server_ip.GetData();
-				const char* pcallnum = cmd->strSession_num.GetData();
-
-				if (pcallnum && pserver){
-					endpoint_distribute_call_info_t* tinfo = (endpoint_distribute_call_info_t*)malloc(sizeof(endpoint_distribute_call_info_t));
-					if (tinfo){
-						memset(tinfo, 0, sizeof(endpoint_distribute_call_info_t));
-						memcpy(tinfo->server_ip, pserver, strlen(pserver));
-						memcpy(tinfo->call_name, pcallnum, strlen(pcallnum));
-						tinfo->etype = INS_HANGUP;
-						tinfo->server_port = cmd->iBranch_server_port;
-						endpoint_distribute_hangup(tinfo);	
-
-						free(tinfo);
-						tinfo = NULL;
-					}
-				}
-			}
-
-			LogEvent(Severity_Middle,LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE,"SIPPhone to idle.");
-			LogEvent(Severity_Middle,LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE,"AssistantChannel to idle.");
-		}
-	}
 }
 
 void CSIPPhoneSession::release_call()
@@ -2195,22 +2176,22 @@ void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const ch
 		Info.state = state;
 		Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
 		m_spCallbackContext->SendMessage(Info);
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
 	}
 
 	if (state == TERMINATED) 
 	{
-		Dbg("%s:%d", __FUNCTION__, __LINE__);
-		if (m_pCall)
-		{
-			Dbg("%s:%d", __FUNCTION__, __LINE__);
+		if (NULL != m_pCall){
 			endpoint_call_destroy(m_pCall);
 			m_pCall = NULL;
 		}
+
+		//Dbg("%s:%d endpoint_destroy m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
+		//if (NULL != m_pEntity->m_pEndpoint) {
+		//	endpoint_destroy(m_pEntity->m_pEndpoint);
+		//	m_pEntity->m_pEndpoint = NULL;
+		//}
 	}
-	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	m_pEntity->SetState(state);
-	Dbg("%s:%d", __FUNCTION__, __LINE__);
 }
 
 int CSIPPhoneSession::make_call( const char *remote_uri )

+ 130 - 86
Module/mod_sipphone/video_session.cpp

@@ -25,6 +25,7 @@
 #include "videorenderobj.h"
 #include "../../Other/libvideocapture/ivideocaptureinterface.h"
 #include <signal.h>
+#include <semaphore.h>
 #endif // RVC_OS_WIN
 
 
@@ -120,6 +121,7 @@ struct video_session_t
 	VideoRenderObj* plocal_render;
 	VideoRenderObj* premote_render;
 	pthread_t ui_threadid;
+	sem_t ui_stop_sem;
 #endif // RVC_OS_WIN
 
 	picture_record_t* pic_record;
@@ -218,7 +220,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();
+	//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;
@@ -286,7 +288,7 @@ static inline Clibvideoqueue *get_active_videoqueue(video_session_t *session)
 
 static void local_get_frame(void *user_data, video_frame *frame)
 {
-	LOG_FUNCTION();
+	//LOG_FUNCTION();
 	video_session_t *session = (video_session_t*)user_data;
 	Clibvideoqueue *q = get_active_videoqueue(session);
 
@@ -323,7 +325,7 @@ static void local_get_frame(void *user_data, video_frame *frame)
 
 static void local_put_frame(void *user_data, video_frame *frame)
 {
-	LOG_FUNCTION();
+	//LOG_FUNCTION();
 	video_session_t *session = (video_session_t*)user_data;
 	video_frame *tmp_frame_encode = NULL;
 
@@ -332,18 +334,14 @@ static void local_put_frame(void *user_data, video_frame *frame)
 		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);
@@ -362,26 +360,24 @@ 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);
+			//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);
 		}
 	}
 
 	if (tmp_frame_encode) {
-		Dbg("%s:%d video frame delete", __FUNCTION__, __LINE__);
+		//Dbg("%s:%d video frame delete", __FUNCTION__, __LINE__);
 		video_frame_delete(tmp_frame_encode);
 	}
 }
@@ -912,7 +908,7 @@ static void	show_remote_agnet_picture(video_session_t *t_session)
 	GetCurrentRunPath(strPath);
 	sprintf(strImgPath, "%s\\bin\\agent.jpg", strPath);
 #else
-
+	strcpy_s(strImgPath, MAX_PATH_SIZE, "./bin/agent.jpg");
 #endif // RVC_OS_WIN
 
 	video_frame* remote_frame = video_frame_new(irecord_video_frame_width, irecord_video_frame_heigt, VIDEO_FORMAT_RGB24);
@@ -1052,7 +1048,7 @@ static int start_local_video_clock(video_session_t* session)
 			&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);
+	Dbg("create session->local_clock addr is 0x%0x", session->local_clock);
 
 	if (0 == rc) {
 		rc = videoclock_start(session->local_clock);
@@ -1436,39 +1432,42 @@ on_error:
 static void stop_video(video_session_t *session)
 {
 	LOG_FUNCTION();
-
-	if (session->local_encode_sws_ctx_env) {
-		sws_freeContext(session->local_encode_sws_ctx_env);
-		session->local_encode_sws_ctx_env = 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_encode_sws_ctx_opt) {
-		sws_freeContext(session->local_encode_sws_ctx_opt);
-		session->local_encode_sws_ctx_opt = NULL;
+#else
+	if (session->local_clock)
+	{
+		Dbg("videoclock_stop local_clock addr is 0x%0x", session->local_clock);
+		videoclock_stop(session->local_clock);
+		videoclock_destroy(session->local_clock);
+		session->local_clock = NULL;
 	}
+#endif // RVC_OS_WIN
 
 	if (session->rtp)
 	{
 		Dbg("begin stop video rtp.");
 		videortp_stop(session->rtp);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		videortp_destroy(session->rtp);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		session->rtp = NULL;
-	}
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
+}
 	else {
 		Dbg("session->rtp == null");
 	}
-
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 #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;
@@ -1481,19 +1480,31 @@ static void stop_video(video_session_t *session)
 		session->remote_player = NULL;
 		Dbg("remote video player destroy.");
 	}
-
 #else
-
-	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;
+	if (session->plocal_render){
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
+		delete session->plocal_render;
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
+		session->plocal_render = NULL;
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 	}
 
+	if (session->premote_render){
+		delete session->premote_render;
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
+		session->premote_render = NULL;
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
+	}
+#endif
 
-#endif // RVC_OS_WIN
+	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;
+	}
 }
 
 #ifdef RVC_OS_WIN
@@ -1891,9 +1902,12 @@ 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);
-
-	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);
+	char str_local_ip[MAX_PATH_SIZE] = { 0 };
+	char str_remote_ip[MAX_PATH_SIZE] = { 0 };
+	translate_ipaddr_from_int(str_local_ip, MAX_PATH_SIZE, session->conf.local_rtp_ip);
+	translate_ipaddr_from_int(str_remote_ip, MAX_PATH_SIZE, session->conf.remote_rtp_ip);
+	Dbg("videorender_func local_pt: %d local_ip: %s local_rtp_port: %d.", session->conf.local_pt, str_local_ip, session->conf.local_rtp_port);
+	Dbg("videorender_func remote_pt: %d remote_ip: %s remote_rtp_port: %d.", session->conf.remote_pt, str_remote_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);
 	Dbg("%s:%d local(%d,%d,%d,%d) remote(%d,%d,%d,%d).", __FUNCTION__, __LINE__, session->conf.local_video_view_x, session->conf.local_video_view_y, session->conf.local_video_view_cx, session->conf.local_video_view_cy,
 		session->conf.remote_video_view_x, session->conf.remote_video_view_y, session->conf.remote_video_view_cx, session->conf.remote_video_view_cy);
@@ -1914,9 +1928,11 @@ void* videorender_func(void* arg)
 
 		start_video(session);
 	}
+	else {
+		Dbg("session remote video render is null.");
+	}
 
 	if (NULL != session->plocal_render){
-
 		videorender_param_t tparam = { 0 };
 		tparam.icx = session->conf.local_video_view_x;
 		tparam.icy = session->conf.local_video_view_y;
@@ -1927,29 +1943,52 @@ void* videorender_func(void* arg)
 		tparam.ivideoformat = VIDEO_FORMAT_RGB24;
 		if (0 == session->plocal_render->SetVideoRenderParam(&tparam)){
 			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);
-				static int icount = 0;
-				if (icount == 0) {
-					video_frame_save_bmpfile("local_test.bmp", tmp_frame_preview);
-					//icount++;
+			video_frame* vfrm = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
+
+			for ( ; ; ){
+				struct timespec ts;
+				clock_gettime(CLOCK_REALTIME, &ts);
+				long unsec = ts.tv_nsec + (1000 * 1000 * 100);
+				ts.tv_sec += (unsec / 1000000000);
+				ts.tv_nsec = (unsec % 1000000000);
+				Dbg("%s:%d", __FUNCTION__, __LINE__);
+				if (0 != sem_timedwait(&session->ui_stop_sem, &ts) && (ETIMEDOUT == errno))
+				{
+					video_frame_fill_black(vfrm);
+					Dbg("%s:%d", __FUNCTION__, __LINE__);
+					video_frame* tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
+					videoq_frame qfrm;
+					qfrm.data = tmp_frame_preview->data[0];
+					Dbg("%s:%d,and current video queue len is %d", __FUNCTION__, __LINE__, session->video_shm_q_preview->GetVideoLens());
+					BOOL result = session->video_shm_q_preview->GetVideo(&qfrm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
+					static int icount = 0;
+					if (icount == 0) {
+						video_frame_save_bmpfile("local_test.bmp", tmp_frame_preview);
+						//icount++;
+					}
+					if (result) {
+						Dbg("%s:%d", __FUNCTION__, __LINE__);
+						session->plocal_render->RenderVideoFrame(tmp_frame_preview);
+					}
+					else {
+						Dbg("%s:%d", __FUNCTION__, __LINE__);
+					}
 				}
-				if (result){
-					session->plocal_render->RenderVideoFrame(tmp_frame_preview);
+				else {
+					Dbg("%s:%d videorender_func exit!", __FUNCTION__, __LINE__);
+					session->plocal_render->HideVideoWindow();
+					break;
 				}
-				usleep(1000 * 20);
 			}
-			video_frame_delete(frm);
+			video_frame_delete(vfrm);
+		}
+		else {
+			Dbg("%s:%d set video render param failed!", __FUNCTION__, __LINE__);
 		}
 	}
-
+	else {
+		Dbg("%s:%d session local video render is null.", __FUNCTION__, __LINE__);
+	}
 
 	return 0;
 }
@@ -1959,7 +1998,7 @@ void* videorender_func(void* arg)
 static int start_ui(video_session_t *session)
 {
 	LOG_FUNCTION();
-	Dbg("start ui session addr is 0x%8x", session);
+	Dbg("start ui session addr is 0x%0x", session);
 
 #ifdef RVC_OS_WIN
 	session->ui_event = CreateEventA(NULL, FALSE, FALSE, NULL);
@@ -2002,13 +2041,21 @@ static int start_ui(video_session_t *session)
 	}
 	return 0;
 #else
-
+	if (0 != sem_init(&session->ui_stop_sem, 0, 0)) {
+		Dbg("%s:%d create ui stop event failed!", __FUNCTION__, __LINE__);
+		return Error_Resource;
+	}
+	else
+	{
+		Dbg("%s:%d create ui stop event success!", __FUNCTION__, __LINE__);
+	}
 	int err = pthread_create(&session->ui_threadid, NULL, videorender_func, session);
 	if (0 == err) {
-		Dbg("create video render thread success, %lu.", session->ui_threadid);
+		Dbg("create video render thread success, thread id is %u.", session->ui_threadid);
 	}
 	else {
 		Dbg("create video render thread failed.");
+		return Error_Resource;
 	}
 
 	return err;
@@ -2018,7 +2065,7 @@ static int start_ui(video_session_t *session)
 static void stop_ui(video_session_t *session)
 {
 	LOG_FUNCTION();
-	Dbg("stop ui session addr is %0x.", session);
+	Dbg("%s:%d session addr is 0x%0x.", __FUNCTION__, __LINE__, session);
 
 #ifdef RVC_OS_WIN
 	if (DOUBLERECORD_CALLTYPE == session->conf.nCallType) {
@@ -2070,17 +2117,15 @@ 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");
+	sem_post(&session->ui_stop_sem);
+	if (session->ui_threadid > 0) {
+		pthread_join(session->ui_threadid, NULL);
 	}
 
+	Dbg("ui thread exit!");
+
+	stop_video(session);
+
 #endif // RVC_OS_WIN
 }
 
@@ -2239,7 +2284,7 @@ int video_session_create(const video_session_conf_t *conf, video_session_t **p_s
 		translate_ipaddr_from_int(str_local, 128, conf->local_rtp_ip);
 		translate_ipaddr_from_int(str_remote, 128, conf->remote_rtp_ip);
 
-		Dbg("video_session_create session addr = %x,local_rtp_ip = %s,local_rtp_port = %d, local_pt = %d, remote_rtp_ip = %s,remote_rtp_port=%d, remote_pt = %d, call type = %d.", 
+		Dbg("video_session_create session addr = 0x%0x,local_rtp_ip = %s,local_rtp_port = %d, local_pt = %d, remote_rtp_ip = %s,remote_rtp_port=%d, remote_pt = %d, call type = %d.", 
 			session, str_local, conf->local_rtp_port,conf->local_pt, str_remote, conf->remote_rtp_port, conf->remote_pt, conf->nCallType);
 
 		memcpy(&session->conf, conf, sizeof(video_session_conf_t));
@@ -2262,7 +2307,7 @@ int video_session_create(const video_session_conf_t *conf, video_session_t **p_s
 		GetCurrentRunPath(strPath);
 		sprintf(strImgPath, "%s\\bin\\error.jpg", strPath);
 #else
-
+		strcpy_s(strImgPath, MAX_PATH_SIZE, "./bin/error.jpg");
 #endif // RVC_OS_WIN		
 		if (ExistsFile(strImgPath))
 		{
@@ -2291,7 +2336,7 @@ int video_session_create(const video_session_conf_t *conf, video_session_t **p_s
 #ifdef RVC_OS_WIN
 		sprintf(strPersonPath, "%s\\bin\\rxk.png", strPath);
 #else
-
+		strcpy_s(strPersonPath, MAX_PATH_SIZE, "./bin/rxk.png");
 #endif // RVC_OS_WIN
 		if (ExistsFile(strPersonPath))
 		{
@@ -2370,7 +2415,7 @@ int video_session_start(video_session_t *session)
 {
 	LOG_FUNCTION();
 
-	Dbg("video_session_start session addr is %0x, session call type is %d.", session, session->conf.nCallType);
+	Dbg("video_session_start session addr is 0x%0x, session call type is %d.", session, session->conf.nCallType);
 
 	int rc = start_ui(session);
 
@@ -2380,7 +2425,7 @@ int video_session_start(video_session_t *session)
 void video_session_stop(video_session_t *session)
 {
 	LOG_FUNCTION();
-	Dbg("video session stop session = %0x", session);
+	Dbg("video session stop session = 0x%0x", session);
 	stop_ui(session);
 }
 
@@ -2492,7 +2537,6 @@ void video_session_destroy(video_session_t *session)
 	if (session->recordareamask){
 		cvReleaseImage(&session->recordareamask);
 	}
-
 	free(session);
 }
 

+ 3 - 1
Other/libaudioframework/audiomicspklinux.c

@@ -168,7 +168,7 @@ static audiostream_vtbl_t g_stream_vtbl = {
 void audiomicspklinux_destroy(audiomicspklinux_t* micspk)
 {
 	sem_post(micspk->audio_device_started_sem);
-
+	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 	if (micspk->ply_stream) {
 		Pa_AbortStream(micspk->ply_stream);
 		Pa_CloseStream(micspk->ply_stream);
@@ -188,6 +188,7 @@ void audiomicspklinux_destroy(audiomicspklinux_t* micspk)
 	}
 	sem_destroy(micspk->audio_device_started_sem);
 
+	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 	//fclose(micspk->pcmfile);
 	//fclose(micspk->putpcmfile);
 	//fclose(micspk->highhzpcmFile);
@@ -214,6 +215,7 @@ static int initialize_speaker(audiomicspklinux_t* micspk)
 	outParam.sampleFormat = paInt16;
 	outParam.suggestedLatency = info->defaultLowOutputLatency;
 	outParam.hostApiSpecificStreamInfo = NULL;
+	audio_log_v(AUDIO_LOG_LEVEL_INFO, "audio output device name is %s.", info->name);
 	if (Pa_IsFormatSupported(NULL, &outParam, info->defaultSampleRate) != paNoError) {
 		audio_log_v(AUDIO_LOG_LEVEL_ERROR, "audio micspk create error, cannot open audio output device");
 		return APR_EGENERAL;

+ 6 - 10
Other/libvideoframework/videoclock.c

@@ -153,28 +153,25 @@ void* local_video_sendfunc(void* param)
 
 	for (;;) {
 		struct timespec ts;
-		int ivalue = -1;
+		//int ivalue = -1;
 		clock_gettime(CLOCK_REALTIME, &ts);
 		long unsec = ts.tv_nsec + (1000 * 1000 * dwTimeout);
 		ts.tv_sec += (unsec / 1000000000);
 		ts.tv_nsec = (unsec % 1000000000);
-		sem_getvalue(&clock->exit_sem, &ivalue);
-		clockDbg(clock, "%s:%d sem value is %d", __FUNCTION__, __LINE__, ivalue);
+		//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));
+			//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);
 		}
 		else {
-			clockDbg(clock, "%s:%d sem value is %d", __FUNCTION__, __LINE__, ivalue);
-			if (1 == ivalue){
 				clockDbg(clock, "%s:%d exit local video send thread.", __FUNCTION__, __LINE__);
 				break;
-			}
 		}
 	}
-	clockDbg(clock, "%s:%d exit local_video_sendfunc", __FUNCTION__, __LINE__);
+	//clockDbg(clock, "%s:%d exit local_video_sendfunc", __FUNCTION__, __LINE__);
 	video_frame_free(&frame);
 
 on_error:
@@ -282,7 +279,7 @@ int videoclock_start(videoclock_t vc)
 	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);
+		clockDbg(vc,"%s:%d pthread create success, and thread id is %u.", __FUNCTION__, __LINE__, vc->thread_id);
 	}
 	else {
 		clockDbg(vc,"%s:%d pthread create failed.", __FUNCTION__, __LINE__);
@@ -310,7 +307,6 @@ int videoclock_stop(videoclock_t vc)
 	if (vc->thread_id > 0){
 		pthread_join(vc->thread_id, NULL);
 	}
-
 #endif
 	return 0;
 }

+ 11 - 6
Other/libvideoframework/videortp.c

@@ -2223,7 +2223,7 @@ int videortp_start(videortp_t *vrtp)
 void videortp_stop(videortp_t* vrtp)
 {
 	int64_t now = TimeInMilliseconds();
-	rtpDbg(vrtp,"start call videortp_stop.");
+	rtpDbg(vrtp,"%s:%d start call videortp_stop.", __FUNCTION__, __LINE__);
 #ifdef _WIN32
 	if (vrtp->evt) {
 		SetEvent(vrtp->evt);
@@ -2239,20 +2239,25 @@ void videortp_stop(videortp_t* vrtp)
 	if (&vrtp->sem_evt) {
 		sem_post(&vrtp->sem_evt);
 		if (0 != vrtp->recv_threadid) {
-			pthread_join(vrtp->recv_threadid, NULL);
-			vrtp->recv_threadid = 0;
+			if (0 == pthread_join(vrtp->recv_threadid, NULL)){
+				vrtp->recv_threadid = 0;
+				rtpDbg(vrtp, "%s:%d pthread join success.", __FUNCTION__, __LINE__);
+			}
+			else {
+				rtpDbg(vrtp, "%s:%d pthread join failed for %s.", __FUNCTION__, __LINE__, strerror(errno));
+			}
 		}
 		sem_destroy(&vrtp->sem_evt);
 	}
 #endif
 
-	rtpDbg(vrtp,"stop rtp recv thread.");
+	rtpDbg(vrtp,"%s:%d stop rtp recv thread.", __FUNCTION__, __LINE__);
 
 	video_stats_receiver_on_stopped(now);
 	video_stats_sender_on_stopped(now);
-	
 	video_jbuffer_api_stop(vrtp->jbuffer);
-	rtpDbg(vrtp,"videortp_stop func end.");
+
+	rtpDbg(vrtp,"%s:%d  videortp_stop func end.", __FUNCTION__, __LINE__);
 }
 
 int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)

+ 1 - 3
Other/libvideorender/libvideorender.cpp

@@ -257,6 +257,7 @@ int VideoRenderImpl::HideVideoWindow()
 
 int VideoRenderImpl::StopVideoRender()
 {
+	HideVideoWindow();
 	return 0;
 }
 
@@ -299,9 +300,6 @@ int VideoRenderImpl::RenderVideoFrame(video_frame* pframe)
 		return iret;
 	}
 
-
-	
-
 	SDL_RenderPresent(m_renderer);
 
 	iret = 0;