vp9_stats

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ErrViewerReadFromTrackID int = iota
	ErrViewerUnmarshalPacketID
	ErrViewerParseVP9PayloadID
	ErrViewerSeqNoJumpID
	ErrViewerInputChannelID
	ErrViewerIVFSegmenterFailed
	ErrViewerPcapWriteID
	NumErrIDs
)
View Source
const (
	DefaultStatsBufferSize = 768
)

Variables

This section is empty.

Functions

func ErrIDToString

func ErrIDToString(errID int) string

Types

type FrameStatistics

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

func NewFrameStatistics

func NewFrameStatistics(bufferSize int) *FrameStatistics

NewFrameStatistics creates a FrameStatistics with the given ring buffer capacity.

func (*FrameStatistics) AcceptPacket

func (stats *FrameStatistics) AcceptPacket(clientReadTime int64, seqNo uint16, rtpTimestamp uint32, nBytes int, payloadDesc *vp9.PayloadDescriptor)

AcceptPacket updates the stat tracker with information about the newly arrived VP9 RTP packet. seqNo is the RTP sequence number used for frame completeness detection. Sequence gaps mark a frame incomplete only if they remain when it is finalized

func (*FrameStatistics) EndSample

func (stats *FrameStatistics) EndSample()

EndSample must be called if your data in TakeSample was successfully published, otherwise don't call this and let the sample grow automatically

func (*FrameStatistics) Initialized

func (stats *FrameStatistics) Initialized() bool

func (*FrameStatistics) SetOnFrameLost

func (stats *FrameStatistics) SetOnFrameLost(fn func(nowNano int64))

SetOnFrameLost registers a callback invoked when a frame is finalized as incomplete. The argument is the current time in UnixNano.

func (*FrameStatistics) TakeSample

func (stats *FrameStatistics) TakeSample(sample *VideoQualitySample)

TakeSample copies the histogram and current FPS into sample (or copies zero's if sample is too small)

type PLIThrottle

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

PLIThrottle rate-limits PLI sending to avoid flooding.

func NewPLIThrottle

func NewPLIThrottle(sendPLI func(), tracker *RTCPTracker, minIntervalNanos int64) *PLIThrottle

NewPLIThrottle wraps sendPLI with rate limiting. minInterval is the minimum nanoseconds between PLI sends (e.g., 100ms = 100_000_000).

func (*PLIThrottle) OnFrameLost

func (p *PLIThrottle) OnFrameLost(nowNano int64)

OnFrameLost is the callback to pass to FrameStatistics. It sends a PLI if enough time has elapsed since the last one.

type Period

type Period struct {
	// StartTimeUS microsecond epoch utc start time of this period
	StartTimeUS int64

	// TotalBytes total bytes seen in this period
	TotalBytes int64

	Errors [NumErrIDs]int32
}

Period aggregated stats for a collection period

func (*Period) String

func (p *Period) String() string

type Publisher

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

Publisher pub-sub goroutine that fans out input samples to subscribers, while accumulating total bytes per period

func NewPublisher

func NewPublisher(input <-chan VideoQualitySample) *Publisher

func (*Publisher) AddSubscriber

func (p *Publisher) AddSubscriber(subscriber func(Period, VideoQualitySample))

func (*Publisher) Errors

func (p *Publisher) Errors() []error

func (*Publisher) IncrError

func (p *Publisher) IncrError(errID int)

func (*Publisher) Run

func (p *Publisher) Run()

func (*Publisher) Stop

func (p *Publisher) Stop()

type RTCPData

type RTCPData struct {
	PLISent int64 `json:"pli_sent,omitempty"`
	SRCount int64 `json:"sr_count,omitempty"`
}

RTCPData carries RTCP feedback stats through the pipeline.

type RTCPTracker

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

RTCPTracker tracks RTCP metrics for a viewer; safe for concurrent use.

func (*RTCPTracker) IncrPLI

func (t *RTCPTracker) IncrPLI()

IncrPLI records that a PLI was sent.

func (*RTCPTracker) IncrSR

func (t *RTCPTracker) IncrSR()

IncrSR records that a Sender Report was received.

func (*RTCPTracker) Snapshot

func (t *RTCPTracker) Snapshot() RTCPData

Snapshot returns the current RTCP counters.

type SVCData

type SVCData struct {
	// Layers histogram of SID x TID counts (counted by packet)
	Layers [nSpatialLayers][nTemporalLayers]int `json:"layers"`

	// MaxRecvSID highest spatial layer observed in the current sample window
	MaxRecvSID uint8 `json:"max_recv_sid"`

	// MaxRecvTID highest temporal layer observed in the current sample window
	MaxRecvTID uint8 `json:"max_recv_tid"`
}

type SampleData

type SampleData struct {
	TotalBytes                int64 `json:"total_bytes"`
	FirstPacketClientReadTime int64 `json:"first_pkt_cl_read_t"`
	LastPacketClientReadTime  int64 `json:"last_pkt_cl_read_t"`
}

SampleData per-sample data which is reset on EndSample()

type VideoQualitySample

type VideoQualitySample struct {
	// SequenceNo monotonic sequence number
	SequenceNo uint64 `json:"seq"`

	// Nickname participant nickname
	Nickname string `json:"nickname"`

	// SmoothFPS latest computed smoothed frame per second value
	SmoothFPS float32 `json:"sm_fps"`

	// BufferFPS latest computed bufferFPS (non-smoothed FPS)
	BufferFPS float32 `json:"buf_fps"`

	// SmoothBitrate latest computed smoothed bits per second value
	SmoothBitrate float32 `json:"sm_br"`

	// BufferBitrate latest computed bufferBitrate (non-smoothed bitrate)
	BufferBitrate float32 `json:"buf_br"`

	// EstimatedFPS best frame per second value we offer
	EstimatedFPS int `json:"est_fps"`

	// DecoderSmoothFPS EWMA-smoothed FPS counting only decodable (complete) frames
	DecoderSmoothFPS float32 `json:"dec_sm_fps"`

	// DecoderBufferFPS buffer-window FPS counting only decodable (complete) frames
	DecoderBufferFPS float32 `json:"dec_buf_fps"`

	// EstimatedDecoderFPS best decodable frame per second value we offer
	EstimatedDecoderFPS int `json:"est_dec_fps"`

	// FrameJitterUS EWMA frame interarrival jitter in microseconds
	FrameJitterUS float64 `json:"frame_jitter_us"`

	// PacketJitterUS RFC 3550 packet-level interarrival jitter in microseconds
	PacketJitterUS float64 `json:"packet_jitter_us"`

	// FramesComplete monotonic count of complete frames
	FramesComplete int64 `json:"frames_complete"`

	// FramesLost monotonic count of incomplete (undecodable) frames
	FramesLost int64 `json:"frames_lost"`

	// SVC scalable video coding specific measurements
	SVC SVCData `json:"svc"`

	// RTCP feedback stats (populated when RTCPTracker is present)
	RTCP RTCPData `json:"rtcp,omitzero"`

	// Sample contains the per-sample measurements
	Sample SampleData `json:"sample"`
}

func (*VideoQualitySample) Mbps

func (sample *VideoQualitySample) Mbps() string

Mbps returns the smooth bitrate formatted as megabits per second, e.g. "1.23 Mbps"

Example
sample := VideoQualitySample{SmoothBitrate: 3_500_000}
fmt.Println(sample.Mbps())
Output:
3.50 Mbps

func (*VideoQualitySample) String

func (sample *VideoQualitySample) String() string

String formats the video quality sample for debug purposes

Jump to

Keyboard shortcuts

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