| | |
| | | #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" |
| | |
| | | using namespace std; |
| | | |
| | | devHttpServer_c::devHttpServer_c() |
| | | : _HttpSrvRetRecieve("0.0.0.0", 8083, 1), erlangDbTool(nullptr), m_SqliteFaceEncap("LocalDataDB"){ |
| | | : _HttpSrvRetRecieve("0.0.0.0", 8083, 1), erlangDbTool(nullptr), m_SqliteFaceEncap("LocalDataDB") { |
| | | init(); |
| | | } |
| | | |
| | |
| | | VssDomainUnitTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | VssLocalSettingTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | CamDevController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | //todo |
| | | CamDevController::instance()->nsqMsgProducerSet(nsqMsgProducer); |
| | | VssUpperSvrTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | |
| | | |
| | |
| | | |
| | | 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 |
| | |
| | | (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; |
| | |
| | | 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流rtsp://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) + |
| | |
| | | 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) { |
| | |
| | | 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) + |
| | |
| | | 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) { |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | } |
| | | 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流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream |
| | | if (value_reader["id"].isNull()) { |
| | | //本地视频源 第一次测试连接 |
| | | //TODO |
| | | //调用rtsp流rtsp://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; |
| | |
| | | if (!reader.parse(content, value_reader)) { |
| | | return "{\"ret_status\": \"传输错误,请检查!\"}"; |
| | | } |
| | | |
| | | //TODO |
| | | //调用rtsp流rtsp://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流rtsp://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(); |
| | | |
| | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | if (ret) { |
| | | //todo |
| | | //todo VideoToImageMulth |
| | | { |
| | | std::string topic = "cut_dura_edit"; |
| | | std::string msg = content; |
| | | 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 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); |
| | |
| | | //#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 |
| | |
| | | |
| | | 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(); |
| | |
| | | ret = erlangDbTool->startNodeDb(FatherNodeName, devID); |
| | | |
| | | if (ret) { |
| | | //如果成功则更新配置文件 |
| | | appConfig.setStringProperty("erlNode", nodeName); |
| | | appConfig.setStringProperty("erlCookie", cookie); |
| | | appConfig.setStringProperty("erlPath", path); |
| | |
| | | runAllApp(); |
| | | // sleep(4); |
| | | } else { |
| | | // 否则则置空配置文件 |
| | | appConfig.setStringProperty("erlNode", ""); |
| | | appConfig.setStringProperty("erlCookie", ""); |
| | | appConfig.setStringProperty("erlPath", ""); |
| | |
| | | |
| | | ret = erlangDbTool->removeNode(); |
| | | |
| | | // 置空配置文件 |
| | | appConfig.setStringProperty("erlNode", ""); |
| | | appConfig.setStringProperty("erlCookie", ""); |
| | | appConfig.setStringProperty("erlPath", ""); |
| | |
| | | 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; |
| | | |
| | |
| | | fieldValues.insert(std::make_pair("bwType", BwType)); |
| | | fieldValues.insert(std::make_pair("startTime", StartTime)); |
| | | fieldValues.insert(std::make_pair("endTime", EndTime)); |
| | | // #todo |
| | | 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)); |
| | |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | //// #todo 上传。仅黑名单。 |
| | | //// #TODO 根据createBy判断是否需要上传 |
| | | // if (createBy == "analyDev" && BwType == "1") { |
| | |
| | | // Enabled); |
| | | // } |
| | | |
| | | |
| | | // send message to other CNode |
| | | erlangDbTool->sendMessage(); |
| | | std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}"); |
| | | return str_result; |
| | |
| | | // 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 + "\","); |
| | |
| | | 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); |
| | |
| | | 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"; |
| | |
| | | } |
| | | } |
| | | |
| | | if (videoStVec.size() >= 1) { |
| | | std::string strVideoName = strPath + videoStVec[0].ToVideoName(); |
| | | 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 { |
| | |
| | | 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\":\"内容有误,请检查!\"}"; |
| | | } |
| | |
| | | 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\":\"内容有误,请检查!\"}"; |
| | |
| | | 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; |
| | | |
| | | |