From c95bfc4a46ec045f418ea8af114ab4ad881c83e6 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 23 Apr 2021 11:17:58 +0800 Subject: [PATCH] Timer: Apply shared FastTimer to RTC server --- trunk/src/app/srs_app_rtc_server.cpp | 15 ++++----------- trunk/src/app/srs_app_rtc_server.hpp | 9 ++++----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index 311da5050..4ba4e6ff4 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -247,7 +247,6 @@ SrsRtcServer::SrsRtcServer() { handler = NULL; hijacker = NULL; - timer = new SrsHourGlass("server", this, 1 * SRS_UTIME_SECONDS); _srs_config->subscribe(this); } @@ -256,8 +255,6 @@ SrsRtcServer::~SrsRtcServer() { _srs_config->unsubscribe(this); - srs_freep(timer); - if (true) { vector::iterator it; for (it = listeners.begin(); it != listeners.end(); ++it) { @@ -271,14 +268,10 @@ srs_error_t SrsRtcServer::initialize() { srs_error_t err = srs_success; - if ((err = timer->tick(5 * SRS_UTIME_SECONDS)) != srs_success) { - return srs_error_wrap(err, "hourglass tick"); - } - - if ((err = timer->start()) != srs_success) { - return srs_error_wrap(err, "start timer"); - } + // The RTC server start a timer, do routines of RTC server. + _srs_hybrid->timer()->subscribe(5 * SRS_UTIME_SECONDS, this); + // Initialize the black hole. if ((err = _srs_blackhole->initialize()) != srs_success) { return srs_error_wrap(err, "black hole"); } @@ -630,7 +623,7 @@ SrsRtcConnection* SrsRtcServer::find_session_by_username(const std::string& user return dynamic_cast(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; diff --git a/trunk/src/app/srs_app_rtc_server.hpp b/trunk/src/app/srs_app_rtc_server.hpp index 16aa12857..075b9d1ed 100644 --- a/trunk/src/app/srs_app_rtc_server.hpp +++ b/trunk/src/app/srs_app_rtc_server.hpp @@ -85,10 +85,9 @@ public: }; // 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: - SrsHourGlass* timer; std::vector listeners; ISrsRtcServerHandler* handler; ISrsRtcServerHijacker* hijacker; @@ -124,9 +123,9 @@ private: ); public: SrsRtcConnection* find_session_by_username(const std::string& ufrag); -// interface ISrsHourGlass -public: - virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick); +// interface ISrsFastTimer +private: + srs_error_t on_timer(srs_utime_t interval, srs_utime_t tick); }; // The RTC server adapter.