RtpServer.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef _RTPSERVER_H_
  2. #define _RTPSERVER_H_
  3. #include <QTcpServer>
  4. #include <QList>
  5. #include "spdlog/spdlog.h"
  6. #include "Rtpcommon.h"
  7. #include "GlobalVariable.h"
  8. #include "RtpOneRoadThread.h"
  9. /**
  10. * RTP监听服务,监听客户端发起的数据接受请求
  11. * 功能:
  12. * 1、监听客户端的连接请求,获取客户端发送过来的UDP端口
  13. * 2、创建一个RTP数据对象,负责发送数据
  14. * 接收的数据:
  15. * 0是登录,1是心跳,2是注销
  16. */
  17. class RTPServer : public QObject
  18. {
  19. Q_OBJECT
  20. public:
  21. explicit RTPServer(QObject *parent = nullptr);
  22. ~RTPServer();
  23. /**
  24. * @brief 启动RTP服务
  25. * @param port 监听端口
  26. * @return 成功返回true,失败返回false
  27. */
  28. bool startServer(int port);
  29. private slots:
  30. /* 处理新连接 */
  31. void do_newConnection();
  32. /* 断开连接 */
  33. void do_disconnect();
  34. /* 接收消息 */
  35. void do_receiveMessage();
  36. private:
  37. /* 处理登录请求 */
  38. void handleLogin(RtpSendClientInfo_t& clientInfo);
  39. /* 处理心跳请求 */
  40. void handleHeartbeat(RtpSendClientInfo_t& clientInfo);
  41. /* 处理注销请求 */
  42. void handleLogout(RtpSendClientInfo_t& clientInfo);
  43. /* 获取发送UDP数据的指针 */
  44. bool getSendUdpSocketPtr(SoundCardRoadInfo_t roadInfo);
  45. private:
  46. std::shared_ptr<spdlog::logger> m_logger = nullptr; /* 日志记录器 */
  47. QTcpServer *m_tcpServer; /* TCP服务器对象 */
  48. int m_port; /* 监听端口 */
  49. QList<QTcpSocket*> m_listClients; /* 客户端连接列表,用于管理多个客户端连接 */
  50. /* 录音通道线程列表,键为录音通道ID,值为对应的RTP线程对象 */
  51. QMap<SoundCardRoadInfo_t, RTPOneRoadThread*> m_mapRoadThreads;
  52. };
  53. #endif // _RTPSERVER_H_