RR报文解析(三)利用LSR, DLSR计算RTT

同样,先附上报文图:
这里写图片描述

首先我们看下RFC3550中,LSR的说明:
last SR timestamp (LSR): 32 bits
The middle 32 bits out of 64 in the NTP timestamp (as explained in
Section 4) received as part of the most recent RTCP sender report
(SR) packet from source SSRC_n. If no SR has been received yet,
the field is set to zero.

翻译过来大概是:这是上一次从SSRC_n源端发过来的SR报文的NTP timestamp(64位)的中间32位(为何如此请看Section 4)。如果没有收到过SR报文,该域置0.

DLSR的说明:
delay since last SR (DLSR): 32 bits
The delay, expressed in units of 1/65536 seconds, between
receiving the last SR packet from source SSRC_n and sending this
reception report block. If no SR packet has been received yet
from SSRC_n, the DLSR field is set to zero.

大概的意思是:这是一个延时,它的值等于发送这个report block的时间,减去它收到的最新的SR报文的时间。

我估计你还没有看懂,我再举个例子吧。假设有A, B两端,A就是本端,B是对端:
这里写图片描述

因此,A到B的往返时间为:rtt = t2 - delay - t1 = t2 - DLSR - LSR。

我们来看下代码:

void RTCPReceiver::HandleReportBlock(
    const RTCPUtility::RTCPPacket& rtcpPacket,
    RTCPPacketInformation& rtcpPacketInformation,
    uint32_t remoteSSRC) {
    //...省略

  int64_t rtt = 0;
  uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR;  //LSR
  if (!receiver_only_ && send_time != 0) {
    uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR;  //DLSR
    // Local NTP time.
    uint32_t receive_time = CompactNtp(NtpTime(*_clock));  //当前时间,即接收到RR的时间

    // RTT in 1/(2^16) seconds.
    uint32_t rtt_ntp = receive_time - delay - send_time;
    // Convert to 1/1000 seconds (milliseconds).
    rtt = CompactNtpRttToMs(rtt_ntp);

    //...省略   
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值