buffer

package
v0.0.0-...-9e343ee Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReportDelta = 1e9

	InitPacketBufferSizeVideo = 300
	InitPacketBufferSizeAudio = 70
)
View Source
const (
	InvalidLayerSpatial  = int32(-1)
	InvalidLayerTemporal = int32(-1)

	DefaultMaxLayerSpatial  = int32(2)
	DefaultMaxLayerTemporal = int32(3)
)
View Source
const (
	QuarterResolution = "q"
	HalfResolution    = "h"
	FullResolution    = "f"
)

Variables

View Source
var (
	ErrFrameEarlierThanKeyFrame            = fmt.Errorf("frame is earlier than current keyframe")
	ErrDDStructureAttachedToNonFirstPacket = fmt.Errorf("dependency descriptor structure is attached to non-first packet of a frame")
)
View Source
var (
	InvalidLayer = VideoLayer{
		Spatial:  InvalidLayerSpatial,
		Temporal: InvalidLayerTemporal,
	}

	DefaultMaxLayer = VideoLayer{
		Spatial:  DefaultMaxLayerSpatial,
		Temporal: DefaultMaxLayerTemporal,
	}
)

Functions

func GetActiveDecodeTargetBitmask

func GetActiveDecodeTargetBitmask(layer VideoLayer, decodeTargets []DependencyDescriptorDecodeTarget) *uint32

func IsAV1KeyFrame

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

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 IsRedCodec

func IsRedCodec(mime string) bool

func IsSvcCodec

func IsSvcCodec(mime string) bool

SVC-TODO: Have to use more conditions to differentiate between SVC-TODO: SVC and non-SVC (could be single layer or simulcast). SVC-TODO: May only need to differentiate between simulcast and non-simulcast SVC-TODO: i. e. may be possible to treat single layer as SVC to get proper/intended functionality.

func IsVP9KeyFrame

func IsVP9KeyFrame(payload []byte) bool

IsVP9KeyFrame 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 LayerPresenceFromTrackInfo

func LayerPresenceFromTrackInfo(trackInfo *livekit.TrackInfo) *[livekit.VideoQuality_HIGH + 1]bool

SIMULCAST-CODEC-TODO: these need to be codec mime aware if and when each codec suppports different layers

func RidToSpatialLayer

func RidToSpatialLayer(rid string, trackInfo *livekit.TrackInfo) int32

func SpatialLayerToRid

func SpatialLayerToRid(layer int32, trackInfo *livekit.TrackInfo) string

func SpatialLayerToVideoQuality

func SpatialLayerToVideoQuality(layer int32, trackInfo *livekit.TrackInfo) livekit.VideoQuality

func VPxPictureIdSizeDiff

func VPxPictureIdSizeDiff(mBit1 bool, mBit2 bool) int

func VideoQualityToRid

func VideoQualityToRid(quality livekit.VideoQuality, trackInfo *livekit.TrackInfo) string

func VideoQualityToSpatialLayer

func VideoQualityToSpatialLayer(quality livekit.VideoQuality, trackInfo *livekit.TrackInfo) int32

Types

type Buffer

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

Buffer contains all packets

func NewBuffer

func NewBuffer(ssrc uint32, maxVideoPkts, maxAudioPkts int) *Buffer

NewBuffer constructs a new Buffer

func (*Buffer) Bind

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

func (*Buffer) Close

func (b *Buffer) Close() error

func (*Buffer) GetAudioLevel

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

func (*Buffer) GetClockRate

func (b *Buffer) GetClockRate() uint32

GetClockRate returns the RTP clock rate

func (*Buffer) GetDeltaStats

func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers

func (*Buffer) GetLastSenderReportTime

func (b *Buffer) GetLastSenderReportTime() time.Time

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, esn uint64) (int, error)

func (*Buffer) GetSenderReportData

func (b *Buffer) GetSenderReportData() *livekit.RTCPSenderReportState

func (*Buffer) GetStats

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

func (*Buffer) GetTemporalLayerFpsForSpatial

func (b *Buffer) GetTemporalLayerFpsForSpatial(layer int32) []float32

func (*Buffer) OnClose

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

func (*Buffer) OnFinalRtpStats

func (b *Buffer) OnFinalRtpStats(fn func(*livekit.RTPStats))

func (*Buffer) OnFpsChanged

func (b *Buffer) OnFpsChanged(f func())

func (*Buffer) OnRtcpFeedback

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

func (*Buffer) OnRtcpSenderReport

func (b *Buffer) OnRtcpSenderReport(fn func())

