receiver

package
v0.0.0-...-709ca8f Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package receiver implements WebRTC receiver functionality for bandwidth estimation tests.

Package receiver implements WebRTC receiver functionality for bandwidth estimation tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecoderCreationFailed is returned when VP8 decoder creation fails.
	ErrDecoderCreationFailed = errors.New("VP8 decoder creation failed")
	// ErrDecoderCloseFailed is returned when decoder close operation fails.
	ErrDecoderCloseFailed = errors.New("decoder close failed")
)

Functions

func IsKeyframe

func IsKeyframe(payload []byte) bool

IsKeyframe checks if the VP8 frame is a keyframe. VP8 keyframes are identified by the P bit in the frame header. See https://tools.ietf.org/html/rfc6386#section-9.1.

func ParseVP8KeyframeDimensions

func ParseVP8KeyframeDimensions(frameData []byte) (int, int, bool)

ParseVP8KeyframeDimensions extracts width and height from a VP8 keyframe. Returns width, height, and whether parsing was successful.

Types

type Option

type Option func(*Receiver) error

Option is a function that configures a Receiver.

func DefaultInterceptors

func DefaultInterceptors() Option

DefaultInterceptors returns an Option that registers the default WebRTC interceptors.

func EnableVP8Decode

func EnableVP8Decode(outputPath string) Option

EnableVP8Decode returns an Option that configures the receiver to decode VP8 frames and save them as PNG images. The outputPath should be the directory path where decoded frames will be saved (e.g., "decoded/").

func EnableVP8DecodeWithMP4

func EnableVP8DecodeWithMP4(basePath string, mp4BasePath string) Option

EnableVP8DecodeWithMP4 returns an Option that configures the receiver to decode VP8 frames and save as both PNG images and MP4 video. Uses a single base path - subdirectories will be created automatically (mp4/ and frames/).

func PacketLogWriter

func PacketLogWriter(rtpWriter, rtcpWriter io.Writer) Option

PacketLogWriter returns an Option that configures RTP and RTCP packet logging.

func SaveVideo

func SaveVideo(basePath string) Option

SaveVideo returns an Option that enables video saving to IVF files. The basePath specifies the base filename for output files (without extension). For multiple tracks, files will be named as basePath_track-N.ivf.

func SetLoggerFactory

func SetLoggerFactory(loggerFactory plogging.LoggerFactory) Option

SetLoggerFactory returns an Option that configures the logger factory.

func SetVideoWriterCallback

func SetVideoWriterCallback(callback VideoWriterCallback) Option

SetVideoWriterCallback returns an Option that sets the callback for video frame processing.

func SetVnet

func SetVnet(v *vnet.Net, publicIPs []string) Option

SetVnet returns an Option that configures the virtual network for testing.

type Receiver

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

Receiver manages a WebRTC connection for receiving media.

func NewReceiver

func NewReceiver(opts ...Option) (*Receiver, error)

NewReceiver creates a new WebRTC receiver with the given options.

func (*Receiver) AcceptOffer

func (r *Receiver) AcceptOffer(offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error)

AcceptOffer processes a WebRTC offer from the remote peer and creates an answer.

func (*Receiver) Close

func (r *Receiver) Close() error

func (*Receiver) SDPHandler

func (r *Receiver) SDPHandler() http.HandlerFunc

SDPHandler returns an HTTP handler for WebRTC signaling.

func (*Receiver) SetupPeerConnection

func (r *Receiver) SetupPeerConnection() error

SetupPeerConnection initializes the WebRTC peer connection.

type VP8Depayloader

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

VP8Depayloader handles VP8 RTP payloads using Pion's VP8Packet.

func NewVP8Depayloader

func NewVP8Depayloader() *VP8Depayloader

NewVP8Depayloader creates a new VP8 depayloader.

func (*VP8Depayloader) FlushFrame

func (d *VP8Depayloader) FlushFrame() ([]byte, bool, uint32)

FlushFrame forces completion of the current frame.

func (*VP8Depayloader) GetFrame

func (d *VP8Depayloader) GetFrame() ([]byte, bool, uint32)

GetFrame returns the current complete frame and resets the assembler.

func (*VP8Depayloader) ProcessPacket

func (d *VP8Depayloader) ProcessPacket(packet *rtp.Packet) (bool, []byte, uint32)

ProcessPacket processes a VP8 RTP packet using Pion's VP8Packet. Returns complete frame data when a frame is complete.

type VP8FrameAssembler

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

VP8FrameAssembler handles assembly of VP8 frames from RTP packets.

func NewVP8FrameAssembler

func NewVP8FrameAssembler(logger logging.LeveledLogger) *VP8FrameAssembler

NewVP8FrameAssembler creates a new VP8 frame assembler.

func (*VP8FrameAssembler) FlushFrame

func (a *VP8FrameAssembler) FlushFrame() (bool, []byte, bool, uint64)

FlushFrame forces completion of any in-progress frame.

func (*VP8FrameAssembler) ProcessPacket

func (a *VP8FrameAssembler) ProcessPacket(packet *rtp.Packet) (bool, []byte, bool, uint64)

ProcessPacket processes an RTP packet and returns a complete frame if available. Returns: - bool: true if a complete frame is available - []byte: the complete frame data, or nil if no frame is available - bool: true if the frame is a keyframe - uint64: the timestamp of the frame.

type VP8FrameProcessor

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

VP8FrameProcessor handles VP8 frame processing pipeline.

func NewVP8FrameProcessor

func NewVP8FrameProcessor(
	width, height int, trackID string, frameCallback VideoWriterCallback, logger logging.LeveledLogger,
) (*VP8FrameProcessor, error)

NewVP8FrameProcessor creates a new VP8 frame processor with callback.

func (*VP8FrameProcessor) Close

func (vp *VP8FrameProcessor) Close() error

Close stops the frame processor and cleans up resources.

func (*VP8FrameProcessor) Decode

func (vp *VP8FrameProcessor) Decode(frameData []byte)

Decode processes a VP8 frame by feeding it to the decoder.

func (*VP8FrameProcessor) GetFrameCount

func (vp *VP8FrameProcessor) GetFrameCount() int

GetFrameCount returns the number of processed frames.

func (*VP8FrameProcessor) HasFirstKeyFrame

func (vp *VP8FrameProcessor) HasFirstKeyFrame() bool

HasFirstKeyFrame returns whether we got the first keyframe.

func (*VP8FrameProcessor) SetFirstKeyFrame

func (vp *VP8FrameProcessor) SetFirstKeyFrame()

SetFirstKeyFrame marks that we got the first keyframe.

type VideoWriterCallback

type VideoWriterCallback func(
	img image.Image, width, height int, isKeyFrame bool, timestamp uint64, trackID string,
)

VideoWriterCallback is the callback function type for video writing.

Jump to

Keyboard shortcuts

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