diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 0a4115764..ec475d335 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -58,6 +58,8 @@ using namespace std; #include #include +#define SRS_TICKID_RTCP 0 + SrsSecurityTransport::SrsSecurityTransport(SrsRtcConnection* s) { session_ = s; @@ -227,6 +229,7 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, SrsContextId parent_cid) nack_enabled_ = false; _srs_config->subscribe(this); + timer_ = new SrsHourGlass(this, 1000 * SRS_UTIME_MILLISECONDS); } SrsRtcPlayStream::~SrsRtcPlayStream() @@ -234,6 +237,7 @@ SrsRtcPlayStream::~SrsRtcPlayStream() _srs_config->unsubscribe(this); srs_freep(trd); + srs_freep(timer_); if (true) { std::map::iterator it; @@ -321,6 +325,10 @@ srs_error_t SrsRtcPlayStream::start() return srs_error_wrap(err, "rtc_sender"); } + if ((err = timer_->start()) != srs_success) { + return srs_error_wrap(err, "start timer"); + } + if (_srs_rtc_hijacker) { if ((err = _srs_rtc_hijacker->on_start_play(session_, this, session_->req)) != srs_success) { return srs_error_wrap(err, "on start play"); @@ -517,6 +525,17 @@ void SrsRtcPlayStream::nack_fetch(vector& pkts, uint32_t ssrc, u } } +srs_error_t SrsRtcPlayStream::notify(int type, srs_utime_t interval, srs_utime_t tick) +{ + srs_error_t err = srs_success; + + if (!is_started) { + return err; + } + + return err; +} + srs_error_t SrsRtcPlayStream::on_rtcp(char* data, int nb_data) { srs_error_t err = srs_success; @@ -770,7 +789,7 @@ uint32_t SrsRtcPlayStream::get_video_publish_ssrc(uint32_t play_ssrc) SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session) { - report_timer = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS); + timer_ = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS); session_ = session; request_keyframe_ = false; @@ -795,7 +814,7 @@ SrsRtcPublishStream::~SrsRtcPublishStream() } srs_freep(req); - srs_freep(report_timer); + srs_freep(timer_); } srs_error_t SrsRtcPublishStream::initialize(SrsRequest* r, SrsRtcStreamDescription* stream_desc) @@ -841,17 +860,16 @@ srs_error_t SrsRtcPublishStream::start() { srs_error_t err = srs_success; - // If report_timer started, we think the publisher is started. if (is_started) { return err; } - if ((err = report_timer->tick(0 * SRS_UTIME_MILLISECONDS)) != srs_success) { - return srs_error_wrap(err, "hourglass tick"); + if ((err = timer_->tick(SRS_TICKID_RTCP, 200 * SRS_UTIME_MILLISECONDS)) != srs_success) { + return srs_error_wrap(err, "rtcp tick"); } - if ((err = report_timer->start()) != srs_success) { - return srs_error_wrap(err, "start report_timer"); + if ((err = timer_->start()) != srs_success) { + return srs_error_wrap(err, "start timer"); } if ((err = _srs_rtc_sources->fetch_or_create(req, &source)) != srs_success) { @@ -1437,14 +1455,20 @@ srs_error_t SrsRtcPublishStream::notify(int type, srs_utime_t interval, srs_utim { srs_error_t err = srs_success; - // TODO: FIXME: Check error. - send_rtcp_rr(); - send_rtcp_xr_rrtr(); + if (!is_started) { + return err; + } - // TODO: FIXME: Check error. - // We should not depends on the received packet, - // instead we should send feedback every Nms. - send_periodic_twcc(); + if (type == SRS_TICKID_RTCP) { + // TODO: FIXME: Check error. + send_rtcp_rr(); + send_rtcp_xr_rrtr(); + + // TODO: FIXME: Check error. + // We should not depends on the received packet, + // instead we should send feedback every Nms. + send_periodic_twcc(); + } return err; } diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index 0a5820dca..baadfd347 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -166,13 +166,14 @@ public: }; // A RTC play stream, client pull and play stream from SRS. -class SrsRtcPlayStream : virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler +class SrsRtcPlayStream : virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler, virtual public ISrsHourGlass { -protected: +private: SrsContextId _parent_cid; SrsCoroutine* trd; SrsRtcConnection* session_; private: + SrsHourGlass* timer_; // key: publish_ssrc, value: send track to process rtp/rtcp std::map audio_tracks_; std::map video_tracks_; @@ -207,6 +208,9 @@ private: srs_error_t send_packets(SrsRtcStream* source, const std::vector& pkts, SrsRtcPlayStreamStatistic& info); public: void nack_fetch(std::vector& pkts, uint32_t ssrc, uint16_t seq); +// interface ISrsHourGlass +public: + virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick); public: srs_error_t on_rtcp(char* data, int nb_data); private: @@ -222,7 +226,7 @@ private: class SrsRtcPublishStream : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler, virtual public ISrsRtcPublishStream { private: - SrsHourGlass* report_timer; + SrsHourGlass* timer_; uint64_t nn_audio_frames; private: SrsRtcConnection* session_; diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index 6e97fde24..779473fcb 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -1506,7 +1506,6 @@ SrsRtcTrackDescription* SrsRtcStreamDescription::find_track_description_by_ssrc( SrsRtcTrackStatistic::SrsRtcTrackStatistic() { - last_written = 0; packets = 0; last_packets = 0; bytes = 0; diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index dcca61f61..459b38d82 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -407,8 +407,6 @@ public: class SrsRtcTrackStatistic { public: - srs_utime_t last_written; - // packets received or sent. uint32_t packets; // packets received or sent at last statistic time.