1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Timer: Apply shared FastTimer to RTC server

This commit is contained in:
winlin 2021-04-23 11:17:58 +08:00
parent 7b413edbb7
commit c95bfc4a46
2 changed files with 8 additions and 16 deletions

View file

@ -247,7 +247,6 @@ SrsRtcServer::SrsRtcServer()
{ {
handler = NULL; handler = NULL;
hijacker = NULL; hijacker = NULL;
timer = new SrsHourGlass("server", this, 1 * SRS_UTIME_SECONDS);
_srs_config->subscribe(this); _srs_config->subscribe(this);
} }
@ -256,8 +255,6 @@ SrsRtcServer::~SrsRtcServer()
{ {
_srs_config->unsubscribe(this); _srs_config->unsubscribe(this);
srs_freep(timer);
if (true) { if (true) {
vector<SrsUdpMuxListener*>::iterator it; vector<SrsUdpMuxListener*>::iterator it;
for (it = listeners.begin(); it != listeners.end(); ++it) { for (it = listeners.begin(); it != listeners.end(); ++it) {
@ -271,14 +268,10 @@ srs_error_t SrsRtcServer::initialize()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if ((err = timer->tick(5 * SRS_UTIME_SECONDS)) != srs_success) { // The RTC server start a timer, do routines of RTC server.
return srs_error_wrap(err, "hourglass tick"); _srs_hybrid->timer()->subscribe(5 * SRS_UTIME_SECONDS, this);
}
if ((err = timer->start()) != srs_success) {
return srs_error_wrap(err, "start timer");
}
// Initialize the black hole.
if ((err = _srs_blackhole->initialize()) != srs_success) { if ((err = _srs_blackhole->initialize()) != srs_success) {
return srs_error_wrap(err, "black hole"); return srs_error_wrap(err, "black hole");
} }
@ -630,7 +623,7 @@ SrsRtcConnection* SrsRtcServer::find_session_by_username(const std::string& user
return dynamic_cast<SrsRtcConnection*>(conn); return dynamic_cast<SrsRtcConnection*>(conn);
} }
srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tick) srs_error_t SrsRtcServer::on_timer(srs_utime_t interval, srs_utime_t tick)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;

View file

@ -85,10 +85,9 @@ public:
}; };
// The RTC server instance, listen UDP port, handle UDP packet, manage RTC connections. // The RTC server instance, listen UDP port, handle UDP packet, manage RTC connections.
class SrsRtcServer : virtual public ISrsUdpMuxHandler, virtual public ISrsHourGlass, virtual public ISrsReloadHandler class SrsRtcServer : public ISrsUdpMuxHandler, public ISrsFastTimer, public ISrsReloadHandler
{ {
private: private:
SrsHourGlass* timer;
std::vector<SrsUdpMuxListener*> listeners; std::vector<SrsUdpMuxListener*> listeners;
ISrsRtcServerHandler* handler; ISrsRtcServerHandler* handler;
ISrsRtcServerHijacker* hijacker; ISrsRtcServerHijacker* hijacker;
@ -124,9 +123,9 @@ private:
); );
public: public:
SrsRtcConnection* find_session_by_username(const std::string& ufrag); SrsRtcConnection* find_session_by_username(const std::string& ufrag);
// interface ISrsHourGlass // interface ISrsFastTimer
public: private:
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick); srs_error_t on_timer(srs_utime_t interval, srs_utime_t tick);
}; };
// The RTC server adapter. // The RTC server adapter.