Skip to content

Commit

Permalink
Add tests for consumer.setPreferredLayers() with temporal layer = 0
Browse files Browse the repository at this point in the history
- Due to an issue in Flatbuffers (google/flatbuffers#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 (google/flatbuffers#8245) but well, maintainers have not released a new version since May 2023 because whatever inexplicable reason.
  • Loading branch information
ibc committed Feb 29, 2024
1 parent 1e9e6f0 commit af7833c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
38 changes: 32 additions & 6 deletions node/src/test/test-Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' });
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand Down
59 changes: 57 additions & 2 deletions rust/tests/integration/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
}],
Expand Down Expand Up @@ -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),
})
);
}
});
Expand Down

0 comments on commit af7833c

Please sign in to comment.