diff --git a/webrtc/TwccContext.cpp b/webrtc/TwccContext.cpp index fe3e6541..4df28f70 100644 --- a/webrtc/TwccContext.cpp +++ b/webrtc/TwccContext.cpp @@ -19,7 +19,7 @@ enum class ExtSeqStatus : int { jumped, }; -void TwccContext::onRtp(uint32_t ssrc, uint16_t twcc_ext_seq) { +void TwccContext::onRtp(uint32_t ssrc, uint16_t twcc_ext_seq, uint64_t stamp_ms) { switch ((ExtSeqStatus) checkSeqStatus(twcc_ext_seq)) { case ExtSeqStatus::jumped: /*回环后,收到回环前的大ext seq包,过滤掉*/ return; case ExtSeqStatus::looped: /*回环,触发发送twcc rtcp*/ onSendTwcc(ssrc); break; @@ -27,7 +27,7 @@ void TwccContext::onRtp(uint32_t ssrc, uint16_t twcc_ext_seq) { default: /*不可达*/assert(0); break; } - auto result = _rtp_recv_status.emplace(twcc_ext_seq, _ticker.createdTime()); + auto result = _rtp_recv_status.emplace(twcc_ext_seq, stamp_ms); if (!result.second) { WarnL << "recv same twcc ext seq:" << twcc_ext_seq; return; @@ -80,7 +80,9 @@ void TwccContext::onSendTwcc(uint32_t ssrc) { auto max = _rtp_recv_status.rbegin()->first; auto begin = _rtp_recv_status.begin(); auto min = begin->first; + //参考时间戳的最小单位是64ms auto ref_time = begin->second >> 6; + //还原基准时间戳 auto last_time = ref_time << 6; FCI_TWCC::TwccPacketStatus status; for (auto seq = min; seq <= max; ++seq) { diff --git a/webrtc/TwccContext.h b/webrtc/TwccContext.h index d005e3ce..76334a2c 100644 --- a/webrtc/TwccContext.h +++ b/webrtc/TwccContext.h @@ -27,7 +27,7 @@ public: TwccContext() = default; ~TwccContext() = default; - void onRtp(uint32_t ssrc, uint16_t twcc_ext_seq); + void onRtp(uint32_t ssrc, uint16_t twcc_ext_seq, uint64_t stamp_ms); void setOnSendTwccCB(onSendTwccCB cb); private: @@ -37,7 +37,6 @@ private: void clearStatus(); private: - Ticker _ticker; uint64_t _min_stamp = 0; uint64_t _max_stamp; std::map _rtp_recv_status; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index cdd69d44..2b74ea8c 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -267,7 +267,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup return; } if (_srtp_session_recv->DecryptSrtp((uint8_t *) buf, &len)) { - onRtp(buf, len); + onRtp(buf, len, _ticker.createdTime()); } return; } @@ -795,7 +795,7 @@ void WebRtcTransportImp::createRtpChannel(const string &rid, uint32_t ssrc, Medi InfoL << "create rtp receiver of ssrc:" << ssrc << ", rid:" << rid << ", codec:" << track.plan_rtp->codec; } -void WebRtcTransportImp::onRtp(const char *buf, size_t len) { +void WebRtcTransportImp::onRtp(const char *buf, size_t len, uint64_t stamp_ms) { _bytes_usage += len; _alive_ticker.resetTime(); @@ -814,7 +814,7 @@ void WebRtcTransportImp::onRtp(const char *buf, size_t len) { string rid; auto twcc_ext = track->rtp_ext_ctx->changeRtpExtId(rtp, true, &rid, RtpExtType::transport_cc); if (twcc_ext && !is_rtx) { - _twcc_ctx.onRtp(ssrc, twcc_ext.getTransportCCSeq()); + _twcc_ctx.onRtp(ssrc, twcc_ext.getTransportCCSeq(), stamp_ms); } auto &ref = track->rtp_channel[rid]; diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index fbdbc6f1..069c0cda 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -109,7 +109,7 @@ protected: virtual void onCheckSdp(SdpType type, RtcSession &sdp); virtual void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) = 0; - virtual void onRtp(const char *buf, size_t len) = 0; + virtual void onRtp(const char *buf, size_t len, uint64_t stamp_ms) = 0; virtual void onRtcp(const char *buf, size_t len) = 0; virtual void onShutdown(const SockException &ex) = 0; virtual void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) = 0; @@ -135,6 +135,7 @@ private: std::shared_ptr _srtp_session_recv; RtcSession::Ptr _offer_sdp; RtcSession::Ptr _answer_sdp; + Ticker _ticker; }; class RtpChannel; @@ -187,7 +188,7 @@ protected: void onCheckSdp(SdpType type, RtcSession &sdp) override; void onRtcConfigure(RtcConfigure &configure) const override; - void onRtp(const char *buf, size_t len) override; + void onRtp(const char *buf, size_t len, uint64_t stamp_ms) override; void onRtcp(const char *buf, size_t len) override; void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override; void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};