直播:后台 JWT 推流、前台画中画;WebRTC 服务与 Nginx WebSocket 代理
Made-with: Cursor
This commit is contained in:
30
server/vendor/github.com/pion/interceptor/internal/ntp/ntp.go
generated
vendored
Normal file
30
server/vendor/github.com/pion/interceptor/internal/ntp/ntp.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Package ntp provides conversion methods between time.Time and NTP timestamps
|
||||
// stored in uint64
|
||||
package ntp
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ToNTP converts a time.Time oboject to an uint64 NTP timestamp
|
||||
func ToNTP(t time.Time) uint64 {
|
||||
// seconds since 1st January 1900
|
||||
s := (float64(t.UnixNano()) / 1000000000) + 2208988800
|
||||
|
||||
// higher 32 bits are the integer part, lower 32 bits are the fractional part
|
||||
integerPart := uint32(s)
|
||||
fractionalPart := uint32((s - float64(integerPart)) * 0xFFFFFFFF)
|
||||
return uint64(integerPart)<<32 | uint64(fractionalPart)
|
||||
}
|
||||
|
||||
// ToTime converts a uint64 NTP timestamps to a time.Time object
|
||||
func ToTime(t uint64) time.Time {
|
||||
seconds := (t & 0xFFFFFFFF00000000) >> 32
|
||||
fractional := float64(t&0x00000000FFFFFFFF) / float64(0xFFFFFFFF)
|
||||
d := time.Duration(seconds)*time.Second + time.Duration(fractional*1e9)*time.Nanosecond
|
||||
|
||||
return time.Unix(0, 0).Add(-2208988800 * time.Second).Add(d)
|
||||
}
|
||||
45
server/vendor/github.com/pion/interceptor/internal/sequencenumber/unwrapper.go
generated
vendored
Normal file
45
server/vendor/github.com/pion/interceptor/internal/sequencenumber/unwrapper.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Package sequencenumber provides a sequence number unwrapper
|
||||
package sequencenumber
|
||||
|
||||
const (
|
||||
maxSequenceNumberPlusOne = int64(65536)
|
||||
breakpoint = 32768 // half of max uint16
|
||||
)
|
||||
|
||||
// Unwrapper stores an unwrapped sequence number
|
||||
type Unwrapper struct {
|
||||
init bool
|
||||
lastUnwrapped int64
|
||||
}
|
||||
|
||||
func isNewer(value, previous uint16) bool {
|
||||
if value-previous == breakpoint {
|
||||
return value > previous
|
||||
}
|
||||
return value != previous && (value-previous) < breakpoint
|
||||
}
|
||||
|
||||
// Unwrap unwraps the next sequencenumber
|
||||
func (u *Unwrapper) Unwrap(i uint16) int64 {
|
||||
if !u.init {
|
||||
u.init = true
|
||||
u.lastUnwrapped = int64(i)
|
||||
return u.lastUnwrapped
|
||||
}
|
||||
|
||||
lastWrapped := uint16(u.lastUnwrapped)
|
||||
delta := int64(i - lastWrapped)
|
||||
if isNewer(i, lastWrapped) {
|
||||
if delta < 0 {
|
||||
delta += maxSequenceNumberPlusOne
|
||||
}
|
||||
} else if delta > 0 && u.lastUnwrapped+delta-maxSequenceNumberPlusOne >= 0 {
|
||||
delta -= maxSequenceNumberPlusOne
|
||||
}
|
||||
|
||||
u.lastUnwrapped += delta
|
||||
return u.lastUnwrapped
|
||||
}
|
||||
Reference in New Issue
Block a user