sender

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: 26 Imported by: 0

Documentation

Overview

Package sender implements WebRTC sender functionality for bandwidth estimation tests.

Package sender implements WebRTC sender functionality for bandwidth estimation tests.

Package sender implements WebRTC sender functionality for bandwidth estimation tests.

Package sender implements WebRTC sender functionality for bandwidth estimation tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBufferClosed              = errors.New("buffer closed")
	ErrNoFrameAvailable          = errors.New("no frame available")
	ErrFailedToAddFrameAfterDrop = errors.New("failed to add frame after dropping oldest")
)

Static errors for err113 compliance.

View Source
var (
	ErrTrackAlreadyExists          = errors.New("track already exists")
	ErrTrackNotFound               = errors.New("track not found")
	ErrTrackDoesNotSupportFrames   = errors.New("track does not support frame injection")
	ErrInvalidNegativeValue        = errors.New("invalid value: must be non-negative")
	ErrAllocationSumMustBePositive = errors.New("sum of allocation values must be greater than 0")
	ErrFailedToCastVideoTrack      = errors.New("failed to cast media track to VideoTrack")
	ErrMissingEncoderConfig        = errors.New("either EncoderBuilder or InitialBitrate must be provided")
)

Static errors for err113 compliance.

Functions

This section is empty.

Types

type ConfigurableWebRTCSender

type ConfigurableWebRTCSender interface {
	GetSettingEngine() *webrtc.SettingEngine
	GetMediaEngine() *webrtc.MediaEngine
	GetRegistry() *interceptor.Registry
	GetEstimatorChan() chan cc.BandwidthEstimator
	SetLogger(plogging.LeveledLogger)
	SetCCLogWriter(io.Writer) // For Sender compatibility
}

ConfigurableWebRTCSender defines the interface that both Sender and RTCSender implement to allow shared option configuration.

type EncodedTrack

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

EncodedTrack represents an encoded video track.

type FrameBuffer

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

FrameBuffer is a simple in-memory frame buffer that implements VideoSource It can be used as a virtual video driver for testing or programmatic frame injection.

func NewFrameBuffer

func NewFrameBuffer(width, height int) *FrameBuffer

NewFrameBuffer creates a new frame buffer with the specified dimensions.

func (*FrameBuffer) Close

func (f *FrameBuffer) Close() error

Close stops the frame buffer and releases resources.

func (*FrameBuffer) ID

func (f *FrameBuffer) ID() string

ID returns the identifier for this video source.

func (*FrameBuffer) Read

func (f *FrameBuffer) Read() (image.Image, func(), error)

Read returns the next available frame from the buffer If no frame is available within the timeout, it returns a black frame.

func (*FrameBuffer) SendFrame

func (f *FrameBuffer) SendFrame(frame image.Image) error

SendFrame adds a frame to the buffer. If the buffer is full, it drops the oldest frame and adds the new one.

func (*FrameBuffer) SetInitialized

func (f *FrameBuffer) SetInitialized()

SetInitialized marks the frame buffer as initialized.

type MediaSource

type MediaSource interface {
	SetTargetBitrate(int)
	SetWriter(func(sample media.Sample) error)
	Start(ctx context.Context) error
}

MediaSource represents a source of media samples that can be sent over WebRTC.

type Option

type Option func(ConfigurableWebRTCSender) error

Option is a function that configures a ConfigurableWebRTCSender.

func CCLogWriter

func CCLogWriter(w io.Writer) Option

CCLogWriter returns an Option that configures congestion control logging.

func DefaultInterceptors

func DefaultInterceptors() Option

DefaultInterceptors returns an Option that registers the default WebRTC interceptors.

func GCC

func GCC(initialBitrate int) Option

GCC returns an Option that configures Google Congestion Control with the specified initial bitrate.

func PacketLogWriter

func PacketLogWriter(rtpWriter, rtcpWriter io.Writer) Option

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

func SetLoggerFactory

func SetLoggerFactory(loggerFactory plogging.LoggerFactory) Option

SetLoggerFactory returns an Option that configures the logger factory.

func SetMediaSource

func SetMediaSource(source MediaSource) Option

SetMediaSource returns an Option that sets the media source for the sender. Note: This only works with the original Sender type, not RTCSender.

