Start stream allocator after creating peer connection. (#3283)
* Start stream allocator after creating peer connection. RTTGetter relies of peer connection being created/started. Starting stream allocator before creating peer connection could race. * set bwe interceptor
This commit is contained in:
+13
-12
@@ -471,6 +471,12 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
connectionDetails: types.NewICEConnectionDetails(params.Transport, params.Logger),
|
connectionDetails: types.NewICEConnectionDetails(params.Transport, params.Logger),
|
||||||
lastNegotiate: time.Now(),
|
lastNegotiate: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bwe, err := t.createPeerConnection()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if params.IsSendSide {
|
if params.IsSendSide {
|
||||||
if params.CongestionControlConfig.UseSendSideBWE {
|
if params.CongestionControlConfig.UseSendSideBWE {
|
||||||
params.Logger.Infow("using send side BWE")
|
params.Logger.Infow("using send side BWE")
|
||||||
@@ -496,10 +502,10 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
}, params.CongestionControlConfig.Enabled, params.CongestionControlConfig.AllowPause)
|
}, params.CongestionControlConfig.Enabled, params.CongestionControlConfig.AllowPause)
|
||||||
t.streamAllocator.OnStreamStateChange(params.Handler.OnStreamStateChange)
|
t.streamAllocator.OnStreamStateChange(params.Handler.OnStreamStateChange)
|
||||||
t.streamAllocator.Start()
|
t.streamAllocator.Start()
|
||||||
}
|
|
||||||
|
|
||||||
if err := t.createPeerConnection(); err != nil {
|
if bwe != nil {
|
||||||
return nil, err
|
t.streamAllocator.SetSendSideBWEInterceptor(bwe)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.eventsQueue.Start()
|
t.eventsQueue.Start()
|
||||||
@@ -507,13 +513,13 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *PCTransport) createPeerConnection() error {
|
func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
||||||
var bwe cc.BandwidthEstimator
|
var bwe cc.BandwidthEstimator
|
||||||
pc, me, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
pc, me, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
||||||
bwe = estimator
|
bwe = estimator
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return bwe, err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.pc = pc
|
t.pc = pc
|
||||||
@@ -530,7 +536,7 @@ func (t *PCTransport) createPeerConnection() error {
|
|||||||
|
|
||||||
t.iceTransport = t.pc.SCTP().Transport().ICETransport()
|
t.iceTransport = t.pc.SCTP().Transport().ICETransport()
|
||||||
if t.iceTransport == nil {
|
if t.iceTransport == nil {
|
||||||
return ErrNoICETransport
|
return bwe, ErrNoICETransport
|
||||||
}
|
}
|
||||||
t.iceTransport.OnSelectedCandidatePairChange(func(pair *webrtc.ICECandidatePair) {
|
t.iceTransport.OnSelectedCandidatePairChange(func(pair *webrtc.ICECandidatePair) {
|
||||||
t.params.Logger.Debugw("selected ICE candidate pair changed", "pair", wrappedICECandidatePairLogger{pair})
|
t.params.Logger.Debugw("selected ICE candidate pair changed", "pair", wrappedICECandidatePairLogger{pair})
|
||||||
@@ -546,12 +552,7 @@ func (t *PCTransport) createPeerConnection() error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.me = me
|
t.me = me
|
||||||
|
return bwe, nil
|
||||||
if bwe != nil && t.streamAllocator != nil {
|
|
||||||
t.streamAllocator.SetSendSideBWEInterceptor(bwe)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *PCTransport) GetPacer() pacer.Pacer {
|
func (t *PCTransport) GetPacer() pacer.Pacer {
|
||||||
|
|||||||
Reference in New Issue
Block a user