From 23bd97eaa5626ad96ca3f5d3e97e93d14705ca6d Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期六, 30 三月 2019 17:50:24 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/yangwu1.3' into 1.3nsq

---
 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp |   47 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 8a1d652..8859d91 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -35,17 +35,21 @@
 
 bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
 
+    //绛夊緟涓嬪眰ffmpeg灏唕tp鍖呰В鐮佹垚涓哄浘鐗囧悗瑙﹀彂淇″彿,鐒跺悗瑙﹀彂褰撳墠绫荤殑submit
     std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) {
         p_this->m_waitSignal = true;
+        //寰幆锛岀敱鎴愬憳鍙橀噺鏉ョ淮鎶よ繖涓嚎绋嬬殑杩愯鐘舵��
         while (p_this->m_waitSignal) {
 //#TODO wait test
 #ifdef TestCode
             DBG("waitSignal(\"DecoderImageOK\") begin");
 #endif
+            //绛夊緟淇″彿瑙﹀彂
             gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK");
 #ifdef TestCode
             DBG("waitSignal(\"DecoderImageOK\") after");
 #endif
+            /****褰曞儚妯″潡浠g爜*****/
             p_this->m_picCount++;
             //鍑犲紶閫変竴寮犳斁鍏edis
             if (p_this->m_picCount % m_nPicsPickOne != 0) {
@@ -54,6 +58,7 @@
                 p_this->m_picCount.store(0);
             }
 
+//            浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖
             p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image);
             {
                 cv::Mat copyMat;
@@ -61,6 +66,8 @@
                 p_this->m_image.copyTo(copyMat);
                 m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat);
             }
+            /*********/
+
             p_this->submit();
         }
         INFO("waitSignalAndEmit is exit...");
@@ -69,6 +76,7 @@
 
     TryCath(
     //--------------鍥芥爣璁惧鎴栧垯鍥芥爣涓嬬骇骞冲彴蹇呴』鏀寔GB28181-2016----------------------------------------------
+    //瑙g爜绾跨▼锛屽彂璧风偣鎾姹傦紝鍚姩ffmpeg瑙g爜妯″潡
         std::thread videoCaptureElementThd([&](VideoCaptureElementWithRtp *p_this, int streamType) {
             DBG("videoCaptureElementThd start...");
             StreamTransType_E etype;
@@ -93,28 +101,52 @@
             }
             DBG("C_RealVideoStart start... m_chanPubID is " << p_this->m_chanPubID << " etype is " << etype
                                                             << " m_userdata is " << m_userdata);
+            //寮�濮嬬偣鎾棰�
             long lrealhandle = C_RealVideoStart(const_cast<char *>(p_this->m_chanPubID.c_str()), etype,
                                                 p_this->streamcallback, m_userdata);
 
             if (lrealhandle != -1) {
+                //鐐规挱鎴愬姛
                 DBG(p_this->m_chanPubID << "  C_RealVideoStart ok ... type is " << etype);
                 p_this->m_running = true;
+                //鍚姩ffmpeg瑙g爜妯″潡
                 p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx);
+                usleep(1000000);
+                //闃诲绾跨▼锛岀瓑寰呭閮ㄨЕ鍙戝叧闂偣鎾�
                 while (p_this->m_running) {
-//                    if(p_this->m_fFmpegDecoderJPG.getRunning()) {
+                    if(p_this->m_fFmpegDecoderJPG.getRunning()) {
                         usleep(300000);
-//                    }else{
-//                        p_this->m_running = false;
-//                        break;
-//                    }
+                    } else {
+
+                        // 鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚�
+                        if (reopenTime < 0) {
+                            p_this->m_running = false;
+                            stop();
+                            INFO("grabFrame faild, element stopping");
+                        } else {
+                            //todo 涓氬姟姝婚攣
+                            usleep((6 - reopenTime--) * 1000000);
+                            INFO("grabFrame faild, try reopen video: ");
+
+                            //鍏抽棴ffmpeg瑙g爜妯″潡
+                            p_this->m_fFmpegDecoderJPG.stopThd();
+                            //鍚姩ffmpeg瑙g爜妯″潡
+                            p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx);
+                            continue;
+                        }
+                    }
                 }
                 DBG("videoCaptureElementThd stop ...");
+                //鍋滄鐐规挱
                 C_RealVideoStop(lrealhandle);
+                //灏唚aitSignalAndEmit 绾跨▼閫�鍑�
                 p_this->m_waitSignal = false;
                 DBG("videoCaptureElementThd stop ok...");
             } else {
+                //鐐规挱澶辫触
                 p_this->m_waitSignal = false;
                 p_this->m_running = false;
+                //鍏抽棴ffmpeg瑙g爜妯″潡
                 p_this->m_fFmpegDecoderJPG.stopThd();
                 ERR(p_this->m_chanPubID << " C_RealVideoStart is error lrealhandle is  " << lrealhandle);
             }
@@ -157,18 +189,21 @@
 //        fwrite(data, sizeof(char), datalen, fp11);
     }
 #endif
-
+    //灏嗗簳灞傜粍濂界殑rtp鍖咃紝瀛樺叆ffmpeg涓殑缂撳瓨闃熷垪
     CHKDBG(p_this->m_fFmpegDecoderJPG.pushInfo(data, datalen, p_this->m_chanPubID), true,
            "pushInfo is error !! handle is " << handle << " datatype is " << datatype << " frametype is " << frametype);
 }
 
 void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() {
+
     if ((!m_running) || (!m_waitSignal)) {
+//        鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚�
         if (reopenTime < 0) {
             stop();
             INFO("grabFrame faild, element stopping");
             return;
         } else {
+            //todo 涓氬姟姝婚攣
             usleep(reopenTime * 1000);
             INFO("grabFrame faild, try reopen video: ");
             startRtpStream(m_streamTransType);

--
Gitblit v1.8.0