From 6151028a8e0e63ed6967faa7c23ff56b076879df Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期五, 05 四月 2019 11:22:03 +0800
Subject: [PATCH] 解决GB28181推多路流问题

---
 QiaoJiaSystem/DataManagerServer/http_configserver.cpp            |   20 +++++-----
 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h   |    2 
 QiaoJiaSystem/VideoToImageMulth/RtspImageRedis.cpp               |    6 +-
 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp |   38 ++++++++++++++-----
 QiaoJiaSystem/StructureApp/FaceRpcElement.cpp                    |    4 +-
 QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp           |   18 ++++++++
 QiaoJiaSystem/StructureApp/FaceExtractElement.cpp                |    2 
 QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp            |    6 +-
 8 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index fbe4abb..59b9305 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -1137,11 +1137,11 @@
                                         std::string brand) const {
 
     if (brand == "haikang") {
-        bool ret = getHKDevSerialNumber(ip.c_str(), port, username.c_str(), passwd.c_str());
-        if (!ret) {
-            ERR("getHKDevSerialNumber ERR");
-            return false;
-        }
+//        bool ret = getHKDevSerialNumber(ip.c_str(), port, username.c_str(), passwd.c_str());
+//        if (!ret) {
+//            ERR("getHKDevSerialNumber ERR");
+//            return false;
+//        }
         //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
         port = 554;//TODO
 //        std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
@@ -1191,11 +1191,11 @@
         return false;//TODO
     } else if (brand == "yushi") {
 //        rtsp://admin:admin@192.168.8.8:554/video1
-        bool ret = getUVDevSerialNumber(ip.c_str(), username.c_str(), passwd.c_str());
-        if (!ret) {
-            ERR("getUVDevSerialNumber ERR");
-            return false;
-        }
+//        bool ret = getUVDevSerialNumber(ip.c_str(), username.c_str(), passwd.c_str());
+//        if (!ret) {
+//            ERR("getUVDevSerialNumber ERR");
+//            return false;
+//        }
 
         port = 554;
 //        std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
index af7f598..f1386f5 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
@@ -5,6 +5,7 @@
 #include <zconf.h>
 #include <opencv2/opencv.hpp>
 #include "FFmpegDecoderJPG.h"
+#include <cstring>
 
 void BASICGB28181::initFFmpeg() {
     av_register_all();
@@ -278,6 +279,20 @@
 
 //        BASICGB28181::avframe_to_cvmat(frame).copyTo(p_this->m_image);
             p_this->m_image = std::move(BASICGB28181::avframe_to_cvmat(p_this->frame));
+            if(p_this->m_image.empty()) {
+                ERR("camID:" << p_this->m_camIdx << " frameW:" << p_this->frame->width << "frame.data.len" << strlen(p_this->frame->data[0]));
+                continue;
+            }
+//            else {
+//                static int count =0;
+//                count ++;
+//                if(count > 100){
+//                    ERR("camID:" << p_this->m_camIdx << " cols:" << p_this->m_image.cols <<\
+//        " rows:" << p_this->m_image.rows << " channels:" << p_this->m_image.channels());
+//                    count = 0;
+//                }
+//
+//            }
 //            灏唅甯т繚瀛樹负蹇収
             if (p_this->m_SnapshotNotSaveRet && (p_this->pkt.flags & AV_PKT_FLAG_KEY)) {
                 try {
@@ -317,6 +332,7 @@
 #endif
             //瑙﹀彂涓婂眰淇″彿
             gSignalLock.emitSigal(p_this->m_camIdx + "DecoderImageOK");
+//            DBG("emitSigal: " << p_this->m_camIdx);
 //#ifdef TestCode
 //        DBG("emitSigal(\"DecoderImageOK\") after");
 //#endif
@@ -536,7 +552,7 @@
     m_frameIndex++;
     m_packetsVec.push_back({m_frameIndex, newPacket});
     if (newPacket.flags & AV_PKT_FLAG_KEY) {
-        DBG("newPacket.flags & AV_PKT_FLAG_KEY   ");
+//        DBG("newPacket.flags & AV_PKT_FLAG_KEY   ");
         m_last_I_FrameId = m_frameIndex;
     }
 }
diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 2f7010f..46e8089 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -48,28 +48,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();
             }
@@ -128,6 +145,7 @@
                             p_this->m_running = false;
                             stop();
                             INFO("grabFrame faild, element stopping");
+                            break;
                         } else {
                             //todo 涓氬姟姝婚攣
                             usleep((6 - reopenTime--) * 1000000);
diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
index f2915cc..c2b7ac8 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
@@ -68,7 +68,7 @@
 
         std::atomic<bool> m_running;
         std::atomic<bool> m_waitSignal;
-        std::atomic<bool> m_waitSignalrunning;
+        std::atomic<bool> m_waitSignalrunning{false};
 
         //鐢ㄦ潵淇濆瓨褰曞儚瑙嗛鐨勮矾寰�
         std::string m_cutPath;
diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
index f965ded..2cc1dd3 100644
--- a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
+++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
@@ -54,7 +54,7 @@
 void FaceExtractElement::submitFaceExtract(FaceToExtract faceToExtract) {
     std::lock_guard<std::mutex> lg(imageQueueMutex);
     if (faceExtractQueue.size() >= VECTOR_MAX) {
-        ERR("FaceExtractElement::submitFaceExtract too fast, imageQueue.size()>=QUEUE_MAX")
+        ERR("FaceExtractElement::submitFaceExtract too fast, imageQueue.size()>=QUEUE_MAX : " << faceExtractQueue.size())
         return;
     }
     faceExtractQueue.push_back(faceToExtract);
diff --git a/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp b/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
index 8ff149f..1a819d4 100644
--- a/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
+++ b/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
@@ -82,7 +82,7 @@
 }
 
 void FaceRpcElement::threadFunc() {
-    INFO("MYH Run Here");
+//    INFO("MYH Run Here");
 //    ClockTimer ct("FaceRpcElement::threadFunc");
 //    {
 //
@@ -135,7 +135,7 @@
                     CvUtil::zoomRectEqual(scoredRect.rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone());
                 triggerScoredRects.push_back(trackingTrigger->getLastRect());
             } else {
-                INFO("No Face Find: " << getProperty("imgKey"));
+                INFO("Face " << getProperty("imgKey") << " quality is too low: " << scoredRect.score);
 //                DBG("trackingTrigger->triggerOnce(scoredRect) is false  ");
             }
         }
diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
index 0943892..38a06c0 100644
--- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
+++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
@@ -193,7 +193,7 @@
         //    auto lst = m_lDBTool->searchCamDevTableAll();
         Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo();
         if (m_controllers.find(index) == m_controllers.end()) {
-            INFO("MYH DEBUG HERE");
+//            INFO("MYH DEBUG HERE");
             if (m_currentCount >= m_maxCount) {
                 ERR("addCamera faild, camera's num is full!")
                 return -1;
@@ -224,7 +224,7 @@
  * @return 鎬绘槸0
  */
 int RtspAnalysManager::removeCamera(const std::string &index) {
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
     if (m_GB28181_Enable) {
         if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end())return -1;
         auto controller = m_controllers_videoCapElem[index];
@@ -250,7 +250,7 @@
     delete imgRedis;
     m_imgRedisControllers.erase(index);
     m_imgRedisCRwLock.unlock();
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
     return 0;
 }
 
diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspImageRedis.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspImageRedis.cpp
index f93a9cf..37150c5 100644
--- a/QiaoJiaSystem/VideoToImageMulth/RtspImageRedis.cpp
+++ b/QiaoJiaSystem/VideoToImageMulth/RtspImageRedis.cpp
@@ -30,13 +30,13 @@
 //缁ф壙鑷埗绫�,绾跨▼鍒濆鍖栫殑涓�浜涘伐浣�
 void RtspImageRedisElement::threadInitial()
 {
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
 }
 
 //缁ф壙鑷埗绫�,绾跨▼缁撴潫鐨勬椂鍊欒皟鐢�
 void RtspImageRedisElement::threadClosing()
 {
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
 }
 
 //淇濆瓨鍥剧墖鍒伴槦鍒椾腑,
@@ -50,7 +50,7 @@
         m_imageQueue.push(NameImagePair_s_t(imageName,img));
     }
     else{
-        ERR("SaveImage Failed ImgName:"<<imageName);
+//        ERR("SaveImage Failed ImgName:"<<imageName);
     }
     return true;
 }

--
Gitblit v1.8.0