diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index b2dc00b75..db3f0cff3 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -410,7 +410,7 @@ func (p *ParticipantImpl) onPublisherAnswer(answer webrtc.SessionDescription) { prometheus.ServiceOperationCounter.WithLabelValues("answer", "error", "write_message").Add(1) return } - p.TransportManager.SetPublisherLocalDescriptionSent(true) + p.TransportManager.PublisherLocalDescriptionSent() if p.isPublisher.Load() != p.CanPublish() { p.isPublisher.Store(p.CanPublish()) @@ -1003,7 +1003,7 @@ func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) { } else { prometheus.ServiceOperationCounter.WithLabelValues("offer", "success", "").Add(1) } - p.TransportManager.SetSubscriberLocalDescriptionSent(true) + p.TransportManager.SubscriberLocalDescriptionSent() } // when a new remoteTrack is created, creates a Track and adds it to room diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index e2d2fc1e4..47b8786b7 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -464,19 +464,13 @@ func (t *PCTransport) maybeNotifyFullyEstablished() { } } -func (t *PCTransport) SetLocalDescriptionSent(sent bool) { +func (t *PCTransport) LocalDescriptionSent() { var cachedLocalCandidates []*webrtc.ICECandidate t.lock.Lock() - t.localDescriptionSent = sent - if sent { - cachedLocalCandidates = t.cachedLocalCandidates - t.cachedLocalCandidates = nil - } else { - t.allowedLocalCandidates = nil - t.allowedRemoteCandidates = nil - t.filteredLocalCandidates = nil - t.filteredRemoteCandidates = nil - } + t.localDescriptionSent = true + + cachedLocalCandidates = t.cachedLocalCandidates + t.cachedLocalCandidates = nil t.lock.Unlock() if t.onICECandidate != nil { @@ -486,6 +480,15 @@ func (t *PCTransport) SetLocalDescriptionSent(sent bool) { } } +func (t *PCTransport) clearLocalDescriptionSentLocked() { + t.localDescriptionSent = false + + t.allowedLocalCandidates = nil + t.allowedRemoteCandidates = nil + t.filteredLocalCandidates = nil + t.filteredRemoteCandidates = nil +} + func (t *PCTransport) SetPreferTCP(preferTCP bool) { t.lock.Lock() t.preferTCP = preferTCP @@ -703,11 +706,7 @@ func (t *PCTransport) SetRemoteDescription(sd webrtc.SessionDescription) error { } if offerRestartICE && t.pendingRestartIceOffer == nil { - t.localDescriptionSent = false - t.allowedLocalCandidates = nil - t.allowedRemoteCandidates = nil - t.filteredLocalCandidates = nil - t.filteredRemoteCandidates = nil + t.clearLocalDescriptionSentLocked() } if offerRestartICE && t.pc.ICEGatheringState() == webrtc.ICEGatheringStateGathering { @@ -978,6 +977,11 @@ func (t *PCTransport) CreateAndSendAnswer(enableDTX bool) error { func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error { t.lock.Lock() defer t.lock.Unlock() + + if options != nil && options.ICERestart { + t.clearLocalDescriptionSentLocked() + } + return t.createAndSendOffer(options) } diff --git a/pkg/rtc/transportmanager.go b/pkg/rtc/transportmanager.go index 04b0efb07..4cf23059e 100644 --- a/pkg/rtc/transportmanager.go +++ b/pkg/rtc/transportmanager.go @@ -173,8 +173,8 @@ func (t *TransportManager) GetPublisherRTPReceiver(mid string) *webrtc.RTPReceiv return t.publisher.GetRTPReceiver(mid) } -func (t *TransportManager) SetPublisherLocalDescriptionSent(sent bool) { - t.publisher.SetLocalDescriptionSent(sent) +func (t *TransportManager) PublisherLocalDescriptionSent() { + t.publisher.LocalDescriptionSent() } func (t *TransportManager) WritePublisherRTCP(pkts []rtcp.Packet) error { @@ -201,8 +201,8 @@ func (t *TransportManager) OnSubscriberStreamStateChange(f func(update *sfu.Stre t.subscriber.OnStreamStateChange(f) } -func (t *TransportManager) SetSubscriberLocalDescriptionSent(sent bool) { - t.subscriber.SetLocalDescriptionSent(sent) +func (t *TransportManager) SubscriberLocalDescriptionSent() { + t.subscriber.LocalDescriptionSent() } func (t *TransportManager) HasSubscriberEverConnected() bool { @@ -375,7 +375,6 @@ func (t *TransportManager) ICERestart(iceConfig *types.IceConfig) error { t.SetICEConfig(*iceConfig) } - t.subscriber.SetLocalDescriptionSent(false) return t.subscriber.CreateAndSendOffer(&webrtc.OfferOptions{ ICERestart: true, })