Keep simulcast information tied to receiver. (#3563)

* Keep simulcast information tied to receiver.

`simulcast` flag in `TrackInfo` is at track lavel. With codec simulcast,
the primary codec (in most cases) is SVC and the backup codec is
simulcast. Back up codec publish changing the track info setting to true
meant that the primary receiver was treated as simulcast if a subscriber
for primary codec joined after the backup codec was published.

Keep track of simulcast flag in receiver.

Also, TrackInfo Cids are from signal. So, keep track of SDP cids
separately. The `simulcastTrackIds` map uses SDP cid. Clean up by all
the SDP cids of a track

* clean up

* clean up

* clean up

* clean up

* test

* Store SdpCid and IsSimulcast in Trackinfo

* clean up

* mock
This commit is contained in:
Raja Subramanian
2025-03-31 19:25:57 +05:30
committed by GitHub
parent ad010cfc43
commit ed5e2f16b2
17 changed files with 393 additions and 188 deletions
+18 -12
View File
@@ -123,6 +123,7 @@ type TrackReceiver interface {
TrackInfo() *livekit.TrackInfo
UpdateTrackInfo(ti *livekit.TrackInfo)
IsSimulcast() bool
// Get primary receiver if this receiver represents a RED codec; otherwise it will return itself
GetPrimaryReceiverForRed() TrackReceiver
@@ -268,18 +269,17 @@ func NewWebRTCReceiver(
isRED: mime.IsMimeTypeStringRED(track.Codec().MimeType),
}
isSVC := false
isSimulcast := trackInfo.GetSimulcast()
if !isSimulcast {
isSVC = mime.IsMimeTypeStringSVC(track.Codec().MimeType)
}
w.isSVC = isSVC
for _, opt := range opts {
w = opt(w)
}
w.trackInfo.Store(utils.CloneProto(trackInfo))
isSVC := false
if !w.IsSimulcast() {
isSVC = mime.IsMimeTypeStringSVC(track.Codec().MimeType)
}
w.isSVC = isSVC
w.downTrackSpreader = NewDownTrackSpreader(DownTrackSpreaderParams{
Threshold: w.lbThreshold,
Logger: logger,
@@ -324,6 +324,16 @@ func (w *WebRTCReceiver) UpdateTrackInfo(ti *livekit.TrackInfo) {
w.streamTrackerManager.UpdateTrackInfo(ti)
}
func (w *WebRTCReceiver) IsSimulcast() bool {
for _, codec := range w.trackInfo.Load().Codecs {
if mime.IsMimeTypeStringEqual(codec.MimeType, w.codec.MimeType) {
return codec.IsSimulcast
}
}
return false
}
func (w *WebRTCReceiver) OnStatsUpdate(fn func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)) {
w.onStatsUpdate = fn
}
@@ -861,13 +871,9 @@ func (w *WebRTCReceiver) closeTracks() {
}
func (w *WebRTCReceiver) DebugInfo() map[string]interface{} {
isSimulcast := !w.isSVC
if ti := w.trackInfo.Load(); ti != nil {
isSimulcast = isSimulcast && len(ti.Layers) > 1
}
info := map[string]interface{}{
"SVC": w.isSVC,
"Simulcast": isSimulcast,
"Simulcast": w.IsSimulcast(),
}
w.bufferMu.RLock()