Skip to content

Commit

Permalink
Use the new TWCC API in example
Browse files Browse the repository at this point in the history
Simplify the bandwidth-estimation-from-disk example to use the
simplified callback-less API.
  • Loading branch information
jech committed Jan 13, 2025
1 parent 9feebd5 commit 571ebf3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
45 changes: 21 additions & 24 deletions examples/bandwidth-estimation-from-disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,40 @@ func main() {
panic(err)
}

// Create a Congestion Controller. This analyzes inbound and outbound data and provides
// suggestions on how much we should be sending.
//
// Passing `nil` means we use the default Estimation Algorithm which is Google Congestion Control.
// You can use the other ones that Pion provides, or write your own!
congestionController, err := cc.NewInterceptor(func() (cc.BandwidthEstimator, error) {
return gcc.NewSendSideBWE(gcc.SendSideBWEInitialBitrate(lowBitrate))
})
if err != nil {
if err := webrtc.ConfigureTWCCHeaderExtensionSender(m, i); err != nil {
panic(err)
}

estimatorChan := make(chan cc.BandwidthEstimator, 1)
congestionController.OnNewPeerConnection(func(id string, estimator cc.BandwidthEstimator) { //nolint: revive
estimatorChan <- estimator
})

i.Add(congestionController)
if err = webrtc.ConfigureTWCCHeaderExtensionSender(m, i); err != nil {
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}

if err = webrtc.RegisterDefaultInterceptors(m, i); err != nil {
api := webrtc.NewAPI(
webrtc.WithInterceptorRegistry(i), webrtc.WithMediaEngine(m),
)

estimator, err := gcc.NewSendSideBWE(
gcc.SendSideBWEInitialBitrate(lowBitrate),
)
if err != nil {
panic(err)
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.NewAPI(webrtc.WithInterceptorRegistry(i), webrtc.WithMediaEngine(m)).NewPeerConnection(webrtc.Configuration{
interceptor, err := cc.NewSingleInterceptor(estimator)
if err != nil {
panic(err)
}
configuration := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
})
}

peerConnection, err := api.NewPeerConnection(
configuration,
webrtc.WithInterceptor(interceptor),
)
if err != nil {
panic(err)
}
Expand All @@ -107,9 +107,6 @@ func main() {
}
}()

// Wait until our Bandwidth Estimator has been created
estimator := <-estimatorChan

// Create a video track
videoTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8}, "video", "pion")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ require (
golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/pion/interceptor => ../interceptor

0 comments on commit 571ebf3

Please sign in to comment.