Documentation
¶
Index ¶
- Constants
- Variables
- type BitrateCalculator
- type BitrateMode
- type BufferedAmountGetter
- type DataChannelWriter
- func NewDataChannelWriterReliable[T BufferedAmountGetter](bufferGetter T, rawDC datachannel.ReadWriteCloserDeadliner, slowThreshold int) *DataChannelWriter[T]
- func NewDataChannelWriterUnreliable[T BufferedAmountGetter](bufferGetter T, rawDC datachannel.ReadWriteCloserDeadliner, ...) *DataChannelWriter[T]
Constants ¶
const ( BitrateDuration = 2 * time.Second BitrateWindow = 100 * time.Millisecond )
Variables ¶
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, mode BitrateMode) *BitrateCalculator
NewBitrateCalculator creates a calculator. See BitrateMode for how mode governs the numerator and denominator.
func (*BitrateCalculator) AddBytes ¶
func (c *BitrateCalculator) AddBytes(bytes int, bufferedAmout int, ts time.Time)
func (*BitrateCalculator) ForceBitrate ¶ added in v1.8.4
func (c *BitrateCalculator) ForceBitrate(ts time.Time) (int, bool)
type BitrateMode ¶ added in v1.13.4
type BitrateMode int
BitrateMode selects how the sliding-window rate is computed.
const ( // BitrateModeBusyOnly divides drained bytes by backlogged ("busy") time // only; idle gaps are excluded from the denominator. All drained bytes count. BitrateModeBusyOnly BitrateMode = iota // BitrateModeExcludeIdleDrain is like BitrateModeBusyOnly but also excludes // bytes drained across a non-backlogged interval from the numerator. BitrateModeExcludeIdleDrain // BitrateModeWallClock divides all bytes by elapsed wall-clock time. For // consumers with no send buffer, e.g. a receiver measuring its incoming rate. BitrateModeWallClock )
func (BitrateMode) String ¶ added in v1.13.4
func (m BitrateMode) String() string
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