Smoother dynacast transition (#390)
This commit is contained in:
+50
-6
@@ -134,6 +134,9 @@ type DownTrack struct {
|
||||
|
||||
// update stats
|
||||
onStatsUpdate func(dt *DownTrack, stat *livekit.AnalyticsStat)
|
||||
|
||||
// when max subscribed layer changes
|
||||
onMaxLayerChanged func(dt *DownTrack, layer int32)
|
||||
}
|
||||
|
||||
// NewDownTrack returns a DownTrack.
|
||||
@@ -336,6 +339,10 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
f(d, pktSize)
|
||||
}
|
||||
|
||||
if tp.isSwitchingToMaxLayer && d.onMaxLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo {
|
||||
d.onMaxLayerChanged(d, layer)
|
||||
}
|
||||
|
||||
d.UpdatePrimaryStats(uint32(pktSize))
|
||||
} else {
|
||||
d.logger.Errorw("writing rtp packet err", err)
|
||||
@@ -369,7 +376,7 @@ func (d *DownTrack) WritePaddingRTP(bytesToSend int) int {
|
||||
// can be sent only on frame boundaries, writing on disabled tracks
|
||||
// will give more options.
|
||||
// LK-TODO-END
|
||||
if d.forwarder.Muted() {
|
||||
if d.forwarder.IsMuted() {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -440,12 +447,25 @@ func (d *DownTrack) WritePaddingRTP(bytesToSend int) int {
|
||||
}
|
||||
|
||||
// Mute enables or disables media forwarding
|
||||
func (d *DownTrack) Mute(val bool) {
|
||||
changed := d.forwarder.Mute(val)
|
||||
func (d *DownTrack) Mute(muted bool) {
|
||||
changed, maxLayers := d.forwarder.Mute(muted)
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
|
||||
if d.onMaxLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo {
|
||||
if muted {
|
||||
d.onMaxLayerChanged(d, InvalidLayerSpatial)
|
||||
} else {
|
||||
//
|
||||
// When unmuting, don't wait for layer lock as
|
||||
// client might need to be notified to start layers
|
||||
// before locking can happen in the forwarder.
|
||||
//
|
||||
d.onMaxLayerChanged(d, maxLayers.spatial)
|
||||
}
|
||||
}
|
||||
|
||||
if d.onSubscriptionChanged != nil {
|
||||
d.onSubscriptionChanged(d)
|
||||
}
|
||||
@@ -478,6 +498,10 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
||||
|
||||
d.connectionStats.Close()
|
||||
|
||||
if d.onMaxLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo {
|
||||
d.onMaxLayerChanged(d, InvalidLayerSpatial)
|
||||
}
|
||||
|
||||
if d.onCloseHandler != nil {
|
||||
d.onCloseHandler()
|
||||
}
|
||||
@@ -485,18 +509,29 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
||||
}
|
||||
|
||||
func (d *DownTrack) SetMaxSpatialLayer(spatialLayer int32) {
|
||||
changed, maxLayers := d.forwarder.SetMaxSpatialLayer(spatialLayer)
|
||||
changed, maxLayers, currentLayers := d.forwarder.SetMaxSpatialLayer(spatialLayer)
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
|
||||
if d.onMaxLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo && maxLayers.SpatialGreaterThanOrEqual(currentLayers) {
|
||||
//
|
||||
// Notify when new max is
|
||||
// 1. Equal to current -> already locked to the new max
|
||||
// 2. Greater than current -> two scenarios
|
||||
// a. is higher than previous max -> client may need to start higher layer before forwarder can lock
|
||||
// b. is lower than previous max -> client can stop higher layer(s)
|
||||
//
|
||||
d.onMaxLayerChanged(d, maxLayers.spatial)
|
||||
}
|
||||
|
||||
if d.onSubscribedLayersChanged != nil {
|
||||
d.onSubscribedLayersChanged(d, maxLayers)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DownTrack) SetMaxTemporalLayer(temporalLayer int32) {
|
||||
changed, maxLayers := d.forwarder.SetMaxTemporalLayer(temporalLayer)
|
||||
changed, maxLayers, _ := d.forwarder.SetMaxTemporalLayer(temporalLayer)
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
@@ -570,6 +605,15 @@ func (d *DownTrack) OnStatsUpdate(fn func(dt *DownTrack, stat *livekit.Analytics
|
||||
d.onStatsUpdate = fn
|
||||
}
|
||||
|
||||
func (d *DownTrack) OnMaxLayerChanged(fn func(dt *DownTrack, layer int32)) {
|
||||
d.onMaxLayerChanged = fn
|
||||
|
||||
// have to send this immediately to set initial values
|
||||
if fn != nil && d.kind == webrtc.RTPCodecTypeVideo {
|
||||
go fn(d, d.forwarder.MaxLayers().spatial)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DownTrack) IsDeficient() bool {
|
||||
return d.forwarder.IsDeficient()
|
||||
}
|
||||
@@ -1041,7 +1085,7 @@ func (d *DownTrack) DebugInfo() map[string]interface{} {
|
||||
"SSRC": d.ssrc,
|
||||
"MimeType": d.codec.MimeType,
|
||||
"Bound": d.bound.get(),
|
||||
"Muted": d.forwarder.Muted(),
|
||||
"Muted": d.forwarder.IsMuted(),
|
||||
"CurrentSpatialLayer": d.forwarder.CurrentLayers().spatial,
|
||||
"Stats": stats,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user