user_app.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * @Description: USERAPP
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-10-13 09:41:50
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2021-10-15 15:57:17
  8. */
  9. #pragma once
  10. #include <iostream>
  11. #include <signal.h>
  12. // ZLMediaKit
  13. #include "Util/logger.h"
  14. #include "Util/NoticeCenter.h"
  15. #include "Poller/EventPoller.h"
  16. #include "Player/PlayerProxy.h"
  17. #include "Rtmp/RtmpPusher.h"
  18. #include "Common/config.h"
  19. #include "Pusher/MediaPusher.h"
  20. #include "Extension/Frame.h"
  21. #include "Util/SqlPool.h"
  22. #include "Network/TcpClient.h"
  23. #include "Poller/Timer.h"
  24. #include "TCPClient.h"
  25. #include "inifile.h"
  26. #include <gst/gst.h>
  27. #include <vector>
  28. #include <map>
  29. #include <time.h>
  30. #include "inference.h"
  31. #include "DataSource.h"
  32. // dataType
  33. #include "SendLogin.h"
  34. #include "NettyServerCommandEnum.h"
  35. #include "NettyServerResultMsg.h"
  36. #include "NettyClientResultMsg.h"
  37. #include "SendLogin.h"
  38. #include "NettyClientCommandEnum.h"
  39. #include "InferData.h"
  40. #include "PIDSClientResultMsg.h"
  41. #include "PIDSServerResultMsg.h"
  42. #include "Notices.h"
  43. using namespace toolkit;
  44. using namespace mediakit;
  45. using namespace inifile;
  46. using namespace std;
  47. namespace MIVA
  48. {
  49. class UserApp
  50. {
  51. public:
  52. /**
  53. * @description: 创建对象
  54. * @param {*}
  55. * @return {std::shared_ptr<UserApp>} 智能指针
  56. * @author: lishengyin
  57. */
  58. static std::shared_ptr<UserApp> CreateNew();
  59. UserApp();
  60. ~UserApp();
  61. /**
  62. * @description: 模块初始化
  63. * @param {string} appName 应用名
  64. * @return {int} 是否成功
  65. * @author: lishengyin
  66. */
  67. int32_t Init(std::string appName);
  68. /**
  69. * @description: 释放数据
  70. * @param {*}
  71. * @return {*}
  72. * @author: lishengyin
  73. */
  74. void Destroy();
  75. /**
  76. * @description: 启动任务
  77. * @param {*}
  78. * @return {*}
  79. * @author: lishengyin
  80. */
  81. void StartTask();
  82. /**
  83. * @description: 赋值struct sockaddr
  84. * @param {sockaddr} *out
  85. * @param {char} *ip
  86. * @param {uint16_t} port
  87. * @return {*}
  88. * @author: lishengyin
  89. */
  90. static void makeAddr(struct sockaddr *out,const char *ip,uint16_t port);
  91. /**
  92. * @description: 最终的结果运算
  93. * @param {uint32_t} noLoad 空载车厢载荷
  94. * @param {uint32_t} dynamicLoad 动态车厢载荷
  95. * @param {int} num 推理结果
  96. * @return {uint32_t} 运算结构
  97. * @author: lishengyin
  98. */
  99. static uint32_t DataCalculation(uint32_t noLoad, uint32_t dynamicLoad, int num);
  100. /**
  101. * @description: 拥挤成都判定
  102. * @param {int} num 识别结果
  103. * @return {uint8_t} 拥挤程度 1-4
  104. * @author: lishengyin
  105. */
  106. static uint8_t GradeDetermination(int num);
  107. private:
  108. IniFile m_ini;
  109. std::string m_appName;
  110. const std::string m_configSrc = "../config/config.ini";
  111. private:
  112. // Natty
  113. std::string Netty_ip;
  114. int32_t Netty_port;
  115. std::string Netty_idName;
  116. // PIS
  117. std::string PIS_ip;
  118. int32_t PIS_port;
  119. std::string PIS_IdName;
  120. // Mysql
  121. std::string sql_ip;
  122. int32_t sql_port;
  123. std::string user;
  124. std::string password;
  125. std::string character;
  126. int device_id;
  127. bool play = false;
  128. bool start = true;
  129. private:
  130. std::shared_ptr<TCPClient> m_tcpClient = NULL;
  131. std::shared_ptr<Inference> m_Infer = NULL;
  132. Socket::Ptr m_udpClient = NULL;
  133. std::vector<DataSource> DataList;
  134. Timer::Ptr m_timer0;
  135. Timer::Ptr m_timer1;
  136. Timer::Ptr m_timer2;
  137. private:
  138. /**
  139. * @description: 监听推理模块广播
  140. * @param {int} Source_id 数据源ID
  141. * @param {int} num 推理结果
  142. * @return {*}
  143. * @author: lishengyin
  144. */
  145. void ListenInfer(int Source_id, int num);
  146. /**
  147. * @description: 监听Netty下发的数据
  148. * @param {Ptr} &pBuf 接受到的数据
  149. * @return {*}
  150. * @author: lishengyin
  151. */
  152. void ListenNettyData(const Buffer::Ptr &pBuf);
  153. /**
  154. * @description: 监听PIS系统的数据
  155. * @param {Ptr} &buf 接受到的数据
  156. * @param {sockaddr} *addr socker信息
  157. * @return {*}
  158. * @author: lishengyin
  159. */
  160. void ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr);
  161. /**
  162. * @description: 监听车厢关门广播
  163. * @param {*}
  164. * @return {*}
  165. * @author: lishengyin
  166. */
  167. void ListenClosed();
  168. /**
  169. * @description: 监听重启识别广播
  170. * @param {*}
  171. * @return {*}
  172. * @author: lishengyin
  173. */
  174. void ListenRelease();
  175. /**
  176. * @description: 监听推理数据广播
  177. * @param {*}
  178. * @return {*}
  179. * @author: lishengyin
  180. */
  181. void ListenInferData();
  182. /**
  183. * @description: 连接Netty
  184. * @param {*}
  185. * @return {*}
  186. * @author: lishengyin
  187. */
  188. void ConnectNetty();
  189. /**
  190. * @description: 上报数据
  191. * @param {*}
  192. * @return {*}
  193. * @author: lishengyin
  194. */
  195. void ReportData();
  196. };
  197. }