datachannel

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BitrateDuration = 2 * time.Second
	BitrateWindow   = 100 * time.Millisecond
)

Variables

View Source
var (
	ErrDataDroppedBySlowReader         = errors.New("data dropped by slow reader")
	ErrDataDroppedByHighBufferedAmount = errors.New("data dropped due to high buffered amount")
)

Functions

This section is empty.

Types

type BitrateCalculator

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

BitrateCalculator calculates bitrate over sliding window

func NewBitrateCalculator

func NewBitrateCalculator(duration time.Duration, window time.Duration) *BitrateCalculator

func (*BitrateCalculator) AddBytes

func (c *BitrateCalculator) AddBytes(bytes int, bufferedAmout int, ts time.Time)

func (*BitrateCalculator) Bitrate

func (c *BitrateCalculator) Bitrate(ts time.Time) (int, bool)

func (*BitrateCalculator) ForceBitrate added in v1.8.4

func (c *BitrateCalculator) ForceBitrate(ts time.Time) (int, bool)

type BufferedAmountGetter

type BufferedAmountGetter interface {
	BufferedAmount() uint64
}

type DataChannelWriter

type DataChannelWriter[T BufferedAmountGetter] struct {
	// contains filtered or unexported fields
}

func NewDataChannelWriterReliable added in v1.9.5

func NewDataChannelWriterReliable[T BufferedAmountGetter](bufferGetter T, rawDC datachannel.ReadWriteCloserDeadliner, slowThreshold int) *DataChannelWriter[T]

NewDataChannelWriterReliable creates a new DataChannelWriter for reliable data channel by detaching it, when writing to the datachanel times out, it will block and retry if the receiver's bitrate is above the slowThreshold or drop the data if it's below the threshold. If the slowThreshold is 0, it will never retry on write timeout.

func NewDataChannelWriterUnreliable added in v1.9.5

func NewDataChannelWriterUnreliable[T BufferedAmountGetter](bufferGetter T, rawDC datachannel.ReadWriteCloserDeadliner, targetLatency time.Duration, minBufferedAmount uint64) *DataChannelWriter[T]

NewDataChannelWriterUnreliable creates a new DataChannelWriter for unreliable data channel. It will drop data when the buffered amount is too high to maintain the target latency. The latency is estimated based on the bitrate in past 1 second. If targetLatency is 0, no buffering control is applied.

func (*DataChannelWriter[T]) BufferedAmountGetter

func (w *DataChannelWriter[T]) BufferedAmountGetter() T

func (*DataChannelWriter[T]) Close

func (w *DataChannelWriter[T]) Close() error

func (*DataChannelWriter[T]) Write

func (w *DataChannelWriter[T]) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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