| | |
| | | } |
| | | |
| | | RtspAnalysElement::RtspAnalysElement(LDBTool *_dbTool) : m_lDBTool(_dbTool), maxCount(50), currentCount(0) { |
| | | init(); |
| | | resetFdfs(); |
| | | init(); |
| | | { |
| | | // std::thread httpServer([&]() { |
| | | // //#todo port |
| | |
| | | } |
| | | |
| | | void RtspAnalysElement::init() { |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | auto lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | m_GB28181_Enable = appPref.getIntData("GB28181_Enable"); |
| | | |
| | | if (lst.size() > 0) { |
| | | Json::Value json; |
| | | for (auto item : lst) { |
| | | string t_camIdex = item.str_cam_dev_id.toStdString(); |
| | | // std::string rtsp_url; |
| | | // if (item.str_brand.toStdString() == "haikang") { |
| | | // //调用rtsp流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream |
| | | // int port = 554;//TODO |
| | | // string username =; |
| | | // DBG("username:" << username << "!!!"); |
| | | // string passwd = item.str_password.toStdString(); |
| | | // string ip = item.str_ip.toStdString(); |
| | | // |
| | | // rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) + |
| | | // "/h264/ch1/main/av_stream"; |
| | | // |
| | | // }//else if(){} |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | std::string rtsp_url = rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(), |
| | | item.str_password.toStdString(), item.str_brand.toStdString()); |
| | | //#todo GB28181 |
| | | if (m_GB28181_Enable) { |
| | | auto lst = m_lDBTool->searchCamDevTableByType(1); |
| | | |
| | | 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) { |
| | | // Json::Value json; |
| | | for (auto &item : lst) { |
| | | std::string t_camIdex = item.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()); |
| | | SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id); |
| | | for (auto &rule:ruleMap) { |
| | | |
| | | // lRec.str_det_thr = rec.value("det_thr").toString(); |
| | | // lRec.str_cmp_thr = rec.value("cmp_thr").toString(); |
| | | auto en_sdk = m_lDBTool->searchCamSdkTableByCamId(item.str_cam_dev_id); |
| | | vector<int> sdkVec = chnString2Vec(en_sdk.str_sdks.toStdString()); |
| | | rule.second.strAddr = item.str_addr; |
| | | rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); |
| | | |
| | | //设置检测得分 |
| | | // std::string s_d = str_det_thr; |
| | | // std::string s_c = str_cmp_thr; |
| | | vector<int> sdkDetCoVec = chnString2Vec(en_sdk.str_det_thr.toStdString()); |
| | | vector<int> sdkComCoVec = chnString2Vec(en_sdk.str_cmp_thr.toStdString()); |
| | | if (rule.second.nSdkType == PerStaticSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (75 + 25 * temp) / 100; |
| | | |
| | | int camId=item.str_cam_dev_id.toInt(); |
| | | int t_size = sdkVec.size(); |
| | | for (int i = 0; i < t_size; i++) { |
| | | switch (sdkVec[i]) { |
| | | case 1: { |
| | | // INFO("face.enable"); |
| | | json["face.enable"] = "1"; |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "face.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "face.cmp"); |
| | | DBG(" TESTCODE " << sdkDetCoVec[i] << " " << sdkComCoVec[i]); |
| | | |
| | | break; |
| | | } else if (rule.second.nSdkType != FaceSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (5 + 90 * temp) / 100; |
| | | } |
| | | case 2: { |
| | | DBG("XX.enable " << "1"); |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "XX.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "XX.cmp"); |
| | | break; |
| | | } |
| | | case 3: { |
| | | // INFO("face.enable"); |
| | | json["yolo.enable"] = "1"; |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "yolo.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "yolo.cmp"); |
| | | break; |
| | | } |
| | | case 4: { |
| | | |
| | | json["perimeter.enable"] = "1"; |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "perimeter.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "perimeter.cmp"); |
| | | setDataByType(4,json,camId); |
| | | break; |
| | | } |
| | | case 5: { |
| | | |
| | | json["crowd.enable"] = "1"; |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "crowd.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "crowd.cmp"); |
| | | setDataByType(5,json,camId); |
| | | break; |
| | | } |
| | | case 6: { |
| | | |
| | | json["keepRight.enable"] = "1"; |
| | | SETSCORE(sdkDetCoVec, i, t_camIdex + "keepRight.det"); |
| | | SETSCORE(sdkComCoVec, i, t_camIdex + "keepRight.cmp"); |
| | | setDataByType(6,json,camId); |
| | | break; |
| | | } |
| | | DBG("fSensitivity" << rule.second.fSensitivity); |
| | | } |
| | | appPref.setStringData(t_camIdex + "rtsp", rtsp_url); |
| | | // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString()); |
| | | // json["rtsp"] = rtsp_url; |
| | | // json["addr"] = item.str_addr.toStdString(); |
| | | |
| | | INFO("cam add is " << item.str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, ruleMap); |
| | | } |
| | | json["rtsp"] = rtsp_url; |
| | | json["addr"] = item.str_addr.toStdString(); |
| | | |
| | | INFO("cam add is " << item.str_addr.toStdString()); |
| | | |
| | | // DBG(t_camIdex); |
| | | |
| | | appPref.getLongData("gpu.index"); |
| | | addCamera(t_camIdex, json.toStyledString()); |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | |
| | | } else { |
| | | |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | |
| | | 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) { |
| | | Json::Value json; |
| | | int startCamNO = appPref.getIntData("CamStart") * appPref.getIntData("CamStep"); |
| | | int CamCount = appPref.getIntData("CamStep"); |
| | | 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 = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(), |
| | | itor->str_password.toStdString(), itor->str_brand.toStdString()); |
| | | SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(itor->str_cam_dev_id); |
| | | for (auto &rule:ruleMap) { |
| | | |
| | | rule.second.strAddr = itor->str_addr; |
| | | rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(itor->str_cam_dev_id, rule.first); |
| | | |
| | | if (rule.second.nSdkType == PerStaticSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (75 + 25 * temp) / 100; |
| | | |
| | | } else if (rule.second.nSdkType != FaceSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (5 + 90 * temp) / 100; |
| | | } |
| | | // if (rule.second.nThreshold < 5 ) |
| | | // { |
| | | // rule.second.fSensitivity=0.95; |
| | | // } |
| | | // else if(rule.second.nThreshold > 95) |
| | | // { |
| | | // rule.second.fSensitivity=0.05; |
| | | // } |
| | | // else |
| | | // { |
| | | // rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100; |
| | | // } |
| | | |
| | | DBG("fSensitivity" << rule.second.fSensitivity); |
| | | } |
| | | appPref.setStringData(t_camIdex + "rtsp", rtsp_url); |
| | | // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString()); |
| | | json["rtsp"] = rtsp_url; |
| | | // json["addr"] = item.str_addr.toStdString(); |
| | | |
| | | INFO("cam add is " << itor->str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, ruleMap); |
| | | itor++; |
| | | } |
| | | // for (auto item : lst) { |
| | | // std::string t_camIdex = item.str_cam_dev_id.toStdString(); |
| | | // std::string rtsp_url = rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(), |
| | | // item.str_password.toStdString(), item.str_brand.toStdString()); |
| | | // SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id); |
| | | // for (auto &rule:ruleMap) { |
| | | // |
| | | // rule.second.strAddr = item.str_addr; |
| | | // rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); |
| | | // |
| | | // if(rule.second.nSdkType == PerStaticSdk) |
| | | // { |
| | | // float temp=1-(float)(rule.second.nThreshold)/100; |
| | | // rule.second.fSensitivity=(75+25*temp)/100; |
| | | // |
| | | // } |
| | | // else if(rule.second.nSdkType != FaceSdk) |
| | | // { |
| | | // float temp=1-(float)(rule.second.nThreshold)/100; |
| | | // rule.second.fSensitivity=(5+90*temp)/100; |
| | | // } |
| | | //// if (rule.second.nThreshold < 5 ) |
| | | //// { |
| | | //// rule.second.fSensitivity=0.95; |
| | | //// } |
| | | //// else if(rule.second.nThreshold > 95) |
| | | //// { |
| | | //// rule.second.fSensitivity=0.05; |
| | | //// } |
| | | //// else |
| | | //// { |
| | | //// rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100; |
| | | //// } |
| | | // |
| | | // DBG("fSensitivity" << rule.second.fSensitivity); |
| | | // } |
| | | // appPref.setStringData(t_camIdex + "rtsp", rtsp_url); |
| | | // // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString()); |
| | | // json["rtsp"] = rtsp_url; |
| | | // // json["addr"] = item.str_addr.toStdString(); |
| | | // |
| | | // INFO("cam add is " << item.str_addr.toStdString()); |
| | | // |
| | | // addCamera(t_camIdex, ruleMap); |
| | | // } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | RtspAnalysElement::~RtspAnalysElement() { |
| | | for (auto controller: controllers) { |
| | |
| | | controllers.clear(); |
| | | } |
| | | |
| | | int RtspAnalysElement::addCamera(const std::string &index, const std::string &json) { |
| | | int RtspAnalysElement::addCamera(const std::string &index, const std::map<int, SdkRule> &sdkRuleMap) { |
| | | if (controllers.find(index) == controllers.end()) { |
| | | if (currentCount >= maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | } |
| | | Json::Reader reader; |
| | | Json::Value value; |
| | | |
| | | if (reader.parse(json, value)) { |
| | | controllers[index] = new AppPipeController(index, sdkRuleMap, true); |
| | | controllers[index]->setfdfsClient(&fdfsClient); |
| | | controllers[index]->start(); |
| | | currentCount++; |
| | | return 0; |
| | | |
| | | controllers[index] = new AppPipeController(index, std::move(value), true); |
| | | // controllers[index] = new AppPipeController(index, std::move(value), false); |
| | | |
| | | controllers[index]->setfdfsClient(&fdfsClient); |
| | | controllers[index]->start(); |
| | | currentCount++; |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } else { |
| | | removeCamera(index); |
| | | DBG("removeCamera " << index) |
| | | return addCamera(index, json); |
| | | return addCamera(index, sdkRuleMap); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | return result; |
| | | } |
| | | void RtspAnalysElement::setDataByType(int type,Json::Value& json,int camId) |
| | | { |
| | | switch (type) { |
| | | case 4: |
| | | { |
| | | auto rule=m_lDBTool->searchPerimeterRuleByCamId(camId); |
| | | json["perimeter.area"]=rule.strAreas.toStdString(); |
| | | json["perimeter.num"]=rule.nAlarmPeopleNum; |
| | | json["perimeter.delay"]=rule.nTriggerDelay; |
| | | json["perimeter.tolerance"]=rule.nTriggertolerance; |
| | | break; |
| | | } |
| | | case 5: |
| | | { |
| | | auto rule=m_lDBTool->searchCrowdRuleByCamId(camId); |
| | | json["crowd.area"]=rule.strAreas.toStdString(); |
| | | json["crowd.num"]=rule.nAlarmPeopleNum; |
| | | json["crowd.delay"]=rule.nTriggerDelay; |
| | | json["crowd.tolerance"]=rule.nTriggertolerance; |
| | | break; |
| | | } |
| | | case 6: |
| | | { |
| | | auto rule=m_lDBTool->searchActRuleByCamId(camId); |
| | | json["keepRight.leftArea"]=rule.strAreas.toStdString(); |
| | | json["keepRight.leftLine"]=rule.strLine.toStdString(); |
| | | json["keepRight.rightArea"]=rule.strExAreas.toStdString(); |
| | | json["keepRight.rightLine"]=rule.strExLine.toStdString(); |
| | | json["keepRight.delay"]=rule.nTriggerDelay; |
| | | json["keepRight.tolerance"]=rule.nTriggertolerance; |
| | | break; |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //void RtspAnalysElement::setDataByType(Json::Value& json,const SdkRule& rule) |
| | | //{ |
| | | // std::string camId=rule.strCamId.toStdString(); |
| | | // sdkRuleMap[rule.nSdkType].weekRuleVec=m_lDBTool->searchCameraWeekRuleByCamId(rule.strCamId,rule.nSdkType); |
| | | // switch (rule.nSdkType) |
| | | // { |
| | | // case FaceSdk: |
| | | // { |
| | | // json["face.enable"] = "1"; |
| | | |
| | | // appPref.setFloatData(camId+"face.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"face.cmp",rule.nThreshold); |
| | | |
| | | |
| | | |
| | | // break; |
| | | // } |
| | | // case CarSdk: |
| | | // { |
| | | // // DBG("XX.enable " << "1"); |
| | | |
| | | // appPref.setFloatData(camId+"xx.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"xx.cmp",rule.nThreshold); |
| | | |
| | | // break; |
| | | // } |
| | | // case YoloSdk: |
| | | // { |
| | | // json["yolo.enable"] = "1"; |
| | | // appPref.setFloatData(camId+"yolo.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"yolo.cmp",rule.nThreshold); |
| | | |
| | | // break; |
| | | // } |
| | | // case PerimeterSdk: |
| | | // { |
| | | // // auto rule=m_lDBTool->searchPerimeterRuleByCamId(camId); |
| | | // json["perimeter.enable"] = 1; |
| | | // json["perimeter.area"]=rule.strAreas.toStdString(); |
| | | // json["perimeter.num"]=rule.nAlarmNumLowerLimit; |
| | | |
| | | // json["perimeter.delay"]=rule.nTriggerDelay; |
| | | // json["perimeter.tolerance"]=rule.nTriggerTolerance; |
| | | // appPref.setFloatData(camId+"perimeter.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"perimeter.cmp",rule.nThreshold); |
| | | |
| | | |
| | | // break; |
| | | // } |
| | | // case CrowdSdk: |
| | | // { |
| | | // json["crowd.enable"] = 1; |
| | | // json["crowd.area"]=rule.strAreas.toStdString(); |
| | | // json["crowd.num"]=rule.nAlarmNumLowerLimit; |
| | | // json["crowd.delay"]=rule.nTriggerDelay; |
| | | // json["crowd.tolerance"]=rule.nTriggerTolerance; |
| | | // appPref.setFloatData(camId+"crowd.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"crowd.cmp",rule.nThreshold); |
| | | |
| | | // break; |
| | | // } |
| | | // case KeepRightSdk: |
| | | // { |
| | | // json["keepRight.enable"] = 1; |
| | | // json["keepRight.leftArea"]=rule.strAreas.toStdString(); |
| | | // json["keepRight.leftLine"]=rule.strLine.toStdString(); |
| | | // json["keepRight.rightArea"]=rule.strExAreas.toStdString(); |
| | | // json["keepRight.rightLine"]=rule.strExLine.toStdString(); |
| | | // json["keepRight.delay"]=rule.nTriggerDelay; |
| | | // json["keepRight.tolerance"]=rule.nTriggerTolerance; |
| | | // appPref.setFloatData(camId+"keepRight.det",rule.nQuality); |
| | | // appPref.setFloatData(camId+"keepRight.cmp",rule.nThreshold); |
| | | // break; |
| | | // } |
| | | // default: |
| | | // break; |
| | | // } |
| | | //} |