From 00f7c180ceedecab842ce2a05308f435f9f54718 Mon Sep 17 00:00:00 2001
From: pansen <pansen626@sina.com>
Date: 星期二, 09 四月 2019 14:24:19 +0800
Subject: [PATCH] # Type(<scope>): <subject>

---
 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp |   79 ++++++++++++++++++++++++++-------------
 1 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 2f7010f..fdd97a4 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -5,6 +5,7 @@
 #include <opencv2/imgproc.hpp>
 #include <qt5/QtCore/QDateTime>
 #include <basic/util/app/AppPreference.hpp>
+#include <basic/util/app/AppConfig.h>
 #include "VideoCaptureElementWithRtp.h"
 #include <VideoToImageMulth/RtspAnalysManager.h>
 
@@ -35,7 +36,7 @@
 
 bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
 
-    if(!m_waitSignalrunning) {
+    if (!m_waitSignalrunning) {
         DBG("std::thread waitSignalAndEmit create New!!");
         //绛夊緟涓嬪眰ffmpeg灏唕tp鍖呰В鐮佹垚涓哄浘鐗囧悗瑙﹀彂淇″彿,鐒跺悗瑙﹀彂褰撳墠绫荤殑submit
         std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) {
@@ -48,28 +49,45 @@
                 DBG("waitSignal(\"DecoderImageOK\") begin");
 #endif
                 //绛夊緟淇″彿瑙﹀彂
+//                DBG("waitSignal before: " << p_this->m_chanPubID);
                 gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK");
+//                DBG("waitSignal: " << p_this->m_chanPubID);
 #ifdef TestCode
                 DBG("waitSignal(\"DecoderImageOK\") after");
 #endif
-                /****褰曞儚妯″潡浠g爜*****/
-                p_this->m_picCount++;
-                //鍑犲紶閫変竴寮犳斁鍏edis
-                if (p_this->m_picCount % m_nPicsPickOne != 0) {
-                    continue;
-                } else {
-                    p_this->m_picCount.store(0);
-                }
+
 
 //            浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖
                 p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image);
+                /****debug*****///todo
+                if (p_this->m_image.empty()) {
+                    ERR("camID:" << p_this->m_chanPubID);
+                    continue;
+                }
+//                else {
+//                    static int count =0;
+//                    count ++;
+//                    if(count > 100){
+//                        ERR("camID:" << p_this->m_chanPubID << " cols:" << p_this->m_image.cols <<\
+//        " rows:" << p_this->m_image.rows << " channels:" << p_this->m_image.channels());
+//                        count = 0;
+//                    }
+//                }
+
                 {
+                    /****褰曞儚妯″潡浠g爜*****/
+                    p_this->m_picCount++;
+                    //鍑犲紶閫変竴寮犳斁鍏edis
+                    if (p_this->m_picCount % m_nPicsPickOne != 0) {
+                        continue;
+                    } else {
+                        p_this->m_picCount.store(0);
+                    }
                     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->m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat);
                 }
-                /*********/
 
                 p_this->submit();
             }
@@ -119,7 +137,7 @@
                 usleep(1000000);
                 //闃诲绾跨▼锛岀瓑寰呭閮ㄨЕ鍙戝叧闂偣鎾�
                 while (p_this->m_running) {
-                    if(p_this->m_fFmpegDecoderJPG.getRunning()) {
+                    if (p_this->m_fFmpegDecoderJPG.getRunning()) {
                         usleep(300000);
                     } else {
 
@@ -128,6 +146,7 @@
                             p_this->m_running = false;
                             stop();
                             INFO("grabFrame faild, element stopping");
+                            break;
                         } else {
                             //todo 涓氬姟姝婚攣
                             usleep((6 - reopenTime--) * 1000000);
@@ -204,20 +223,20 @@
 
 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);
-//            return;
-//        }
-//    }
+    if (m_publishVideoRet) {
+        if (videoPublishElement == nullptr) {
+            string path = appConfig.getStringProperty("srsAddr") + "cam" + m_chanPubID + ".flv";
+            cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height"));
+            int gupIdx = appPref.getIntData("gpu.index");
+            videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx);
+        } else {
+            videoPublishElement->stop();
+            videoPublishElement->wait();
+            delete videoPublishElement;
+            videoPublishElement = nullptr;
+        }
+    }
+
     fireConnectors();
 }
 
@@ -270,3 +289,11 @@
 
     return t_FilePath;
 }
+
+void BASICGB28181::VideoCaptureElementWithRtp::startPublishVideo() {
+    m_publishVideoRet = true;
+}
+
+void BASICGB28181::VideoCaptureElementWithRtp::stopPublishVideo() {
+    m_publishVideoRet = false;
+}

--
Gitblit v1.8.0