mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Extract rtc server in app
This commit is contained in:
parent
a757b7f903
commit
3a58d9859c
8 changed files with 940 additions and 849 deletions
|
@ -409,104 +409,5 @@ private:
|
|||
srs_error_t on_binding_request(SrsStunPacket* r);
|
||||
};
|
||||
|
||||
class SrsUdpMuxSender : virtual public ISrsUdpSender, virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler
|
||||
{
|
||||
private:
|
||||
srs_netfd_t lfd;
|
||||
SrsRtcServer* server;
|
||||
SrsCoroutine* trd;
|
||||
private:
|
||||
srs_cond_t cond;
|
||||
bool waiting_msgs;
|
||||
bool gso;
|
||||
int nn_senders;
|
||||
private:
|
||||
// Hotspot msgs, we are working on it.
|
||||
// @remark We will wait util all messages are ready.
|
||||
std::vector<srs_mmsghdr> hotspot;
|
||||
// Cache msgs, for other coroutines to fill it.
|
||||
std::vector<srs_mmsghdr> cache;
|
||||
int cache_pos;
|
||||
// The max number of messages for sendmmsg. If 1, we use sendmsg to send.
|
||||
int max_sendmmsg;
|
||||
// The total queue length, for each sender.
|
||||
int queue_length;
|
||||
// The extra queue ratio.
|
||||
int extra_ratio;
|
||||
int extra_queue;
|
||||
public:
|
||||
SrsUdpMuxSender(SrsRtcServer* s);
|
||||
virtual ~SrsUdpMuxSender();
|
||||
public:
|
||||
virtual srs_error_t initialize(srs_netfd_t fd, int senders);
|
||||
private:
|
||||
void free_mhdrs(std::vector<srs_mmsghdr>& mhdrs);
|
||||
public:
|
||||
virtual srs_error_t fetch(srs_mmsghdr** pphdr);
|
||||
virtual srs_error_t sendmmsg(srs_mmsghdr* hdr);
|
||||
virtual bool overflow();
|
||||
virtual void set_extra_ratio(int r);
|
||||
public:
|
||||
virtual srs_error_t cycle();
|
||||
// interface ISrsReloadHandler
|
||||
public:
|
||||
virtual srs_error_t on_reload_rtc_server();
|
||||
};
|
||||
|
||||
class SrsRtcServer : virtual public ISrsUdpMuxHandler, virtual public ISrsHourGlass
|
||||
{
|
||||
private:
|
||||
SrsHourGlass* timer;
|
||||
std::vector<SrsUdpMuxListener*> listeners;
|
||||
std::vector<SrsUdpMuxSender*> senders;
|
||||
private:
|
||||
std::map<std::string, SrsRtcSession*> map_username_session; // key: username(local_ufrag + ":" + remote_ufrag)
|
||||
std::map<std::string, SrsRtcSession*> map_id_session; // key: peerip(ip + ":" + port)
|
||||
public:
|
||||
SrsRtcServer();
|
||||
virtual ~SrsRtcServer();
|
||||
public:
|
||||
virtual srs_error_t initialize();
|
||||
public:
|
||||
// TODO: FIXME: Support gracefully quit.
|
||||
// TODO: FIXME: Support reload.
|
||||
srs_error_t listen_udp();
|
||||
virtual srs_error_t on_udp_packet(SrsUdpMuxSocket* skt);
|
||||
srs_error_t listen_api();
|
||||
public:
|
||||
// Peer start offering, we answer it.
|
||||
srs_error_t create_session(
|
||||
SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, bool publish,
|
||||
SrsRtcSession** psession
|
||||
);
|
||||
// We start offering, create_session2 to generate offer, setup_session2 to handle answer.
|
||||
srs_error_t create_session2(SrsSdp& local_sdp, SrsRtcSession** psession);
|
||||
srs_error_t setup_session2(SrsRtcSession* session, SrsRequest* req, const SrsSdp& remote_sdp);
|
||||
public:
|
||||
bool insert_into_id_sessions(const std::string& peer_id, SrsRtcSession* session);
|
||||
void check_and_clean_timeout_session();
|
||||
int nn_sessions();
|
||||
SrsRtcSession* find_session_by_username(const std::string& ufrag);
|
||||
private:
|
||||
SrsRtcSession* find_session_by_peer_id(const std::string& peer_id);
|
||||
// interface ISrsHourGlass
|
||||
public:
|
||||
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick);
|
||||
};
|
||||
|
||||
// The RTC server adapter.
|
||||
class RtcServerAdapter : public ISrsHybridServer
|
||||
{
|
||||
private:
|
||||
SrsRtcServer* rtc;
|
||||
public:
|
||||
RtcServerAdapter();
|
||||
virtual ~RtcServerAdapter();
|
||||
public:
|
||||
virtual srs_error_t initialize();
|
||||
virtual srs_error_t run();
|
||||
virtual void stop();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue