From ed223aee5fe5f3b222488549597976f34c679c3d Mon Sep 17 00:00:00 2001
From: pansen <pansen626@sina.com>
Date: 星期二, 05 三月 2019 14:00:47 +0800
Subject: [PATCH] 代码格式化及部分bug修改

---
 QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp |  183 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 148 insertions(+), 35 deletions(-)

diff --git a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp
index 828dc70..efb8645 100644
--- a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp
+++ b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp
@@ -10,24 +10,24 @@
 
 //RtspAnalysElement::RtspAnalysElement() {}
 
-std::string RtspAnalysElement::resetFdfs(std::string ip, unsigned int port, std::string content) {
-
-    std::thread reset([&]() {
-        fdfsClient.rwLock.rdlock();
-        if (fdfsClient.fastFds != nullptr) {
-            delete fdfsClient.fastFds;
-        }
-        fdfsClient.fastFds = new FastFds("fastDfsClient.conf");
-        fdfsClient.rwLock.unlock();
-    });
-    reset.detach();
-
-    return "";
-}
+//std::string RtspAnalysElement::resetFdfs(std::string ip, unsigned int port, std::string content) {
+//
+//    std::thread reset([&]() {
+//        fdfsClient.rwLock.rdlock();
+//        if (fdfsClient.fastFds != nullptr) {
+//            delete fdfsClient.fastFds;
+//        }
+//        fdfsClient.fastFds = new FastFds("fastDfsClient.conf");
+//        fdfsClient.rwLock.unlock();
+//    });
+//    reset.detach();
+//
+//    return "";
+//}
 
 RtspAnalysElement::RtspAnalysElement(LDBTool *_dbTool) : m_lDBTool(_dbTool), maxCount(50), currentCount(0) {
     init();
-    resetFdfs();
+//    resetFdfs();
     {
 //        std::thread httpServer([&]() {
 //            //#todo port
@@ -68,43 +68,155 @@
 }
 
 void RtspAnalysElement::init() {
-    auto lst = m_lDBTool->searchCamDevTableAll();
     Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo();
+#ifndef GB28181
+    auto lst = m_lDBTool->searchCamDevTableAll();
 
     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) {
         Json::Value json;
-        for (auto item : lst) {
-            std::string t_camIdex = item.str_cam_dev_id.toStdString();
-            std::string rtsp_url = rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(),
-                                                 item.str_password.toStdString(), item.str_brand.toStdString());
-            SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id);
+        int startCamNO = appPref.getIntData("CamStart") * appPref.getIntData("CamStep");
+        int CamCount = appPref.getIntData("CamStep");
+        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 = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(),
+                                                 itor->str_password.toStdString(), itor->str_brand.toStdString());
+            SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(itor->str_cam_dev_id);
             for (auto &rule:ruleMap) {
 
-                rule.second.strAddr = item.str_addr;
-                rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first);
+                rule.second.strAddr = itor->str_addr;
+                rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(itor->str_cam_dev_id, rule.first);
 
-                if(rule.second.nSdkType == FaceSdk) continue;
+                if (rule.second.nSdkType == PerStaticSdk) {
+                    float temp = 1 - (float) (rule.second.nThreshold) / 100;
+                    rule.second.fSensitivity = (75 + 25 * temp) / 100;
 
-                if (rule.second.nThreshold < 5 )
-                {
-                    rule.second.fSensitivity=0.95;
+                } else if (rule.second.nSdkType != FaceSdk) {
+                    float temp = 1 - (float) (rule.second.nThreshold) / 100;
+                    rule.second.fSensitivity = (5 + 90 * temp) / 100;
                 }
-                else if(rule.second.nThreshold > 95)
-                {
-                     rule.second.fSensitivity=0.05;
-                }
-                else
-                {
-                    rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100;
-                }
+//                if (rule.second.nThreshold < 5 )
+//                {
+//                    rule.second.fSensitivity=0.95;
+//                }
+//                else if(rule.second.nThreshold > 95)
+//                {
+//                     rule.second.fSensitivity=0.05;
+//                }
+//                else
+//                {
+//                    rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100;
+//                }
 
                 DBG("fSensitivity" << rule.second.fSensitivity);
             }
             appPref.setStringData(t_camIdex + "rtsp", rtsp_url);
             // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString());
             json["rtsp"] = rtsp_url;
+            // json["addr"] = item.str_addr.toStdString();
+
+            INFO("cam add is " << itor->str_addr.toStdString());
+
+            addCamera(t_camIdex, ruleMap);
+            itor++;
+        }
+//        for (auto item : lst) {
+//            std::string t_camIdex = item.str_cam_dev_id.toStdString();
+//            std::string rtsp_url = rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(),
+//                                                 item.str_password.toStdString(), item.str_brand.toStdString());
+//            SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id);
+//            for (auto &rule:ruleMap) {
+//
+//                rule.second.strAddr = item.str_addr;
+//                rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first);
+//
+//                if(rule.second.nSdkType == PerStaticSdk)
+//                {
+//                    float temp=1-(float)(rule.second.nThreshold)/100;
+//                    rule.second.fSensitivity=(75+25*temp)/100;
+//
+//                }
+//                else if(rule.second.nSdkType != FaceSdk)
+//                {
+//                    float temp=1-(float)(rule.second.nThreshold)/100;
+//                     rule.second.fSensitivity=(5+90*temp)/100;
+//                }
+////                if (rule.second.nThreshold < 5 )
+////                {
+////                    rule.second.fSensitivity=0.95;
+////                }
+////                else if(rule.second.nThreshold > 95)
+////                {
+////                     rule.second.fSensitivity=0.05;
+////                }
+////                else
+////                {
+////                    rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100;
+////                }
+//
+//                DBG("fSensitivity" << rule.second.fSensitivity);
+//            }
+//            appPref.setStringData(t_camIdex + "rtsp", rtsp_url);
+//            // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString());
+//            json["rtsp"] = rtsp_url;
+//            // json["addr"] = item.str_addr.toStdString();
+//
+//            INFO("cam add is " << item.str_addr.toStdString());
+//
+//            addCamera(t_camIdex, ruleMap);
+//        }
+    } else {
+        ERR("searchCamDevTableAll size is 0");
+    }
+
+#else
+    auto lst = m_lDBTool->searchCamDevTableByType(1);
+
+    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) {
+//        Json::Value json;
+
+        for (auto &item : lst) {
+            std::string t_camIdex = item.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());
+            SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id);
+            for (auto &rule:ruleMap) {
+
+                rule.second.strAddr = item.str_addr;
+                rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first);
+
+                if (rule.second.nSdkType == PerStaticSdk) {
+                    float temp = 1 - (float) (rule.second.nThreshold) / 100;
+                    rule.second.fSensitivity = (75 + 25 * temp) / 100;
+
+                } else if (rule.second.nSdkType != FaceSdk) {
+                    float temp = 1 - (float) (rule.second.nThreshold) / 100;
+                    rule.second.fSensitivity = (5 + 90 * temp) / 100;
+                }
+                DBG("fSensitivity" << rule.second.fSensitivity);
+            }
+            appPref.setStringData(t_camIdex + "rtsp", rtsp_url);
+            // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString());
+//            json["rtsp"] = rtsp_url;
             // json["addr"] = item.str_addr.toStdString();
 
             INFO("cam add is " << item.str_addr.toStdString());
@@ -115,6 +227,7 @@
         ERR("searchCamDevTableAll size is 0");
     }
 
+#endif
 }
 
 RtspAnalysElement::~RtspAnalysElement() {

--
Gitblit v1.8.0