From a2ea58c567a078bb97a9e45a56fe50df41438d22 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期一, 15 四月 2019 10:37:31 +0800
Subject: [PATCH] 整合c++ver1.3的修改代码进入该分支

---
 QiaoJiaSystem/DataManagerServer/http_configserver.cpp |  192 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 137 insertions(+), 55 deletions(-)

diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index 3e580ce..52adf80 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -22,6 +22,7 @@
 #include <time.h>
 #include <dirent.h>
 #include "basic/pipe_element/ffmpeg/basic_struct_for_video_image.h"
+#include <basic/timer_counter/Clocktimer.h>
 
 #include "vss/controller/VssDevTblController.h"
 #include "vss/controller/VssChannelTblController.h"
@@ -73,6 +74,10 @@
 void devHttpServer_c::init(void) {
 
     std::string strDevId = appConfig.getStringProperty("DEV_ID");
+
+    //nsq
+    nsqMsgProducer = new BasicMsg::Nsq::NsqMsgProducer("127.0.0.1", "4150");
+    nsqMsgProducer->init();
 
 //    DSVAD010120181119
     m_batch = strDevId.substr(5, 2);
@@ -1114,6 +1119,17 @@
 
     if (DEV_NO_TYPE == dev_type) {//add new camera
         db_c.updateConfigTableByDevType(DEV_CAMERA);
+        {
+            //#todo
+//            std::string topic = "VideoToImageMulth";
+//            std::string topic1 = "VideoAnalysFromHC";
+//            Json::Value json_cfg;
+//            json_cfg["cam_edit"] = content;
+//            std::string msg = json_cfg.toStyledString();
+//            DBG("msg:" << msg);
+//            nsqMsgProducer->Publish(topic, (void *) (&msg));
+//            nsqMsgProducer->Publish(topic1, (void *) (&msg));
+        }
         runAllApp();
     }
         //edit camera's sdks
@@ -1121,9 +1137,20 @@
              (rec_sdk_old.str_det_thr != rec_sdk.str_det_thr) ||
              (rec_sdk_old.str_cmp_thr != rec_sdk.str_cmp_thr)) */
     {
-        killVideoAnalysFromHCApp();
-        sleep(1);
-        runAllApp();
+        //#todo sendMessage To haikang&VideoToImage
+        {
+            std::string topic = "VideoToImageMulth";
+            std::string topic1 = "VideoAnalysFromHC";
+            Json::Value json_cfg;
+            json_cfg["cam_edit"] = content;
+            std::string msg = json_cfg.toStyledString();
+            DBG("msg:" << msg);
+            nsqMsgProducer->Publish(topic, (void *) (&msg));
+            nsqMsgProducer->Publish(topic1, (void *) (&msg));
+        }
+//        killVideoAnalysFromHCApp();
+//        sleep(1);
+//        runAllApp();
     }
 
     Json::Value value_out;
@@ -1137,11 +1164,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) +
@@ -1167,8 +1194,8 @@
         std::string publish_basepath = rtmpAddr + "cam" + str_uuid;
         DBG("publish_basepath:" << publish_basepath);
         appPref.setStringData("publish.basepath", publish_basepath);
