@@ -64,40 +64,40 @@ func main() {
64
64
panic (err )
65
65
}
66
66
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 {
76
68
panic (err )
77
69
}
78
70
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 {
86
72
panic (err )
87
73
}
88
74
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 {
90
83
panic (err )
91
84
}
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 {
95
90
ICEServers : []webrtc.ICEServer {
96
91
{
97
92
URLs : []string {"stun:stun.l.google.com:19302" },
98
93
},
99
94
},
100
- })
95
+ }
96
+
97
+ peerConnection , err := api .NewPeerConnection (
98
+ configuration ,
99
+ webrtc .WithInterceptor (interceptor ),
100
+ )
101
101
if err != nil {
102
102
panic (err )
103
103
}
@@ -107,9 +107,6 @@ func main() {
107
107
}
108
108
}()
109
109
110
- // Wait until our Bandwidth Estimator has been created
111
- estimator := <- estimatorChan
112
-
113
110
// Create a video track
114
111
videoTrack , err := webrtc .NewTrackLocalStaticSample (webrtc.RTPCodecCapability {MimeType : webrtc .MimeTypeVP8 }, "video" , "pion" )
115
112
if err != nil {
0 commit comments