func SetVnet

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

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

type RTCSender

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

RTCSender is a generic sender that can work with any frame source.

func NewRTCSender

func NewRTCSender(opts ...Option) (*RTCSender, error)

NewRTCSender creates a new generic sender with GCC bandwidth estimation by default.

func (*RTCSender) AcceptAnswer

func (s *RTCSender) AcceptAnswer(answer *webrtc.SessionDescription) error

AcceptAnswer processes the WebRTC answer.

func (*RTCSender) AddVideoTrack

func (s *RTCSender) AddVideoTrack(info VideoTrackInfo) error

AddVideoTrack adds a new video track.

func (*RTCSender) Close

func (s *RTCSender) Close() error

Close releases all resources.

func (*RTCSender) CreateOffer

func (s *RTCSender) CreateOffer() (*webrtc.SessionDescription, error)

CreateOffer creates a WebRTC offer.

func (*RTCSender) GetEncodeFrameOk

func (s *RTCSender) GetEncodeFrameOk() bool

GetEncodeFrameOk returns the current encode frame status.

func (*RTCSender) GetEstimatorChan

func (s *RTCSender) GetEstimatorChan() chan cc.BandwidthEstimator

GetEstimatorChan returns the bandwidth estimator channel.

func (*RTCSender) GetMediaEngine

func (s *RTCSender) GetMediaEngine() *webrtc.MediaEngine

GetMediaEngine returns the media engine.

func (*RTCSender) GetPeerConnection

func (s *RTCSender) GetPeerConnection() *webrtc.PeerConnection

GetPeerConnection returns the WebRTC peer connection.

func (*RTCSender) GetRegistry

func (s *RTCSender) GetRegistry() *interceptor.Registry

GetRegistry returns the interceptor registry.

func (*RTCSender) GetSettingEngine

func (s *RTCSender) GetSettingEngine() *webrtc.SettingEngine

GetSettingEngine returns the setting engine.

func (*RTCSender) GetWebRTCTrackLocal

func (s *RTCSender) GetWebRTCTrackLocal(trackID string) (*webrtc.TrackLocalStaticSample, error)

GetWebRTCTrackLocal returns the WebRTC track for a specific track ID.

func (*RTCSender) SendFrame

func (s *RTCSender) SendFrame(trackID string, frame image.Image) error

SendFrame sends a frame to a specific track.

func (*RTCSender) SetBitrateAllocation

func (s *RTCSender) SetBitrateAllocation(allocation map[string]float64) error

SetBitrateAllocation sets custom bitrate allocation for tracks. allocation is a map of track ID to arbitrary positive numbers representing relative weights The values will be normalized internally (each value divided by sum of all values) Pass nil to return to equal distribution.

func (*RTCSender) SetCCLogWriter

func (s *RTCSender) SetCCLogWriter(w io.Writer)

SetCCLogWriter sets the congestion control log writer.

func (*RTCSender) SetLogger

func (s *RTCSender) SetLogger(logger logging.LeveledLogger)

SetLogger sets the logger.

func (*RTCSender) SetupPeerConnection

func (s *RTCSender) SetupPeerConnection() error

SetupPeerConnection initializes the WebRTC peer connection.

func (*RTCSender) Start

func (s *RTCSender) Start(ctx context.Context) error

Start begins the encoding and bitrate control loop.

type Sender

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

Sender manages a WebRTC connection for sending media.

func NewSender

func NewSender(source MediaSource, opts ...Option) (*Sender, error)

NewSender creates a new WebRTC sender with the given media source and options.

func (*Sender) AcceptAnswer

func (s *Sender) AcceptAnswer(answer *webrtc.SessionDescription) error

AcceptAnswer processes a WebRTC answer from the remote peer.

func (*Sender) CreateOffer

func (s *Sender) CreateOffer() (*webrtc.SessionDescription, error)

CreateOffer creates a WebRTC offer for signaling.

func (*Sender) GetEstimatorChan

func (s *Sender) GetEstimatorChan() chan cc.BandwidthEstimator

GetEstimatorChan returns the bandwidth estimator channel.

func (*Sender) GetMediaEngine

func (s *Sender) GetMediaEngine() *webrtc.MediaEngine

GetMediaEngine returns the media engine.