-        appPref.setIntData("pulish.width", 640);
-        appPref.setIntData("pulish.height", 360);
+//        appPref.setIntData("pulish.width", 1920);
+//        appPref.setIntData("pulish.height", 1080);
 
         if (m_rtmp.find(ip) != m_rtmp.end()) {
             if (m_rtmp[ip].appPC == nullptr) {
@@ -1191,11 +1218,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) +
@@ -1220,8 +1247,8 @@
         std::string publish_basepath = rtmpAddr + "cam" + str_uuid;
         DBG("publish_basepath:" << publish_basepath);
         appPref.setStringData("publish.basepath", publish_basepath);
-        appPref.setIntData("pulish.width", 640);
-        appPref.setIntData("pulish.height", 360);
+//        appPref.setIntData("pulish.width", 1920);
+//        appPref.setIntData("pulish.height", 1080);
 
         if (m_rtmp.find(ip) != m_rtmp.end()) {
             if (m_rtmp[ip].appPC == nullptr) {
@@ -1267,6 +1294,7 @@
             if (m_rtmp[ip].userCounter == 0) {
                 m_rtmp[ip].appPC->stop();
                 m_rtmp[ip].appPC->wait();
+                delete m_rtmp[ip].appPC;
                 m_rtmp.erase(ip);
             }
         }
@@ -1291,28 +1319,41 @@
     }
     Json::Value value;
     if (value_reader.isMember("id")) {
-        if (value_reader["id"].isNull()) return "{\"ret_status\": \"id鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
-        value["connect_status"] = "True";
-        std::string rtmp_url = appConfig.getStringProperty("srsAddr");
-        rtmp_url.append("cam").append(value_reader["id"].asCString());
-        value["video_url"] = rtmp_url;
-        out = value.toStyledString();
-
-    } else {
-        //TODO
-        //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
+        if (value_reader["id"].isNull()) {
+            //鏈湴瑙嗛婧� 绗竴娆℃祴璇曡繛鎺�
+            //TODO
+            //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
 //    std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":"  + std::to_string(port) + "/h264/ch1/main/av_stream";
-        bool ret = cam_connect_video_start(value_reader["str_ip"].asString(), value_reader["n_port"].asInt(), \
+            bool ret = cam_connect_video_start(value_reader["str_ip"].asString(), value_reader["n_port"].asInt(), \
                             value_reader["str_username"].asString(), value_reader["str_password"].asString(), \
                             value_reader["str_brand"].asString());
-        if (!ret) {
+            if (!ret) {
+                return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+            }
+            std::string rtmp_url = m_rtmp[value_reader["str_ip"].asCString()].appPC->getRtmp();
+            value["connect_status"] = "True";
+            value["video_url"] = rtmp_url;
+            out = value.toStyledString();
+        } else if (!value_reader["type"].isNull()) {
+
+            value["connect_status"] = "True";
+            std::string rtmp_url = appConfig.getStringProperty("srsAddr");
+            rtmp_url.append("cam").append(value_reader["id"].asCString());
+            value["video_url"] = rtmp_url;
+            out = value.toStyledString();
+            {
+                std::string topic = "VideoToImageMulth";
+                Json::Value json_cfg;
+                json_cfg["cam_startPublish"] = content;
+                std::string msg = json_cfg.toStyledString();
+                DBG("msg:" << msg);
+                nsqMsgProducer->Publish(topic, (void *) (&msg));
+            }
+        } else {
             return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
         }
-
-        std::string rtmp_url = m_rtmp[value_reader["str_ip"].asCString()].appPC->getRtmp();
-        value["connect_status"] = "True";
-        value["video_url"] = rtmp_url;
-        out = value.toStyledString();
+    } else {
+        return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
     }
 
     return out;
@@ -1330,19 +1371,32 @@
     if (!reader.parse(content, value_reader)) {
         return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
     }
-
-    //TODO
-    //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
-//    std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":"  + std::to_string(port) + "/h264/ch1/main/av_stream";
-    DBG("cam_connect_video_stop begin");
-    bool ret = cam_connect_video_stop(value_reader["str_ip"].asString());
-    if (!ret) {
-        return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
-    }
-    DBG("cam_connect_video_stop end");
-
     Json::Value value;
-    value["ret_status"] = "ok_ack";
+    if (value_reader.isMember("id")) {
+        value["ret_status"] = "ok_ack";
+        cam_connect_video_stop(value_reader["str_ip"].asString());
+        {
+            std::string topic = "VideoToImageMulth";
+            Json::Value json_cfg;
+            json_cfg["cam_stopPublish"] = content;
+            std::string msg = json_cfg.toStyledString();
+            DBG("msg:" << msg);
+            nsqMsgProducer->Publish(topic, (void *) (&msg));
+        }
+    } else {
+        //TODO
+        //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
+//    std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":"  + std::to_string(port) + "/h264/ch1/main/av_stream";
+        DBG("cam_connect_video_stop begin");
+        bool ret = cam_connect_video_stop(value_reader["str_ip"].asString());
+        if (!ret) {
+            return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+        }
+        DBG("cam_connect_video_stop end");
+
+        value["ret_status"] = "ok_ack";
+    }
+
 
     std::string out = value.toStyledString();
 
@@ -1403,12 +1457,22 @@
         QString cam_id = QString::fromStdString(value_reader["str_cam_dev_id"].asString());
         int ret = db_c.deleteCamDevandSdkByCamID(cam_id);
         if (ret) {
-            killVideoAnalysFromHCApp();
+//            killVideoAnalysFromHCApp();
             int dev_record = db_c.searchCamDevNumber();
             if (dev_record == 0) {
                 db_c.updateConfigTableByDevType(DEV_NO_TYPE);
             } else {
-                runAllApp();
+//                runAllApp();
+            }
+            {
+                std::string topic = "VideoToImageMulth";
+                std::string topic1 = "VideoAnalysFromHC";
+                Json::Value json_cfg;
+                json_cfg["cam_del"] = content;
+                std::string msg = json_cfg.toStyledString();
+                DBG("msg:" << msg);
+                nsqMsgProducer->Publish(topic, (void *) (&msg));
+                nsqMsgProducer->Publish(topic1, (void *) (&msg));
             }
             return "{\"ret_status\": \"ok_ack\"}";
         } else {
@@ -1529,9 +1593,15 @@
     }
 
     if (ret) {
-        killVideoAnalysFromHCApp();
-        sleep(1);
-        runAllApp();
+        //todo VideoToImageMulth
+        {
+            std::string topic = "VideoToImageMulth";
+            Json::Value json_cfg;
+            json_cfg["cut_dura_edit"] = content;
+            std::string msg = json_cfg.toStyledString();
+            DBG("msg:" << msg);
+            nsqMsgProducer->Publish(topic, (void *) (&msg));
+        }
         return "{\"ret_status\": \"ok_ack\"}";
     } else {
         return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
@@ -2671,6 +2741,7 @@
             std::string strSelectTemplate = R"#( -vf "select=eq(n\,%d)")#";
             sprintf(selectExpBuff, strSelectTemplate.c_str(), frameIdDiff - 1);
             if (videoSt.Valid() && imgSt.Valid()) {
+                ClockTimer clockTimer1("ffmpeg getpic");
                 std::string cmd("ffmpeg -i '" + videoPath + "'" + std::string(selectExpBuff) + " -vframes 1" + " -y '" +
                                 str_imgName + "'");
                 INFO("Video To Image Cmd: " << cmd);
@@ -2680,17 +2751,20 @@
                 return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
             }
 
+            ClockTimer clockTimer2("cv::imread(str_imgName)");
             cv::Mat img = cv::imread(str_imgName);
             if (img.empty()) {
                 ERR("{\"error\":\"Video File error\"}");
                 return "{\"error\":\"瑙嗛鏂囦欢閿欒\"}";
             }
 
+            ClockTimer clockTimer3("CvUtil::cvMat2Buffer(img, buffer)");
             std::vector<unsigned char> buffer;
             CvUtil::cvMat2Buffer(img, buffer);
             std::string img_url = "http://";
             fdfsClient.rwLock.rdlock();
             if (fdfsClient.fastFds != nullptr) {
+                ClockTimer clockTimer4("fdfsClient.fastFds->uploadFile");
                 std::string t_strImg = "";
                 if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
                     img_url = "upload image fail";
@@ -3262,11 +3336,19 @@
         if (db_c.updateSdkRule(rule)) {
 //            if(rule.nIsRun==1)
 
-            killVideoAnalysFromHCApp();
-            sleep(1);
-            runAllApp();
+//            killVideoAnalysFromHCApp();
+//            sleep(1);
+//            runAllApp();
 
-
+            {
+                std::string topic = "VideoAnalysFromHC";
+                Json::Value json_cfg;
+                json_cfg["editSdkRule"] = content;
+                std::string msg = json_cfg.toStyledString();
+                DBG("msg:" << msg);
+                usleep(1000);
+                nsqMsgProducer->Publish(topic, (void *) (&msg));
+            }
             return "{\"ret_status\": \"ok_ack\"}";
         } else {
             return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";

--
Gitblit v1.8.0