GlobalFuncThread.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. #include "GlobalFuncThread.h"
  2. #include "GlobalConfig.h"
  3. #include "spdlog/spdlog.h"
  4. FuncThreadInfo::FuncThreadInfo()
  5. {
  6. ChannelID = -1;
  7. strChannelName = "";
  8. appFunction = AppFunction::APP_NONE;
  9. RunState = RunTimeState::RUN_STATE_NONE;
  10. strFunctionName = "";
  11. StartTime = QDateTime::currentDateTime();
  12. EndTime = QDateTime::currentDateTime();
  13. listRoomCamActInfo.clear();
  14. mapCameraName.clear();
  15. }
  16. FuncThreadInfo::~FuncThreadInfo()
  17. {
  18. }
  19. FuncThreadInfo& FuncThreadInfo::operator=(FuncThreadInfo& other)
  20. {
  21. if(this != &other)
  22. {
  23. ChannelID = other.ChannelID;
  24. strChannelName = other.strChannelName;
  25. appFunction = other.appFunction;
  26. RunState = other.RunState;
  27. strFunctionName = other.strFunctionName;
  28. StartTime = other.StartTime;
  29. EndTime = other.EndTime;
  30. listRoomCamActInfo = other.listRoomCamActInfo;
  31. mapCameraName = other.mapCameraName;
  32. }
  33. return *this;
  34. }
  35. /**
  36. * @brief 添加算法信息,这里不能直接创建房间,需要先判断有没有已有的房间,因为有的应用功能可能会包含多个房间
  37. * 已经提前被创建过了
  38. *
  39. * @param info
  40. * @return true
  41. * @return false
  42. */
  43. bool FuncThreadInfo::addActionInfo(const ActionInfo& info)
  44. {
  45. /* 根据此类的功能,添加算法信息 */
  46. if(appFunction == AppFunction::APP_NONE)
  47. {
  48. return false;
  49. }
  50. /* 将其添加到对应的房间 */
  51. bool isFind = false;
  52. for(auto& roomInfo : listRoomCamActInfo)
  53. {
  54. if((roomInfo.RoomID == info.RoomID) && (roomInfo.RoomType == info.RoomType))
  55. {
  56. isFind = true;
  57. // roomInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  58. roomInfo.addCameraAction(info.CameraID, info.ActionID);
  59. break;
  60. }
  61. }
  62. /* 没找到这个房间,就创建 */
  63. if(!isFind)
  64. {
  65. RoomCamActInfo roomCamActInfo;
  66. roomCamActInfo.RoomID = info.RoomID;
  67. roomCamActInfo.RoomType = info.RoomType;
  68. roomCamActInfo.strRoomName = info.strRoomName;
  69. roomCamActInfo.addCameraAction(info.CameraID, info.ActionID);
  70. listRoomCamActInfo.push_back(roomCamActInfo);
  71. }
  72. return true;
  73. }
  74. /* 清空算法信息 */
  75. void FuncThreadInfo::clearActionList()
  76. {
  77. listRoomCamActInfo.clear();
  78. }
  79. /* 获取摄像机名称 */
  80. std::string FuncThreadInfo::getCameraName(int CameraID)
  81. {
  82. auto it = mapCameraName.find(CameraID);
  83. if(it != mapCameraName.end())
  84. {
  85. return it->second;
  86. }
  87. return "";
  88. }
  89. /**
  90. * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
  91. * 这里是添加应用功能和时间段信息
  92. *
  93. * @param func
  94. * @return true
  95. * @return false
  96. */
  97. bool ListFuncActInfo::addFuncThreadInfo(const AppAndTimeInfo& func)
  98. {
  99. if(func.AppType == 0)
  100. {
  101. return false;
  102. }
  103. /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
  104. for(int i = 0; i < 8; ++i)
  105. {
  106. if(func.AppType & 0x01)
  107. {
  108. /* 查找有没有这个应用 */
  109. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_OnWork);
  110. if(pFuncThreadInfo != nullptr)
  111. {
  112. /* 更新时间信息 */
  113. pFuncThreadInfo->StartTime = func.StartTime;
  114. pFuncThreadInfo->EndTime = func.EndTime;
  115. continue;
  116. }
  117. FuncThreadInfo* fa = new FuncThreadInfo;
  118. fa->ChannelID = func.ChannelID;
  119. fa->appFunction = AppFunction::APP_OnWork;
  120. fa->strFunctionName = "人员在岗识别";
  121. fa->StartTime = func.StartTime;
  122. fa->EndTime = func.EndTime;
  123. listFuncThreadInfo.push_back(fa);
  124. }
  125. else if(func.AppType & 0x02)
  126. {
  127. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Contraband);
  128. if(pFuncThreadInfo != nullptr)
  129. {
  130. /* 更新时间信息 */
  131. pFuncThreadInfo->StartTime = func.StartTime;
  132. pFuncThreadInfo->EndTime = func.EndTime;
  133. continue;
  134. }
  135. FuncThreadInfo* fa = new FuncThreadInfo;
  136. fa->ChannelID = func.ChannelID;
  137. fa->appFunction = AppFunction::APP_Contraband;
  138. fa->strFunctionName = "违禁品识别";
  139. fa->StartTime = func.StartTime;
  140. fa->EndTime = func.EndTime;
  141. listFuncThreadInfo.push_back(fa);
  142. }
  143. else if (func.AppType & 0x04)
  144. {
  145. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Illegal);
  146. if(pFuncThreadInfo != nullptr)
  147. {
  148. /* 更新时间信息 */
  149. pFuncThreadInfo->StartTime = func.StartTime;
  150. pFuncThreadInfo->EndTime = func.EndTime;
  151. continue;
  152. }
  153. FuncThreadInfo* fa = new FuncThreadInfo;
  154. fa->ChannelID = func.ChannelID;
  155. fa->appFunction = AppFunction::APP_Illegal;
  156. fa->strFunctionName = "非法入侵检测";
  157. fa->StartTime = func.StartTime;
  158. fa->EndTime = func.EndTime;
  159. listFuncThreadInfo.push_back(fa);
  160. }
  161. else if (func.AppType & 0x08)
  162. {
  163. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Fatigue);
  164. if(pFuncThreadInfo != nullptr)
  165. {
  166. /* 更新时间信息 */
  167. pFuncThreadInfo->StartTime = func.StartTime;
  168. pFuncThreadInfo->EndTime = func.EndTime;
  169. continue;
  170. }
  171. FuncThreadInfo* fa = new FuncThreadInfo;
  172. fa->ChannelID = func.ChannelID;
  173. fa->appFunction = AppFunction::APP_Fatigue;
  174. fa->strFunctionName = "疲劳检测";
  175. fa->StartTime = func.StartTime;
  176. fa->EndTime = func.EndTime;
  177. listFuncThreadInfo.push_back(fa);
  178. }
  179. else if (func.AppType & 0x10)
  180. {
  181. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Regional);
  182. if(pFuncThreadInfo != nullptr)
  183. {
  184. /* 更新时间信息 */
  185. pFuncThreadInfo->StartTime = func.StartTime;
  186. pFuncThreadInfo->EndTime = func.EndTime;
  187. continue;
  188. }
  189. FuncThreadInfo* fa = new FuncThreadInfo;
  190. fa->ChannelID = func.ChannelID;
  191. fa->appFunction = AppFunction::APP_Regional;
  192. fa->strFunctionName = "区域人员检测";
  193. fa->StartTime = func.StartTime;
  194. fa->EndTime = func.EndTime;
  195. listFuncThreadInfo.push_back(fa);
  196. }
  197. else if (func.AppType & 0x20)
  198. {
  199. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Mouse);
  200. if(pFuncThreadInfo != nullptr)
  201. {
  202. /* 更新时间信息 */
  203. pFuncThreadInfo->StartTime = func.StartTime;
  204. pFuncThreadInfo->EndTime = func.EndTime;
  205. continue;
  206. }
  207. FuncThreadInfo* fa = new FuncThreadInfo;
  208. fa->ChannelID = func.ChannelID;
  209. fa->appFunction = AppFunction::APP_Mouse;
  210. fa->strFunctionName = "老鼠识别";
  211. fa->StartTime = func.StartTime;
  212. fa->EndTime = func.EndTime;
  213. listFuncThreadInfo.push_back(fa);
  214. }
  215. else if (func.AppType & 0x40)
  216. {
  217. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_PlayPhone);
  218. if(pFuncThreadInfo != nullptr)
  219. {
  220. /* 更新时间信息 */
  221. pFuncThreadInfo->StartTime = func.StartTime;
  222. pFuncThreadInfo->EndTime = func.EndTime;
  223. continue;
  224. }
  225. FuncThreadInfo* fa = new FuncThreadInfo;
  226. fa->ChannelID = func.ChannelID;
  227. fa->appFunction = AppFunction::APP_PlayPhone;
  228. fa->strFunctionName = "玩手机识别";
  229. fa->StartTime = func.StartTime;
  230. fa->EndTime = func.EndTime;
  231. listFuncThreadInfo.push_back(fa);
  232. }
  233. else if (func.AppType & 0x80)
  234. {
  235. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_NoMask);
  236. if(pFuncThreadInfo != nullptr)
  237. {
  238. /* 更新时间信息 */
  239. pFuncThreadInfo->StartTime = func.StartTime;
  240. pFuncThreadInfo->EndTime = func.EndTime;
  241. continue;
  242. }
  243. FuncThreadInfo* fa = new FuncThreadInfo;
  244. fa->ChannelID = func.ChannelID;
  245. fa->appFunction = AppFunction::APP_NoMask;
  246. fa->strFunctionName = "未戴口罩识别";
  247. fa->StartTime = func.StartTime;
  248. fa->EndTime = func.EndTime;
  249. listFuncThreadInfo.push_back(fa);
  250. }
  251. else if (func.AppType & 0x0100)
  252. {
  253. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_AllDown);
  254. if(pFuncThreadInfo != nullptr)
  255. {
  256. /* 更新时间信息 */
  257. pFuncThreadInfo->StartTime = func.StartTime;
  258. pFuncThreadInfo->EndTime = func.EndTime;
  259. continue;
  260. }
  261. FuncThreadInfo* fa = new FuncThreadInfo;
  262. fa->ChannelID = func.ChannelID;
  263. fa->appFunction = AppFunction::APP_AllDown;
  264. fa->strFunctionName = "摔倒识别";
  265. fa->StartTime = func.StartTime;
  266. fa->EndTime = func.EndTime;
  267. listFuncThreadInfo.push_back(fa);
  268. }
  269. }
  270. return true;
  271. }
  272. /**
  273. * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
  274. *
  275. * @param info
  276. * @return true
  277. * @return false
  278. */
  279. bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
  280. {
  281. if(info.ActionID.empty())
  282. {
  283. return false;
  284. }
  285. /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
  286. if(info.ActionID == GVariable.ActFaceIdentify)
  287. {
  288. /* 人员在岗识别 */
  289. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_OnWork);
  290. if(pFuncThreadInfo != nullptr)
  291. {
  292. pFuncThreadInfo->addActionInfo(info);
  293. }
  294. /* 非法入侵检测 */
  295. pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Illegal);
  296. if(pFuncThreadInfo != nullptr)
  297. {
  298. pFuncThreadInfo->addActionInfo(info);
  299. }
  300. }
  301. /* 人员计数 */
  302. else if (info.ActionID == GVariable.ActPersonCount)
  303. {
  304. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Regional);
  305. if(pFuncThreadInfo != nullptr)
  306. {
  307. pFuncThreadInfo->addActionInfo(info);
  308. }
  309. }
  310. /* 违禁物品 */
  311. else if (info.ActionID == GVariable.ActContraband)
  312. {
  313. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Contraband);
  314. if(pFuncThreadInfo != nullptr)
  315. {
  316. pFuncThreadInfo->addActionInfo(info);
  317. }
  318. }
  319. /* 玩手机 */
  320. else if (info.ActionID == GVariable.ActPlayPhone)
  321. {
  322. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_PlayPhone);
  323. if(pFuncThreadInfo != nullptr)
  324. {
  325. pFuncThreadInfo->addActionInfo(info);
  326. }
  327. }
  328. /* 睡岗识别 */
  329. else if (info.ActionID == GVariable.ActSleep)
  330. {
  331. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
  332. if(pFuncThreadInfo != nullptr)
  333. {
  334. pFuncThreadInfo->addActionInfo(info);
  335. }
  336. }
  337. /* 疲劳检测 */
  338. else if(info.ActionID == GVariable.ActFatigueDetection)
  339. {
  340. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Fatigue);
  341. if(pFuncThreadInfo != nullptr)
  342. {
  343. pFuncThreadInfo->addActionInfo(info);
  344. }
  345. }
  346. /* 动物识别 */
  347. else if (info.ActionID == GVariable.ActAnimalDetect)
  348. {
  349. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
  350. if(pFuncThreadInfo != nullptr)
  351. {
  352. pFuncThreadInfo->addActionInfo(info);
  353. }
  354. }
  355. /* 老鼠识别 */
  356. else if (info.ActionID == GVariable.ActMouseDetect)
  357. {
  358. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_Mouse);
  359. if(pFuncThreadInfo != nullptr)
  360. {
  361. pFuncThreadInfo->addActionInfo(info);
  362. }
  363. }
  364. /* 口罩识别 */
  365. else if (info.ActionID == GVariable.ActNoMask)
  366. {
  367. auto pFuncThreadInfo = findAppFunction(info.ChannelID, AppFunction::APP_NoMask);
  368. if(pFuncThreadInfo != nullptr)
  369. {
  370. pFuncThreadInfo->addActionInfo(info);
  371. }
  372. }
  373. else {
  374. SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
  375. return false;
  376. }
  377. return true;
  378. }
  379. /**
  380. * @brief 清空无用的功能信息
  381. * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
  382. *
  383. */
  384. void ListFuncActInfo::clearNoneFuncThreadInfo()
  385. {
  386. for(auto it0 = listFuncThreadInfo.begin(); it0 != listFuncThreadInfo.end();)
  387. {
  388. if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
  389. {
  390. delete *it0;
  391. it0 = listFuncThreadInfo.erase(it0);
  392. }else {
  393. ++it0;
  394. }
  395. }
  396. }
  397. /* 清空算法列表 */
  398. void ListFuncActInfo::clearActionList()
  399. {
  400. for(auto& it0 : listFuncThreadInfo)
  401. {
  402. it0->listRoomCamActInfo.clear();
  403. }
  404. }
  405. /* 查找应用信息 */
  406. bool ListFuncActInfo::findAppFunction(const AppFunction func)
  407. {
  408. for(const auto& it0 : listFuncThreadInfo)
  409. {
  410. if(it0->appFunction == func)
  411. {
  412. return true;
  413. }
  414. }
  415. return false;
  416. }
  417. /* 根据频率和功能查找实例 */
  418. FuncThreadInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
  419. {
  420. for(const auto& it0 : listFuncThreadInfo)
  421. {
  422. if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
  423. {
  424. return it0;
  425. }
  426. }
  427. return nullptr;
  428. }
  429. /**
  430. * @brief 查找这个应用信息
  431. *
  432. * @param func
  433. * @return FuncThreadInfo*
  434. */
  435. FuncThreadInfo* ListFuncActInfo::findAppFunction(const FuncThreadInfo& func)
  436. {
  437. for(const auto& it0 : listFuncThreadInfo)
  438. {
  439. if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
  440. {
  441. return it0;
  442. }
  443. }
  444. return nullptr;
  445. }
  446. /* ====================================================================================
  447. * ************************ GlobalThreadInfo成员函数 *****************************
  448. * ====================================================================================*/
  449. /* 获取线程运行标志位 */
  450. bool GlobalThreadInfo::getRunning() const
  451. {
  452. return m_bRunning;
  453. }
  454. /* 设置线程运行标志位 */
  455. void GlobalThreadInfo::setRunning(bool bRunning)
  456. {
  457. m_bRunning = bRunning;
  458. }
  459. /* 手动给功能块列表加锁 */
  460. void GlobalThreadInfo::lockRunFAI()
  461. {
  462. m_mutexRunFAI.lock();
  463. }
  464. /* 手动解锁 */
  465. void GlobalThreadInfo::unlockRunFAI()
  466. {
  467. m_mutexRunFAI.unlock();
  468. }
  469. /**
  470. * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
  471. * 这里是添加应用功能和时间段信息
  472. *
  473. * @param func
  474. * @return true
  475. * @return false
  476. */
  477. bool GlobalThreadInfo::addFuncThreadInfo(const AppAndTimeInfo& func)
  478. {
  479. if(func.AppType == 0)
  480. {
  481. return false;
  482. }
  483. /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
  484. for(int i = 0; i < 8; ++i)
  485. {
  486. FuncThreadInfo* fa = new FuncThreadInfo;
  487. fa->ChannelID = func.ChannelID;
  488. fa->StartTime = func.StartTime;
  489. fa->EndTime = func.EndTime;
  490. fa->RunState = RunTimeState::RUN_STATE_NONE;
  491. if(func.AppType & 0x01)
  492. {
  493. /* 查找有没有这个应用 */
  494. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_OnWork);
  495. if(pFuncThreadInfo != nullptr)
  496. {
  497. /* 更新时间信息 */
  498. pFuncThreadInfo->StartTime = func.StartTime;
  499. pFuncThreadInfo->EndTime = func.EndTime;
  500. continue;
  501. }
  502. fa->appFunction = AppFunction::APP_OnWork;
  503. fa->strFunctionName = "人员在岗识别";
  504. m_listFuncThreadInfo.push_back(fa);
  505. }
  506. else if(func.AppType & 0x02)
  507. {
  508. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Contraband);
  509. if(pFuncThreadInfo != nullptr)
  510. {
  511. /* 更新时间信息 */
  512. pFuncThreadInfo->StartTime = func.StartTime;
  513. pFuncThreadInfo->EndTime = func.EndTime;
  514. continue;
  515. }
  516. fa->appFunction = AppFunction::APP_Contraband;
  517. fa->strFunctionName = "违禁品识别";
  518. m_listFuncThreadInfo.push_back(fa);
  519. }
  520. else if (func.AppType & 0x04)
  521. {
  522. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Illegal);
  523. if(pFuncThreadInfo != nullptr)
  524. {
  525. /* 更新时间信息 */
  526. pFuncThreadInfo->StartTime = func.StartTime;
  527. pFuncThreadInfo->EndTime = func.EndTime;
  528. continue;
  529. }
  530. fa->appFunction = AppFunction::APP_Illegal;
  531. fa->strFunctionName = "非法入侵检测";
  532. m_listFuncThreadInfo.push_back(fa);
  533. }
  534. else if (func.AppType & 0x08)
  535. {
  536. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Fatigue);
  537. if(pFuncThreadInfo != nullptr)
  538. {
  539. /* 更新时间信息 */
  540. pFuncThreadInfo->StartTime = func.StartTime;
  541. pFuncThreadInfo->EndTime = func.EndTime;
  542. continue;
  543. }
  544. fa->appFunction = AppFunction::APP_Fatigue;
  545. fa->strFunctionName = "疲劳检测";
  546. m_listFuncThreadInfo.push_back(fa);
  547. }
  548. else if (func.AppType & 0x10)
  549. {
  550. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Regional);
  551. if(pFuncThreadInfo != nullptr)
  552. {
  553. /* 更新时间信息 */
  554. pFuncThreadInfo->StartTime = func.StartTime;
  555. pFuncThreadInfo->EndTime = func.EndTime;
  556. continue;
  557. }
  558. fa->appFunction = AppFunction::APP_Regional;
  559. fa->strFunctionName = "区域人员检测";
  560. m_listFuncThreadInfo.push_back(fa);
  561. }
  562. else if (func.AppType & 0x20)
  563. {
  564. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_Mouse);
  565. if(pFuncThreadInfo != nullptr)
  566. {
  567. /* 更新时间信息 */
  568. pFuncThreadInfo->StartTime = func.StartTime;
  569. pFuncThreadInfo->EndTime = func.EndTime;
  570. continue;
  571. }
  572. fa->appFunction = AppFunction::APP_Mouse;
  573. fa->strFunctionName = "老鼠识别";
  574. m_listFuncThreadInfo.push_back(fa);
  575. }
  576. else if (func.AppType & 0x40)
  577. {
  578. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_PlayPhone);
  579. if(pFuncThreadInfo != nullptr)
  580. {
  581. /* 更新时间信息 */
  582. pFuncThreadInfo->StartTime = func.StartTime;
  583. pFuncThreadInfo->EndTime = func.EndTime;
  584. continue;
  585. }
  586. fa->appFunction = AppFunction::APP_PlayPhone;
  587. fa->strFunctionName = "玩手机识别";
  588. m_listFuncThreadInfo.push_back(fa);
  589. }
  590. else if (func.AppType & 0x80)
  591. {
  592. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_NoMask);
  593. if(pFuncThreadInfo != nullptr)
  594. {
  595. /* 更新时间信息 */
  596. pFuncThreadInfo->StartTime = func.StartTime;
  597. pFuncThreadInfo->EndTime = func.EndTime;
  598. continue;
  599. }
  600. fa->appFunction = AppFunction::APP_NoMask;
  601. fa->strFunctionName = "未戴口罩识别";
  602. m_listFuncThreadInfo.push_back(fa);
  603. }
  604. else if (func.AppType & 0x0100)
  605. {
  606. auto pFuncThreadInfo = findAppFunction(func.ChannelID, AppFunction::APP_AllDown);
  607. if(pFuncThreadInfo != nullptr)
  608. {
  609. /* 更新时间信息 */
  610. pFuncThreadInfo->StartTime = func.StartTime;
  611. pFuncThreadInfo->EndTime = func.EndTime;
  612. continue;
  613. }
  614. fa->appFunction = AppFunction::APP_AllDown;
  615. fa->strFunctionName = "摔倒识别";
  616. m_listFuncThreadInfo.push_back(fa);
  617. }
  618. }
  619. return true;
  620. }
  621. /**
  622. * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
  623. * 根据功能需要,将算法ID加入到对应的功能中
  624. *
  625. * @param info
  626. * @return true
  627. * @return false
  628. */
  629. bool GlobalThreadInfo::addActionInfo(const ActionInfo& info)
  630. {
  631. if(info.ActionID.empty())
  632. {
  633. return false;
  634. }
  635. /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
  636. if(info.ActionID == GVariable.ActFaceIdentify)
  637. {
  638. /* 人员在岗识别 */
  639. setAppFunction(info, AppFunction::APP_OnWork);
  640. /* 非法入侵检测 */
  641. setAppFunction(info, AppFunction::APP_Illegal);
  642. }
  643. /* 人员计数 */
  644. else if (info.ActionID == GVariable.ActPersonCount)
  645. {
  646. /* 区域人员检测(人员计数?) */
  647. setAppFunction(info, AppFunction::APP_Regional);
  648. /* 非法入侵检测 */
  649. setAppFunction(info, AppFunction::APP_Illegal);
  650. /* 人员在岗识别 */
  651. setAppFunction(info, AppFunction::APP_OnWork);
  652. }
  653. /* 违禁物品 */
  654. else if (info.ActionID == GVariable.ActContraband)
  655. {
  656. setAppFunction(info, AppFunction::APP_Contraband);
  657. }
  658. /* 玩手机 */
  659. else if (info.ActionID == GVariable.ActPlayPhone)
  660. {
  661. setAppFunction(info, AppFunction::APP_PlayPhone);
  662. }
  663. /* 睡岗识别 */
  664. else if (info.ActionID == GVariable.ActSleep)
  665. {
  666. setAppFunction(info, AppFunction::APP_Fatigue);
  667. }
  668. /* 疲劳检测 */
  669. else if(info.ActionID == GVariable.ActFatigueDetection)
  670. {
  671. setAppFunction(info, AppFunction::APP_Fatigue);
  672. }
  673. /* 动物识别 */
  674. else if (info.ActionID == GVariable.ActAnimalDetect)
  675. {
  676. setAppFunction(info, AppFunction::APP_Mouse);
  677. }
  678. /* 老鼠识别 */
  679. else if (info.ActionID == GVariable.ActMouseDetect)
  680. {
  681. setAppFunction(info, AppFunction::APP_Mouse);
  682. }
  683. /* 口罩识别 */
  684. else if (info.ActionID == GVariable.ActNoMask)
  685. {
  686. setAppFunction(info, AppFunction::APP_NoMask);
  687. }
  688. else {
  689. SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
  690. return false;
  691. }
  692. return true;
  693. }
  694. /**
  695. * @brief 清空无用的功能信息
  696. * 摄像机和算法信息为空的,或者运行状态为RUN_STATE_EXITCOMPLET,都会被清理掉
  697. *
  698. */
  699. void GlobalThreadInfo::clearNoneFuncThreadInfo()
  700. {
  701. for(auto it0 = m_listFuncThreadInfo.begin(); it0 != m_listFuncThreadInfo.end();)
  702. {
  703. if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_EXITCOMPLET))
  704. {
  705. delete *it0;
  706. it0 = m_listFuncThreadInfo.erase(it0);
  707. }else {
  708. ++it0;
  709. }
  710. }
  711. }
  712. /* 清空算法列表(直接清空房间信息) */
  713. void GlobalThreadInfo::clearActionList()
  714. {
  715. for(auto& it0 : m_listFuncThreadInfo)
  716. {
  717. // for(auto& it1 : it0->listRoomCamActInfo)
  718. // {
  719. // it1.mapCameraAction.clear();
  720. // }
  721. it0->listRoomCamActInfo.clear();
  722. }
  723. }
  724. /* 设置没有配置摄像机的功能退出 */
  725. void GlobalThreadInfo::setNoneCameraFuncStop()
  726. {
  727. for(auto& it : m_listFuncThreadInfo)
  728. {
  729. if(it->listRoomCamActInfo.empty())
  730. {
  731. if(it->RunState == RunTimeState::RUN_STATE_NONE)
  732. {
  733. SPDLOG_INFO("频道:{:<15} 功能:{:<20}房间信息为空,无需开启线程",it->strChannelName, it->strFunctionName);
  734. }
  735. else if(it->RunState == RunTimeState::RUN_STATE_RUN)
  736. {
  737. SPDLOG_INFO("频道:{:<10}功能:{:<20}房间信息为空,停止线程",it->strChannelName, it->strFunctionName);
  738. }
  739. it->RunState = RunTimeState::RUN_STATE_STOP;
  740. }
  741. }
  742. }
  743. /* 查找应用信息 */
  744. bool GlobalThreadInfo::findAppFunction(const AppFunction func)
  745. {
  746. for(const auto& it0 : m_listFuncThreadInfo)
  747. {
  748. if(it0->appFunction == func)
  749. {
  750. return true;
  751. }
  752. }
  753. return false;
  754. }
  755. /* 根据频率和功能查找实例 */
  756. FuncThreadInfo* GlobalThreadInfo::findAppFunction(const int ChannelID, const AppFunction func)
  757. {
  758. for(const auto& it0 : m_listFuncThreadInfo)
  759. {
  760. if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
  761. {
  762. return it0;
  763. }
  764. }
  765. return nullptr;
  766. }
  767. /**
  768. * @brief 查找这个应用信息
  769. *
  770. * @param func
  771. * @return FuncThreadInfo*
  772. */
  773. FuncThreadInfo* GlobalThreadInfo::findAppFunction(const FuncThreadInfo& func)
  774. {
  775. for(const auto& it0 : m_listFuncThreadInfo)
  776. {
  777. if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
  778. {
  779. return it0;
  780. }
  781. }
  782. return nullptr;
  783. }
  784. /* 设置应用信息 */
  785. void GlobalThreadInfo::setAppFunction(const ActionInfo& info, const AppFunction func)
  786. {
  787. auto pFuncThreadInfo = findAppFunction(info.ChannelID, func);
  788. if(pFuncThreadInfo != nullptr)
  789. {
  790. pFuncThreadInfo->addActionInfo(info);
  791. pFuncThreadInfo->RunState = RunTimeState::RUN_STATE_INIT;
  792. }
  793. }
  794. /* 设置线程状态 */
  795. void GlobalThreadInfo::setThreadState(FuncThreadInfo* pInfo, RunTimeState state)
  796. {
  797. std::lock_guard<std::mutex> look(m_mutexRunFAI);
  798. auto p = findAppFunction(*pInfo);
  799. if(p != nullptr)
  800. {
  801. p->RunState = state;
  802. }
  803. }
  804. void GlobalThreadInfo::setThreadState(FuncThreadInfo& pInfo, RunTimeState state)
  805. {
  806. std::lock_guard<std::mutex> look(m_mutexRunFAI);
  807. auto p = findAppFunction(pInfo);
  808. if(p != nullptr)
  809. {
  810. p->RunState = state;
  811. }
  812. }
  813. /**
  814. * @brief 功能线程更新功能信息,这里是从内存中的数组里获取
  815. *
  816. * @param pInfo
  817. * @return true
  818. * @return false
  819. */
  820. bool GlobalThreadInfo::updateFuncInfo(FuncThreadInfo* pInfo)
  821. {
  822. pInfo->clearActionList();
  823. std::lock_guard<std::mutex> look(m_mutexRunFAI);
  824. auto fa = findAppFunction(*pInfo);
  825. if(fa == nullptr)
  826. {
  827. return false;
  828. }
  829. *pInfo = *fa;
  830. return true;
  831. }
  832. bool GlobalThreadInfo::updateFuncInfo(FuncThreadInfo& pInfo)
  833. {
  834. pInfo.clearActionList();
  835. std::lock_guard<std::mutex> look(m_mutexRunFAI);
  836. auto fa = findAppFunction(pInfo);
  837. if(fa == nullptr)
  838. {
  839. return false;
  840. }
  841. pInfo = *fa;
  842. return true;
  843. }
  844. /* 更新频率信息 */
  845. // void GlobalThreadInfo::setChannelInfo(std::map<int, std::string> mapChannelName)
  846. // {
  847. // }
  848. /* 设置摄像机信息 */
  849. void GlobalThreadInfo::setCameraInfo(std::map<int, std::string> mapCameraName)
  850. {
  851. for(auto& it : m_listFuncThreadInfo)
  852. {
  853. it->mapCameraName.clear();
  854. it->mapCameraName = mapCameraName;
  855. }
  856. }