Help us shape the future of Go! Take the 2026 Go Developer Survey

flexfec

package
v1.13.11 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package flexfec implements a FlexFEC-03 decoder used to recover RTP packets lost on the publisher leg before they are forwarded downstream. https://datatracker.ietf.org/doc/html/draft-ietf-payload-flexible-fec-scheme-03

The recovery logic is ported from pion/interceptor pkg/flexfec (https://github.com/pion/interceptor, MIT License, Copyright The Pion community), which is itself modeled on libwebrtc's ForwardErrorCorrection receiver. Deviations from the pion implementation:

  • FEC packets are deep-copied only when retained (callers reuse packet memory), while protected media is read from the owning packet store
  • packet masks are expanded on demand instead of retaining per-packet protection entries
  • recovery XORs the stored RTP wire representation directly
  • failed recoveries are not emitted as empty packets
  • usage counters for metrics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

Decoder recovers lost media packets of a single protected SSRC from a FlexFEC-03 repair stream. It is not safe for concurrent use; the owning buffer serializes access.

func NewDecoder

func NewDecoder(
	fecSSRC uint32,
	protectedSSRC uint32,
	mediaPacketLookup MediaPacketLookup,
	logger logger.Logger,
) *Decoder

func (*Decoder) DecodeFEC

func (d *Decoder) DecodeFEC(receivedPacket *rtp.Packet) []*rtp.Packet

DecodeFEC ingests a packet of either the FEC stream (fecSSRC) or the protected media stream (protectedSSRC) and returns any media packets that became recoverable. Ownership of returned packets transfers to the caller.

func (*Decoder) Stats

func (d *Decoder) Stats() DecoderStats

type DecoderStats

type DecoderStats struct {
	// FEC packets fed to the decoder
	FECPacketsReceived uint64
	// FEC bytes fed to the decoder (RTP payload sizes)
	FECBytesReceived uint64
	// FEC packets that could not be used: parse failures, foreign protected
	// SSRC, empty masks and duplicates
	FECPacketsDiscarded uint64
	// media packets reconstructed from FEC
	PacketsRecovered uint64
}

DecoderStats accumulates FEC usage counters. Snapshot via Decoder.Stats.

type MediaPacketLookup

type MediaPacketLookup func(sequenceNumber uint16, dst []byte) (int, error)

MediaPacketLookup copies a protected media packet into dst. The caller serializes access with writes to the underlying packet store.

Jump to

Keyboard shortcuts

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