func (*Sender) GetRegistry

func (s *Sender) GetRegistry() *interceptor.Registry

GetRegistry returns the interceptor registry.

func (*Sender) GetSettingEngine

func (s *Sender) GetSettingEngine() *webrtc.SettingEngine

GetSettingEngine returns the setting engine.

func (*Sender) GetSource

func (s *Sender) GetSource() MediaSource

GetSource returns the media source used by the sender.

func (*Sender) SetCCLogWriter

func (s *Sender) SetCCLogWriter(w io.Writer)

SetCCLogWriter sets the congestion control log writer.

func (*Sender) SetLogger

func (s *Sender) SetLogger(logger logging.LeveledLogger)

SetLogger sets the logger.

func (*Sender) SetupPeerConnection

func (s *Sender) SetupPeerConnection() error

SetupPeerConnection initializes the WebRTC peer connection.

func (*Sender) SignalHTTP

func (s *Sender) SignalHTTP(addr, route string) error

SignalHTTP performs WebRTC signaling over HTTP.

func (*Sender) Start

func (s *Sender) Start(ctx context.Context) error

Start begins the media sending process and runs until context is done.

type SimulcastFilesSource

type SimulcastFilesSource struct {
	WriteSample func(media.Sample) error
	// contains filtered or unexported fields
}

SimulcastFilesSource is a media source that switches between different quality video files based on the target bitrate.

func NewSimulcastFilesSource

func NewSimulcastFilesSource() *SimulcastFilesSource

NewSimulcastFilesSource returns a new SimulcastFilesSource.

func (*SimulcastFilesSource) Close

func (s *SimulcastFilesSource) Close() error

Close stops the simulcast source and cleans up resources.

func (*SimulcastFilesSource) SetTargetBitrate

func (s *SimulcastFilesSource) SetTargetBitrate(rate int)

SetTargetBitrate sets the target bitrate for the simulcast source.

func (*SimulcastFilesSource) SetWriter

func (s *SimulcastFilesSource) SetWriter(f func(sample media.Sample) error)

SetWriter sets the sample writer function.

func (*SimulcastFilesSource) Start

func (s *SimulcastFilesSource) Start(ctx context.Context) error

Start begins the simulcast process and runs until context is done.

type StatisticalEncoderSource

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

StatisticalEncoderSource is a source that fakes a media encoder using syncodec.StatisticalCodec.

func NewStatisticalEncoderSource

func NewStatisticalEncoderSource() *StatisticalEncoderSource

NewStatisticalEncoderSource returns a new StatisticalEncoderSource.

func (*StatisticalEncoderSource) Close

func (s *StatisticalEncoderSource) Close() error

Close stops the encoder and cleans up resources.

func (*StatisticalEncoderSource) SetTargetBitrate

func (s *StatisticalEncoderSource) SetTargetBitrate(rate int)

SetTargetBitrate sets the target bitrate for the encoder.

func (*StatisticalEncoderSource) SetWriter

func (s *StatisticalEncoderSource) SetWriter(f func(sample media.Sample) error)

SetWriter sets the sample writer function.

func (*StatisticalEncoderSource) Start

Start begins the encoding process and runs until context is done.

func (*StatisticalEncoderSource) WriteFrame

func (s *StatisticalEncoderSource) WriteFrame(frame syncodec.Frame)

WriteFrame writes a frame to the encoder.

type VideoSource

type VideoSource interface {
	ID() string
	Read() (image.Image, func(), error)
	Close() error
}

VideoSource represents any source of video frames (camera, file, virtual buffer, etc.)

type VideoTrackInfo

type VideoTrackInfo struct {
	TrackID        string
	Width          int
	Height         int
	EncoderBuilder codec.VideoEncoderBuilder
	InitialBitrate int // Optional: if EncoderBuilder is nil, a default VP8 encoder with this bitrate will be created
}

VideoTrackInfo holds information about a video track.

type WebRTCSender

type WebRTCSender interface {
	SetupPeerConnection() error
	CreateOffer() (*webrtc.SessionDescription, error)
	AcceptAnswer(answer *webrtc.SessionDescription) error
	Start(ctx context.Context) error
}

WebRTCSender is a common interface for different sender implementations.

Jump to

Keyboard shortcuts

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