前移时间戳生成逻辑,防止耗时代码干扰时间戳精度

This commit is contained in:
xiongziliang 2021-10-07 15:49:33 +08:00
parent 29cc6a94f2
commit 438fd952f2
4 changed files with 11 additions and 9 deletions

View File

@ -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) {

View File

@ -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<uint32_t /*twcc_ext_seq*/, uint64_t/*recv time in ms*/> _rtp_recv_status;

View File

@ -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];

View File

@ -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<RTC::SrtpSession> _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 {};