123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- #include "GlobalFuncThread.h"
- #include "GlobalConfig.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 == GVariable.ActFaceIdentify)
- {
- /* 人员在岗识别 */
- 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 == GVariable.ActPersonCount)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Regional);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 违禁物品 */
- else if (info.ActionID == GVariable.ActContraband)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Contraband);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 玩手机 */
- else if (info.ActionID == GVariable.ActPlayPhone)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_PlayPhone);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 睡岗识别 */
- else if (info.ActionID == GVariable.ActSleep)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 疲劳检测 */
- else if(info.ActionID == GVariable.ActFatigueDetection)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 动物识别 */
- else if (info.ActionID == GVariable.ActAnimalDetect)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 老鼠识别 */
- else if (info.ActionID == GVariable.ActMouseDetect)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- }
- }
- /* 口罩识别 */
- else if (info.ActionID == GVariable.ActNoMask)
- {
- 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)
- {
- FuncThreadInfo* fa = new FuncThreadInfo;
- fa->ChannelID = func.ChannelID;
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- fa->RunState = RunTimeState::RUN_STATE_NONE;
- if(func.AppType & 0x01)
- {
- /* 查找有没有这个应用 */
- auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_OnWork);
- if(pFuncThreadInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncThreadInfo->StartTime = func.StartTime;
- pFuncThreadInfo->EndTime = func.EndTime;
- continue;
- }
- fa->appFunction = AppFunction::APP_OnWork;
- fa->strFunctionName = "人员在岗识别";
- 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;
- }
- fa->appFunction = AppFunction::APP_Contraband;
- fa->strFunctionName = "违禁品识别";
- 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;
- }
- fa->appFunction = AppFunction::APP_Illegal;
- fa->strFunctionName = "非法入侵检测";
- 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;
- }
- fa->appFunction = AppFunction::APP_Fatigue;
- fa->strFunctionName = "疲劳检测";
- 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;
- }
- fa->appFunction = AppFunction::APP_Regional;
- fa->strFunctionName = "区域人员检测";
- 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;
- }
- fa->appFunction = AppFunction::APP_Mouse;
- fa->strFunctionName = "老鼠识别";
- 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;
- }
- fa->appFunction = AppFunction::APP_PlayPhone;
- fa->strFunctionName = "玩手机识别";
- 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;
- }
- fa->appFunction = AppFunction::APP_NoMask;
- fa->strFunctionName = "未戴口罩识别";
- 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;
- }
- fa->appFunction = AppFunction::APP_AllDown;
- fa->strFunctionName = "摔倒识别";
- 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 == GVariable.ActFaceIdentify)
- {
- /* 人员在岗识别 */
- setAppFunction(info, AppFunction::APP_OnWork);
- /* 非法入侵检测 */
- setAppFunction(info, AppFunction::APP_Illegal);
- }
- /* 人员计数 */
- else if (info.ActionID == GVariable.ActPersonCount)
- {
- /* 区域人员检测(人员计数?) */
- setAppFunction(info, AppFunction::APP_Regional);
- /* 非法入侵检测 */
- setAppFunction(info, AppFunction::APP_Illegal);
- /* 人员在岗识别 */
- setAppFunction(info, AppFunction::APP_OnWork);
- }
- /* 违禁物品 */
- else if (info.ActionID == GVariable.ActContraband)
- {
- setAppFunction(info, AppFunction::APP_Contraband);
- }
- /* 玩手机 */
- else if (info.ActionID == GVariable.ActPlayPhone)
- {
- setAppFunction(info, AppFunction::APP_PlayPhone);
- }
- /* 睡岗识别 */
- else if (info.ActionID == GVariable.ActSleep)
- {
- setAppFunction(info, AppFunction::APP_Fatigue);
- }
- /* 疲劳检测 */
- else if(info.ActionID == GVariable.ActFatigueDetection)
- {
- setAppFunction(info, AppFunction::APP_Fatigue);
- }
- /* 动物识别 */
- else if (info.ActionID == GVariable.ActAnimalDetect)
- {
- setAppFunction(info, AppFunction::APP_Mouse);
- }
- /* 老鼠识别 */
- else if (info.ActionID == GVariable.ActMouseDetect)
- {
- setAppFunction(info, AppFunction::APP_Mouse);
- }
- /* 口罩识别 */
- else if (info.ActionID == GVariable.ActNoMask)
- {
- setAppFunction(info, AppFunction::APP_NoMask);
- }
- 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())
- {
- if(it->RunState == RunTimeState::RUN_STATE_NONE)
- {
- SPDLOG_INFO("频道:{:<15} 功能:{:<20}房间信息为空,无需开启线程",it->strChannelName, it->strFunctionName);
- }
- else if(it->RunState == RunTimeState::RUN_STATE_RUN)
- {
- SPDLOG_INFO("频道:{:<10}功能:{:<20}房间信息为空,停止线程",it->strChannelName, it->strFunctionName);
- }
- it->RunState = RunTimeState::RUN_STATE_STOP;
- }
- }
- }
- /* 查找应用信息 */
- 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::setAppFunction(const ActionInfo& info, const AppFunction func)
- {
- auto pFuncThreadInfo = findAppFunction(info.ChannelID, func);
- if(pFuncThreadInfo != nullptr)
- {
- pFuncThreadInfo->addActionInfo(info);
- pFuncThreadInfo->RunState = RunTimeState::RUN_STATE_INIT;
- }
- }
- /* 设置线程状态 */
- 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;
- }
- }
|