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

来源:互联网 发布:域名后缀org含义 编辑:程序博客网 时间:2020/11/25 15:47

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

首先我们看下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);    //...省略   }