buffer

package
v0.15.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GapHistogramNumBins = 101
	SequenceNumberMin   = uint16(0)
	SequenceNumberMax   = uint16(65535)
	NumSequenceNumbers  = 65536
	FirstSnapshotId     = 1
	SnInfoSize          = 2048
	SnInfoMask          = SnInfoSize - 1
)
View Source
const (
	ReportDelta = 1e9
)

Variables

View Source
var (
	ErrPacketNotFound = errors.New("packet not found in cache")
	ErrBufferTooSmall = errors.New("buffer too small")
	ErrPacketTooOld   = errors.New("received packet too old")
	ErrRTXPacket      = errors.New("packet already received")
)

Functions

func AggregateRTPStats added in v0.15.6

func AggregateRTPStats(statsList []*livekit.RTPStats) *livekit.RTPStats

func IsAV1Keyframe added in v0.15.7

func IsAV1Keyframe(payload []byte) bool

IsAV1Keyframe detects if av1 payload is a keyframe taken from https://github.com/jech/galene/blob/master/codecs/codecs.go all credits belongs to Juliusz Chroboczek @jech and the awesome Galene SFU

func IsH264Keyframe added in v0.15.0

func IsH264Keyframe(payload []byte) bool

IsH264Keyframe detects if h264 payload is a keyframe this code was taken from https://github.com/jech/galene/blob/codecs/rtpconn/rtpreader.go#L45 all credits belongs to Juliusz Chroboczek @jech and the awesome Galene SFU

func IsVp9Keyframe added in v0.15.7

func IsVp9Keyframe(payload []byte) bool

IsAV1Keyframe detects if vp9 payload is a keyframe taken from https://github.com/jech/galene/blob/master/codecs/codecs.go all credits belongs to Juliusz Chroboczek @jech and the awesome Galene SFU

func VP8PictureIdSizeDiff

func VP8PictureIdSizeDiff(mBit1 bool, mBit2 bool) int

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

func NewBucket

func NewBucket(buf *[]byte) *Bucket

func (*Bucket) AddPacket

func (b *Bucket) AddPacket(pkt []byte) ([]byte, error)

func (*Bucket) GetPacket

func (b *Bucket) GetPacket(buf []byte, sn uint16) (i int, err error)

type Buffer

type Buffer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Buffer contains all packets

func NewBuffer

func NewBuffer(ssrc uint32, vp, ap *sync.Pool) *Buffer

NewBuffer constructs a new Buffer

func (*Buffer) Bind

func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapability)

func (*Buffer) Close

func (b *Buffer) Close() error

func (*Buffer) GetAudioLevel added in v0.15.7

func (b *Buffer) GetAudioLevel() (float64, bool)

func (*Buffer) GetClockRate

func (b *Buffer) GetClockRate() uint32

GetClockRate returns the RTP clock rate

func (*Buffer) GetDeltaStats added in v0.15.7

func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers

func (*Buffer) GetMediaSSRC

func (b *Buffer) GetMediaSSRC() uint32

GetMediaSSRC returns the associated SSRC of the RTP stream

func (*Buffer) GetPacket

func (b *Buffer) GetPacket(buff []byte, sn uint16) (int, error)

func (*Buffer) GetQualityInfo added in v0.15.6

func (b *Buffer) GetQualityInfo() *RTPSnapshotInfo

func (*Buffer) GetStats

func (b *Buffer) GetStats() *livekit.RTPStats

func (*Buffer) OnClose

func (b *Buffer) OnClose(fn func())

func (*Buffer) OnRtcpFeedback added in v0.15.7

func (b *Buffer) OnRtcpFeedback(fn func(fb []rtcp.Packet))

func (*Buffer) Read

func (b *Buffer) Read(buff []byte) (n int, err error)

func (*Buffer) ReadExtended

func (b *Buffer) ReadExtended() (*ExtPacket, error)

func (*Buffer) SendPLI added in v0.15.4

func (b *Buffer) SendPLI()

func (*Buffer) SetAudioLevelParams added in v0.15.7

