From a2673edc68a502f9a88ddf8e42f4aded9a8d94ef Mon Sep 17 00:00:00 2001
From: pansen <pansen626@sina.com>
Date: 星期二, 02 四月 2019 18:48:31 +0800
Subject: [PATCH] 修改信息结构

---
 QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 156 insertions(+), 19 deletions(-)

diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
index 9eee39c..ae0cd84 100644
--- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
+++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
@@ -7,14 +7,127 @@
 
 
 using std::string;
+void *gRtspAnalysManagerCamera = nullptr;
 
 RtspAnalysManager::RtspAnalysManager(LDBTool *_dbTool) : m_lDBTool(nullptr), m_maxCount(50), m_currentCount(0) {
-    INFO("MYH DEBUG HERE");
-    m_lDBTool = new LDBTool;
+//    INFO("MYH DEBUG HERE");
+    m_lDBTool = _dbTool;
     init();
+
+    //nsq   set callback func
+    DBG("NsqMsgConsumer Init");
+    nsqMsgConsumer = new BasicMsg::Nsq::NsqMsgConsumer("127.0.0.1", "4150", "cut_dura_edit",
+                                                       to_string(appPref.getIntData("RpcVTIMPort")));
+    nsqMsgConsumer->setMessageCallback(std::bind(&OnMsgFunc, std::placeholders::_1, this));
+    nsqMsgConsumer->init();
+    DBG("NsqMsgConsumer Init END!!");
 
 }
 
+void RtspAnalysManager::OnMsgFunc(void *msgPtr, void *pThisPtr) {
+    evnsq::Message *msg = (evnsq::Message *) msgPtr;
+    DBG("Received a message, id=" << msg->id << " message=[" << msg->body.ToString() << "]");
+    RtspAnalysManager *pthis = (RtspAnalysManager *) pThisPtr;
+    Json::Reader reader;
+    Json::Value value;
+    if (reader.parse(msg->body.ToString(), value)) {
+        auto itor_json_end = value.end();
+        Json::Value cfg_val;
+        for (auto itor_json = value.begin(); itor_json != itor_json_end; ++itor_json) {
+            if (itor_json->isString() && reader.parse(itor_json->asString(), cfg_val)) {
+                if (itor_json.name() == "cut_dura_edit") {
+                    int cut_max_duration = cfg_val["cut_max_duration"].asInt();
+                    int cut_min_duration = cfg_val["cut_min_duration"].asInt();
+                    DBG("cut_max_duration: " << cut_max_duration << "   cut_min_duration: " << cut_min_duration);
+                    appPref.setIntData("n_cut_max_duration", cut_max_duration);
+                    appPref.setIntData("n_cut_min_duration", cut_min_duration);
+
+                    DBG("cut_max_duration: " << cut_max_duration << "   cut_min_duration: " << cut_min_duration);
+//        m_GB28181_Enable = appPref.getIntData("GB28181_Enable");
+//*****************************#todo extract to func ************************************
+                    //#todo GB28181
+                    if (pthis->m_GB28181_Enable) {
+                        DBG("searchCamDevTableByType before");
+                        auto lst = pthis->m_lDBTool->searchCamDevTableByType(1);
+                        DBG("searchCamDevTableByType size:" << lst.size());
+                        if (lst.size() > 0) {
+                            int startCamNO = appPref.getIntData("CamStartNO");
+                            int CamCount = appPref.getIntData("CamEndNO") - appPref.getIntData("CamStartNO") + 1;
+                            INFO("StartCamNO: " << startCamNO << " CamCount: " << CamCount);
+                            auto itor = lst.begin();
+
+                            if (startCamNO >= lst.size()) {
+                                ERR("startCamNO > lst.size()");
+                                return;
+                            }
+
+                            for (int i = 0; i < startCamNO; i++) {
+                                itor++;
+                            }
+                            for (int i = 0; i < CamCount; i++) {
+                                if (itor == lst.end()) {
+                                    ERR("itor == lst.end()");
+                                    return;
+                                }
+                                std::string t_camIdex = itor->str_cam_dev_id.toStdString();
+                                DBG("-----camID:" << t_camIdex << "min:" << cut_min_duration << "max:"
+                                                  << cut_max_duration);
+                                pthis->m_controllers_videoCapElem[t_camIdex]->SetVideoMinMaxSeconds(cut_min_duration,
+                                                                                                    cut_max_duration);
+                                itor++;
+                            }
+                        } else {
+                            ERR("searchCamDevTableByType size is 0");
+                        }
+                    } else {
+                        auto lst = pthis->m_lDBTool->searchCamDevTableByType(0);
+                        if (lst.size() > 0) {
+                            int startCamNO = appPref.getIntData("CamStartNO");
+                            int CamCount = appPref.getIntData("CamEndNO") - appPref.getIntData("CamStartNO") + 1;
+                            INFO("StartCamNO: " << startCamNO << " CamCount: " << CamCount);
+                            auto itor = lst.begin();
+
+                            if (startCamNO >= lst.size()) {
+                                ERR("startCamNO > lst.size()");
+                                return;
+                            }
+
+                            for (int i = 0; i < startCamNO; i++) {
+                                itor++;
+                            }
+
+                            for (int i = 0; i < CamCount; i++) {
+                                if (itor == lst.end()) {
+                                    ERR("itor == lst.end()");
+                                    return;
+                                }
+                                std::string t_camIdex = itor->str_cam_dev_id.toStdString();
+                                DBG("-----camID:" << t_camIdex << "min:" << cut_min_duration << "max:"
+                                                  << cut_max_duration);
+                                pthis->m_controllers[t_camIdex]->SetVideoMinMaxSeconds(cut_min_duration,
+                                                                                       cut_max_duration);
+                                itor++;
+                            }
+
+                        } else {
+                            ERR("searchCamDevTableByType size is 0");
+                        }
+                    }
+//***************************************************************************************
+                }
+
+            } else {
+
+                DBG("itor value is not string ");
+                continue;
+            }
+        }
+
+
+    } else {
+        ERR("Error Message!!");
+    }
+}
 
 static std::string rtspAddrBuild(std::string ip, const int port, std::string username,
                                  std::string passwd, std::string brand) {
@@ -39,7 +152,10 @@
 
 //鍒濆鍖栧嚱鏁�
 void RtspAnalysManager::init() {
-    INFO("MYH DEBUG HERE")
+//    INFO("MYH DEBUG HERE")
+
+    gRtspAnalysManagerCamera = this;
+    DBG("gRtspAnalysManagerCamera ADDR:" << gRtspAnalysManagerCamera);
 
     m_GB28181_Enable = appPref.getIntData("GB28181_Enable");
     //#todo GB28181
@@ -51,16 +167,36 @@
         appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration);
         appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration);
         if (lst.size() > 0) {
-            for (auto item : lst) {
-                std::string t_camIdex = item.str_cam_dev_id.toStdString();
+            int startCamNO = appPref.getIntData("CamStartNO");
+            int CamCount = appPref.getIntData("CamEndNO") - appPref.getIntData("CamStartNO") + 1;
+            INFO("StartCamNO: " << startCamNO << " CamCount: " << CamCount);
+            auto itor = lst.begin();
+
+            if (startCamNO >= lst.size()) {
+                ERR("startCamNO > lst.size()");
+                return;
+            }
+
+            for (int i = 0; i < startCamNO; i++) {
+                itor++;
+            }
+
+            for (int i = 0; i < CamCount; i++) {
+                if (itor == lst.end()) {
+                    ERR("itor == lst.end()");
+                    return;
+                }
+                std::string t_camIdex = itor->str_cam_dev_id.toStdString();
                 std::string rtsp_url = "GB28181";
-//            rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(),
-//                                                 item.str_password.toStdString(), item.str_brand.toStdString());
-                INFO("cam add is " << item.str_addr.toStdString());
+
+                INFO("cam add is " << itor->str_addr.toStdString());
+
                 addCamera(t_camIdex, rtsp_url);
+                sleep(1);
+                itor++;
             }
         } else {
-            ERR("searchCamDevTableAll size is 0");
+            ERR("searchCamDevTableByType size is 0");
         }
 
     } else {
@@ -115,7 +251,7 @@
 //
 //        }
         } else {
-            ERR("searchCamDevTableAll size is 0");
+            ERR("searchCamDevTableByType size is 0");
         }
     }
 }
@@ -152,7 +288,7 @@
 
         //#todo end
         if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end()) {
-            INFO("MYH DEBUG HERE");
+//            INFO("MYH DEBUG HERE");
             if (m_currentCount >= m_maxCount) {
                 ERR("addCamera faild, camera's num is full!")
                 return -1;
@@ -170,7 +306,8 @@
 //                25, 0, 0, this);
 
             m_controllers_videoCapElem[index] = new PushStreamAppPipeController(const_cast<string &>(index),
-                                                                                25, 0, 0, this);
+                                                                                25, 0, appPref.getIntData("gpu.index"),
+                                                                                this);
             m_controllers_videoCapElem[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration,
                                                                      lst_dev.n_cut_max_duration);
             m_controllers_videoCapElem[index]->start();
@@ -197,7 +334,7 @@
             m_imgRedisControllers[index] = new RtspImageRedisElement(index);
             m_imgRedisControllers[index]->start();
 
-            m_controllers[index] = new RtspCaptureElement(rtsp, index, 25, 3000, 0, this);
+            m_controllers[index] = new RtspCaptureElement(rtsp, index, 25, 3000, appPref.getIntData("gpu.index"), this);
             m_controllers[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration);
             m_controllers[index]->start();
             m_currentCount++;
@@ -254,7 +391,7 @@
  * @return
  */
 int RtspAnalysManager::removeAll() {
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
 
     if (m_GB28181_Enable) {
         for (auto controller: m_controllers_videoCapElem) {
@@ -275,7 +412,7 @@
         }
         m_controllers.clear();
     }
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
 
     m_imgRedisCRwLock.wrlock();
     for (auto controller: m_imgRedisControllers) {
@@ -290,7 +427,7 @@
 
 
     m_currentCount = 0;
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
     return 0;
 }
 
@@ -333,18 +470,18 @@
 
 //淇濆瓨瑙嗛鍒癛tspImageRedis鐨勯槦鍒�,鐢盧tspCaptureElement璋冪敤
 bool RtspAnalysManager::SaveImageToRedis(const std::string &camId, const std::string &imageName, const cv::Mat &img) {
-    INFO("MYH DEBUG HERE  " << camId);
+//    INFO("MYH DEBUG HERE  " << camId);
 
 //    m_imgRedisCRwLock.rdlock();
     auto item = m_imgRedisControllers.find(camId);
     if (item != m_imgRedisControllers.end()) {
-        INFO("Save Succeed Cam: " << camId << " ImageKey: " << imageName);
+//        INFO("Save Succeed Cam: " << camId << " ImageKey: " << imageName);
         item->second->SaveImage(imageName, img);
     } else {
         ERR("Save Failed Cam: " << camId << " ImageKey: " << imageName);
     }
 //    m_imgRedisCRwLock.unlock();
-    INFO("MYH DEBUG HERE");
+//    INFO("MYH DEBUG HERE");
     return true;
 }
 

--
Gitblit v1.8.0