Source File
abssendtimeextension.go
Belonging Package
github.com/pion/rtp
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage rtpimport ()const (absSendTimeExtensionSize = 3)// AbsSendTimeExtension is a extension payload format in// http://www.webrtc.org/experiments/rtp-hdrext/abs-send-timetype AbsSendTimeExtension struct {Timestamp uint64}// Marshal serializes the members to buffer.func ( AbsSendTimeExtension) () ([]byte, error) {return []byte{byte(.Timestamp & 0xFF0000 >> 16),byte(.Timestamp & 0xFF00 >> 8),byte(.Timestamp & 0xFF),}, nil}// Unmarshal parses the passed byte slice and stores the result in the members.func ( *AbsSendTimeExtension) ( []byte) error {if len() < absSendTimeExtensionSize {return errTooSmall}.Timestamp = uint64([0])<<16 | uint64([1])<<8 | uint64([2])return nil}// Estimate absolute send time according to the receive time.// Note that if the transmission delay is larger than 64 seconds, estimated time will be wrong.func ( *AbsSendTimeExtension) ( time.Time) time.Time {:= toNtpTime():= &0xFFFFFFC000000000 | (.Timestamp&0xFFFFFF)<<14if < {// Receive time must be always later than send time-= 0x1000000 << 14}return toTime()}// NewAbsSendTimeExtension makes new AbsSendTimeExtension from time.Time.func ( time.Time) *AbsSendTimeExtension {return &AbsSendTimeExtension{Timestamp: toNtpTime() >> 14,}}func toNtpTime( time.Time) uint64 {var uint64var uint64:= uint64(.UnixNano()) // nolint: gosec // G115 false positive= / 1e9+= 0x83AA7E80 // offset in seconds between unix epoch and ntp epoch= % 1e9<<= 32/= 1e9<<= 32return |}func toTime( uint64) time.Time {:= >> 32:= & 0xFFFFFFFF*= 1e9>>= 32-= 0x83AA7E80:= *1e9 +return time.Unix(0, int64()) // nolint: gosec // G115 false positive}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |