美文网首页
webrtc中ntp时间戳的计算

webrtc中ntp时间戳的计算

作者: hijiang | 来源:发表于2019-08-02 16:35 被阅读0次

NTP时间在webrtc中是rtt计算的基础,NTP时间戳是从1900年1月1日经历的秒数,一般用64位表示,高32位表示秒数的整数部分,低32位每位表示微秒部分(以秒为单位的小数)的232=4.294967296*109倍;

来看看webrtc的处理:

const double kMagicNtpFractionalUnit = 4.294967296E+9;(=2^32)
// Retrieve an NTP absolute timestamp.
  NtpTime CurrentNtpTime() const override {
    timeval tv = CurrentTimeVal();//获取到tv结构,包括tv_sec及tv_usec
    double microseconds_in_seconds;
    uint32_t seconds;
    Adjust(tv, &seconds, &microseconds_in_seconds);//计算1900开始的秒数及微秒
    uint32_t fractions = static_cast<uint32_t>(
        microseconds_in_seconds * kMagicNtpFractionalUnit + 0.5);
    return NtpTime(seconds, fractions);
  }
static void Adjust(const timeval& tv,
                     uint32_t* adjusted_s,
                     double* adjusted_us_in_s) {
    *adjusted_s = tv.tv_sec + kNtpJan1970;//NTP时间是从1900年开始,所以需要加上这个70年经过的秒数
    *adjusted_us_in_s = tv.tv_usec / 1e6;//微秒时间的小数表示

    if (*adjusted_us_in_s >= 1) {
      *adjusted_us_in_s -= 1;
      ++*adjusted_s;
    } else if (*adjusted_us_in_s < -1) {
      *adjusted_us_in_s += 1;
      --*adjusted_s;
    }
  }
};

同时,webrtc中sr包及rr中中last_sr是一种压缩过的NTP时间戳,采用32位表示,只保留原来64位的中继32位,高16位表示秒数,低16位表示微秒,单位也一样。
webrtc使用下面这个函数将64位ntp时间戳转为32位的ntp时间戳:

// Helper function for compact ntp representation:
// RFC 3550, Section 4. Time Format.
// Wallclock time is represented using the timestamp format of
// the Network Time Protocol (NTP).
// ...
// In some fields where a more compact representation is
// appropriate, only the middle 32 bits are used; that is, the low 16
// bits of the integer part and the high 16 bits of the fractional part.
inline uint32_t CompactNtp(NtpTime ntp) {
  return (ntp.seconds() << 16) | (ntp.fractions() >> 16);
}

webrtc中,last_sr,使用的是32为NTP,delay使用的是1/2^16秒为单位;

相关文章

  • webrtc中ntp时间戳的计算

    NTP时间在webrtc中是rtt计算的基础,NTP时间戳是从1900年1月1日经历的秒数,一般用64位表示,高3...

  • webrtc RTT计算及NTP时间戳

    RTT:round-trip time(往返时延),是指从数据包发送开始,到接收端确认接收,然后发送确认给发送端总...

  • web的时间戳与NTP

    1、滴答滴答滴 :(就是平台相关的计算ns时间,记住是相对时间哦) 2、webrtc 开机计算一次 NTP矫正时间...

  • ntp服务器搭建

    1. NTP简介 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间...

  • 记一次离线部署ntp时间对时服务器

    NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议NTP...

  • NTP时间戳转换

    场景 腾讯视频云直播答题NTP时间同步方案是在推流 URL 之后添加 &txAddTimestamp=2 参数(之...

  • 简单搭建本地ntp时间服务器

    标签(空格分隔): Linux ntp NTP(Network Time Protocol): 同步网络中各个计算...

  • 搭建ntp服务

    ntp简介 ntp全称Network Time Protocol(NTP)是用来使计算机[时间同步化的一种协议,它...

  • Linux服务器时间同步

    NTP 是什么? NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算...

  • 4. [HDP-准备] ntp(Network Time Pro

    ndp介绍:NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间...

网友评论

      本文标题:webrtc中ntp时间戳的计算

      本文链接:https://www.haomeiwen.com/subject/fcgldctx.html