| | |
| | | //初始化函数 |
| | | void RtspAnalysManager::init() { |
| | | INFO("MYH DEBUG HERE") |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | //设置视频的最长和最短时间间隔 |
| | | 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) { |
| | | int startCamNO = appPref.getIntData("CamStart") * appPref.getIntData("CamStep"); |
| | | int CamCount = appPref.getIntData("CamStep"); |
| | | INFO("StartCamNO: " << startCamNO << " CamStep: " << CamCount); |
| | | auto itor = lst.begin(); |
| | | m_GB28181_Enable = appPref.getIntData("GB28181_Enable"); |
| | | //#todo GB28181 |
| | | if (m_GB28181_Enable) { |
| | | auto lst = m_lDBTool->searchCamDevTableByType(1); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | if (startCamNO >= lst.size()) { |
| | | ERR("startCamNO > lst.size()"); |
| | | return; |
| | | //设置视频的最长和最短时间间隔 |
| | | 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(); |
| | | 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()); |
| | | addCamera(t_camIdex, rtsp_url); |
| | | sleep(1); |
| | | } |
| | | } else { |
| | | ERR("searchCamDevTableByType size is 0"); |
| | | } |
| | | |
| | | for (int i = 0; i < startCamNO; i++) { |
| | | } else { |
| | | auto lst = m_lDBTool->searchCamDevTableByType(0); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | 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()); |
| | | INFO("JumpCam: " << t_camIdex << " URL: " << rtsp_url); |
| | | itor++; |
| | | } |
| | | //设置视频的最长和最短时间间隔 |
| | | 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) { |
| | | int startCamNO = appPref.getIntData("CamStartNO"); |
| | | int CamCount = appPref.getIntData("CamEndNO") - appPref.getIntData("CamStartNO") + 1; |
| | | INFO("StartCamNO: " << startCamNO << " CamCount: " << CamCount); |
| | | auto itor = lst.begin(); |
| | | |
| | | for (int i = 0; i < CamCount; i++) { |
| | | if (itor == lst.end()) { |
| | | ERR("itor == lst.end()"); |
| | | if (startCamNO >= lst.size()) { |
| | | ERR("startCamNO > lst.size()"); |
| | | 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()); |
| | | INFO("cam add is " << itor->str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, rtsp_url); |
| | | itor++; |
| | | } |
| | | for (int i = 0; i < startCamNO; i++) { |
| | | |
| | | 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()); |
| | | INFO("JumpCam: " << t_camIdex << " URL: " << rtsp_url); |
| | | 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()); |
| | | INFO("cam add is " << itor->str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, rtsp_url); |
| | | itor++; |
| | | } |
| | | |
| | | // for (auto item : lst) |
| | | // { |
| | |
| | | // addCamera(t_camIdex, rtsp_url); |
| | | // |
| | | // } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } else { |
| | | ERR("searchCamDevTableByType size is 0"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | RtspAnalysManager::~RtspAnalysManager() { |
| | |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | INFO("Delete Controller: " << controller.first); |
| | | delete controller.second; |
| | | } |
| | | m_controllers_videoCapElem.clear(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return -1 添加失败,0 添加成功 |
| | | */ |
| | | int RtspAnalysManager::addCamera(const std::string &index, const std::string &rtsp) { |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | if (m_controllers.find(index) == m_controllers.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | if (m_GB28181_Enable) { |
| | | //#todo |
| | | // why search lst ? |
| | | // auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | //#todo end |
| | | if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | m_imgRedisCRwLock.unlock(); |
| | | |
| | | //VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1) |
| | | // m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( |
| | | // const_cast<string &>(index), |
| | | // 25, 0, 0, this); |
| | | |
| | | m_controllers_videoCapElem[index] = new PushStreamAppPipeController(const_cast<string &>(index), |
| | | 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(); |
| | | m_currentCount++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | |
| | | m_controllers[index] = new RtspCaptureElement(rtsp, index, 25, 3000, 0, this); |
| | | m_controllers[index]->start(); |
| | | m_controllers[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration); |
| | | m_currentCount++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | // why search lst ? |
| | | // auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | if (m_controllers.find(index) == m_controllers.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | |
| | | 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++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | int RtspAnalysManager::removeCamera(const std::string &index) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_controllers.find(index) == m_controllers.end())return -1; |
| | | auto controller = m_controllers[index]; |
| | | controller->stop(); |
| | | controller->wait(); |
| | | delete controller; |
| | | m_controllers.erase(index); |
| | | m_currentCount--; |
| | | if (m_GB28181_Enable) { |
| | | if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end())return -1; |
| | | auto controller = m_controllers_videoCapElem[index]; |
| | | controller->stop(); |
| | | controller->wait(); |
| | | delete controller; |
| | | m_controllers_videoCapElem.erase(index); |
| | | m_currentCount--; |
| | | } else { |
| | | if (m_controllers.find(index) == m_controllers.end())return -1; |
| | | auto controller = m_controllers[index]; |
| | | controller->stop(); |
| | | controller->wait(); |
| | | delete controller; |
| | | m_controllers.erase(index); |
| | | m_currentCount--; |
| | | } |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | auto imgRedis = m_imgRedisControllers[index]; |
| | | imgRedis->stop(); |
| | | imgRedis->wait(); |
| | | delete imgRedis; |
| | | m_imgRedisControllers.erase(index); |
| | | m_imgRedisCRwLock.unlock(); |
| | | INFO("MYH DEBUG HERE"); |
| | | return 0; |
| | | } |
| | |
| | | */ |
| | | int RtspAnalysManager::removeAll() { |
| | | INFO("MYH DEBUG HERE"); |
| | | for (auto controller: m_controllers) { |
| | | controller.second->stop(); |
| | | |
| | | if (m_GB28181_Enable) { |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | controller.second->stop(); |
| | | } |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers_videoCapElem.clear(); |
| | | } else { |
| | | for (auto controller: m_controllers) { |
| | | controller.second->stop(); |
| | | } |
| | | for (auto controller: m_controllers) { |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | } |
| | | for (auto controller: m_controllers) { |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | INFO("MYH DEBUG HERE"); |
| | | |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | for (auto controller: m_imgRedisControllers) { |
| | | controller.second->stop(); |
| | | } |
| | |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | m_imgRedisControllers.clear(); |
| | | m_imgRedisCRwLock.unlock(); |
| | | |
| | | |
| | | m_currentCount = 0; |
| | |
| | | return m_currentCount; |
| | | } |
| | | |
| | | |
| | | //录取视频的RPC的接口函数 |
| | | ::std::string RtspAnalysManager::recordVideo(const ::std::string &name, const ::Ice::Current &) { |
| | | INFO("Record Video For: " << name); |
| | | ImageName_s_t nameSt = ImageName_s_t::fromString(name); |
| | | if (nameSt.Valid()) { |
| | | auto pCaptureElem = m_controllers.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers.end()) { |
| | | pCaptureElem->second->SaveVideo(name); |
| | | if (m_GB28181_Enable) { |
| | | auto pCaptureElem = m_controllers_videoCapElem.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers_videoCapElem.end()) { |
| | | //#todo ~~~~~~!!!!!!! 这里有bug 需要放开调试 |
| | | pCaptureElem->second->SaveVideo(name); |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | } |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | auto pCaptureElem = m_controllers.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers.end()) { |
| | | pCaptureElem->second->SaveVideo(name); |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | } |
| | | } |
| | | } else { |
| | | ERR("Record Video Failed:Name Not Valid Name: " << name); |
| | |
| | | |
| | | //保存视频到RtspImageRedis的队列,由RtspCaptureElement调用 |
| | | bool RtspAnalysManager::SaveImageToRedis(const std::string &camId, const std::string &imageName, const cv::Mat &img) { |
| | | INFO("MYH DEBUG HERE"); |
| | | 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); |
| | |
| | | } else { |
| | | ERR("Save Failed Cam: " << camId << " ImageKey: " << imageName); |
| | | } |
| | | // m_imgRedisCRwLock.unlock(); |
| | | INFO("MYH DEBUG HERE"); |
| | | return true; |
| | | } |