关于 RTCP中的NTP Time计算有很多人不清楚,还好因为有很多开源的rtp库,这里可以参考ORTP库中的算法:
//oRTP开源工程
uint64_t ortp_timeval_to_ntp(const struct timeval *tv){
uint64_t msw;
uint64_t lsw;
msw=tv->tv_sec + 0x83AA7E80; /* 0x83AA7E80 is the number of seconds from 1900 to 1970 */
lsw=(uint32_t)((double)tv->tv_usec*(double)(((uint64_t)1)<<32)*1.0e-6);
return msw<<32 | lsw;
}
static void sender_info_init(sender_info_t *info, RtpSession *session){
struct timeval tv;
uint64_t ntp;
ortp_gettimeofday(&tv,NULL);
ntp=ortp_timeval_to_ntp(&tv);
info->ntp_timestamp_msw=htonl(ntp >>32);
info->ntp_timestamp_lsw=htonl(ntp & 0xFFFFFFFF);
info->rtp_timestamp=hton
本文详细介绍了如何计算RTCP包中的NTP时间,包括从`ortp_timeval_to_ntp`函数到`tsk_time_get_ntp_ms`的实现。通过分析开源项目如oRTP和Doubango的代码,以及解决实际问题的经验分享,阐述了NTP时间戳的MSW和LSW计算方法,特别是LSW单位为232.8皮秒的由来。
订阅专栏 解锁全文
1679

被折叠的 条评论
为什么被折叠?



