diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index 40bbc48dc0..9659a1ee34 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -1318,6 +1318,7 @@ SrsRtcFrameBuilder::SrsRtcFrameBuilder(ISrsStreamBridge* bridge) header_sn_ = 0; memset(cache_video_pkts_, 0, sizeof(cache_video_pkts_)); rtp_key_frame_ts_ = -1; + sync_state_ = -1; } SrsRtcFrameBuilder::~SrsRtcFrameBuilder() @@ -1366,8 +1367,18 @@ srs_error_t SrsRtcFrameBuilder::on_rtp(SrsRtpPacket *pkt) // Have no received any sender report, can't calculate avsync_time, // discard it to avoid timestamp problem in live source + const SrsRtpHeader& h = pkt->header; if (pkt->get_avsync_time() <= 0) { + if (sync_state_ < 0) { + srs_trace("RTC: Discard no-sync %s, ssrc=%u, seq=%u, ts=%u, state=%d", pkt->is_audio() ? "Audio" : "Video", + h.get_ssrc(), h.get_sequence(), h.get_timestamp(), sync_state_); + sync_state_ = 0; + } return err; + } else if (sync_state_ < 1) { + srs_trace("RTC: Accept sync %s, ssrc=%u, seq=%u, ts=%u, state=%d", pkt->is_audio() ? "Audio" : "Video", + h.get_ssrc(), h.get_sequence(), h.get_timestamp(), sync_state_); + sync_state_ = 2; } if (pkt->is_audio()) { diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index 191e7d7ec4..e9ee683fa6 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -318,6 +318,8 @@ class SrsRtcFrameBuilder uint16_t header_sn_; uint16_t lost_sn_; int64_t rtp_key_frame_ts_; + // The state for timestamp sync state. -1 for init. 0 not sync. 1 sync. + int sync_state_; public: SrsRtcFrameBuilder(ISrsStreamBridge* bridge); virtual ~SrsRtcFrameBuilder();