#ifndef _RTPSERVER_H_ #define _RTPSERVER_H_ #include #include #include #include "spdlog/spdlog.h" #include "Rtpcommon.h" #include "GlobalVariable.h" #include "RtpOneRoadThread.h" /** RTP监听服务,监听客户端发起的数据接受请求 功能: 1、监听客户端的连接请求,获取客户端发送过来的UDP端口 2、从ThreadManager中获取RTP发送线程实例,将需要发送的对比项通道信息发送给 RTP发送线程,RTP发送线程会将数据发送到客户端的UDP端口 3、RTP发送线程使用的UDP端口从这里确定,与客户端信息一同发送过去 接收的数据: 0是登录,1是心跳,2是注销 登录: 客户端在连接成功后,发送过来的登录信息是 RtpRecvClientInfo_t 结构体中的内容。 */ class RTPServer : public QObject { Q_OBJECT public: explicit RTPServer(QObject *parent = nullptr); ~RTPServer(); /** * @brief 启动RTP服务 * @param port 监听端口 * @return 成功返回true,失败返回false */ bool thread_task(int port); /* 停止线程 */ void stopThreadBlock(); private slots: /* 处理新连接 */ void do_newConnection(); /* 监听服务错误 */ void do_error(QAbstractSocket::SocketError socketError); /* 断开连接 */ void do_disconnect(); /* 接收消息 */ void do_receiveMessage(); private: /* 处理登录请求 */ void handleLogin(RtpSendClientInfo_t& clientInfo); /* 处理心跳请求 */ void handleHeartbeat(RtpSendClientInfo_t& clientInfo); /* 处理注销请求 */ void handleLogout(RtpSendClientInfo_t& clientInfo); /* 获取发送UDP数据的指针 */ bool getSendUdpSocketPtr(SoundCardRoadInfo_t roadInfo); private: std::shared_ptr m_logger = nullptr; /* 日志记录器 */ QEventLoop m_eventLoop; /* 事件循环,用于处理异步操作 */ std::atomic_bool m_isStoped = true; /* 线程是否已经停止标志位 */ QTcpServer *m_tcpServer; /* TCP服务器对象 */ int m_port; /* 监听端口 */ QList m_listClients; /* 客户端连接列表,用于管理多个客户端连接 */ /* 录音通道线程列表,键为录音通道ID,值为对应的RTP线程对象 */ QMap m_mapRoadThreads; }; #endif // _RTPSERVER_H_