buffer

package
v0.0.0-...-4d7396a Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GapHistogramNumBins = 101
	SequenceNumberMin   = uint16(0)
	SequenceNumberMax   = uint16(65535)
	NumSequenceNumbers  = 65536
)
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

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

func IsH264Keyframe

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 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, o Options)

func (*Buffer) Close

func (b *Buffer) Close() error

func (*Buffer) GetClockRate

func (b *Buffer) GetClockRate() uint32

GetClockRate returns the RTP clock rate

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

func (b *Buffer) GetQualityInfo() *RTPSnapshotInfo

func (*Buffer) GetStats

func (b *Buffer) GetStats() *StreamStatsWithLayers

func (*Buffer) OnAudioLevel

func (b *Buffer) OnAudioLevel(fn func(level uint8, durationMs uint32))

func (*Buffer) OnClose

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

func (*Buffer) OnFeedback

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

func (*Buffer) OnTransportWideCC

func (b *Buffer) OnTransportWideCC(fn func(sn uint16, timeNS int64, marker bool))

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

func (b *Buffer) SendPLI()

func (*Buffer) SetLastFractionLostReport

func (b *Buffer) SetLastFractionLostReport(lost uint8)

func (*Buffer) SetLogger

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

func (*Buffer) SetPLIThrottle

func (b *Buffer) SetPLIThrottle(duration int64)

func (*Buffer) SetRTT

func (b *Buffer) SetRTT(rtt uint32)

func (*Buffer) SetSenderReportData

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

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

type ConnectionQualityParams struct {
	LossPercentage float32
	Jitter         float32
	Rtt            uint32
}

type DataStats

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

func NewDataStats

func NewDataStats(params DataStatsParam) *DataStats

func (*DataStats) Stop

func (s *DataStats) Stop()

func (*DataStats) ToProtoActive

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

func (*DataStats) ToProtoAggregateOnly

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

func (*DataStats) Update

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

type DataStatsParam

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

type LayerStats struct {
	TotalPackets uint32
	TotalBytes   uint64
	TotalFrames  uint32
}

type NackQueue

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

func NewNACKQueue

func NewNACKQueue() *NackQueue

func (*NackQueue) Pairs

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

func (*NackQueue) Push

func (n *NackQueue) Push(sn uint16)

func (*NackQueue) Remove

func (n *NackQueue) Remove(sn uint16)

func (*NackQueue) SetRTT

func (n *NackQueue) SetRTT(rtt uint32)

type NtpTime

type NtpTime uint64

func ToNtpTime

func ToNtpTime(t time.Time) NtpTime

func (NtpTime) Duration

func (t NtpTime) Duration() time.Duration

func (NtpTime) Time

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 RTPFlowState

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

type RTPSnapshotInfo

type RTPSnapshotInfo struct {
	PacketsExpected uint32
	PacketsLost     uint32
	MaxJitter       float64
	MaxRtt          uint32
}

type RTPStats

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

func NewRTPStats

func NewRTPStats(params RTPStatsParams) *RTPStats

func (*RTPStats) GetRtcpSenderReport

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

func (*RTPStats) GetRtt

func (r *RTPStats) GetRtt() uint32

func (*RTPStats) GetTotalBytes

func (r *RTPStats) GetTotalBytes() uint64

func (*RTPStats) GetTotalBytesSansDuplicate

func (r *RTPStats) GetTotalBytesSansDuplicate() uint64

func (*RTPStats) GetTotalPackets

func (r *RTPStats) GetTotalPackets() uint32

func (*RTPStats) GetTotalPacketsSansDuplicate

func (r *RTPStats) GetTotalPacketsSansDuplicate() uint32

func (*RTPStats) IsActive

func (r *RTPStats) IsActive() bool

func (*RTPStats) LastPli

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

func (*RTPStats) NewSnapshotId

func (r *RTPStats) NewSnapshotId() uint32

func (*RTPStats) SetRtcpSenderReportData

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

func (*RTPStats) SnapshotInfo

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

func (*RTPStats) SnapshotRtcpReceptionReport

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

func (*RTPStats) Stop

func (r *RTPStats) Stop()

func (*RTPStats) TimeSinceLastPli

func (r *RTPStats) TimeSinceLastPli() int64

func (*RTPStats) ToProto

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

func (*RTPStats) ToString

func (r *RTPStats) ToString() string

func (*RTPStats) Update

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

func (*RTPStats) UpdateFir

func (r *RTPStats) UpdateFir(firCount uint32)

func (*RTPStats) UpdateFirTime

func (r *RTPStats) UpdateFirTime()

func (*RTPStats) UpdateJitter

func (r *RTPStats) UpdateJitter(jitter float64)

func (*RTPStats) UpdateKeyFrame

func (r *RTPStats) UpdateKeyFrame(kfCount uint32)

func (*RTPStats) UpdateLayerLockPliAndTime

func (r *RTPStats) UpdateLayerLockPliAndTime(pliCount uint32)

func (*RTPStats) UpdateNack

func (r *RTPStats) UpdateNack(nackCount uint32)

func (*RTPStats) UpdateNackAndMiss

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

func (*RTPStats) UpdateNackMiss

func (r *RTPStats) UpdateNackMiss(nackMissCount uint32)

func (*RTPStats) UpdatePacketsLost

func (r *RTPStats) UpdatePacketsLost(packetsLost uint32)

func (*RTPStats) UpdatePli

func (r *RTPStats) UpdatePli(pliCount uint32)

func (*RTPStats) UpdatePliAndTime

func (r *RTPStats) UpdatePliAndTime(pliCount uint32)

func (*RTPStats) UpdatePliTime

func (r *RTPStats) UpdatePliTime()

func (*RTPStats) UpdateRtt

func (r *RTPStats) UpdateRtt(rtt uint32)

type RTPStatsParams

type RTPStatsParams struct {
	ClockRate uint32
}

type Snapshot

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

type StreamStatsWithLayers

type StreamStatsWithLayers struct {
	RTPStats *livekit.RTPStats
	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