|
@@ -0,0 +1,974 @@
|
|
|
+#include "GlobalFuncThread.h"
|
|
|
+
|
|
|
+#include "spdlog/spdlog.h"
|
|
|
+
|
|
|
+FuncThreadInfo::FuncThreadInfo()
|
|
|
+{
|
|
|
+ ChannelID = -1;
|
|
|
+ strChannelName = "";
|
|
|
+ appFunction = AppFunction::APP_NONE;
|
|
|
+ RunState = RunTimeState::RUN_STATE_NONE;
|
|
|
+ strFunctionName = "";
|
|
|
+ StartTime = QDateTime::currentDateTime();
|
|
|
+ EndTime = QDateTime::currentDateTime();
|
|
|
+ listRoomCamActInfo.clear();
|
|
|
+ mapCameraName.clear();
|
|
|
+}
|
|
|
+
|
|
|
+FuncThreadInfo::~FuncThreadInfo()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+FuncThreadInfo& FuncThreadInfo::operator=(FuncThreadInfo& other)
|
|
|
+{
|
|
|
+ if(this != &other)
|
|
|
+ {
|
|
|
+ ChannelID = other.ChannelID;
|
|
|
+ strChannelName = other.strChannelName;
|
|
|
+ appFunction = other.appFunction;
|
|
|
+ RunState = other.RunState;
|
|
|
+ strFunctionName = other.strFunctionName;
|
|
|
+ StartTime = other.StartTime;
|
|
|
+ EndTime = other.EndTime;
|
|
|
+ listRoomCamActInfo = other.listRoomCamActInfo;
|
|
|
+ mapCameraName = other.mapCameraName;
|
|
|
+ }
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 添加算法信息,这里不能直接创建房间,需要先判断有没有已有的房间,因为有的应用功能可能会包含多个房间
|
|
|
+ * 已经提前被创建过了
|
|
|
+ *
|
|
|
+ * @param info
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+bool FuncThreadInfo::addActionInfo(const ActionInfo& info)
|
|
|
+{
|
|
|
+ /* 根据此类的功能,添加算法信息 */
|
|
|
+ if(appFunction == AppFunction::APP_NONE)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* 将其添加到对应的房间 */
|
|
|
+ bool isFind = false;
|
|
|
+ for(auto& roomInfo : listRoomCamActInfo)
|
|
|
+ {
|
|
|
+ if((roomInfo.RoomID == info.RoomID) && (roomInfo.RoomType == info.RoomType))
|
|
|
+ {
|
|
|
+ isFind = true;
|
|
|
+ // roomInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
|
|
|
+ roomInfo.addCameraAction(info.CameraID, info.ActionID);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 没找到这个房间,就创建 */
|
|
|
+ if(!isFind)
|
|
|
+ {
|
|
|
+ RoomCamActInfo roomCamActInfo;
|
|
|
+ roomCamActInfo.RoomID = info.RoomID;
|
|
|
+ roomCamActInfo.RoomType = info.RoomType;
|
|
|
+ roomCamActInfo.strRoomName = info.strRoomName;
|
|
|
+ roomCamActInfo.addCameraAction(info.CameraID, info.ActionID);
|
|
|
+ listRoomCamActInfo.push_back(roomCamActInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+/* 清空算法信息 */
|
|
|
+void FuncThreadInfo::clearActionList()
|
|
|
+{
|
|
|
+ listRoomCamActInfo.clear();
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取摄像机名称 */
|
|
|
+std::string FuncThreadInfo::getCameraName(int CameraID)
|
|
|
+{
|
|
|
+ auto it = mapCameraName.find(CameraID);
|
|
|
+ if(it != mapCameraName.end())
|
|
|
+ {
|
|
|
+ return it->second;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
|
|
|
+ * 这里是添加应用功能和时间段信息
|
|
|
+ *
|
|
|
+ * @param func
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+bool ListFuncActInfo::addFuncThreadInfo(const AppAndTimeInfo& func)
|
|
|
+{
|
|
|
+ if(func.AppType == 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
|
|
|
+ for(int i = 0; i < 8; ++i)
|
|
|
+ {
|
|
|
+ if(func.AppType & 0x01)
|
|
|
+ {
|
|
|
+ /* 查找有没有这个应用 */
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_OnWork);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_OnWork;
|
|
|
+ fa->strFunctionName = "人员在岗识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if(func.AppType & 0x02)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Contraband);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Contraband;
|
|
|
+ fa->strFunctionName = "违禁品识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x04)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Illegal);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Illegal;
|
|
|
+ fa->strFunctionName = "非法入侵检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x08)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Fatigue;
|
|
|
+ fa->strFunctionName = "疲劳检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x10)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Regional);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Regional;
|
|
|
+ fa->strFunctionName = "区域人员检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x20)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Mouse;
|
|
|
+ fa->strFunctionName = "老鼠识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x40)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_PlayPhone);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_PlayPhone;
|
|
|
+ fa->strFunctionName = "玩手机识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x80)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_NoMask);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_NoMask;
|
|
|
+ fa->strFunctionName = "未戴口罩识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x0100)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_AllDown);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_AllDown;
|
|
|
+ fa->strFunctionName = "摔倒识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
|
|
|
+ *
|
|
|
+ * @param info
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
|
|
|
+{
|
|
|
+ if(info.ActionID.empty())
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
|
|
|
+ if(info.ActionID == g_actionList.ActFace)
|
|
|
+ {
|
|
|
+ /* 人员在岗识别 */
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_OnWork);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ /* 非法入侵检测 */
|
|
|
+ pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Illegal);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 人员计数 */
|
|
|
+ else if (info.ActionID == g_actionList.ActPersonNumber)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Regional);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 违禁物品 */
|
|
|
+ else if (info.ActionID == g_actionList.ActContraband)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Contraband);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 玩手机 */
|
|
|
+ else if (info.ActionID == g_actionList.ActPlayPhone)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_PlayPhone);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 睡岗识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActSleep)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 疲劳检测 */
|
|
|
+ else if(info.ActionID == g_actionList.ActFatigueDetection)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 动物识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActAnimalDetect)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 老鼠识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActMouseDetect)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 口罩识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActMask)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_NoMask);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 清空无用的功能信息
|
|
|
+ * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
|
|
|
+ *
|
|
|
+ */
|
|
|
+void ListFuncActInfo::clearNoneFuncThreadInfo()
|
|
|
+{
|
|
|
+ for(auto it0 = listFuncThreadInfo.begin(); it0 != listFuncThreadInfo.end();)
|
|
|
+ {
|
|
|
+ if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
|
|
|
+ {
|
|
|
+ delete *it0;
|
|
|
+ it0 = listFuncThreadInfo.erase(it0);
|
|
|
+ }else {
|
|
|
+ ++it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 清空算法列表 */
|
|
|
+void ListFuncActInfo::clearActionList()
|
|
|
+{
|
|
|
+ for(auto& it0 : listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ it0->listRoomCamActInfo.clear();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 查找应用信息 */
|
|
|
+bool ListFuncActInfo::findAppFunction(const AppFunction func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if(it0->appFunction == func)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+/* 根据频率和功能查找实例 */
|
|
|
+FuncThreadInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
|
|
|
+ {
|
|
|
+ return it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 查找这个应用信息
|
|
|
+ *
|
|
|
+ * @param func
|
|
|
+ * @return FuncThreadInfo*
|
|
|
+ */
|
|
|
+FuncThreadInfo* ListFuncActInfo::findAppFunction(const FuncThreadInfo& func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
|
|
|
+ {
|
|
|
+ return it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/* ====================================================================================
|
|
|
+ * ************************ GlobalThreadInfo成员函数 *****************************
|
|
|
+ * ====================================================================================*/
|
|
|
+
|
|
|
+/* 获取线程运行标志位 */
|
|
|
+bool GlobalThreadInfo::getRunning() const
|
|
|
+{
|
|
|
+ return m_bRunning;
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置线程运行标志位 */
|
|
|
+void GlobalThreadInfo::setRunning(bool bRunning)
|
|
|
+{
|
|
|
+ m_bRunning = bRunning;
|
|
|
+}
|
|
|
+
|
|
|
+/* 手动给功能块列表加锁 */
|
|
|
+void GlobalThreadInfo::lockRunFAI()
|
|
|
+{
|
|
|
+ m_mutexRunFAI.lock();
|
|
|
+}
|
|
|
+
|
|
|
+/* 手动解锁 */
|
|
|
+void GlobalThreadInfo::unlockRunFAI()
|
|
|
+{
|
|
|
+ m_mutexRunFAI.unlock();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
|
|
|
+ * 这里是添加应用功能和时间段信息
|
|
|
+ *
|
|
|
+ * @param func
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+bool GlobalThreadInfo::addFuncThreadInfo(const AppAndTimeInfo& func)
|
|
|
+{
|
|
|
+ if(func.AppType == 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
|
|
|
+ for(int i = 0; i < 8; ++i)
|
|
|
+ {
|
|
|
+ if(func.AppType & 0x01)
|
|
|
+ {
|
|
|
+ /* 查找有没有这个应用 */
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_OnWork);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_OnWork;
|
|
|
+ fa->strFunctionName = "人员在岗识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if(func.AppType & 0x02)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Contraband);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Contraband;
|
|
|
+ fa->strFunctionName = "违禁品识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x04)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Illegal);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Illegal;
|
|
|
+ fa->strFunctionName = "非法入侵检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x08)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Fatigue;
|
|
|
+ fa->strFunctionName = "疲劳检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x10)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Regional);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Regional;
|
|
|
+ fa->strFunctionName = "区域人员检测";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x20)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_Mouse;
|
|
|
+ fa->strFunctionName = "老鼠识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x40)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_PlayPhone);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_PlayPhone;
|
|
|
+ fa->strFunctionName = "玩手机识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x80)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_NoMask);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_NoMask;
|
|
|
+ fa->strFunctionName = "未戴口罩识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ else if (func.AppType & 0x0100)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_AllDown);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ /* 更新时间信息 */
|
|
|
+ pFuncThreadInfo->StartTime = func.StartTime;
|
|
|
+ pFuncThreadInfo->EndTime = func.EndTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FuncThreadInfo* fa = new FuncThreadInfo;
|
|
|
+ fa->ChannelID = func.ChannelID;
|
|
|
+ fa->appFunction = AppFunction::APP_AllDown;
|
|
|
+ fa->strFunctionName = "摔倒识别";
|
|
|
+ fa->StartTime = func.StartTime;
|
|
|
+ fa->EndTime = func.EndTime;
|
|
|
+ m_listFuncThreadInfo.push_back(fa);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
|
|
|
+ * 根据功能需要,将算法ID加入到对应的功能中
|
|
|
+ *
|
|
|
+ * @param info
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+bool GlobalThreadInfo::addActionInfo(const ActionInfo& info)
|
|
|
+{
|
|
|
+ if(info.ActionID.empty())
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
|
|
|
+ if(info.ActionID == g_actionList.ActFace)
|
|
|
+ {
|
|
|
+ /* 人员在岗识别 */
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_OnWork);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ /* 非法入侵检测 */
|
|
|
+ pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Illegal);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 人员计数 */
|
|
|
+ else if (info.ActionID == g_actionList.ActPersonNumber)
|
|
|
+ {
|
|
|
+ /* 区域人员检测(人员计数?) */
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Regional);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ /* 非法入侵检测 */
|
|
|
+ pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Illegal);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ /* 人员在岗识别 */
|
|
|
+ pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_OnWork);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 违禁物品 */
|
|
|
+ else if (info.ActionID == g_actionList.ActContraband)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Contraband);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 玩手机 */
|
|
|
+ else if (info.ActionID == g_actionList.ActPlayPhone)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_PlayPhone);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 睡岗识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActSleep)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 疲劳检测 */
|
|
|
+ else if(info.ActionID == g_actionList.ActFatigueDetection)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 动物识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActAnimalDetect)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 老鼠识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActMouseDetect)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 口罩识别 */
|
|
|
+ else if (info.ActionID == g_actionList.ActMask)
|
|
|
+ {
|
|
|
+ auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_NoMask);
|
|
|
+ if(pFuncThreadInfo != nullptr)
|
|
|
+ {
|
|
|
+ pFuncThreadInfo->addActionInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 清空无用的功能信息
|
|
|
+ * 摄像机和算法信息为空的,或者运行状态为RUN_STATE_EXITCOMPLET,都会被清理掉
|
|
|
+ *
|
|
|
+ */
|
|
|
+void GlobalThreadInfo::clearNoneFuncThreadInfo()
|
|
|
+{
|
|
|
+ for(auto it0 = m_listFuncThreadInfo.begin(); it0 != m_listFuncThreadInfo.end();)
|
|
|
+ {
|
|
|
+ if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_EXITCOMPLET))
|
|
|
+ {
|
|
|
+ delete *it0;
|
|
|
+ it0 = m_listFuncThreadInfo.erase(it0);
|
|
|
+ }else {
|
|
|
+ ++it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 清空算法列表(直接清空房间信息) */
|
|
|
+void GlobalThreadInfo::clearActionList()
|
|
|
+{
|
|
|
+ for(auto& it0 : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ // for(auto& it1 : it0->listRoomCamActInfo)
|
|
|
+ // {
|
|
|
+ // it1.mapCameraAction.clear();
|
|
|
+ // }
|
|
|
+ it0->listRoomCamActInfo.clear();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置没有配置摄像机的功能退出 */
|
|
|
+void GlobalThreadInfo::setNoneCameraFuncStop()
|
|
|
+{
|
|
|
+ for(auto& it : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if(it->listRoomCamActInfo.empty())
|
|
|
+ {
|
|
|
+ it->RunState = RunTimeState::RUN_STATE_STOP;
|
|
|
+ SPDLOG_INFO("《{}》房间信息为空,退出检测", it->strFunctionName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 查找应用信息 */
|
|
|
+bool GlobalThreadInfo::findAppFunction(const AppFunction func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if(it0->appFunction == func)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+/* 根据频率和功能查找实例 */
|
|
|
+FuncThreadInfo* GlobalThreadInfo::findAppFunction(const int ChannelID, const AppFunction func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
|
|
|
+ {
|
|
|
+ return it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 查找这个应用信息
|
|
|
+ *
|
|
|
+ * @param func
|
|
|
+ * @return FuncThreadInfo*
|
|
|
+ */
|
|
|
+FuncThreadInfo* GlobalThreadInfo::findAppFunction(const FuncThreadInfo& func)
|
|
|
+{
|
|
|
+ for(const auto& it0 : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
|
|
|
+ {
|
|
|
+ return it0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置线程状态 */
|
|
|
+void GlobalThreadInfo::setThreadState(FuncThreadInfo* pInfo, RunTimeState state)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> look(m_mutexRunFAI);
|
|
|
+ auto p = findAppFunction(*pInfo);
|
|
|
+ if(p != nullptr)
|
|
|
+ {
|
|
|
+ p->RunState = state;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GlobalThreadInfo::setThreadState(FuncThreadInfo& pInfo, RunTimeState state)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> look(m_mutexRunFAI);
|
|
|
+ auto p = findAppFunction(pInfo);
|
|
|
+ if(p != nullptr)
|
|
|
+ {
|
|
|
+ p->RunState = state;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 功能线程更新功能信息,这里是从内存中的数组里获取
|
|
|
+ *
|
|
|
+ * @param pInfo
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+ bool GlobalThreadInfo::updateFuncInfo(FuncThreadInfo* pInfo)
|
|
|
+{
|
|
|
+ pInfo->clearActionList();
|
|
|
+ std::lock_guard<std::mutex> look(m_mutexRunFAI);
|
|
|
+ auto fa = findAppFunction(*pInfo);
|
|
|
+ if(fa == nullptr)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ *pInfo = *fa;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+bool GlobalThreadInfo::updateFuncInfo(FuncThreadInfo& pInfo)
|
|
|
+{
|
|
|
+ pInfo.clearActionList();
|
|
|
+ std::lock_guard<std::mutex> look(m_mutexRunFAI);
|
|
|
+ auto fa = findAppFunction(pInfo);
|
|
|
+ if(fa == nullptr)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ pInfo = *fa;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* 更新频率信息 */
|
|
|
+// void GlobalThreadInfo::setChannelInfo(std::map<int, std::string> mapChannelName)
|
|
|
+// {
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+/* 设置摄像机信息 */
|
|
|
+void GlobalThreadInfo::setCameraInfo(std::map<int, std::string> mapCameraName)
|
|
|
+{
|
|
|
+ for(auto& it : m_listFuncThreadInfo)
|
|
|
+ {
|
|
|
+ it->mapCameraName.clear();
|
|
|
+ it->mapCameraName = mapCameraName;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|