From 2b1a3988c9fd35c39e3e43d0382d65a13c45efee Mon Sep 17 00:00:00 2001
From: xuxiuxi <554325746@qq.com>
Date: 星期四, 14 三月 2019 10:38:27 +0800
Subject: [PATCH] Merge branch 'yw.1.2.fixbug' of http://192.168.1.226:10010/r/development/c++ into yw.1.2.fixbug

---
 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp |   88 +++++++++++++++++++++++++------------------
 1 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 77862e7..3efd923 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -6,18 +6,17 @@
 #include <qt5/QtCore/QDateTime>
 #include <basic/util/app/AppPreference.hpp>
 #include "VideoCaptureElementWithRtp.h"
+#include <VideoToImageMulth/RtspAnalysManager.h>
 
 //std::string BASICGB28181::VideoCaptureElementWithRtp::m_chanPubID;
 //BASICGB28181::FFmpegDecoderJPG BASICGB28181::VideoCaptureElementWithRtp::m_fFmpegDecoderJPG;
 
 BASICGB28181::VideoCaptureElementWithRtp::VideoCaptureElementWithRtp(std::string &chanPubID, int fps,
                                                                      int streamTransType,
-                                                                     int gpuIdx) : m_chanPubID(chanPubID), m_fps(fps),
-                                                                                   m_running(false),
-                                                                                   m_waitSignal(false),
-                                                                                   m_streamTransType(streamTransType),
-                                                                                   m_gpuIdx(gpuIdx),
-                                                                                   m_userdata((long) this) {
+                                                                     int gpuIdx, RtspAnalysManager *manager)
+    : m_chanPubID(chanPubID), m_fps(fps), m_running(false),
+      m_waitSignal(false), m_streamTransType(streamTransType),
+      m_gpuIdx(gpuIdx), m_userdata((long) this), m_pManager(manager) {
 //    m_chanPubID = chanPubID;
 
     m_cutPath = appPref.getStringData("user.loop.absolute.path");
@@ -35,6 +34,38 @@
 }
 
 bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
+
+    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
+            p_this->m_picCount++;
+            //鍑犲紶閫変竴寮犳斁鍏edis
+            if (p_this->m_picCount % m_nPicsPickOne != 0) {
+                continue;
+            } else {
+                p_this->m_picCount.store(0);
+            }
+
+            p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image);
+            {
+                cv::Mat copyMat;
+                std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName();
+                p_this->m_image.copyTo(copyMat);
+                m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat);
+            }
+            p_this->submit();
+        }
+        INFO("waitSignalAndEmit is exit...");
+    }, this);
+    waitSignalAndEmit.detach();
 
     TryCath(
     //--------------鍥芥爣璁惧鎴栧垯鍥芥爣涓嬬骇骞冲彴蹇呴』鏀寔GB28181-2016----------------------------------------------
@@ -74,8 +105,10 @@
                 }
                 DBG("videoCaptureElementThd stop ...");
                 C_RealVideoStop(lrealhandle);
+                p_this->m_waitSignal = false;
                 DBG("videoCaptureElementThd stop ok...");
             } else {
+                p_this->m_waitSignal = false;
                 p_this->m_running = false;
                 p_this->m_fFmpegDecoderJPG.stopThd();
                 ERR(p_this->m_chanPubID << " C_RealVideoStart is error lrealhandle is  " << lrealhandle);
@@ -125,42 +158,23 @@
 }
 
 void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() {
+    if ((!m_running) || (!m_waitSignal)) {
+        if (reopenTime < 0) {
+            stop();
+            INFO("grabFrame faild, element stopping");
+            return;
+        } else {
+            usleep(reopenTime * 1000);
+            INFO("grabFrame faild, try reopen video: ");
+            startRtpStream(m_streamTransType);
+            return;
+        }
+    }
     fireConnectors();
 }
 
 void BASICGB28181::VideoCaptureElementWithRtp::threadInitial() {
 
-    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
-            p_this->m_picCount++;
-            //鍑犲紶閫変竴寮犳斁鍏edis
-            if (p_this->m_picCount % m_nPicsPickOne != 0) {
-                continue;
-            } else {
-                p_this->m_picCount.store(0);
-            }
-
-            p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image);
-            {
-                cv::Mat copyMat;
-                std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName();
-                p_this->m_image.copyTo(copyMat);
-//                m_pManager->SaveImageToRedis(m_camId, imageName, copyMat);
-            }
-            p_this->submit();
-        }
-        INFO("waitSignalAndEmit is exit...");
-    }, this);
-    waitSignalAndEmit.detach();
     startRtpStream(m_streamTransType);
 }
 

--
Gitblit v1.8.0