From af7833c69d722abcabb8f25441012a187754afcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Thu, 29 Feb 2024 16:45:31 +0100 Subject: [PATCH] Add tests for consumer.setPreferredLayers() with temporal layer = 0 - Due to an issue in Flatbuffers (https://github.com/google/flatbuffers/issues/8245) when we call `consumer.setPreferredLayers()` with `temporalLayer: 0`, we are NOT passing `temporalLayer` to the worker so it selects the highest available temporal layer instead. - This PR tests that use case in both Node and Rust, and tests should fail until the Flatbuffers issue is resolved. - BTW the Flatbuffers issue was already fixed long ago (https://github.com/google/flatbuffers/issues/8245) but well, maintainers have not released a new version since May 2023 because whatever inexplicable reason. --- node/src/test/test-Consumer.ts | 38 ++++++++++++++++--- rust/tests/integration/consumer.rs | 59 +++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/node/src/test/test-Consumer.ts b/node/src/test/test-Consumer.ts index 829ee29fe1..de4b450438 100644 --- a/node/src/test/test-Consumer.ts +++ b/node/src/test/test-Consumer.ts @@ -123,10 +123,10 @@ const ctx: TestContext = { }, ], encodings: [ - { ssrc: 22222222, rtx: { ssrc: 22222223 } }, - { ssrc: 22222224, rtx: { ssrc: 22222225 } }, - { ssrc: 22222226, rtx: { ssrc: 22222227 } }, - { ssrc: 22222228, rtx: { ssrc: 22222229 } }, + { ssrc: 22222222, scalabilityMode: 'L1T5', rtx: { ssrc: 22222223 } }, + { ssrc: 22222224, scalabilityMode: 'L1T5', rtx: { ssrc: 22222225 } }, + { ssrc: 22222226, scalabilityMode: 'L1T5', rtx: { ssrc: 22222227 } }, + { ssrc: 22222228, scalabilityMode: 'L1T5', rtx: { ssrc: 22222229 } }, ], rtcp: { cname: 'FOOBAR', @@ -389,7 +389,9 @@ test('transport.consume() succeeds', async () => { }); expect(videoConsumer.preferredLayers).toEqual({ spatialLayer: 3, - temporalLayer: 0, + // |temporalLayer| was not given in |preferredLayers| in transport.consume() + // so it should be set to the highest one. + temporalLayer: 4, }); expect(videoConsumer.currentLayers).toBeUndefined(); expect(videoConsumer.appData).toEqual({ baz: 'LOL' }); @@ -729,7 +731,7 @@ test('consumer.dump() succeeds', async () => { rtx: { ssrc: videoConsumer.rtpParameters.encodings?.[0].rtx?.ssrc, }, - scalabilityMode: 'L4T1', + scalabilityMode: 'L4T5', }, ]); expect(Array.isArray(dump2.consumableRtpEncodings)).toBe(true); @@ -870,8 +872,32 @@ test('consumer.setPreferredLayers() succeed', async () => { expect(videoConsumer.preferredLayers).toEqual({ spatialLayer: 2, + temporalLayer: 3, + }); + + await videoConsumer.setPreferredLayers({ spatialLayer: 3 }); + + expect(videoConsumer.preferredLayers).toEqual({ + spatialLayer: 3, + temporalLayer: 4, + }); + + await videoConsumer.setPreferredLayers({ spatialLayer: 3, temporalLayer: 0 }); + + expect(videoConsumer.preferredLayers).toEqual({ + spatialLayer: 3, temporalLayer: 0, }); + + await videoConsumer.setPreferredLayers({ + spatialLayer: 66, + temporalLayer: 66, + }); + + expect(videoConsumer.preferredLayers).toEqual({ + spatialLayer: 3, + temporalLayer: 4, + }); }, 2000); test('consumer.setPreferredLayers() with wrong arguments rejects with TypeError', async () => { diff --git a/rust/tests/integration/consumer.rs b/rust/tests/integration/consumer.rs index 35fdaa214e..f191c7bda9 100644 --- a/rust/tests/integration/consumer.rs +++ b/rust/tests/integration/consumer.rs @@ -159,21 +159,25 @@ fn video_producer_options() -> ProducerOptions { encodings: vec![ RtpEncodingParameters { ssrc: Some(22222222), + scalability_mode: "L1T5".parse().unwrap(), rtx: Some(RtpEncodingParametersRtx { ssrc: 22222223 }), ..RtpEncodingParameters::default() }, RtpEncodingParameters { ssrc: Some(22222224), + scalability_mode: "L1T5".parse().unwrap(), rtx: Some(RtpEncodingParametersRtx { ssrc: 22222225 }), ..RtpEncodingParameters::default() }, RtpEncodingParameters { ssrc: Some(22222226), + scalability_mode: "L1T5".parse().unwrap(), rtx: Some(RtpEncodingParametersRtx { ssrc: 22222227 }), ..RtpEncodingParameters::default() }, RtpEncodingParameters { ssrc: Some(22222228), + scalability_mode: "L1T5".parse().unwrap(), rtx: Some(RtpEncodingParametersRtx { ssrc: 22222229 }), ..RtpEncodingParameters::default() }, @@ -555,7 +559,10 @@ fn consume_succeeds() { video_consumer.preferred_layers(), Some(ConsumerLayers { spatial_layer: 3, - temporal_layer: Some(0) + // |temporal_layer| was not given in |preferred_layers| in + // transport.consume() so it should be set to the highest + // one. + temporal_layer: Some(4) }) ); assert_eq!(video_consumer.current_layers(), None); @@ -1091,7 +1098,7 @@ fn dump_succeeds() { .unwrap() .rtx, dtx: None, - scalability_mode: "L4T1".parse().unwrap(), + scalability_mode: "L4T5".parse().unwrap(), rid: None, max_bitrate: None, }], @@ -1324,8 +1331,56 @@ fn set_preferred_layers_succeeds() { video_consumer.preferred_layers(), Some(ConsumerLayers { spatial_layer: 2, + temporal_layer: Some(3), + }) + ); + + video_consumer + .set_preferred_layers(ConsumerLayers { + spatial_layer: 3, + temporal_layer: None, + }) + .await + .expect("Failed to set preferred layers consumer"); + + assert_eq!( + video_consumer.preferred_layers(), + Some(ConsumerLayers { + spatial_layer: 3, + temporal_layer: Some(4), + }) + ); + + video_consumer + .set_preferred_layers(ConsumerLayers { + spatial_layer: 3, temporal_layer: Some(0), }) + .await + .expect("Failed to set preferred layers consumer"); + + assert_eq!( + video_consumer.preferred_layers(), + Some(ConsumerLayers { + spatial_layer: 3, + temporal_layer: Some(0), + }) + ); + + video_consumer + .set_preferred_layers(ConsumerLayers { + spatial_layer: 66, + temporal_layer: Some(66), + }) + .await + .expect("Failed to set preferred layers consumer"); + + assert_eq!( + video_consumer.preferred_layers(), + Some(ConsumerLayers { + spatial_layer: 3, + temporal_layer: Some(4), + }) ); } });