Return max spatial layer from selectors. (#1743)

* Return max spatial layer from selectors.

With differing requirements of SVC and allowing overshoot in Simulcast,
selectors are best placed to indicate what is the max spatial layer when
they indicate a switch to max spatial layer.

* fix test

* prevent race
This commit is contained in:
Raja Subramanian
2023-05-26 12:49:31 +05:30
committed by GitHub
parent fc8375f150
commit 1c920812d3
8 changed files with 15 additions and 1 deletions
+6
View File
@@ -140,7 +140,9 @@ func TestRoomJoin(t *testing.T) {
t.Run("cannot exceed max participants", func(t *testing.T) { t.Run("cannot exceed max participants", func(t *testing.T) {
rm := newRoomWithParticipants(t, testRoomOpts{num: 1}) rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
rm.lock.Lock()
rm.protoRoom.MaxParticipants = 1 rm.protoRoom.MaxParticipants = 1
rm.lock.Unlock()
p := newMockParticipant("second", types.ProtocolVersion(0), false, false) p := newMockParticipant("second", types.ProtocolVersion(0), false, false)
err := rm.Join(p, nil, nil, iceServersForRoom) err := rm.Join(p, nil, nil, iceServersForRoom)
@@ -347,8 +349,10 @@ func TestRoomClosure(t *testing.T) {
isClosed = true isClosed = true
}) })
p := rm.GetParticipants()[0] p := rm.GetParticipants()[0]
rm.lock.Lock()
// allows immediate close after // allows immediate close after
rm.protoRoom.EmptyTimeout = 0 rm.protoRoom.EmptyTimeout = 0
rm.lock.Unlock()
rm.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonClientRequestLeave) rm.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonClientRequestLeave)
time.Sleep(time.Duration(RoomDepartureGrace)*time.Second + defaultDelay) time.Sleep(time.Duration(RoomDepartureGrace)*time.Second + defaultDelay)
@@ -377,7 +381,9 @@ func TestRoomClosure(t *testing.T) {
rm.OnClose(func() { rm.OnClose(func() {
isClosed = true isClosed = true
}) })
rm.lock.Lock()
rm.protoRoom.EmptyTimeout = 1 rm.protoRoom.EmptyTimeout = 1
rm.lock.Unlock()
time.Sleep(1010 * time.Millisecond) time.Sleep(1010 * time.Millisecond)
rm.CloseIfEmpty() rm.CloseIfEmpty()
+1 -1
View File
@@ -624,7 +624,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
d.bytesSent.Add(uint32(hdr.MarshalSize() + len(payload))) d.bytesSent.Add(uint32(hdr.MarshalSize() + len(payload)))
if tp.isSwitchingToMaxSpatial && d.onMaxSubscribedLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo { if tp.isSwitchingToMaxSpatial && d.onMaxSubscribedLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo {
d.onMaxSubscribedLayerChanged(d, d.forwarder.MaxLayer().Spatial) d.onMaxSubscribedLayerChanged(d, tp.maxSpatialLayer)
} }
if extPkt.KeyFrame { if extPkt.KeyFrame {
+2
View File
@@ -129,6 +129,7 @@ type TranslationParams struct {
isResuming bool isResuming bool
isSwitchingToRequestSpatial bool isSwitchingToRequestSpatial bool
isSwitchingToMaxSpatial bool isSwitchingToMaxSpatial bool
maxSpatialLayer int32
rtp *TranslationParamsRTP rtp *TranslationParamsRTP
codecBytes []byte codecBytes []byte
ddBytes []byte ddBytes []byte
@@ -1570,6 +1571,7 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
tp.isResuming = result.IsResuming tp.isResuming = result.IsResuming
tp.isSwitchingToRequestSpatial = result.IsSwitchingToRequestSpatial tp.isSwitchingToRequestSpatial = result.IsSwitchingToRequestSpatial
tp.isSwitchingToMaxSpatial = result.IsSwitchingToMaxSpatial tp.isSwitchingToMaxSpatial = result.IsSwitchingToMaxSpatial
tp.maxSpatialLayer = result.MaxSpatialLayer
tp.ddBytes = result.DependencyDescriptorExtension tp.ddBytes = result.DependencyDescriptorExtension
tp.marker = result.RTPMarker tp.marker = result.RTPMarker
+1
View File
@@ -1717,6 +1717,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
isSwitchingToMaxSpatial: true, isSwitchingToMaxSpatial: true,
maxSpatialLayer: 1,
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
snOrdering: SequenceNumberOrderingContiguous, snOrdering: SequenceNumberOrderingContiguous,
sequenceNumber: 23339, sequenceNumber: 23339,
@@ -230,6 +230,7 @@ func (d *DependencyDescriptor) Select(extPkt *buffer.ExtPacket, _layer int32) (r
} }
if d.currentLayer.Spatial == d.maxLayer.Spatial { if d.currentLayer.Spatial == d.maxLayer.Spatial {
result.IsSwitchingToMaxSpatial = true result.IsSwitchingToMaxSpatial = true
result.MaxSpatialLayer = d.currentLayer.Spatial
d.logger.Infow( d.logger.Infow(
"reached max layer", "reached max layer",
"current", d.currentLayer, "current", d.currentLayer,
+2
View File
@@ -98,6 +98,7 @@ func (s *Simulcast) Select(extPkt *buffer.ExtPacket, layer int32) (result VideoL
if s.currentLayer.Spatial >= s.maxLayer.Spatial { if s.currentLayer.Spatial >= s.maxLayer.Spatial {
result.IsSwitchingToMaxSpatial = true result.IsSwitchingToMaxSpatial = true
result.MaxSpatialLayer = s.currentLayer.Spatial
s.logger.Infow( s.logger.Infow(
"reached max layer", "reached max layer",
"current", s.currentLayer, "current", s.currentLayer,
@@ -136,6 +137,7 @@ func (s *Simulcast) Select(extPkt *buffer.ExtPacket, layer int32) (result VideoL
if s.currentLayer.Spatial >= s.maxLayer.Spatial { if s.currentLayer.Spatial >= s.maxLayer.Spatial {
result.IsSwitchingToMaxSpatial = true result.IsSwitchingToMaxSpatial = true
result.MaxSpatialLayer = s.currentLayer.Spatial
} }
if s.currentLayer.Spatial >= s.maxLayer.Spatial || s.currentLayer.Spatial == s.maxSeenLayer.Spatial { if s.currentLayer.Spatial >= s.maxLayer.Spatial || s.currentLayer.Spatial == s.maxSeenLayer.Spatial {
@@ -11,6 +11,7 @@ type VideoLayerSelectorResult struct {
IsResuming bool IsResuming bool
IsSwitchingToRequestSpatial bool IsSwitchingToRequestSpatial bool
IsSwitchingToMaxSpatial bool IsSwitchingToMaxSpatial bool
MaxSpatialLayer int32
RTPMarker bool RTPMarker bool
DependencyDescriptorExtension []byte DependencyDescriptorExtension []byte
} }
+1
View File
@@ -85,6 +85,7 @@ func (v *VP9) Select(extPkt *buffer.ExtPacket, _layer int32) (result VideoLayerS
if v.currentLayer.Spatial != v.maxLayer.Spatial && updatedLayer.Spatial == v.maxLayer.Spatial { if v.currentLayer.Spatial != v.maxLayer.Spatial && updatedLayer.Spatial == v.maxLayer.Spatial {
result.IsSwitchingToMaxSpatial = true result.IsSwitchingToMaxSpatial = true
result.MaxSpatialLayer = updatedLayer.Spatial
v.logger.Infow( v.logger.Infow(
"reached max layer", "reached max layer",
"current", v.currentLayer, "current", v.currentLayer,