| | |
| | | using std::string; |
| | | void *gRtspAnalysManagerCamera = nullptr; |
| | | |
| | | RtspAnalysManager::RtspAnalysManager(LDBTool *_dbTool) : m_lDBTool(nullptr), m_maxCount(50), m_currentCount(0) { |
| | | // INFO("MYH DEBUG HERE"); |
| | | 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) { |
| | | std::string rtsp_url; |
| | |
| | | return rtsp_url; |
| | | } |
| | | |
| | | RtspAnalysManager::RtspAnalysManager(LDBTool *_dbTool) : m_lDBTool(nullptr), m_maxCount(50), m_currentCount(0) { |
| | | // INFO("MYH DEBUG HERE"); |
| | | m_lDBTool = _dbTool; |
| | | init(); |
| | | |
| | | IMPORT_APP_ARGS; |
| | | //nsq set callback func |
| | | DBG("NsqMsgConsumer Init"); |
| | | string pName(argv[0]); |
| | | 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!!"); |
| | | |
| | | } |
| | | |
| | | 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) { |
| | | //#todo 使用策略模式?发送端多个指令累积后发送? |
| | | 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 GB28181 |
| | | if (pthis->m_GB28181_Enable) { |
| | | for (auto &item : pthis->m_controllers_videoCapElem) { |
| | | item.second->SetVideoMinMaxSeconds(cut_min_duration, cut_max_duration); |
| | | } |
| | | } else { |
| | | for (auto &item : pthis->m_controllers) { |
| | | item.second->SetVideoMinMaxSeconds(cut_min_duration, cut_max_duration); |
| | | } |
| | | } |
| | | } else if (itor_json.name() == "cam_edit") { |
| | | string 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()) { |
| | | INFO("cam add is " << cfg_val["str_addr"].asString()); |
| | | pthis->addCamera(cam_idx, "GB28181"); |
| | | } |
| | | } else { |
| | | if (pthis->m_controllers.find(cam_idx) != pthis->m_controllers.end()) { |
| | | std::string rtsp_url = rtspAddrBuild(cfg_val["str_ip"].asString(), 554, |
| | | cfg_val["str_username"].asString(), |
| | | cfg_val["str_password"].asString(), |
| | | cfg_val["str_brand"].asString()); |
| | | INFO("cam add is " << cfg_val["str_addr"].asString()); |
| | | pthis->addCamera(cam_idx, rtsp_url); |
| | | } |
| | | } |
| | | } else if (itor_json.name() == "cam_del") { |
| | | string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | if (pthis->m_GB28181_Enable) { |
| | | pthis->removeCamera(cam_idx); |
| | | } else { |
| | | pthis->removeCamera(cam_idx); |
| | | } |
| | | } |
| | | } else { |
| | | DBG("itor value is not string "); |
| | | continue; |
| | | } |
| | | } |
| | | } else { |
| | | ERR("Error Message!!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | //初始化函数 |
| | | void RtspAnalysManager::init() { |
| | | // INFO("MYH DEBUG HERE") |