From 080afae264fe7ff89a54886f28dff208fe5a06c4 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期二, 16 四月 2019 22:01:35 +0800
Subject: [PATCH] 整合代码
---
QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 796 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 628 insertions(+), 168 deletions(-)
diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index bc399be..4e61e33 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -21,6 +21,15 @@
//#include "HcRecord.h"
#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"
+#include "vss/controller/VssDomainUnitTblController.h"
+#include "vss/controller/VssLocalSettingTblController.h"
+#include "vss/controller/VssUpperSvrTblController.h"
+#include "vss/controller/CamDevController.h"
using namespace std;
@@ -65,10 +74,16 @@
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);
m_SerialNumber = strDevId.substr(7, 2);
+ DBG("DevID: " << strDevId << " Batch: " << m_batch << " SerNum: " << m_SerialNumber);
fdfsClient.rwLock.wrlock();
fdfsClient.fastFds = new FastFds("WebFDSClient.conf");
@@ -240,6 +255,18 @@
std::placeholders::_3, std::placeholders::_4));
+ BaseDao::initConnection();
+ BaseSqliteDao::setLDBTool(&db_c);
+ VssDevTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+ VssChannelTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+ VssDomainUnitTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+ VssLocalSettingTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+ CamDevController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+ //todo
+ CamDevController::instance()->nsqMsgProducerSet(nsqMsgProducer);
+ VssUpperSvrTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
+
+
_HttpSrvRetRecieve.start();
_HttpSrvRetRecieve.waitForShutDown();
}
@@ -272,10 +299,10 @@
elem["n_duration"] = iter->n_duration;
elem["str_brand"] = iter->str_brand.toStdString();
elem["str_reserved"] = iter->str_reserved.toStdString();
- cout << elem.toStyledString() << endl;
+ DBG(elem.toStyledString());
value.append(elem);
}
- cout << value.toStyledString() << endl;
+ DBG(value.toStyledString());
// std::string out = value.toStyledString();
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
@@ -395,6 +422,7 @@
/*sdk login*/
ulRet = IMOS_MW_Login(username, passwd, ip, 0, szUserID);
if (ERR_COMMON_SUCCEED != ulRet) {
+ (VOID) IMOS_MW_Cleanup();
printf("Login error ulRet[%lu]", ulRet);
return false;
}
@@ -402,6 +430,8 @@
pstBasicInfo = (IMOS_MW_BASIC_DEVICE_INFO_S *) malloc(sizeof(IMOS_MW_BASIC_DEVICE_INFO_S));
ulRet = IMOS_MW_GetDeviceStatus(szUserID, 0, IMOS_MW_STATUS_BASIC_INFO, (void *) pstBasicInfo);
if (ERR_COMMON_SUCCEED != ulRet) {
+ (VOID) IMOS_MW_Logout(szUserID);
+ (VOID) IMOS_MW_Cleanup();
printf("GetDeviceStatus Error[%lu]\n", ulRet);
return false;
}
@@ -673,7 +703,7 @@
}
dev_rec.str_storage_dev_id = QString::fromLatin1((const char *) serialnumber);//鑾峰彇纾佺洏闃靛垪鐨勮澶噄d
- std::cout << dev_rec.str_storage_dev_id.toStdString() << std::endl;
+ DBG(dev_rec.str_storage_dev_id.toStdString());
ret = db_c.updateDeviceTable(dev_rec);
} else {
return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
@@ -720,7 +750,7 @@
std::string str_result;
std::string str_tmp;
for (int i = 0; i < lvecUsefulChans.size(); i++) {
- std::cout << lvecUsefulChans.at(i) << std::endl;
+ DBG(lvecUsefulChans.at(i));
str_tmp = std::to_string(lvecUsefulChans.at(i));
str_result += str_tmp;
str_result += ",";
@@ -865,17 +895,17 @@
}
}
- cout << elem.toStyledString() << endl;
+ DBG(elem.toStyledString());
value.append(elem);
}
for (std::vector<int>::iterator it1 = chns.begin(); it1 != chns.end(); it1++) {
chn_unused["n_chn"] = *it1;
- cout << "*it1" << *it1 << endl;
+ DBG("*it1" << *it1);
value.append(chn_unused);
}
- cout << value.toStyledString() << endl;
+ DBG(value.toStyledString());
// std::string out = value.toStyledString();
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
return out;
@@ -946,8 +976,10 @@
void devHttpServer_c::killVideoAnalysFromHCApp() const {
string local_passwd = appConfig.getStringProperty("localPasswd");
- string cmd_kill = "echo \"" + local_passwd + "\" | sudo -S pkill -9 VideoAnalysFrom";
- system(cmd_kill.c_str());
+ string cmd_kill_VideoAnalys = "echo \"" + local_passwd + "\" | sudo -S pkill -9 VideoAnalys";
+ system(cmd_kill_VideoAnalys.c_str());
+ string cmd_kill_VideoToIma = "echo \"" + local_passwd + "\" | sudo -S pkill -9 VideoToIma";
+ system(cmd_kill_VideoToIma.c_str());
DBG("system(\"sudo -S pkill -9 VideoAnalysFromHC\");");
}
@@ -978,27 +1010,42 @@
elem["str_latitude"] = iter->str_latitude.toStdString();
elem["str_ip"] = iter->str_ip.toStdString();
elem["n_port"] = iter->n_port;
+ elem["type"] = iter->type;
elem["str_username"] = iter->str_username.toStdString();
elem["str_password"] = iter->str_password.toStdString();
elem["str_brand"] = iter->str_brand.toStdString();
elem["str_reserved"] = iter->str_reserved.toStdString();
+ SdkRuleMap ruleMap = db_c.searchSdkRuleByCamId(iter->str_cam_dev_id);
+
+ int count = ruleMap.size();
+ elem["nSdkTypes"] = Json::arrayValue;
+
+ if (count > 0) {
+ for (auto rule:ruleMap) {
+ if (rule.second.nIsRun == 1) {
+ elem["nSdkTypes"].append(rule.second.nSdkType);
+ }
+ }
+ }
// Record_Cam_Sdk rec_sdk = db_c.searchCamSdkTableByCamId(iter->str_cam_dev_id);
// elem["str_sdks"] = rec_sdk.str_sdks.toStdString();
// elem["str_det_thr"] = rec_sdk.str_det_thr.toStdString();
// elem["str_cmp_thr"] = rec_sdk.str_cmp_thr.toStdString();
- cout << elem.toStyledString() << endl;
+ DBG(elem.toStyledString());
value.append(elem);
}
- cout << value.toStyledString() << endl;
+ DBG(value.toStyledString());
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
return out;
}
+
#define ADD_CAMERA 0
#define EDIT_CAMERA 1
+
//缂栬緫鎽勫儚鏈�
std::string devHttpServer_c::cam_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
DBG("ip:" << ip << "; port:" << port);
@@ -1010,7 +1057,7 @@
Record_Cam_Dev rec;
Record_Cam_Sdk rec_sdk_old;
Record_Cam_Sdk rec_sdk;
- int type=-1;
+ int type = -1;
int dev_type = db_c.searchDevTypeFromConfigTable();
if (DEV_STORAGE == dev_type) {
return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
@@ -1025,7 +1072,7 @@
if ((!ret) || (serialnumber[0] == 0)) {
return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
-
+ rec.type = 0;
rec.str_cam_dev_id = QString::fromLatin1((const char *) serialnumber);//鎽勫儚鏈篿d cam_mac
rec.str_name = QString::fromStdString(value["str_name"].asString());
rec.str_addr = QString::fromStdString(value["str_addr"].asString());
@@ -1036,45 +1083,35 @@
rec.str_username = QString::fromStdString(value["str_username"].asString());
rec.str_password = QString::fromStdString(value["str_password"].asString());
rec.str_brand = QString::fromStdString(value["str_brand"].asString());
- type=value["n_type"].asInt();
+ rec.str_reserved = QString::fromStdString(value["str_reserved"].asString());
+ type = value["n_type"].asInt();
// rec_sdk_old = db_c.searchCamSdkTableByCamId(rec.str_cam_dev_id);
// rec_sdk.str_cam_dev_id = rec.str_cam_dev_id;
// rec_sdk.str_sdks = QString::fromStdString(value["str_sdks"].asString());
// rec_sdk.str_det_thr = QString::fromStdString(value["str_det_thr"].asString());
// rec_sdk.str_cmp_thr = QString::fromStdString(value["str_cmp_thr"].asString());
- bool is_exist=db_c.searchCamDevByCamId(rec.str_cam_dev_id);
- if(ADD_CAMERA == type )
- {
- if(is_exist)
- {
- return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
- }
- else
- {
- ret =db_c.insertCamDevTable(rec);
- if (!ret) {
- return "err_db_content";
- }
- }
- }
- else if(EDIT_CAMERA == type )
- {
- if(is_exist)
- {
- ret = db_c.updateCamDevTable(rec);
+ bool is_exist = db_c.searchCamDevByCamId(rec.str_cam_dev_id);
+ if (ADD_CAMERA == type) {
+ if (is_exist) {
+ return "{\"ret_status\": \"璇峰嬁閲嶅娣诲姞!\"}";
+ } else {
+ ret = db_c.insertCamDevTable(rec);
if (!ret) {
return "err_db_content";
}
}
- else
- {
- return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ } else if (EDIT_CAMERA == type) {
+ if (is_exist) {
+ ret = db_c.updateCamDevTable(rec);
+ if (!ret) {
+ return "err_db_content";
+ }
+ } else {
+ return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
- }
- else
- {
- return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ } else {
+ return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
@@ -1084,16 +1121,38 @@
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
+ //edit camera's sdks
else/* if ((rec_sdk_old.str_sdks != rec_sdk.str_sdks) ||
(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;
@@ -1107,11 +1166,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) +
@@ -1137,8 +1196,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) {
@@ -1161,11 +1220,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) +
@@ -1190,8 +1249,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) {
@@ -1237,6 +1296,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);
}
}
@@ -1255,26 +1315,48 @@
Json::Reader reader;
Json::Value value_reader;
-
+ std::string out;
if (!reader.parse(content, value_reader)) {
return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
-
- //TODO
- //璋冪敤rtsp娴乺tsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
+ Json::Value value;
+ if (value_reader.isMember("id")) {
+ 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\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+ } else {
return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
-
- std::string rtmp_url = m_rtmp[value_reader["str_ip"].asCString()].appPC->getRtmp();
- Json::Value value;
- value["connect_status"] = "True";
- value["video_url"] = rtmp_url;
- std::string out = value.toStyledString();
return out;
}
@@ -1291,19 +1373,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();
@@ -1364,12 +1459,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 {
@@ -1408,7 +1513,7 @@
"sed -i '/tracker_server=/d' ./WebFDSClient.conf && sed -i '/\\\"host:port\\\"/atracker_server=" + \
value["web_pic_ip"].asString() + ":" + std::to_string(value["web_pic_port"].asInt()) + \
"' ./WebFDSClient.conf";//
- std::cout << "cmd_web:" << cmd_web << std::endl;
+ DBG("cmd_web:" << cmd_web);
system(cmd_web.c_str());
//#todo fastDfsClient
@@ -1417,7 +1522,7 @@
"sed -i '/tracker_server=/d' ./fastDfsClient.conf && sed -i '/\\\"host:port\\\"/atracker_server=" + \
value["es_pic_ip"].asString() + ":" + std::to_string(value["es_pic_port"].asInt()) + \
"' ./fastDfsClient.conf";
- std::cout << "cmd_es:" << cmd_es << std::endl;
+ DBG("cmd_es:" << cmd_es);
system(cmd_es.c_str());
//#todo config
@@ -1430,12 +1535,12 @@
fdfsClient.rwLock.unlock();
}
- //# http client 127.0.0.1:9999/resetFdfs
- std::string http_cmd = "http://127.0.0.1:9999/resetFdfs";
- HttpRequestWithCrul httpRequestWithCrul;
- std::string response_bak = "";
- std::string postParams_bak = "";
- httpRequestWithCrul.curl_post_req("http://127.0.0.1:9999/resetFdfs", postParams_bak, response_bak);
+// //# http client 127.0.0.1:9999/resetFdfs
+// std::string http_cmd = "http://127.0.0.1:9999/resetFdfs";
+// HttpRequestWithCrul httpRequestWithCrul;
+// std::string response_bak = "";
+// std::string postParams_bak = "";
+// httpRequestWithCrul.curl_post_req("http://127.0.0.1:9999/resetFdfs", postParams_bak, response_bak);
}
} else {
return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
@@ -1490,9 +1595,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\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
@@ -1572,7 +1683,7 @@
// system("sed -i 's/address .*$/address 192.168.1.111/g' test");
std::string cmd_ip =
"sed -i 's/address .*$/address " + ip_addr + "/g' /etc/network/interfaces";
- std::cout << "cmd_ip:" << cmd_ip << std::endl;
+ DBG("cmd_ip:" << cmd_ip);
system(cmd_ip.c_str());
//淇敼config.json
@@ -1652,6 +1763,13 @@
return out;
}
+//{
+// "cookie": "abc", //闆嗙兢cookie
+// "fatherNodeName": "main@192.168.1.186", //寮曞鑺傜偣鍚嶇О,娣诲姞寮曞鑺傜偣鏃惰鍊间负" "(鍐呬负绌烘牸)
+// "culID" : "uuid", //闆嗙兢id
+// "culName" : "name", //闆嗙兢鍚嶇О
+// "devID" : "uuid" //璁惧id
+//}
std::string devHttpServer_c::addNode(std::string ip, unsigned int port, std::string content, PResponse &response) {
DBG("ip:" << ip << "; port:" << port);
DBG("content: " << content);
@@ -1664,25 +1782,32 @@
//#todo nodes have counter?
//#todo nodeName Automatic generated?
//#todo devId+num
+ // 鐢熸垚鑺傜偣id - uuid
std::string uuid = GetUUId::getUUID();
+ // 鑾峰彇褰撳墠鏈哄櫒ip
unsigned char ip_old[15] = {0};
std::string str_netIfName = appConfig.getStringProperty("netIfName");
GetIpAddress(str_netIfName.c_str(), ip_old);
std::string str_ip((char *) ip_old);
+ // 鑺傜偣鍚嶇О
std::string nodeName = uuid.append("@" + str_ip);
std::string cookie = value["cookie"].asString();
+ // 寮曞鑺傜偣
std::string FatherNodeName = value["fatherNodeName"].asString();
//#todo ClusterID ClusterName
+ // 闆嗙兢id
std::string clusterID = value["culID"].asString();
+ // 涓虹┖鍒欑敓鎴�,鍚﹀垯鐩存帴浣跨敤
clusterID = clusterID.size() > 0 ? clusterID : GetUUId::getUUID();
std::string clusterName = value["culName"].asString();
+
std::string devID = value["devID"].asString();
std::string devName = value["devName"].asString();
-
+ // erlang鑺傜偣淇濆瓨璺緞/opt/erlang/${uuid}
std::string path = std::string("/opt/erlang/").append(nodeName.substr(0, nodeName.find("@")));
if (erlangDbTool != nullptr) {
//gaunbi node
@@ -1694,6 +1819,7 @@
if (cookie.size() > 0 && (clusterID.size() > 0 || clusterName.size() > 0)) {
// erlangDbTool = new ErlangTool::ErlangDbTool(path, nodeName, cookie);
+ // #todo 杩涚▼鍚� -> get from argv[0]
string str_tmp = "DataWebserver";
erlangDbTool = new ErlangTool::ErlangDbTool(path, nodeName, cookie, clusterID, clusterName, str_tmp);
bool ret = erlangDbTool->initErlang();
@@ -1702,6 +1828,7 @@
ret = erlangDbTool->startNodeDb(FatherNodeName, devID);
if (ret) {
+ //濡傛灉鎴愬姛鍒欐洿鏂伴厤缃枃浠�
appConfig.setStringProperty("erlNode", nodeName);
appConfig.setStringProperty("erlCookie", cookie);
appConfig.setStringProperty("erlPath", path);
@@ -1714,6 +1841,7 @@
runAllApp();
// sleep(4);
} else {
+ // 鍚﹀垯鍒欑疆绌洪厤缃枃浠�
appConfig.setStringProperty("erlNode", "");
appConfig.setStringProperty("erlCookie", "");
appConfig.setStringProperty("erlPath", "");
@@ -1746,6 +1874,7 @@
ret = erlangDbTool->removeNode();
+ // 缃┖閰嶇疆鏂囦欢
appConfig.setStringProperty("erlNode", "");
appConfig.setStringProperty("erlCookie", "");
appConfig.setStringProperty("erlPath", "");
@@ -1860,31 +1989,90 @@
// bool ret = false;
if (reader.parse(content, value)) {
+ std::string Uuid = value["uuid"].asString();
std::string TableType = value["TableType"].asString();
std::string TableName = value["TableName"].asString();
+ // 闆嗙兢鍐呭悓姝�
int SyncType = atoi(value["SyncType"].asCString());
std::string BwType = value["BwType"].asString();
std::string StartTime = value["StartTime"].asString();
std::string EndTime = value["EndTime"].asString();
+
+ // 鏄惁涓婁紶
+ std::string UploadFlag = value["IsSync"].asString();
+ UploadFlag = UploadFlag.empty() ? "0" : UploadFlag;
+
+ // 搴曞簱闃堝��
+ std::string CmpThreshold = value["threshold"].asString();
+ CmpThreshold = CmpThreshold.empty() ? "60" : CmpThreshold;
+ // 鏄惁鍚敤
+ std::string Enabled = value["enabled"].asString();
+ Enabled = Enabled.empty() ? "1" : Enabled;
+
+ std::string createBy = value["createBy"].asString();
+
+ string str_uuid;
+ uuid_t t_uuid;
+ char str[36];
+ uuid_generate(t_uuid);
+ uuid_unparse(t_uuid, str);
+ str_uuid = str;
+ Uuid = Uuid.empty() ? str_uuid : Uuid;
+// if (createBy == "analyDev") {
+// Uuid = Uuid.empty() ? str_uuid : Uuid;
+// } else if (createBy == "conCemter") {
+// if (Uuid.empty()) {
+// response->write(SimpleWeb::StatusCode::client_error_bad_request, "{\"error\":\"鍙傛暟閿欒锛� \"}");
+// return "";
+// }
+// }
+
+
bool ret = false;
- if (SyncType == 1) {
- //鍚屾搴�
- ret = erlangDbTool->createDatabase(TableType, TableName, SyncType, BwType, StartTime, EndTime);
- } else if (SyncType == 0) {
- TableName.insert(0, "lt_");
- //鏈湴搴�
- FieldValues fieldValues;
- fieldValues.insert(std::make_pair("uuid", GetUUId::getUUID()));
- fieldValues.insert(std::make_pair("tableName", TableName));
- fieldValues.insert(std::make_pair("tableDesc", "ceshi"));
- fieldValues.insert(std::make_pair("tableType", TableType));
- fieldValues.insert(std::make_pair("bwType", BwType));
- fieldValues.insert(std::make_pair("startTime", StartTime));
- fieldValues.insert(std::make_pair("endTime", EndTime));
- fieldValues.insert(std::make_pair("create_by", "who"));
- ret = m_SqliteFaceEncap.createTable(TableName, fieldValues);
+ FieldValues fieldValues;
+ fieldValues.insert(std::make_pair("uuid", Uuid));
+ fieldValues.insert(std::make_pair("tableName", TableName));
+ fieldValues.insert(std::make_pair("tableDesc", "ceshi"));
+ fieldValues.insert(std::make_pair("tableType", TableType));
+ fieldValues.insert(std::make_pair("bwType", BwType));
+ fieldValues.insert(std::make_pair("startTime", StartTime));
+ fieldValues.insert(std::make_pair("endTime", EndTime));
+ fieldValues.insert(std::make_pair("create_by", createBy));
+ fieldValues.insert(std::make_pair("uploadFlag", UploadFlag));
+ fieldValues.insert(std::make_pair("cmpThreshold", CmpThreshold));
+ fieldValues.insert(std::make_pair("enabled", Enabled));
+
+
+ if (TableType == "person") {
+ if (SyncType == 1) {
+ //鍚屾搴�
+ ret = erlangDbTool->createDatabase(Uuid, fieldValues);
+ } else if (SyncType == 0) {
+ TableName.insert(0, "lt_");
+ fieldValues["tableName"] = TableName;
+ //鏈湴搴�
+ ret = m_SqliteFaceEncap.createTable(TableName, fieldValues);
+ }
+ } else if (TableType == "car") {
+ ERR(" not not_implemented");
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"绫诲瀷閿欒锛屾湭瀹炵幇锛� \"}");
+ return "";
+ } else {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"绫诲瀷閿欒锛屾湭璇嗗埆锛� \"}");
+ return "";
}
+//// #todo 涓婁紶銆備粎榛戝悕鍗曘��
+//// #TODO 鏍规嵁createBy鍒ゆ柇鏄惁闇�瑕佷笂浼�
+// if (createBy == "analyDev" && BwType == "1") {
+//// string &Uuid, string &TableName, string &SyncType, string &StartTime,string &EndTime,
+//// string &UploadFlag, string &CmpThreshold, string &Enabled
+// string str_SyncType(to_string(SyncType));
+// UploadTaskToMonitorCenter(Uuid, TableName, str_SyncType, StartTime, EndTime, UploadFlag, CmpThreshold,
+// Enabled);
+// }
+
+ // send message to other CNode
erlangDbTool->sendMessage();
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
return str_result;
@@ -1954,9 +2142,12 @@
// auto resType = erlangDbTool->findAllTypeInfo();
string json = "[";
for (auto &item : resDB) {
+ //-------------------maybe delete ?------------------------
if (item.second.tableName.find("lt_") == 0) {
continue;
}
+ //-------------------maybe delete end----------------------
+
string subJson = "{ ";
subJson.append("\"uuid\":\"" + item.second.uuid + "\",");
subJson.append("\"tableName\":\"" + item.second.tableName + "\",");
@@ -2073,6 +2264,12 @@
img_str.append(fdfsClient.fastFds->getIp() + "/").append(img_tmp);
img_url.swap(img_str);
}
+ } else {
+ std::string img_str = "http://";
+ if (fdfsClient.fastFds != nullptr) {
+ img_str.append(fdfsClient.fastFds->getIp() + "/").append(img_url);
+ img_url.swap(img_str);
+ }
}
auto t_results = m_curlDownloadImg.download_jpeg(const_cast<char *>(img_url.c_str()));
@@ -2171,7 +2368,7 @@
fieldValues.insert(std::make_pair("uuid", strUUID));
fieldValues.insert(std::make_pair("idCard", idcard));
- m_SqliteFaceEncap.updateFace(TableName, addFaceData, fieldValues);
+ ret_addPerson = m_SqliteFaceEncap.updateFace(TableName, addFaceData, fieldValues);
}
} else {
@@ -2329,26 +2526,27 @@
std::string BwType = value["BwType"].asString();
std::string StartTime = value["StartTime"].asString();
std::string EndTime = value["EndTime"].asString();
-
+ //#鏇存柊搴曞簱绠$悊琛�
+ FieldValues fieldValues;
+ fieldValues.insert(std::make_pair("uuid", Uuid));
+ fieldValues.insert(std::make_pair("tableName", TableName));
+// fieldValues.insert(std::make_pair("tableDesc", "ceshi2"));
+ fieldValues.insert(std::make_pair("tableType", TableType));
+ fieldValues.insert(std::make_pair("bwType", BwType));
+ fieldValues.insert(std::make_pair("startTime", StartTime));
+ fieldValues.insert(std::make_pair("endTime", EndTime));
+// fieldValues.insert(std::make_pair("create_by", "who"));
bool ret = false;
if (SyncType == 1) {
//鍚屾搴�
- ret = erlangDbTool->updateDatabase(Uuid, TableType, TableName, SyncType, BwType, StartTime, EndTime);
+ ret = erlangDbTool->updateDatabase("sys_o_tables", fieldValues);
} else if (SyncType == 0) {
//鏈湴搴�
- //#鏇存柊搴曞簱绠$悊琛�
- FieldValues fieldValues;
- fieldValues.insert(std::make_pair("uuid", Uuid));
if (TableName.find("lt_") != 0) {
TableName.insert(0, "lt_");
}
- fieldValues.insert(std::make_pair("tableName", TableName));
-// fieldValues.insert(std::make_pair("tableDesc", "ceshi2"));
- fieldValues.insert(std::make_pair("tableType", TableType));
- fieldValues.insert(std::make_pair("bwType", BwType));
- fieldValues.insert(std::make_pair("startTime", StartTime));
- fieldValues.insert(std::make_pair("endTime", EndTime));
-// fieldValues.insert(std::make_pair("create_by", "who"));
+ fieldValues["tableName"] = TableName;
+
ret = m_SqliteFaceEncap.updateTable("sys_o_tables", fieldValues);
}
@@ -2396,21 +2594,14 @@
}
}
-std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
- PResponse &response) {
- DBG("ip:" << ip << "; port:" << port);
- DBG("content: " << content);
- Json::Reader reader;
- Json::Value value;
- try {
- if (reader.parse(content, value)) {
- std::string videoPath;
- std::string devId = value["videoNum"].asString();
- std::string picDate = value["picDate"].asString();
- //std::string path_uuid = videoPath;//value["path_uuid"].asString();
+std::string devHttpServer_c::getAlarmImageByPicDateAndDevId(const std::string &picDate, const std::string &devId,
+ PResponse &response) {
+ try {
+ if (!devId.empty() && !picDate.empty()) {
+ std::string videoPath;
qint64 sub;
- std::string path = getVideoPathByTime(picDate, devId, sub);
+ std::string path = getVideoPathByPicDate(picDate, devId, sub);
if (path.empty()) {
ERR("{\"error\":\"not find path\"}");
@@ -2502,12 +2693,10 @@
}
fdfsClient.rwLock.unlock();
std::string result("{\"img_url\":\"" + img_url + "\"}");
-// cout << result << endl;
return result;
} else {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
return "";
-// return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
}
catch (std::exception ex) {
@@ -2518,28 +2707,159 @@
}
}
+
+std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
+ PResponse &response) {
+ INFO("ip:" << ip << "; port:" << port << "content: " << content);
+ Json::Reader reader;
+ Json::Value value;
+ try {
+ if (reader.parse(content, value)) {
+ std::string devId = value["videoNum"].asString();
+ std::string picDate = value["picDate"].asString();
+ std::string imgKey = value["imgKey"].asString();
+ //鍏煎鏃х増鏈�
+ if (imgKey == "undefined" || imgKey.empty()) {
+ DBG("getAlarmImageByPicDateAndDevId " << imgKey);
+ return getAlarmImageByPicDateAndDevId(picDate, devId, response);
+ } else {
+ DBG("getAlarmImageByImageKeyAndDevId " << imgKey);
+ return getAlarmImageByImageKeyAndDevId(imgKey, devId, response);
+ }
+ } else {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
+ ERR("ImageURL:浼犺緭閿欒锛岃妫�鏌�");
+ return "";
+ }
+ }
+ catch (std::exception ex) {
+ std::string message = "{\"error\":\"寮傚父閿欒锛�";
+ message.append(const_cast<char *>(ex.what())).append("\"}");
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
+ ERR("ImageURL:寮傚父閿欒 " << ex.what());
+ return "";
+ }
+}
+
+
+std::string devHttpServer_c::getAlarmImageByImageKeyAndDevId(const std::string &imgKey, const std::string &devId,
+ PResponse &response) {
+ try {
+ if (!devId.empty() && !imgKey.empty()) {
+ std::string videoPath;
+ std::string path = getVideoPathByImgKey(imgKey, devId);
+ if (path.empty()) {
+ ERR("Not Find Path: " << path);
+ return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
+ }
+ videoPath.clear();
+ videoPath = path;
+
+ VideoName_s_t videoSt = VideoName_s_t::fromString(path);
+ ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
+
+ //#todo 鎸夌収鏃堕棿鍛藉悕
+ std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
+
+ auto frameIdDiff = imgSt.m_frameId - videoSt.m_startFrameId;
+ char selectExpBuff[32] = {0};
+ 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);
+ system(cmd.c_str());
+ } else {
+ ERR("Parse Video and Image Failed Path: " << path << " ImageId: " << imgKey);
+ 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";
+ ERR("Upload Image Failed " << str_imgName);
+ } else {
+ std::string str_tmp_cmd("rm -f '" + str_imgName + "'");
+ system(str_tmp_cmd.c_str());
+ img_url.append(t_strImg);
+ img_url.clear();
+ img_url = t_strImg;
+ }
+ }
+ fdfsClient.rwLock.unlock();
+ std::string result("{\"img_url\":\"" + img_url + "\"}");
+ INFO("ImageURL:" << img_url);
+ return result;
+ } else {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
+ ERR("ImageURL:浼犺緭閿欒锛岃妫�鏌�");
+ return "";
+ }
+ }
+ catch (std::exception ex) {
+ std::string message = "{\"error\":\"寮傚父閿欒锛�";
+ message.append(const_cast<char *>(ex.what())).append("\"}");
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
+ ERR("ImageURL:寮傚父閿欒 " << ex.what());
+ return "";
+ }
+}
+
+
std::string
devHttpServer_c::getRecordVideoPath(std::string ip, unsigned int port, std::string content, PResponse &response) {
Json::Reader reader;
Json::Value value;
+ INFO("REQ From: " << ip << ":" << port << " Content:" << content);
if (reader.parse(content, value)) {
std::string devId = value["videoNum"].asString();
std::string picDate = value["picDate"].asString();
- qint64 sub;
- std::string path = getVideoPathByTime(picDate, devId, sub);
- if (path.empty()) {
+ std::string imgKey = value["imgKey"].asString();
+ std::string path;
- return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ //鍏煎鏃х増鏈�
+ if (imgKey == "undefined" || imgKey.empty()) {
+ qint64 sub;
+ path = getVideoPathByPicDate(picDate, devId, sub);
+ } else {
+ path = getVideoPathByImgKey(imgKey, devId);
+ }
+ //std::string path = getVideoPathByImgKey(imgKey, devId, sub);
+ ERR("VideoNum: " << devId << " PicDate: " << picDate << " imgKey: " << imgKey);
+ if (path.empty()) {
+ std::string strRsp = "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ ERR("RSP:" << strRsp);
+ return strRsp;
} else {
std::string result = "{\"file_path\":\"" + path + "\"}";
+ INFO("RSP:" << result);
return result;
}
} else {
- return "{\"ret_status\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ std::string strRsp = "{\"ret_status\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ ERR("RSP:" << strRsp);
+ return strRsp;
}
}
+
std::string devHttpServer_c::findDevId(std::string ip, unsigned int port, std::string content, PResponse &response) {
@@ -2613,11 +2933,12 @@
appConfig.setStringProperty("DEV_ID", dev_id);
appConfig.save();
- //std::cout<<dev_id<<std::endl;
+
return true;
}
-std::string devHttpServer_c::getVideoPathByTime(const std::string &time, const std::string &camId, qint64 &sub) {
+
+std::string devHttpServer_c::getVideoPathByPicDate(const std::string &time, const std::string &camId, qint64 &sub) {
std::string t_FilePath = appConfig.getStringProperty("cutPath");
bool find = false;
@@ -2677,6 +2998,81 @@
}
+
+std::string devHttpServer_c::GetVideoNameByImgKey(const std::string &imgKey, const std::string &strPath) {
+ static std::mutex g_mutex;
+ std::lock_guard<std::mutex> lock(g_mutex);
+ std::vector<std::string> vec = forEachFileByImgKey(strPath);
+ ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
+ if (!imgSt.Valid()) {
+ ERR("ParseImageName Failed : " << imgKey);
+ return "";
+ }
+ std::vector<VideoName_s_t> videoStVec;
+ for (const auto &item : vec) {
+ auto videoParseResult = VideoName_s_t::fromString(item);
+ if (videoParseResult.Valid()) {
+ if (videoParseResult.m_startFrameId <= imgSt.m_frameId &&
+ imgSt.m_frameId <= videoParseResult.m_endFrameId) {
+ auto imgTm = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
+ auto videoTm = AppUtil::ParseFromHypenTimeStr(videoParseResult.m_timeStamp);
+ if (AppUtil::IsRightAfterLeft(imgTm, videoTm)) {
+ videoStVec.emplace_back(videoParseResult);
+ INFO("Image " << imgKey << " Video: " << item << " Match");
+ } else {
+ ERR("Image " << imgKey << " Video: " << item << " Not Match");
+ }
+ } else {
+ ERR("ImageID: " << imgSt.m_frameId << " VideoRange: " << videoParseResult.m_startFrameId << " , "
+ << videoParseResult.m_endFrameId);
+ }
+
+ } else {
+ ERR("VideoName : " << item << " Parse Failed");
+ }
+ }
+
+ std::vector<VideoName_s_t> videoStVec_;
+ auto imgTm_ = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
+ for (auto &item : videoStVec) {
+ auto resTime_ = AppUtil::ParseFromHypenTimeStr(item.m_timeStamp);
+ auto timeRes = difftime(mktime(&resTime_), mktime(&imgTm_));
+ if ((timeRes < 0 && difftime(mktime(&imgTm_), mktime(&resTime_)) >= 30) || (timeRes / 60 >= 3)) {
+ continue;
+ }
+ videoStVec_.emplace_back(item);
+ }
+
+ if (videoStVec_.size() >= 1) {
+ std::string strVideoName = strPath + videoStVec_[0].ToVideoName();
+ INFO("ImageName: " << imgKey << " SingleMatchVideo: " << strVideoName);
+ return strVideoName;
+ } else {
+ ERR("ImageName: " << imgKey << " MatchVideoCount: " << videoStVec.size());
+ for (auto &item:vec) {
+ ERR("VideoName: " << item);
+ }
+ return "";
+ }
+}
+
+//鏂扮殑鏍规嵁鍥剧墖鍚嶇О鑾峰彇璺緞鐨勬柟娉�
+std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId) {
+ INFO("GetVideoFor: " << imgKey << " CamID:" << camId);
+ ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
+
+ struct tm imgTime = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
+ char curFolder[128] = {0};
+ // 201901/26/2019012614 ---- 201901/26/2019012615 {骞存湀}/{鏃/{骞存湀鏃ユ椂}/
+ sprintf(curFolder, "%04d%02d/%02d/%04d%02d%02d%02d/", imgTime.tm_year + 1900, imgTime.tm_mon + 1,
+ imgTime.tm_mday,
+ imgTime.tm_year + 1900, imgTime.tm_mon + 1, imgTime.tm_mday, imgTime.tm_hour);
+ std::string t_FilePath = appConfig.getStringProperty("cutPath");
+ std::string videoPath = t_FilePath + "/" + camId + "/" + std::string(curFolder);
+ return GetVideoNameByImgKey(imgKey, videoPath);
+}
+
+
qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string &str_tmpTime) {
// std::string cmd_getVideoFileTime(
// " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
@@ -2701,6 +3097,7 @@
return len_ms;
}
+//鑾峰彇鏌愪釜鐩綍涓嬬殑鎵�鏈夋枃浠讹紝涓嶅甫鎵╁睍鍚�
std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name) {
std::vector<std::string> v;
auto dir = opendir(dir_name.data());
@@ -2714,6 +3111,26 @@
temp = filename.substr(0, filename.rfind('.'));
v.push_back(temp);
+ }
+
+ }
+ closedir(dir);
+ }
+ return v;
+}
+
+//鑾峰彇鏌愪釜鐩綍涓嬬殑鎵�鏈夋枃浠讹紝甯︽墿灞曞悕
+std::vector<std::string> devHttpServer_c::forEachFileByImgKey(const std::string &dir_name) {
+ std::vector<std::string> v;
+ auto dir = opendir(dir_name.data());
+ struct dirent *ent;
+ int len = 0;
+ if (dir) {
+ while ((ent = readdir(dir)) != NULL) {
+ std::string filename = std::string(ent->d_name);
+ std::string temp;
+ if (filename != "." && filename != "..") {
+ v.push_back(filename);
}
}
@@ -2932,6 +3349,10 @@
rule.strExAreas = value["strExAreas"].asCString();
rule.strLine = value["strLine"].asCString();
rule.strExLine = value["strExLine"].asCString();
+
+ if (!value["strPerimeterObjType"].empty()) {
+ rule.strPerimeterObjType = value["strPerimeterObjType"].asCString();
+ }
if (rule.strCamId.isEmpty()) {
return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
@@ -2955,11 +3376,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\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
@@ -3000,6 +3429,7 @@
obj["strExAreas"] = rule.second.strExAreas.toStdString();
obj["strLine"] = rule.second.strLine.toStdString();
obj["strExLine"] = rule.second.strExLine.toStdString();
+ obj["strPerimeterObjType"] = rule.second.strPerimeterObjType.toStdString();
Json::Value weekRuleArray;
@@ -3031,30 +3461,55 @@
}
std::string devHttpServer_c::getSnapshot(std::string ip, unsigned int port, std::string content, PResponse &response) {
+ DBG("ip:" << ip << "; port:" << port);
+ DBG("content: " << content);
Json::Reader reader;
Json::Value value;
if (reader.parse(content, value)) {
-
- std::string ip = value["str_ip"].asString();
+ std::string str_imgName = "";
+ std::string rtsp_ip = value["str_ip"].asString();
// int port= value["n_port"].asInt();
int port = 554;
std::string username = value["str_username"].asString();
std::string pass = value["str_password"].asString();
std::string brand = value["str_brand"].asString();
- std::string rtsp_url = rtspAddrBuild(ip, port, username, pass, brand);
- if (rtsp_url.empty()) {
- return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ std::string rtsp_url = rtspAddrBuild(rtsp_ip, port, username, pass, brand);
+
+ if (value.isMember("id")) {
+ if (value["id"].isNull()) return "{\"ret_status\": \"id鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ str_imgName.append("./").append(value["id"].asString()).append(".jpg");
+ } else {
+ if (rtsp_url.empty()) {
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+// unsigned char serialnumber[SERIALNO_LEN] = {0};
+// int ret = getDevSerialNumber(ip.c_str(), port,username.c_str(),pass.c_str(),brand.c_str(),serialnumber);
+
+
+// if ((!ret) || (serialnumber[0] == 0))
+// {
+// return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+// }
+
+// std::string str_cam_dev_id = std::string((char *) serialnumber);//鎽勫儚鏈篿d cam_mac
+
+ str_imgName = appConfig.getStringProperty("cutPath");
+ if (str_imgName.back() != '/') {
+ str_imgName.push_back('/');
+ }
+ str_imgName += rtsp_ip;
+ str_imgName += "-";
+ str_imgName += "snapshot.jpg";
+ //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg
+ std::string cmd(
+ "ffmpeg -i " + rtsp_url +
+ " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " +
+ str_imgName);
+// std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25 -f image2 -s 1920*1080 -y " + str_imgName);
+ DBG(cmd);
+ system(cmd.c_str());
}
- std::string str_imgName = appConfig.getStringProperty("cutPath");
- if (str_imgName.back() != '/') {
- str_imgName.push_back('/');
- }
- str_imgName += "snapshot.jpg";
- //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg
- std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25 -f image2 -s 1920*1080 -y " + str_imgName);
- DBG(cmd);
- system(cmd.c_str());
cv::Mat img = cv::imread(str_imgName);
@@ -3069,13 +3524,18 @@
CvUtil::cvMat2Buffer(img, buffer);
std::string strImgUrlTmp = "";
fdfsClient.fastFds->uploadFile(buffer, strImgUrlTmp, "jpg");
- strImgUrl.append(fdfsClient.fastFds->getIp() + "/" + strImgUrlTmp);
+ // strImgUrl.append(fdfsClient.fastFds->getIp() + "/" + strImgUrlTmp);
strImgUrl.clear();
strImgUrl = strImgUrlTmp;
}
fdfsClient.rwLock.unlock();
Json::Value result;
result["imgUrl"] = strImgUrl;
+ if (value.isMember("id")) {
+ db_c.updateCamDevSnapshotbyID(value["id"].asString().c_str(), QString::fromStdString(strImgUrl));
+ } else {
+ db_c.updateCamDevSnapshot(QString::fromStdString(rtsp_ip), QString::fromStdString(strImgUrl));
+ }
return result.toStyledString();
--
Gitblit v1.8.0