func (*Buffer) Read

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

func (*Buffer) ReadExtended

func (b *Buffer) ReadExtended(buf []byte) (*ExtPacket, error)

func (*Buffer) SendPLI

func (b *Buffer) SendPLI(force bool)

func (*Buffer) SetAudioLevelParams

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

func (*Buffer) SetAudioLossProxying

func (b *Buffer) SetAudioLossProxying(enable bool)

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) SetPaused

func (b *Buffer) SetPaused(paused bool)

func (*Buffer) SetPrimaryBufferForRTX

func (b *Buffer) SetPrimaryBufferForRTX(primaryBuffer *Buffer)

func (*Buffer) SetRTT

func (b *Buffer) SetRTT(rtt uint32)

func (*Buffer) SetSenderReportData

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

func (*Buffer) SetTWCCAndExtID

func (b *Buffer) SetTWCCAndExtID(twcc *twcc.Responder, extID uint8)

func (*Buffer) Write

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

Write adds an RTP Packet, ordering is not guaranteed, newer packets may arrive later

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 DependencyDescriptorDecodeTarget

type DependencyDescriptorDecodeTarget struct {
	Target int
	Layer  VideoLayer
}

func ProcessFrameDependencyStructure

func ProcessFrameDependencyStructure(structure *dd.FrameDependencyStructure) []DependencyDescriptorDecodeTarget

func (*DependencyDescriptorDecodeTarget) String

type DependencyDescriptorParser

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

func NewDependencyDescriptorParser

func NewDependencyDescriptorParser(ddExtID uint8, logger logger.Logger, onMaxLayerChanged func(int32, int32)) *DependencyDescriptorParser

func (*DependencyDescriptorParser) Parse

type ExtDependencyDescriptor

type ExtDependencyDescriptor struct {
	Descriptor *dd.DependencyDescriptor

	DecodeTargets              []DependencyDescriptorDecodeTarget
	StructureUpdated           bool
	ActiveDecodeTargetsUpdated bool
	Integrity                  bool
	ExtFrameNum                uint64
	// the frame number of the keyframe which the current frame depends on
	ExtKeyFrameNum uint64
}

type ExtPacket

type ExtPacket struct {
	VideoLayer
	Arrival              int64
	ExtSequenceNumber    uint64
	ExtTimestamp         uint64
	Packet               *rtp.Packet
	Payload              interface{}
	KeyFrame             bool
	RawPacket            []byte
	DependencyDescriptor *ExtDependencyDescriptor
	AbsCaptureTimeExt    *act.AbsCaptureTime
	IsOutOfOrder         bool
}

type Factory

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

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

func (*Factory) SetRTXPair

func (f *Factory) SetRTXPair(repair, base uint32)

type FactoryOfBufferFactory

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

func NewFactoryOfBufferFactory

func NewFactoryOfBufferFactory(trackingPacketsVideo int, trackingPacketsAudio int) *FactoryOfBufferFactory

func (*FactoryOfBufferFactory) CreateBufferFactory

func (f *FactoryOfBufferFactory) CreateBufferFactory() *Factory

type FrameEntity

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

func (*FrameEntity) AddPacket

func (fe *FrameEntity) AddPacket(extSeq uint64, ddVal *dd.DependencyDescriptor)

func (*FrameEntity) Integrity

func (fe *FrameEntity) Integrity() bool

func (*FrameEntity) Reset

func (fe *FrameEntity) Reset()

type FrameIntegrityChecker

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

func NewFrameIntegrityChecker

func NewFrameIntegrityChecker(frameCount, packetCount int) *FrameIntegrityChecker

func (*FrameIntegrityChecker) AddPacket

func (fc *FrameIntegrityChecker) AddPacket(extSeq uint64, extFrameNum uint64, ddVal *dd.DependencyDescriptor)

func (*FrameIntegrityChecker) FrameIntegrity

func (fc *FrameIntegrityChecker) FrameIntegrity(extFrameNum uint64) bool

type FrameRateCalculator

type FrameRateCalculator interface {
	RecvPacket(ep *ExtPacket) bool
	GetFrameRate() []float32
	Completed() bool
}

type FrameRateCalculatorDD

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

FrameRateCalculator based on Dependency descriptor

func NewFrameRateCalculatorDD

func NewFrameRateCalculatorDD(clockRate uint32, logger logger.Logger) *FrameRateCalculatorDD

func (*FrameRateCalculatorDD) Completed

func (f *FrameRateCalculatorDD) Completed() bool

func (*FrameRateCalculatorDD) GetFrameRateCalculatorForSpatial

