Documentation
¶
Index ¶
- Constants
- Variables
- type BitrateCalculator
- 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) *BitrateCalculator
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 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