func (b *Buffer) SetAudioLevelParams(audioLevelParams audio.AudioLevelParams)

func (*Buffer) SetLastFractionLostReport

func (b *Buffer) SetLastFractionLostReport(lost uint8)

func (*Buffer) SetLogger added in v0.15.4

func (b *Buffer) SetLogger(logger logger.Logger)

func (*Buffer) SetPLIThrottle added in v0.15.4

func (b *Buffer) SetPLIThrottle(duration int64)

func (*Buffer) SetRTT added in v0.15.4

func (b *Buffer) SetRTT(rtt uint32)

func (*Buffer) SetSenderReportData

func (b *Buffer) SetSenderReportData(rtpTime uint32, ntpTime uint64)

func (*Buffer) SetTWCC added in v0.15.7

func (b *Buffer) SetTWCC(twcc *twcc.Responder)

func (*Buffer) Write

func (b *Buffer) Write(pkt []byte) (n int, err error)

Write adds an RTP Packet, out of order, new packet may be arrived later

type ConnectionQualityParams added in v0.15.6

type ConnectionQualityParams struct {
	LossPercentage float32
	Jitter         float32
	Rtt            uint32
}

type DataStats added in v0.15.6

type DataStats struct {
	// contains filtered or unexported fields
}

func NewDataStats added in v0.15.6

func NewDataStats(params DataStatsParam) *DataStats

func (*DataStats) Stop added in v0.15.6

func (s *DataStats) Stop()

func (*DataStats) ToProtoActive added in v0.15.6

func (s *DataStats) ToProtoActive() *livekit.RTPStats

func (*DataStats) ToProtoAggregateOnly added in v0.15.6

func (s *DataStats) ToProtoAggregateOnly() *livekit.RTPStats

func (*DataStats) Update added in v0.15.6

func (s *DataStats) Update(bytes int, time int64)

type DataStatsParam added in v0.15.6

type DataStatsParam struct {
	WindowDuration time.Duration
}

type ExtPacket

type ExtPacket struct {
	Head          bool
	Arrival       int64
	Packet        *rtp.Packet
	Payload       interface{}
	KeyFrame      bool
	RawPacket     []byte
	SpatialLayer  int32
	TemporalLayer int32
}

type Factory

type Factory struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBufferFactory

func NewBufferFactory(trackingPackets int) *Factory

func (*Factory) GetBuffer

func (f *Factory) GetBuffer(ssrc uint32) *Buffer

func (*Factory) GetBufferPair

func (f *Factory) GetBufferPair(ssrc uint32) (*Buffer, *RTCPReader)

func (*Factory) GetOrNew

func (f *Factory) GetOrNew(packetType packetio.BufferPacketType, ssrc uint32) io.ReadWriteCloser

func (*Factory) GetRTCPReader

func (f *Factory) GetRTCPReader(ssrc uint32) *RTCPReader

type LayerStats added in v0.15.4

type LayerStats struct {
	Packets uint32
	Bytes   uint64
	Frames  uint32
}

type NackQueue added in v0.15.0

type NackQueue struct {
	// contains filtered or unexported fields
}

func NewNACKQueue added in v0.15.0

func NewNACKQueue() *NackQueue

func (*NackQueue) Pairs added in v0.15.0

func (n *NackQueue) Pairs() ([]rtcp.NackPair, int)

func (*NackQueue) Push added in v0.15.0

func (n *NackQueue) Push(sn uint16)

func (*NackQueue) Remove added in v0.15.0

func (n *NackQueue) Remove(sn uint16)

func (*NackQueue) SetRTT added in v0.15.4

func (n *NackQueue) SetRTT(rtt uint32)

type NtpTime added in v0.15.6

type NtpTime uint64

func ToNtpTime added in v0.15.6

func ToNtpTime(t time.Time) NtpTime

func (NtpTime) Duration added in v0.15.6

func (t NtpTime) Duration() time.Duration

func (NtpTime) Time added in v0.15.6

func (t NtpTime) Time() time.Time

type Options

type Options struct {
	MaxBitRate uint64
}

