Skip to content

Commit a15b168

Browse files
committed
Reset WHEP state when WHIP publisher changes
New publisher might not have Simulcast layers/need new keyframe
1 parent 8cc4e88 commit a15b168

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

internal/webrtc/sessions/session/session.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (s *Session) AddHost(peerConnection *webrtc.PeerConnection) (err error) {
8484
host.RemoveTracks()
8585
return fmt.Errorf("session already has a host")
8686
}
87+
s.resetWHEPSessionsForNewHost()
8788
host.WHEPSessionsSnapshot.Store(make(map[string]*whep.WHEPSession))
8889
s.updateHostWHEPSessionsSnapshot()
8990
s.HasHost.Store(true)
@@ -237,6 +238,18 @@ func (s *Session) updateHostWHEPSessionsSnapshot() {
237238
host.WHEPSessionsSnapshot.Store(snapshot)
238239
}
239240

241+
func (s *Session) resetWHEPSessionsForNewHost() {
242+
s.WHEPSessionsLock.RLock()
243+
for _, whepSession := range s.WHEPSessions {
244+
if whepSession == nil {
245+
continue
246+
}
247+
248+
whepSession.ResetForNewPublisher()
249+
}
250+
s.WHEPSessionsLock.RUnlock()
251+
}
252+
240253
// Get the status of the current session
241254
func (s *Session) GetStreamStatus() (status whipSessionStatus) {
242255
s.WHEPSessionsLock.RLock()

internal/webrtc/sessions/whep/whep.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ func (w *WHEPSession) SendPLI() {
137137
w.pliSender()
138138
}
139139

140+
// Reset per-publisher delivery state when a new WHIP publisher connects.
141+
func (w *WHEPSession) ResetForNewPublisher() {
142+
w.VideoLock.Lock()
143+
defer w.VideoLock.Unlock()
144+
145+
w.AudioLayerCurrent.Store("")
146+
w.VideoLayerCurrent.Store("")
147+
w.videoLayerPriority = 0
148+
w.videoLayerExplicit = false
149+
w.IsWaitingForKeyframe.Store(true)
150+
}
151+
140152
func (w *WHEPSession) updateVideoBitrateLocked(now time.Time) {
141153
if w.videoBitrateWindowStart.IsZero() {
142154
w.videoBitrateWindowStart = now

0 commit comments

Comments
 (0)