Skip to content

Commit 571ebf3

Browse files
committed
Use the new TWCC API in example
Simplify the bandwidth-estimation-from-disk example to use the simplified callback-less API.
1 parent 9feebd5 commit 571ebf3

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

examples/bandwidth-estimation-from-disk/main.go

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,40 @@ func main() {
6464
panic(err)
6565
}
6666

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

79-
estimatorChan := make(chan cc.BandwidthEstimator, 1)
80-
congestionController.OnNewPeerConnection(func(id string, estimator cc.BandwidthEstimator) { //nolint: revive
81-
estimatorChan <- estimator
82-
})
83-
84-
i.Add(congestionController)
85-
if err = webrtc.ConfigureTWCCHeaderExtensionSender(m, i); err != nil {
71+
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
8672
panic(err)
8773
}
8874

89-
if err = webrtc.RegisterDefaultInterceptors(m, i); err != nil {
75+
api := webrtc.NewAPI(
76+
webrtc.WithInterceptorRegistry(i), webrtc.WithMediaEngine(m),
77+
)
78+
79+
estimator, err := gcc.NewSendSideBWE(
80+
gcc.SendSideBWEInitialBitrate(lowBitrate),
81+
)
82+
if err != nil {
9083
panic(err)
9184
}
92-
93-
// Create a new RTCPeerConnection
94-
peerConnection, err := webrtc.NewAPI(webrtc.WithInterceptorRegistry(i), webrtc.WithMediaEngine(m)).NewPeerConnection(webrtc.Configuration{
85+
interceptor, err := cc.NewSingleInterceptor(estimator)
86+
if err != nil {
87+
panic(err)
88+
}
89+
configuration := webrtc.Configuration{
9590
ICEServers: []webrtc.ICEServer{
9691
{
9792
URLs: []string{"stun:stun.l.google.com:19302"},
9893
},
9994
},
100-
})
95+
}
96+
97+
peerConnection, err := api.NewPeerConnection(
98+
configuration,
99+
webrtc.WithInterceptor(interceptor),
100+
)
101101
if err != nil {
102102
panic(err)
103103
}
@@ -107,9 +107,6 @@ func main() {
107107
}
108108
}()
109109

110-
// Wait until our Bandwidth Estimator has been created
111-
estimator := <-estimatorChan
112-
113110
// Create a video track
114111
videoTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8}, "video", "pion")
115112
if err != nil {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ require (
3434
golang.org/x/sys v0.28.0 // indirect
3535
gopkg.in/yaml.v3 v3.0.1 // indirect
3636
)
37+
38+
replace github.com/pion/interceptor => ../interceptor

0 commit comments

Comments
 (0)