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 ¶
- Variables
- type ConfigurableWebRTCSender
- type EncodedTrack
- type FrameBuffer
- type MediaSource
- type Option
- func CCLogWriter(w io.Writer) Option
- func DefaultInterceptors() Option
- func GCC(initialBitrate int) Option
- func PacketLogWriter(rtpWriter, rtcpWriter io.Writer) Option
- func SetLoggerFactory(loggerFactory plogging.LoggerFactory) Option
- func SetMediaSource(source MediaSource) Option
- func SetVnet(v *vnet.Net, publicIPs []string) Option
- type RTCSender
- func (s *RTCSender) AcceptAnswer(answer *webrtc.SessionDescription) error
- func (s *RTCSender) AddVideoTrack(info VideoTrackInfo) error
- func (s *RTCSender) Close() error
- func (s *RTCSender) CreateOffer() (*webrtc.SessionDescription, error)
- func (s *RTCSender) GetEncodeFrameOk() bool
- func (s *RTCSender) GetEstimatorChan() chan cc.BandwidthEstimator
- func (s *RTCSender) GetMediaEngine() *webrtc.MediaEngine
- func (s *RTCSender) GetPeerConnection() *webrtc.PeerConnection
- func (s *RTCSender) GetRegistry() *interceptor.Registry
- func (s *RTCSender) GetSettingEngine() *webrtc.SettingEngine
- func (s *RTCSender) GetWebRTCTrackLocal(trackID string) (*webrtc.TrackLocalStaticSample, error)
- func (s *RTCSender) SendFrame(trackID string, frame image.Image) error
- func (s *RTCSender) SetBitrateAllocation(allocation map[string]float64) error
- func (s *RTCSender) SetCCLogWriter(w io.Writer)
- func (s *RTCSender) SetLogger(logger logging.LeveledLogger)
- func (s *RTCSender) SetupPeerConnection() error
- func (s *RTCSender) Start(ctx context.Context) error
- type Sender
- func (s *Sender) AcceptAnswer(answer *webrtc.SessionDescription) error
- func (s *Sender) CreateOffer() (*webrtc.SessionDescription, error)
- func (s *Sender) GetEstimatorChan() chan cc.BandwidthEstimator
- func (s *Sender) GetMediaEngine() *webrtc.MediaEngine
- func (s *Sender) GetRegistry() *interceptor.Registry
- func (s *Sender) GetSettingEngine() *webrtc.SettingEngine
- func (s *Sender) GetSource() MediaSource
- func (s *Sender) SetCCLogWriter(w io.Writer)
- func (s *Sender) SetLogger(logger logging.LeveledLogger)
- func (s *Sender) SetupPeerConnection() error
- func (s *Sender) SignalHTTP(addr, route string) error
- func (s *Sender) Start(ctx context.Context) error
- type SimulcastFilesSource
- type StatisticalEncoderSource
- func (s *StatisticalEncoderSource) Close() error
- func (s *StatisticalEncoderSource) SetTargetBitrate(rate int)
- func (s *StatisticalEncoderSource) SetWriter(f func(sample media.Sample) error)
- func (s *StatisticalEncoderSource) Start(ctx context.Context) error
- func (s *StatisticalEncoderSource) WriteFrame(frame syncodec.Frame)
- type VideoSource
- type VideoTrackInfo
- type WebRTCSender
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
GCC returns an Option that configures Google Congestion Control with the specified initial bitrate.
func PacketLogWriter ¶
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.
type RTCSender ¶
type RTCSender struct {
// contains filtered or unexported fields
}
RTCSender is a generic sender that can work with any frame source.
func NewRTCSender ¶
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) CreateOffer ¶
func (s *RTCSender) CreateOffer() (*webrtc.SessionDescription, error)
CreateOffer creates a WebRTC offer.
func (*RTCSender) GetEncodeFrameOk ¶
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) SetBitrateAllocation ¶
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 ¶
SetCCLogWriter sets the congestion control log writer.
func (*RTCSender) SetLogger ¶
func (s *RTCSender) SetLogger(logger logging.LeveledLogger)
SetLogger sets the logger.
func (*RTCSender) SetupPeerConnection ¶
SetupPeerConnection initializes the WebRTC peer connection.
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 ¶
SetCCLogWriter sets the congestion control log writer.
func (*Sender) SetLogger ¶
func (s *Sender) SetLogger(logger logging.LeveledLogger)
SetLogger sets the logger.
func (*Sender) SetupPeerConnection ¶
SetupPeerConnection initializes the WebRTC peer connection.
func (*Sender) SignalHTTP ¶
SignalHTTP performs WebRTC signaling over HTTP.
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.
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 ¶
func (s *StatisticalEncoderSource) Start(ctx context.Context) error
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 ¶
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.