From f946a62d3921e86b44ff8e2973138304b9cd53cd Mon Sep 17 00:00:00 2001 From: chenshijun <csj_sky@126.com> Date: 星期二, 16 四月 2019 16:36:32 +0800 Subject: [PATCH] 解决修改参数和推流画面跳跃问题 --- QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 2 QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp | 45 +++++++++------ QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.h | 2 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h | 3 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp | 16 +++-- QiaoJiaSystem/DataManagerServer/vss/controller/CamDevController.h | 33 +++++++++++ QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp | 2 QiaoJiaSystem/StructureApp/FaceExtractElement.cpp | 2 QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp | 15 ++++ QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp | 4 10 files changed, 90 insertions(+), 34 deletions(-) diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp index bfb927c..85d8485 100644 --- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp +++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp @@ -262,6 +262,8 @@ VssDomainUnitTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); VssLocalSettingTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); CamDevController::instance()->registerHttpServices(_HttpSrvRetRecieve); + //todo + CamDevController::instance()->nsqMsgProducerSet(nsqMsgProducer); VssUpperSvrTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); diff --git a/QiaoJiaSystem/DataManagerServer/vss/controller/CamDevController.h b/QiaoJiaSystem/DataManagerServer/vss/controller/CamDevController.h index 22aa644..2656b88 100755 --- a/QiaoJiaSystem/DataManagerServer/vss/controller/CamDevController.h +++ b/QiaoJiaSystem/DataManagerServer/vss/controller/CamDevController.h @@ -8,6 +8,7 @@ #include "vss/model/CamDev.h" #include "VssBaseController.h" #include <mysql++.h> +#include <NsqMsgTool.hpp> using namespace std; @@ -24,6 +25,14 @@ static CamDevController *instance() { static CamDevController instance; return &instance; + } + +private: + //shared_ptr + BasicMsg::Nsq::NsqMsgProducer *_nsqMsgProducer; +public: + void nsqMsgProducerSet(BasicMsg::Nsq::NsqMsgProducer *nsqMsgProducer){ + _nsqMsgProducer = nsqMsgProducer; } public: @@ -163,6 +172,18 @@ } } + + { + 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 responseJsonValue.toStyledString(); } @@ -245,6 +266,18 @@ idJsonValue.asString()); } } + + { + 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)); + } + return responseJsonValue.toStyledString(); } diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp index 299ec03..7787821 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp +++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp @@ -373,7 +373,7 @@ bool BASICGB28181::FFmpegDecoderJPG::stopThd() { TryCath( - DBG(m_camIdx << " FFmpegDecoderJPG stopThd ... " << m_camIdx); + DBG("FFmpegDecoderJPG stopThd ... " << m_camIdx); m_running = false; ); return true; diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp index 9712880..fb01c4d 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp +++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp @@ -53,6 +53,9 @@ #ifdef TestCode DBG("waitSignal(\"DecoderImageOK\") after"); #endif + // 浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖 + p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); + { if (p_this->m_publishVideoRet) { if (p_this->videoPublishElement == nullptr) { @@ -60,12 +63,13 @@ cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); int gupIdx = appPref.getIntData("gpu.index"); DBG("videoPublishpath: " << p_this->m_chanPubID << path << " h:" << size_.height); - p_this->videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); + p_this->videoPublishElement = new ffmpeg::PipeVideoPublishElement(path, size_, "flv", 25, gupIdx); p_this->videoPublishElement->start(); } else { -// DBG("videoPublishElement->setImage() : " << p_this->m_chanPubID); if (!p_this->m_image.empty()) { +// DBG("videoPublishElement->setImage() : " << p_this->m_chanPubID); p_this->videoPublishElement->setImage(p_this->m_image); + p_this->videoPublishElement->submit(); } else { ERR("m_image.empty()"); } @@ -92,8 +96,6 @@ p_this->m_picCount.store(0); } -// 浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖 - p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); { cv::Mat copyMat; std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); @@ -154,14 +156,14 @@ } else { // 鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚� - if (reopenTime < 0) { + if (p_this->reopenTime < 0) { p_this->m_running = false; stop(); INFO("grabFrame faild, element stopping"); } else { //todo 涓氬姟姝婚攣 - usleep((6 - reopenTime--) * 1000000); - INFO("grabFrame faild, try reopen video, reopenTime:" << reopenTime); + usleep((6 - p_this->reopenTime--) * 1000000); + INFO("grabFrame faild, try reopen video, reopenTime:" << p_this->reopenTime); //鍏抽棴ffmpeg瑙g爜妯″潡 p_this->m_fFmpegDecoderJPG.stopThd(); diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h index 8e0a92c..b77d67f 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h +++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h @@ -37,7 +37,6 @@ */ bool getRunning(); - /*** * 鑾峰彇鍥剧墖 * @return @@ -78,7 +77,7 @@ //鐢ㄦ潵淇濆瓨褰曞儚瑙嗛鐨勮矾寰� std::string m_cutPath; std::atomic<bool> m_publishVideoRet{false}; - ffmpeg::VideoPublishElement * videoPublishElement{nullptr}; + ffmpeg::PipeVideoPublishElement * videoPublishElement{nullptr}; private: /*** * 鍚姩瀹炴椂娴佹帴鏀舵暟鎹嚎绋� diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp index 88e51e8..4a49548 100644 --- a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp +++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp @@ -54,7 +54,7 @@ void FaceExtractElement::submitFaceExtract(FaceToExtract faceToExtract) { std::lock_guard<std::mutex> lg(imageQueueMutex); if (faceExtractQueue.size() >= VECTOR_MAX) { - ERR("FaceExtractElement::submitFaceExtract too fast, imageQueue.size()>=QUEUE_MAX : " << faceExtractQueue.size()) + ERR("FaceExtractElement::submitFaceExtract too fast, imageQueue.size()>=QUEUE_MAX") return; } faceExtractQueue.push_back(faceToExtract); diff --git a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp index a0bac2a..9900ab5 100644 --- a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp +++ b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp @@ -32,20 +32,18 @@ IMPORT_APP_ARGS; //nsq set callback func DBG("NsqMsgConsumer Init"); - string pName(argv[0]); - if(argv[0][0] == '.' && argv[0][1] == '/') - { + DBG("argv[0]:" << argv[0]); + if(argv[0][0] == '.' && argv[0][1] == '/'){ string pName(argv[0]+2, argv[0]+strlen(argv[0])); - DBG("pName(argv[0]) :" << pName); + DBG("pName:" << pName); nsqMsgConsumer = new BasicMsg::Nsq::NsqMsgConsumer("127.0.0.1", "4150", pName, to_string(appPref.getIntData("RpcVTIMPort"))); }else{ string pName(argv[0]); - DBG("pName(argv[0]) :" << pName); + DBG("pName:" << pName); nsqMsgConsumer = new BasicMsg::Nsq::NsqMsgConsumer("127.0.0.1", "4150", pName, to_string(appPref.getIntData("RpcVTIMPort"))); } - nsqMsgConsumer->setMessageCallback(std::bind(&OnMsgFunc, std::placeholders::_1, this)); nsqMsgConsumer->init(); DBG("NsqMsgConsumer Init END!!"); @@ -104,12 +102,16 @@ //#todo 浣跨敤绛栫暐妯″紡?鍙戦�佺澶氫釜鎸囦护绱Н鍚庡彂閫�? if (itor_json->isString() && reader.parse(itor_json->asString(), cfg_val)) { if (itor_json.name() == "cam_edit" || itor_json.name() == "editSdkRule") { - string cam_idx = ""; - if(itor_json.name() == "cam_edit"){ - cam_idx = cfg_val["str_cam_dev_id"].asString(); - } else { - cam_idx = cfg_val["strCamId"].asString(); - } + string cam_idx = ""; + if(itor_json.name() == "cam_edit"){ + if (pthis->m_GB28181_Enable){ + cam_idx = cfg_val["equipCode"].asString(); + }else{ + cam_idx = cfg_val["str_cam_dev_id"].asString(); + } + } else { + cam_idx = cfg_val["strCamId"].asString(); + } if (pthis->controllers.find(cam_idx) != pthis->controllers.end()) { if (pthis->m_GB28181_Enable) { @@ -134,7 +136,13 @@ } } } else if (itor_json.name() == "cam_del") { - string cam_idx = cfg_val["str_cam_dev_id"].asString(); +// string cam_idx = cfg_val["str_cam_dev_id"].asString(); + string cam_idx = ""; + if(cfg_val["equipCode"].asString().size()){ + cam_idx = cfg_val["equipCode"].asString(); + }else if(cfg_val["str_cam_dev_id"].asString().size()){ + cam_idx = cfg_val["str_cam_dev_id"].asString(); + } pthis->removeCamera(cam_idx); } } else { @@ -262,15 +270,16 @@ rule.second.strAddr = item.str_addr; rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); - if (rule.second.nSdkType == PerStaticSdk) { +// if (rule.second.nSdkType == PerStaticSdk || rule.second.nSdkType == PerimeterSdk +// || rule.second.nSdkType == KeepRightSdk || rule.second.nSdkType == KeepRightSdk) { float temp = (float)1 - (float) (rule.second.nThreshold) / 100; rule.second.fSensitivity = (temp * 50 + 50) / 100; // rule.second.fSensitivity = (temp * 25 + 75) / 100; - } 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.nSdkType != FaceSdk) { +// float temp = (float)1 - (float) (rule.second.nThreshold) / 100; +// rule.second.fSensitivity = (temp * 90 + 5) / 100; +// } DBG("fSensitivity" << rule.second.fSensitivity); } appPref.setStringData(t_camIdex + "rtsp", rtsp_url); diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp index fa3087a..295ad0b 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp @@ -90,7 +90,13 @@ } } } else if (itor_json.name() == "cam_edit") { - string cam_idx = cfg_val["str_cam_dev_id"].asString(); + string cam_idx = ""; + if(pthis->m_GB28181_Enable){ + cam_idx = cfg_val["equipCode"].asString(); + }else{ + cam_idx = cfg_val["str_cam_dev_id"].asString(); + } + if (pthis->m_GB28181_Enable) { if (pthis->m_controllers_videoCapElem.find(cam_idx) != pthis->m_controllers_videoCapElem.end()) { @@ -108,7 +114,12 @@ } } } else if (itor_json.name() == "cam_del") { - string cam_idx = cfg_val["str_cam_dev_id"].asString(); + string cam_idx = ""; + if(pthis->m_GB28181_Enable){ + cam_idx = cfg_val["equipCode"].asString(); + }else{ + cam_idx = cfg_val["str_cam_dev_id"].asString(); + } pthis->removeCamera(cam_idx); } else if (itor_json.name() == "cam_startPublish") { string cam_idx = cfg_val["id"].asString(); diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp index 33a73fc..7316f37 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp @@ -49,8 +49,7 @@ string path = appConfig.getStringProperty("srsAddr") + "cam" + m_camId + ".flv"; cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); int gupIdx = appPref.getIntData("gpu.index"); - DBG("size_:" << size_.width << "X" << size_.height); - videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); + videoPublishElement = new ffmpeg::PipeVideoPublishElement(path, size_, "flv", 25, gupIdx); videoPublishElement->start(); } else { // DBG("videoPublishElement->setImage()"); @@ -60,6 +59,7 @@ if (!copyMat.empty()) { videoPublishElement->setImage(copyMat); + videoPublishElement->submit(); } else { DBG("copyMat.empty()"); } diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.h b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.h index af806a5..da3d6c3 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.h +++ b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.h @@ -56,7 +56,7 @@ std::atomic<bool> m_publishVideoRet{false}; - ffmpeg::VideoPublishElement *videoPublishElement{nullptr}; + ffmpeg::PipeVideoPublishElement *videoPublishElement{nullptr}; // Redis鐨勫伐鍏风被 // HiredisTool m_redisTool; -- Gitblit v1.8.0