func (f *FrameRateCalculatorDD) GetFrameRateCalculatorForSpatial(spatial int32) *FrameRateCalculatorForDDLayer

func (*FrameRateCalculatorDD) GetFrameRateForSpatial

func (f *FrameRateCalculatorDD) GetFrameRateForSpatial(spatial int32) []float32

func (*FrameRateCalculatorDD) RecvPacket

func (f *FrameRateCalculatorDD) RecvPacket(ep *ExtPacket) bool

func (*FrameRateCalculatorDD) SetMaxLayer

func (f *FrameRateCalculatorDD) SetMaxLayer(spatial, temporal int32)

type FrameRateCalculatorForDDLayer

type FrameRateCalculatorForDDLayer struct {
	*FrameRateCalculatorDD
	// contains filtered or unexported fields
}

func (*FrameRateCalculatorForDDLayer) GetFrameRate

func (f *FrameRateCalculatorForDDLayer) GetFrameRate() []float32

type FrameRateCalculatorForVP9Layer

type FrameRateCalculatorForVP9Layer struct {
	*FrameRateCalculatorVP9
	// contains filtered or unexported fields
}

func (*FrameRateCalculatorForVP9Layer) GetFrameRate

func (f *FrameRateCalculatorForVP9Layer) GetFrameRate() []float32

type FrameRateCalculatorVP8

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

FrameRateCalculator based on PictureID in VP8

func NewFrameRateCalculatorVP8

func NewFrameRateCalculatorVP8(clockRate uint32, logger logger.Logger) *FrameRateCalculatorVP8

func (FrameRateCalculatorVP8) Completed

func (f FrameRateCalculatorVP8) Completed() bool

func (FrameRateCalculatorVP8) GetFrameRate

func (f FrameRateCalculatorVP8) GetFrameRate() []float32

func (*FrameRateCalculatorVP8) RecvPacket

func (f *FrameRateCalculatorVP8) RecvPacket(ep *ExtPacket) bool

type FrameRateCalculatorVP9

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

FrameRateCalculator based on PictureID in VP9

func NewFrameRateCalculatorVP9

func NewFrameRateCalculatorVP9(clockRate uint32, logger logger.Logger) *FrameRateCalculatorVP9

func (*FrameRateCalculatorVP9) Completed

func (f *FrameRateCalculatorVP9) Completed() bool

func (*FrameRateCalculatorVP9) GetFrameRateCalculatorForSpatial

func (f *FrameRateCalculatorVP9) GetFrameRateCalculatorForSpatial(spatial int32) *FrameRateCalculatorForVP9Layer

func (*FrameRateCalculatorVP9) GetFrameRateForSpatial

func (f *FrameRateCalculatorVP9) GetFrameRateForSpatial(spatial int32) []float32

func (*FrameRateCalculatorVP9) RecvPacket

func (f *FrameRateCalculatorVP9) RecvPacket(ep *ExtPacket) bool

type PacketHistory

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

func NewPacketHistory

func NewPacketHistory(packetCount int) *PacketHistory

func (*PacketHistory) AddPacket

func (ph *PacketHistory) AddPacket(extSeq uint64)

func (*PacketHistory) PacketsConsecutive

func (ph *PacketHistory) PacketsConsecutive(start, end uint64) bool

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 StreamStatsWithLayers

type StreamStatsWithLayers struct {
	RTPStats *rtpstats.RTPDeltaInfo
	Layers   map[int32]*rtpstats.RTPDeltaInfo
}

type VP8

type VP8 struct {
	FirstByte byte
	S         bool

	I         bool
	M         bool
	PictureID uint16 /* 7 or 15 bits, picture ID */

	L         bool
	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.
	T   bool
	TID uint8 /* 2 bits temporal layer idx */
	Y   bool

	K      bool
	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) Marshal

func (v *VP8) Marshal() ([]byte, error)

func (*VP8) MarshalTo

func (v *VP8) MarshalTo(buf []byte) (int, 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

type VideoLayer

type VideoLayer struct {
	Spatial  int32
	Temporal int32
}

func (VideoLayer) GreaterThan

func (v VideoLayer) GreaterThan(v2 VideoLayer) bool

func (VideoLayer) IsValid

func (v VideoLayer) IsValid() bool

func (VideoLayer) SpatialGreaterThanOrEqual

func (v VideoLayer) SpatialGreaterThanOrEqual(v2 VideoLayer) bool

func (VideoLayer) String

func (v VideoLayer) String() string

Jump to

Keyboard shortcuts

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