BufferOptions provides configuration options for the buffer

type RTCPReader

type RTCPReader struct {
	// contains filtered or unexported fields
}

func NewRTCPReader

func NewRTCPReader(ssrc uint32) *RTCPReader

func (*RTCPReader) Close

func (r *RTCPReader) Close() error

func (*RTCPReader) OnClose

func (r *RTCPReader) OnClose(fn func())

func (*RTCPReader) OnPacket

func (r *RTCPReader) OnPacket(f func([]byte))

func (*RTCPReader) Read

func (r *RTCPReader) Read(_ []byte) (n int, err error)

func (*RTCPReader) Write

func (r *RTCPReader) Write(p []byte) (n int, err error)

type RTPDeltaInfo added in v0.15.7

type RTPDeltaInfo struct {
	Packets          uint32
	Bytes            uint64
	PacketsDuplicate uint32
	BytesDuplicate   uint64
	PacketsPadding   uint32
	BytesPadding     uint64
	PacketsLost      uint32
	Frames           uint32
	RttMax           uint32
	JitterMax        float64
	Nacks            uint32
	Plis             uint32
	Firs             uint32
}

type RTPFlowState added in v0.15.6

type RTPFlowState struct {
	IsHighestSN        bool
	HasLoss            bool
	LossStartInclusive uint16
	LossEndExclusive   uint16
}

type RTPSnapshotInfo added in v0.15.6

type RTPSnapshotInfo struct {
	PacketsExpected uint32
	PacketsLost     uint32
	JitterMax       float64
	RttMax          uint32
}

type RTPStats added in v0.15.6

type RTPStats struct {
	// contains filtered or unexported fields
}

func NewRTPStats added in v0.15.6

func NewRTPStats(params RTPStatsParams) *RTPStats

func (*RTPStats) DeltaInfo added in v0.15.7

func (r *RTPStats) DeltaInfo(snapshotId uint32) *RTPDeltaInfo

func (*RTPStats) GetRtcpSenderReport added in v0.15.6

func (r *RTPStats) GetRtcpSenderReport(ssrc uint32) *rtcp.SenderReport

func (*RTPStats) GetRtt added in v0.15.6

func (r *RTPStats) GetRtt() uint32

func (*RTPStats) GetTotalPacketsPrimary added in v0.15.6

func (r *RTPStats) GetTotalPacketsPrimary() uint32

func (*RTPStats) IsActive added in v0.15.6

func (r *RTPStats) IsActive() bool

func (*RTPStats) LastPli added in v0.15.6

func (r *RTPStats) LastPli() time.Time

func (*RTPStats) NewSnapshotId added in v0.15.6

func (r *RTPStats) NewSnapshotId() uint32

func (*RTPStats) SetLogger added in v0.15.6

func (r *RTPStats) SetLogger(logger logger.Logger)

func (*RTPStats) SetRtcpSenderReportData added in v0.15.6

func (r *RTPStats) SetRtcpSenderReportData(rtpTS uint32, ntpTS NtpTime, arrival time.Time)

func (*RTPStats) SnapshotInfo added in v0.15.6

func (r *RTPStats) SnapshotInfo(snapshotId uint32) *RTPSnapshotInfo

func (*RTPStats) SnapshotRtcpReceptionReport added in v0.15.6

func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8, snapshotId uint32) *rtcp.ReceptionReport

func (*RTPStats) Stop added in v0.15.6

func (r *RTPStats) Stop()

func (*RTPStats) TimeSinceLastPli added in v0.15.6

func (r *RTPStats) TimeSinceLastPli() int64

func (*RTPStats) ToProto added in v0.15.6

func (r *RTPStats) ToProto() *livekit.RTPStats

func (*RTPStats) ToString added in v0.15.6

func (r *RTPStats) ToString() string

func (*RTPStats) Update added in v0.15.6

func (r *RTPStats) Update(rtph *rtp.Header, payloadSize int, paddingSize int, packetTime int64) (flowState RTPFlowState)

func (*RTPStats) UpdateFir added in v0.15.6

func (r *RTPStats) UpdateFir(firCount uint32)

