user_app.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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-13 09:41:52
  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. static std::shared_ptr<UserApp> CreateNew();
  53. UserApp();
  54. ~UserApp();
  55. int32_t Init(std::string appName);
  56. void Destroy();
  57. void StartTask();
  58. static void makeAddr(struct sockaddr *out,const char *ip,uint16_t port);
  59. static uint32_t DataCalculation(uint32_t noLoad, uint32_t dynamicLoad, int num);
  60. static uint8_t GradeDetermination(int num);
  61. private:
  62. IniFile m_ini;
  63. std::string m_appName;
  64. const std::string m_configSrc = "../config/config.ini";
  65. private:
  66. // Natty
  67. std::string Netty_ip;
  68. int32_t Netty_port;
  69. std::string Netty_idName;
  70. // PIS
  71. std::string PIS_ip;
  72. int32_t PIS_port;
  73. std::string PIS_IdName;
  74. // Mysql
  75. std::string sql_ip;
  76. int32_t sql_port;
  77. std::string user;
  78. std::string password;
  79. std::string character;
  80. int device_id;
  81. bool play = false;
  82. bool start = true;
  83. private:
  84. std::shared_ptr<TCPClient> m_tcpClient = NULL;
  85. std::shared_ptr<Inference> m_Infer = NULL;
  86. Socket::Ptr m_udpClient = NULL;
  87. std::vector<DataSource> DataList;
  88. Timer::Ptr m_timer0;
  89. Timer::Ptr m_timer1;
  90. Timer::Ptr m_timer2;
  91. private:
  92. void ListenInfer(int Source_id, int num);
  93. void ListenNettyData(const Buffer::Ptr &pBuf);
  94. void ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr);
  95. void ListenClosed();
  96. void ListenRelease();
  97. void ListenInferData();
  98. void ConnectNetty();
  99. void ReportData();
  100. };
  101. }