From 5f5e870de69efe56d571a2c93362942af5bb49a5 Mon Sep 17 00:00:00 2001
From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期四, 20 七月 2017 14:30:55 +0800
Subject: [PATCH] restart

---
 RtspFace/PL_RTSPClient.cpp |   75 +++++++++++++++++++++++++------------
 1 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/RtspFace/PL_RTSPClient.cpp b/RtspFace/PL_RTSPClient.cpp
index 3439925..7bcf9d9 100644
--- a/RtspFace/PL_RTSPClient.cpp
+++ b/RtspFace/PL_RTSPClient.cpp
@@ -32,12 +32,14 @@
 	MB_Frame lastFrame;
 
 	RtspClientParam lastParam;
-	
+
+	volatile bool killed;
+
 	RTSPClient_Internal() : 
 		rtspConfig(), live_daemon_thid(0), 
 		eventLoopWatchVariable(0), live_daemon_running(false), 
 		frame_mutex(new pthread_mutex_t), continue_mutex(new pthread_mutex_t), 
-		lastFrame(), lastParam()
+		lastFrame(), lastParam(), killed(false)
 	{
 		pthread_mutex_init(frame_mutex, NULL);
 		pthread_mutex_init(continue_mutex, NULL);
@@ -167,7 +169,13 @@
 	RTSPClient_Internal* in = (RTSPClient_Internal*)internal;
 	
 	in->eventLoopWatchVariable = 1;
+
+	pthread_mutex_unlock(in->continue_mutex);
+	pthread_mutex_unlock(in->frame_mutex);
+
 	pthread_join(in->live_daemon_thid, NULL);
+
+	in->reset();
 }
 
 bool PL_RTSPClient::pay(const PipeMaterial& pm)
@@ -187,19 +195,38 @@
 		return false;
 	}
 
+	if (in->killed)
+	{
+		LOGP(WARN, "killed 1");
+		return false;
+	}
+
 	ret = pthread_mutex_lock(in->frame_mutex);
 	if(ret != 0)
 	{
 		LOGP(ERROR, "pthread_mutex_lock: %s/n", strerror(ret));
 		return false;
 	}
-	
+
+	if (in->killed)
+	{
+		LOGP(WARN, "killed 2");
+		return false;
+	}
+
 	pm.type = PipeMaterial::PMT_FRAME;
 	pm.buffer = &(in->lastFrame);
 	pm.buffSize = 0;
 	pm.former = this;
 
 	return true;
+}
+
+void PL_RTSPClient::kill()
+{
+	RTSPClient_Internal* in = (RTSPClient_Internal*)internal;
+	in->killed = true;
+	pthread_mutex_unlock(in->frame_mutex);
 }
 
 void rtsp_client_set_param_callback(void* arg, RtspClientParam& param)
@@ -222,30 +249,30 @@
 	sprintf(tmp, "%u", param.height); client->manager->set_param(PLGP_RTSP_HEIGHT, std::string(tmp));
 	sprintf(tmp, "%u", param.fps); client->manager->set_param(PLGP_RTSP_FPS, std::string(tmp));
 
-    /*
-    std::string fmtp(client->manager->get_param(PLGP_RTSP_FMTP));
-    if (fmtp.empty())
-        return ;
+	/*
+	std::string fmtp(client->manager->get_param(PLGP_RTSP_FMTP));
+	if (fmtp.empty())
+		return ;
 
-    uint32_t numSPropRecords = 0;
-    SPropRecord *p_record = parseSPropParameterSets(fmtp.c_str(), numSPropRecords);
-    if (numSPropRecords < 2)
-    {
-        LOG_WARN << "numSPropRecords < 2" << std::endl;
-        return ;
-    }
+	uint32_t numSPropRecords = 0;
+	SPropRecord *p_record = parseSPropParameterSets(fmtp.c_str(), numSPropRecords);
+	if (numSPropRecords < 2)
+	{
+		LOG_WARN << "numSPropRecords < 2" << std::endl;
+		return ;
+	}
 
-    SPropRecord &sps = p_record[0];
-    SPropRecord &pps = p_record[1];
+	SPropRecord &sps = p_record[0];
+	SPropRecord &pps = p_record[1];
 
-    LOG_INFO << "sps.sPropLength" << sps.sPropLength << LOG_ENDL;
-    for (int i = 0; i < sps.sPropLength; i++)
-        LOGP(INFO, "0x%02X ", (int)sps.sPropBytes[i]);
+	LOG_INFO << "sps.sPropLength" << sps.sPropLength << LOG_ENDL;
+	for (int i = 0; i < sps.sPropLength; i++)
+		LOGP(INFO, "0x%02X ", (int)sps.sPropBytes[i]);
 	
-    LOG_INFO << "pps.sPropLength" << pps.sPropLength << LOG_ENDL;
-    for (int i = 0; i < pps.sPropLength; i++)
-        LOGP(INFO, "0x%02X ", (int)pps.sPropBytes[i]);
-    */
+	LOG_INFO << "pps.sPropLength" << pps.sPropLength << LOG_ENDL;
+	for (int i = 0; i < pps.sPropLength; i++)
+		LOGP(INFO, "0x%02X ", (int)pps.sPropBytes[i]);
+	*/
 }
 
 void rtsp_client_frame_callback(void* arg, uint8_t* buffer, size_t buffSize, timeval presentationTime)
@@ -281,6 +308,6 @@
 	int ret = pthread_mutex_lock(in->continue_mutex);
 	if(ret != 0)
 	{
-		LOG_ERROR << "pthread_mutex_unlock continue_mutex: " << strerror(ret) << std::endl;
+		LOG_ERROR << "pthread_mutex_lock continue_mutex: " << strerror(ret) << std::endl;
 	}
 }

--
Gitblit v1.8.0