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 | 150 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 141 insertions(+), 9 deletions(-) diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp index 961c0c5..ae0cd84 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp @@ -14,8 +14,120 @@ 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) { @@ -55,14 +167,33 @@ 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("searchCamDevTableByType size is 0"); @@ -175,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(); @@ -202,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++; @@ -338,12 +470,12 @@ //淇濆瓨瑙嗛鍒癛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); -- Gitblit v1.8.0