|
@@ -845,42 +845,47 @@ void SPAServer::threadRoomCamera()
|
|
|
*
|
|
|
* @param pRAInfo 传入房间ID和算法ID
|
|
|
*/
|
|
|
-void SPAServer::threadActPersonWork(RoomActionInfo* RAInfo)
|
|
|
+void SPAServer::threadActPersonWork(FuncActionInfo* RFAInfo)
|
|
|
{
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "开启人员在岗识别线程,RoomID:{} ,Action:{}", RAInfo->RoomID, RAInfo->ActionID);
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "开启 {} 线程,ChannelID:{} ,", RFAInfo->strFunctionName, RFAInfo->ChannelID);
|
|
|
/* 创建读取Redis的实例 */
|
|
|
std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
|
|
|
/* 局部变量 */
|
|
|
- std::shared_ptr<RoomActionInfo> pRAInfo = std::make_shared<RoomActionInfo>();
|
|
|
- *pRAInfo = *RAInfo;
|
|
|
- int CameraCount = pRAInfo->listCameraID.size();
|
|
|
- /* 摄像机数目小于0就退出线程 */
|
|
|
+ std::shared_ptr<FuncActionInfo> pRFAInfo = std::make_shared<FuncActionInfo>();
|
|
|
+ *pRFAInfo = *RFAInfo;
|
|
|
+
|
|
|
while (m_threadRunning)
|
|
|
{
|
|
|
- /* 更新算法关联的摄像机个数 */
|
|
|
- pRAInfo->listCameraID.clear();
|
|
|
- updateRoomActionCameraCount(pRAInfo);
|
|
|
- CameraCount = pRAInfo->listCameraID.size();
|
|
|
- if(CameraCount == 0)
|
|
|
+ /* 更新线程信息 */
|
|
|
+ updateFuncInfo(pRFAInfo);
|
|
|
+ if(pRFAInfo->appFunction == AppFunction::APP_NONE)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 读取Redis数据 */
|
|
|
- for(const auto& camID : pRAInfo->listCameraID)
|
|
|
+ for(const auto& RoomInfo : pRFAInfo->listRoomCamActInfo)
|
|
|
{
|
|
|
- std::string strKey = std::to_string(camID) + ":" + pRAInfo->ActionID;
|
|
|
- std::string strRetValue;
|
|
|
- if(!fromRedis->getRedisString(strKey, strRetValue))
|
|
|
+ for(const auto& it : RoomInfo.mapCameraAction)
|
|
|
{
|
|
|
- SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
|
|
|
- continue;
|
|
|
+ std::string strKey = std::to_string(it.first) + ":" + it.second;
|
|
|
+ std::string strRetValue;
|
|
|
+ if(!fromRedis->getRedisString(strKey, strRetValue))
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ /* 解析数据 */
|
|
|
+ AlarmInfo alarmInfo;
|
|
|
+ parseRedisData(strRetValue, alarmInfo);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- /* 解析数据 */
|
|
|
- AlarmInfo alarmInfo;
|
|
|
- parseRedisData(strRetValue, alarmInfo);
|
|
|
}
|
|
|
}
|
|
|
+ setThreadState(pRFAInfo, RunTimeState::RUN_STATE_STOP);
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "关闭 {} 线程,ChannelID:{}", pRFAInfo->strFunctionName, pRFAInfo->ChannelID);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -894,51 +899,95 @@ void SPAServer::threadActPersonWork(RoomActionInfo* RAInfo)
|
|
|
*
|
|
|
* @param RAInfo 传入的房间ID和算法ID
|
|
|
*/
|
|
|
-void SPAServer::threadActRegionalPersonnelDetection(RoomActionInfo* RAInfo)
|
|
|
+void SPAServer::threadActRegionalPersonnelDetection(FuncActionInfo* RFAInfo)
|
|
|
{
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "开启区域人员检测线程,RoomID:{} ,Action:{}", RAInfo->RoomID, RAInfo->ActionID);
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "开启 {} 线程,ChannelID:{} ,", RFAInfo->strFunctionName, RFAInfo->ChannelID);
|
|
|
/* 创建读取Redis的实例 */
|
|
|
std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
|
|
|
/* 局部变量 */
|
|
|
- std::shared_ptr<RoomActionInfo> pRAInfo = std::make_shared<RoomActionInfo>();
|
|
|
+ std::shared_ptr<FuncActionInfo> pRFAInfo = std::make_shared<FuncActionInfo>();
|
|
|
/* 创建写入数据库实例 */
|
|
|
std::shared_ptr<ToEQMDataBase> toEQMDataBase = std::make_shared<ToEQMDataBase>();
|
|
|
- *pRAInfo = *RAInfo;
|
|
|
- int CameraCount = 0;
|
|
|
+ *pRFAInfo = *RFAInfo;
|
|
|
/* 保存每个摄像机的报警信息 */
|
|
|
std::shared_ptr<std::list<AlarmInfo>> pListAlarmInfo = std::make_shared<std::list<AlarmInfo>>();
|
|
|
+ /* 保存人员计数的信息 */
|
|
|
+ std::shared_ptr<ListRoomFaceInfo> pListRoomFaceInfo = std::make_shared<ListRoomFaceInfo>();
|
|
|
|
|
|
while (m_threadRunning)
|
|
|
{
|
|
|
- /* 更新算法关联的摄像机个数 */
|
|
|
- pRAInfo->listCameraID.clear();
|
|
|
- updateRoomActionCameraCount(pRAInfo);
|
|
|
- CameraCount = pRAInfo->listCameraID.size();
|
|
|
- /* 摄像机数目等于0就退出线程 */
|
|
|
- if(CameraCount == 0)
|
|
|
+ /* 更新线程信息 */
|
|
|
+ updateFuncInfo(pRFAInfo);
|
|
|
+ if(pRFAInfo->appFunction == AppFunction::APP_NONE)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 读取Redis数据 */
|
|
|
- for(const auto& camID : pRAInfo->listCameraID)
|
|
|
+ pListAlarmInfo->clear();
|
|
|
+ for(const auto& RoomInfo : pRFAInfo->listRoomCamActInfo)
|
|
|
{
|
|
|
- std::string strKey = std::to_string(camID) + ":" + pRAInfo->ActionID;
|
|
|
- std::string strRetValue;
|
|
|
- if(!fromRedis->getRedisString(strKey, strRetValue))
|
|
|
+ for(const auto& it : RoomInfo.mapCameraAction)
|
|
|
{
|
|
|
- SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
- continue;
|
|
|
+ std::string strKey = std::to_string(it.first) + ":" + it.second;
|
|
|
+ std::string strRetValue;
|
|
|
+ if(!fromRedis->getRedisString(strKey, strRetValue))
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ /* 解析数据 */
|
|
|
+ AlarmInfo alarmInfo;
|
|
|
+ parseRedisData(strRetValue, alarmInfo);
|
|
|
+ /* 判断事件的时效性,超过多少秒不更新就可能是超脑挂了 */
|
|
|
+ if(isEventTimeVaild(alarmInfo.EventTime))
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_WARN(m_logger, "Redis Key:{} 数据长时间没有更新,EventTime:{}",strKey, alarmInfo.EventTime);
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ pListAlarmInfo->push_back(alarmInfo);
|
|
|
}
|
|
|
- /* 解析数据 */
|
|
|
- AlarmInfo alarmInfo;
|
|
|
- parseRedisBaseData(strRetValue, alarmInfo);
|
|
|
- parseRedisBBoxesData(strRetValue, alarmInfo);
|
|
|
}
|
|
|
+
|
|
|
+ /* 处理数据,将报警信息的人脸信息取出来,放入到人脸信息列表中 */
|
|
|
+ for(auto& alarmInfo : *pListAlarmInfo)
|
|
|
+ {
|
|
|
+ /* 添加到人脸列表中,会自动去重,自动创建对应的频道和房间信息 */
|
|
|
+ pListRoomFaceInfo->addRoomFaceInfo(alarmInfo);
|
|
|
+ }
|
|
|
+ /* 计算人脸个数,并判断是否需要写入数据库 */
|
|
|
+ QDateTime now = QDateTime::currentDateTime();
|
|
|
+ for(auto it = pListRoomFaceInfo->listRoomFaceInfo.begin(); it != pListRoomFaceInfo->listRoomFaceInfo.end(); )
|
|
|
+ {
|
|
|
+ if(it->MaxNum < it->listPersonInfo.size())
|
|
|
+ {
|
|
|
+ it->MaxNum = it->listPersonInfo.size();
|
|
|
+ }
|
|
|
+ if(it->MinNum > it->listPersonInfo.size())
|
|
|
+ {
|
|
|
+ it->MinNum = it->listPersonInfo.size();
|
|
|
+ }
|
|
|
+ /* 判断是否需要写入数据库,超过设置的时间就写入,默认是600秒 */
|
|
|
+ if(now.toSecsSinceEpoch() - it->StartTime.toSecsSinceEpoch() > g_config.AppUpdateOnWorkTimeInterval)
|
|
|
+ {
|
|
|
+ /* 写入数据库 */
|
|
|
+ if(toEQMDataBase->insertOnWorkInfo(*it))
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "ChannelID:{}, RoomID:{}, 在岗信息写入数据库成功, StartTime", it->ChannelID, it->RoomID, it->StartTime.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
+ /* 删除这条信息 */
|
|
|
+ it = pListRoomFaceInfo->listRoomFaceInfo.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ++it;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- setThreadState(pRAInfo, RunTimeState::RUN_STATE_STOP);
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "关闭区域人员检测线程,RoomID:{} ,Action:{}", RAInfo->RoomID, RAInfo->ActionID);
|
|
|
+ setThreadState(pRFAInfo, RunTimeState::RUN_STATE_STOP);
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "关闭 {} 线程,ChannelID:{}", pRFAInfo->strFunctionName, pRFAInfo->ChannelID);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1159,21 +1208,6 @@ bool SPAServer::insertCameraToAction(RoomActionInfo* pRAInfo, std::list<RoomCame
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-/* 更新房间、算法需要的摄像机个数,从内存中更新 */
|
|
|
-bool SPAServer::updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAInfo)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> look(m_mutexRunRAI);
|
|
|
- for(auto& it : m_runListRoomActionInfo.getData())
|
|
|
- {
|
|
|
- if((it->RoomID == pRAInfo->RoomID) && (it->ActionID == pRAInfo->ActionID))
|
|
|
- {
|
|
|
- it->listCameraID = pRAInfo->listCameraID;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* @brief 功能线程更新功能信息,这里是从内存中的数组里获取
|