You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
// Copyright 2020, Chef. All rights reserved.
|
|
|
|
|
// https://github.com/q191201771/lal
|
|
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a MIT-style license
|
|
|
|
|
// that can be found in the License file.
|
|
|
|
|
//
|
|
|
|
|
// Author: Chef (191201771@qq.com)
|
|
|
|
|
|
|
|
|
|
package rtprtcp
|
|
|
|
|
|
|
|
|
|
// (70 * 365 + 17) * 24 * 60 * 60
|
|
|
|
|
const offset uint64 = 2208988800
|
|
|
|
|
|
|
|
|
|
// 将ntp时间戳转换为Unix时间戳,Unix时间戳单位是纳秒
|
|
|
|
|
func NTP2UnixNano(v uint64) uint64 {
|
|
|
|
|
msw := v >> 32
|
|
|
|
|
lsw := v & 0xFFFFFFFF
|
|
|
|
|
return (msw-offset)*1e9 + (lsw*1e9)>>32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将ntp时间戳(高32位低32位分开的形式)转换为Unix时间戳
|
|
|
|
|
func MSWLSW2UnixNano(msw, lsw uint64) uint64 {
|
|
|
|
|
return NTP2UnixNano(MSWLSW2NTP(msw, lsw))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// msw是ntp的高32位,lsw是ntp的低32位
|
|
|
|
|
func MSWLSW2NTP(msw, lsw uint64) uint64 {
|
|
|
|
|
return (msw << 32) | lsw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//func UnixNano2NTP(v uint64) uint64 {
|
|
|
|
|
// msw := v / 1e9 + offset
|
|
|
|
|
// lsw := ((v % 1e9) << 32) / 1e9
|
|
|
|
|
// return (msw << 32) | lsw
|
|
|
|
|
//}
|