From cda9e6b9d98c1fa7747e6d950047b7b860dc6605 Mon Sep 17 00:00:00 2001 From: bgrozev Date: Fri, 21 Feb 2025 13:52:56 -0600 Subject: [PATCH] fix: Sources with type NONE should not have effective constraints (#2292) * fix: Sources with type NONE should not have effective constraints. When a source has video type NONE or DISABLED, it has been signaled but is not transmitted. For the purpose of generating effective constraints, it should be as if the source was not present. A change of effective constraints is the trigger for creating a new mapping for a receiver. If a receiver has effective constraints for a source with type NONE, and that source is later enabled, the effective constraints don't change, and the mapping is not created. This should fix #2288. * squash: Adjust unit tests. --- .../videobridge/cc/allocation/Prioritize.kt | 2 +- .../cc/allocation/EffectiveConstraintsTest.kt | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt index e76a5be00b..c6fd9c0c78 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt @@ -74,7 +74,7 @@ fun getEffectiveConstraints( var sourcesWithNonZeroConstraints = 0 return sources.associateWith { source -> - if (sourcesWithNonZeroConstraints >= effectiveLastN) { + if (!source.videoType.isEnabled() || sourcesWithNonZeroConstraints >= effectiveLastN) { VideoConstraints.NOTHING } else { allocationSettings.getConstraints(source.sourceName).also { diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt index 9601a205c3..89bf1f6653 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt @@ -41,7 +41,7 @@ class EffectiveConstraintsTest : ShouldSpec() { val s3 = testSource("e1", "s3") val s4 = testSource("e1", "s4", videoType = VideoType.DISABLED) val s5 = testSource("e1", "s5", videoType = VideoType.DISABLED) - val s6 = testSource("e1", "s6", videoType = VideoType.DISABLED) + val s6 = testSource("e1", "s6", videoType = VideoType.NONE) val defaultConstraints = VideoConstraints(180) @@ -97,9 +97,7 @@ class EffectiveConstraintsTest : ShouldSpec() { defaultConstraints = VideoConstraints.NOTHING, videoConstraints = mapOf("s4" to VideoConstraints(720)) ) - getEffectiveConstraints(sources, allocationSettings) shouldBe zeroEffectiveConstraints.apply { - put(s4, VideoConstraints(720)) - } + getEffectiveConstraints(sources, allocationSettings) shouldBe zeroEffectiveConstraints } context("When the top sources have the video DISABLED") { // The top sources in speaker order have videoType = DISABLED @@ -108,7 +106,7 @@ class EffectiveConstraintsTest : ShouldSpec() { context("With default settings") { val allocationSettings = AllocationSettings(lastN = 1, defaultConstraints = defaultConstraints) getEffectiveConstraints(sources, allocationSettings) shouldBe zeroEffectiveConstraints.apply { - put(s4, VideoConstraints(180)) + put(s1, VideoConstraints(180)) } } context("With default constraints 0 and non-zero constraints for a source with video DISABLED") { @@ -117,9 +115,7 @@ class EffectiveConstraintsTest : ShouldSpec() { defaultConstraints = VideoConstraints.NOTHING, videoConstraints = mapOf("s5" to VideoConstraints(180)) ) - getEffectiveConstraints(sources, allocationSettings) shouldBe zeroEffectiveConstraints.apply { - put(s5, VideoConstraints(180)) - } + getEffectiveConstraints(sources, allocationSettings) shouldBe zeroEffectiveConstraints } context("With default constraints 0 and non-zero constraints for a source with video enabled") { val allocationSettings = AllocationSettings( @@ -159,9 +155,9 @@ class EffectiveConstraintsTest : ShouldSpec() { context("And default settings") { val allocationSettings = AllocationSettings(lastN = 3, defaultConstraints = defaultConstraints) getEffectiveConstraints(endpoints, allocationSettings) shouldBe zeroEffectiveConstraints.apply { - put(s4, VideoConstraints(180)) - put(s5, VideoConstraints(180)) - put(s6, VideoConstraints(180)) + put(s1, VideoConstraints(180)) + put(s2, VideoConstraints(180)) + put(s3, VideoConstraints(180)) } } context("And non-zero constraints for sources down the list") { @@ -175,7 +171,6 @@ class EffectiveConstraintsTest : ShouldSpec() { ) ) getEffectiveConstraints(endpoints, allocationSettings) shouldBe zeroEffectiveConstraints.apply { - put(s6, VideoConstraints(180)) put(s2, VideoConstraints(180)) put(s3, VideoConstraints(180)) }