cc

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cc implements common constructs used by Congestion Controllers

Package cc implements an interceptor for bandwidth estimation that can be used with different BandwidthEstimators.

Index

Constants

View Source
const TwccExtensionAttributesKey = iota

TwccExtensionAttributesKey identifies the TWCC value in the attribute collection so we don't need to reparse.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acknowledgment

type Acknowledgment struct {
	SequenceNumber uint16 // Either RTP SequenceNumber or TWCC
	SSRC           uint32
	Size           int
	Departure      time.Time
	Arrival        time.Time
	ECN            rtcp.ECN

	// only for stats, not used in cc algorithms
	Stats AcknowledgmentStats
}

Acknowledgment holds information about a packet and if/when it has been sent/received.

func (Acknowledgment) String

func (a Acknowledgment) String() string

type AcknowledgmentStats

type AcknowledgmentStats struct {
	FrameID uint16 // if not video, set to 0, otherwise a sequence number start from 1
}

only for stats, not used in cc algorithms

type BandwidthEstimator

type BandwidthEstimator interface {
	AddStream(*interceptor.StreamInfo, interceptor.RTPWriter) interceptor.RTPWriter
	WriteRTCP([]rtcp.Packet, interceptor.Attributes) error
	GetTargetBitrate() int
	OnTargetBitrateChange(f func(bitrate int))
	GetStats() map[string]interface{}
	Close() error
}

BandwidthEstimator is the interface that will be returned by a NewPeerConnectionCallback and can be used to query current bandwidth metrics and add feedback manually.

type BandwidthEstimatorFactory

type BandwidthEstimatorFactory func() (BandwidthEstimator, error)

BandwidthEstimatorFactory creates new BandwidthEstimators.

type FeedbackAdapter

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

FeedbackAdapter converts incoming RTCP Packets (TWCC and RFC8888) into Acknowledgments. Acknowledgments are the common format that Congestion Controllers in Pion understand.

func NewFeedbackAdapter

func NewFeedbackAdapter() *FeedbackAdapter

NewFeedbackAdapter returns a new FeedbackAdapter.

func (*FeedbackAdapter) OnRFC8888Feedback

func (f *FeedbackAdapter) OnRFC8888Feedback(_ time.Time, feedback *rtcp.CCFeedbackReport) []Acknowledgment

OnRFC8888Feedback converts incoming Congestion Control Feedback RTCP packet to Acknowledgments.

func (*FeedbackAdapter) OnSent

func (f *FeedbackAdapter) OnSent(ts time.Time, header *rtp.Header, size int, attributes interceptor.Attributes) error

OnSent records that and when an outgoing packet was sent for later mapping to acknowledgments.

func (*FeedbackAdapter) OnTransportCCFeedback

func (f *FeedbackAdapter) OnTransportCCFeedback(
	now time.Time, feedback *rtcp.TransportLayerCC,
) ([]Acknowledgment, error)

OnTransportCCFeedback converts incoming TWCC RTCP packet feedback to Acknowledgments.

type Interceptor

type Interceptor struct {
	interceptor.NoOp
	// contains filtered or unexported fields
}

Interceptor implements Google Congestion Control.

func (*Interceptor) BindLocalStream

func (c *Interceptor) BindLocalStream(
	info *interceptor.StreamInfo, writer interceptor.RTPWriter,
) interceptor.RTPWriter

BindLocalStream lets you modify any outgoing RTP packets. It is called once for per LocalStream. The returned method will be called once per rtp packet.

func (*Interceptor) BindRTCPReader

func (c *Interceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.RTCPReader

BindRTCPReader lets you modify any incoming RTCP packets. It is called once per sender/receiver, however this might change in the future. The returned method will be called once per packet batch.

func (*Interceptor) Close

func (c *Interceptor) Close() error

Close closes the interceptor and the associated bandwidth estimator.

type InterceptorFactory

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

InterceptorFactory is a factory for CC interceptors.

func NewInterceptor

func NewInterceptor(factory BandwidthEstimatorFactory, opts ...Option) (*InterceptorFactory, error)

NewInterceptor returns a new CC interceptor factory.

func (*InterceptorFactory) NewInterceptor

func (f *InterceptorFactory) NewInterceptor(id string) (interceptor.Interceptor, error)

NewInterceptor returns a new CC interceptor.

func (*InterceptorFactory) OnNewPeerConnection

func (f *InterceptorFactory) OnNewPeerConnection(cb NewPeerConnectionCallback)

OnNewPeerConnection sets a callback that is called when a new CC interceptor is created.

type NewPeerConnectionCallback

type NewPeerConnectionCallback func(id string, estimator BandwidthEstimator)

NewPeerConnectionCallback returns the BandwidthEstimator for the PeerConnection with id.

type Option

type Option func(*Interceptor) error

Option can be used to set initial options on CC interceptors.

Jump to

Keyboard shortcuts

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