Split out mediatransportutil (#1071)

This commit is contained in:
Raja Subramanian
2022-10-06 23:55:59 +05:30
committed by GitHub
parent c3120679e6
commit 792349cc56
19 changed files with 30 additions and 1568 deletions
-34
View File
@@ -3,7 +3,6 @@ package buffer
import (
"encoding/binary"
"errors"
"time"
"github.com/livekit/protocol/logger"
)
@@ -353,36 +352,3 @@ func IsAV1Keyframe(payload []byte) bool {
}
// -------------------------------------
var (
ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
)
type NtpTime uint64
func (t NtpTime) Duration() time.Duration {
sec := (t >> 32) * 1e9
frac := (t & 0xffffffff) * 1e9
nsec := frac >> 32
if uint32(frac) >= 0x80000000 {
nsec++
}
return time.Duration(sec + nsec)
}
func (t NtpTime) Time() time.Time {
return ntpEpoch.Add(t.Duration())
}
func ToNtpTime(t time.Time) NtpTime {
nsec := uint64(t.Sub(ntpEpoch))
sec := nsec / 1e9
nsec = (nsec - sec*1e9) << 32
frac := nsec / 1e9
if nsec%1e9 >= 1e9/2 {
frac++
}
return NtpTime(sec<<32 | frac)
}
// ------------------------------------------