func (*RTPStats) UpdateFirTime added in v0.15.6

func (r *RTPStats) UpdateFirTime()

func (*RTPStats) UpdateFromReceiverReport added in v0.15.7

func (r *RTPStats) UpdateFromReceiverReport(extHighestSN uint32, packetsLost uint32, rtt uint32, jitter float64)

func (*RTPStats) UpdateKeyFrame added in v0.15.6

func (r *RTPStats) UpdateKeyFrame(kfCount uint32)

func (*RTPStats) UpdateLayerLockPliAndTime added in v0.15.6

func (r *RTPStats) UpdateLayerLockPliAndTime(pliCount uint32)

func (*RTPStats) UpdateNack added in v0.15.6

func (r *RTPStats) UpdateNack(nackCount uint32)

func (*RTPStats) UpdateNackAndMiss added in v0.15.6

func (r *RTPStats) UpdateNackAndMiss(nackCount uint32, nackMissCount uint32)

func (*RTPStats) UpdateNackMiss added in v0.15.6

func (r *RTPStats) UpdateNackMiss(nackMissCount uint32)

func (*RTPStats) UpdatePli added in v0.15.6

func (r *RTPStats) UpdatePli(pliCount uint32)

func (*RTPStats) UpdatePliAndTime added in v0.15.6

func (r *RTPStats) UpdatePliAndTime(pliCount uint32)

func (*RTPStats) UpdatePliTime added in v0.15.6

func (r *RTPStats) UpdatePliTime()

func (*RTPStats) UpdateRtt added in v0.15.6

func (r *RTPStats) UpdateRtt(rtt uint32)

type RTPStatsParams added in v0.15.6

type RTPStatsParams struct {
	ClockRate              uint32
	IsReceiverReportDriven bool
	Logger                 logger.Logger
}

type SnInfo added in v0.15.7

type SnInfo struct {
	// contains filtered or unexported fields
}

type Snapshot added in v0.15.6

type Snapshot struct {
	// contains filtered or unexported fields
}

type StreamStatsWithLayers added in v0.15.4

type StreamStatsWithLayers struct {
	RTPStats *RTPDeltaInfo
	Layers   map[int]LayerStats
}

type VP8

type VP8 struct {
	FirstByte byte

	PictureIDPresent int
	PictureID        uint16 /* 8 or 16 bits, picture ID */
	MBit             bool

	TL0PICIDXPresent int
	TL0PICIDX        uint8 /* 8 bits temporal level zero index */

	// Optional Header If either of the T or K bits are set to 1,
	// the TID/Y/KEYIDX extension field MUST be present.
	TIDPresent int
	TID        uint8 /* 2 bits temporal layer idx */
	Y          uint8

	KEYIDXPresent int
	KEYIDX        uint8 /* 5 bits of key frame idx */

	HeaderSize int

	// IsKeyFrame is a helper to detect if current packet is a keyframe
	IsKeyFrame bool
}

VP8 is a helper to get temporal data from VP8 packet header

VP8 Payload Descriptor
		0 1 2 3 4 5 6 7                      0 1 2 3 4 5 6 7
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
		|X|R|N|S|R| PID | (REQUIRED)        |X|R|N|S|R| PID | (REQUIRED)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	X:  |I|L|T|K| RSV   | (OPTIONAL)   X:   |I|L|T|K| RSV   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	I:  |M| PictureID   | (OPTIONAL)   I:   |M| PictureID   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	L:  |   TL0PICIDX   | (OPTIONAL)        |   PictureID   |
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	T/K:|TID|Y| KEYIDX  | (OPTIONAL)   L:   |   TL0PICIDX   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	T/K:|TID|Y| KEYIDX  | (OPTIONAL)
		+-+-+-+-+-+-+-+-+

func (*VP8) MarshalTo

func (v *VP8) MarshalTo(buf []byte) error

func (*VP8) Unmarshal

func (v *VP8) Unmarshal(payload []byte) error

Unmarshal parses the passed byte slice and stores the result in the VP8 this method is called upon

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL