Avoid reconnect loop for unsupported downtrack (#1754)
* Avoid reconnect loop for unsupported downtrack If the client subscribes to a track which codec is unsupported by the client, sfu will trigger negotiation failed and issue a full reconnect after received client answer. If the client try to subscribe that track then it will got full reconnect again. That will cause a infinite reconnect loop until the client don't subscribe that track. This PR will unsubscribe the error track for the client and send a SubscriptionResponse that contain the reason to indicates the track's codec is not supported to avoid the reconnect loop.
This commit is contained in:
+10
-4
@@ -199,7 +199,7 @@ type DownTrack struct {
|
||||
writeStream webrtc.TrackLocalWriter
|
||||
rtcpReader *buffer.RTCPReader
|
||||
onCloseHandler func(willBeResumed bool)
|
||||
onBinding func()
|
||||
onBinding func(error)
|
||||
|
||||
listenerLock sync.RWMutex
|
||||
receiverReportListeners []ReceiverReportListener
|
||||
@@ -336,8 +336,14 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
||||
}
|
||||
|
||||
if codec.MimeType == "" {
|
||||
err := webrtc.ErrUnsupportedCodec
|
||||
onBinding := d.onBinding
|
||||
d.bindLock.Unlock()
|
||||
return webrtc.RTPCodecParameters{}, webrtc.ErrUnsupportedCodec
|
||||
d.logger.Infow("bind error for unsupported codec", "codecs", d.upstreamCodecs, "remoteParameters", t.CodecParameters())
|
||||
if onBinding != nil {
|
||||
onBinding(err)
|
||||
}
|
||||
return webrtc.RTPCodecParameters{}, err
|
||||
}
|
||||
|
||||
// if a downtrack is closed before bind, it already unsubscribed from client, don't do subsequent operation and return here.
|
||||
@@ -367,7 +373,7 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
||||
|
||||
d.codec = codec.RTPCodecCapability
|
||||
if d.onBinding != nil {
|
||||
d.onBinding()
|
||||
d.onBinding(nil)
|
||||
}
|
||||
d.bound.Store(true)
|
||||
d.bindLock.Unlock()
|
||||
@@ -990,7 +996,7 @@ func (d *DownTrack) OnCloseHandler(fn func(willBeResumed bool)) {
|
||||
d.onCloseHandler = fn
|
||||
}
|
||||
|
||||
func (d *DownTrack) OnBinding(fn func()) {
|
||||
func (d *DownTrack) OnBinding(fn func(error)) {
|
||||
d.onBinding = fn
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user