From 6540a2a9d69432c4cc475e3b32eae11e9e0ace73 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期四, 11 四月 2019 20:28:10 +0800
Subject: [PATCH] 1.srs的分辨率在config.json配置 2.单播推流控制,国标摄像机差一个关闭测试 3. 底库字段添加

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

diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 2f7010f..40b3a8c 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) {
@@ -52,6 +53,36 @@
 #ifdef TestCode
                 DBG("waitSignal(\"DecoderImageOK\") after");
 #endif
+                {
+                    if (p_this->m_publishVideoRet) {
+                        if (p_this->videoPublishElement == nullptr) {
+                            string path = appConfig.getStringProperty("srsAddr") + "cam" + p_this->m_chanPubID + ".flv";
+                            cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height"));
+                            int gupIdx = appPref.getIntData("gpu.index");
+                            DBG("videoPublishpath: "  << p_this->m_chanPubID << path << " h:" << size_.height);
+                            p_this->videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx);
+                            p_this->videoPublishElement->start();
+                        } else {
+                            DBG("videoPublishElement->setImage() : " << p_this->m_chanPubID);
+                            if (!p_this->m_image.empty()) {
+                                p_this->videoPublishElement->setImage(p_this->m_image);
+                            } else {
+                                ERR("m_image.empty()");
+                            }
+                        }
+                    } else {
+                        if (p_this->videoPublishElement != nullptr) {
+                            DBG("videoPublishElement->stop() :"  << p_this->m_chanPubID);
+                            p_this->videoPublishElement->stop();
+                            p_this->videoPublishElement->wait();
+                            delete p_this->videoPublishElement;
+                            p_this->videoPublishElement = nullptr;
+                        }else{
+                            DBG("videoPublishElement null :" << p_this->m_chanPubID);
+                        }
+                    }
+                }
+
                 /****褰曞儚妯″潡浠g爜*****/
                 p_this->m_picCount++;
                 //鍑犲紶閫変竴寮犳斁鍏edis
@@ -119,7 +150,7 @@
                 usleep(1000000);
                 //闃诲绾跨▼锛岀瓑寰呭閮ㄨЕ鍙戝叧闂偣鎾�
                 while (p_this->m_running) {
-                    if(p_this->m_fFmpegDecoderJPG.getRunning()) {
+                    if (p_this->m_fFmpegDecoderJPG.getRunning()) {
                         usleep(300000);
                     } else {
 
@@ -203,21 +234,33 @@
 }
 
 void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() {
-
-//    if ((!m_running) || (!m_waitSignal)) {
-////        鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚�
-//        if (reopenTime < 0) {
-//            stop();
-//            INFO("grabFrame faild, element stopping");
-//            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");
+//                DBG("videoPublishpath:" << path << " h:" << size_.height << " w:" << size_.width);
+//                videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx);
+//                videoPublishElement->start();
+//            } else {
+//                if (!m_image.empty()) {
+//                    videoPublishElement->setImage(m_image);
+//                } else {
+//                    ERR("m_image.empty()");
+//                }
+//            }
 //        } else {
-//            //todo 涓氬姟姝婚攣
-//            usleep(reopenTime * 1000);
-//            INFO("grabFrame faild, try reopen video: ");
-//            startRtpStream(m_streamTransType);
-//            return;
+//            if (videoPublishElement != nullptr) {
+//                DBG("videoPublishElement->stop()");
+//                videoPublishElement->stop();
+//                videoPublishElement->wait();
+//                delete videoPublishElement;
+//                videoPublishElement = nullptr;
+//            }
 //        }
 //    }
+
     fireConnectors();
 }
 
@@ -270,3 +313,11 @@
 
     return t_FilePath;
 }
+
+void BASICGB28181::VideoCaptureElementWithRtp::startPublishVideo() {
+    m_publishVideoRet = true;
+}
+
+void BASICGB28181::VideoCaptureElementWithRtp::stopPublishVideo() {
+    m_publishVideoRet = false;
+}

--
Gitblit v1.8.0