Skip to content

Commit 54a5be1

Browse files
committed
Refactor configuration tests
1 parent 7e6056c commit 54a5be1

File tree

1 file changed

+63
-79
lines changed

1 file changed

+63
-79
lines changed

test/ex_webrtc/peer_connection/configuration_test.exs

Lines changed: 63 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
2020
@h264_codec %RTPCodecParameters{
2121
payload_type: @payload_type,
2222
mime_type: "video/H264",
23-
clock_rate: 90_000
23+
clock_rate: 90_000,
24+
sdp_fmtp_line: %FMTP{
25+
pt: @payload_type,
26+
level_asymmetry_allowed: true,
27+
packetization_mode: 1,
28+
profile_level_id: 0x42E01F
29+
}
2430
}
2531

2632
@vp8_codec %RTPCodecParameters{
@@ -35,6 +41,13 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
3541
clock_rate: 90_000
3642
}
3743

44+
@av1_codec %RTPCodecParameters{
45+
payload_type: @payload_type,
46+
mime_type: "video/AV1",
47+
clock_rate: 90_000,
48+
sdp_fmtp_line: %FMTP{pt: @payload_type, level_idx: 5, profile: 0, tier: 0}
49+
}
50+
3851
@rtx %RTPCodecParameters{
3952
payload_type: @payload_type,
4053
mime_type: "video/rtx",
@@ -265,13 +278,19 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
265278
audio_codecs: [%{@opus_codec | payload_type: 111}]
266279
)
267280

281+
# opus should change its payload type as it is defined without fmtp, hence every fmtp from sdp is accepted
282+
# h264 should have payload type 112 as this is the one that has the same fmtp
268283
sdp =
269284
"""
270-
m=audio 9 UDP/TLS/RTP/SAVPF 0
285+
m=audio 9 UDP/TLS/RTP/SAVPF 115
271286
a=rtpmap:115 opus/48000/2
272-
m=video 9 UDP/TLS/RTP/SAVPF 1
287+
a=fmtp:111 minptime=10;maxaveragebitrate=96000;stereo=1;sprop-stereo=1;useinbandfec=1
288+
m=video 9 UDP/TLS/RTP/SAVPF 100 111 112
273289
a=rtpmap:100 VP8/90000
274290
a=rtpmap:111 H264/90000
291+
a=fmtp:111 profile-level-id=42e01f;packetization-mode=0;level-asymmetry-allowed=1
292+
a=rtpmap:112 H264/90000
293+
a=fmtp:112 profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1
275294
"""
276295
|> ExSDP.parse!()
277296

@@ -280,7 +299,7 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
280299
assert %Configuration{
281300
audio_codecs: [%RTPCodecParameters{payload_type: 115}],
282301
video_codecs: [
283-
%RTPCodecParameters{payload_type: 111},
302+
%RTPCodecParameters{payload_type: 112},
284303
%RTPCodecParameters{payload_type: 100}
285304
]
286305
} = config
@@ -297,19 +316,27 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
297316
%{@rtx | payload_type: 111, sdp_fmtp_line: %FMTP{pt: 111, apt: 94}},
298317
%{@vp8_codec | payload_type: 96},
299318
%{@rtx | payload_type: 100, sdp_fmtp_line: %FMTP{pt: 100, apt: 96}},
300-
%{@vp9_codec | payload_type: 108}
319+
%{@vp9_codec | payload_type: 108},
320+
%{@av1_codec | payload_type: 102},
321+
%{@rtx | payload_type: 113, sdp_fmtp_line: %FMTP{pt: 113, apt: 102}}
301322
]
302323
)
303324

304-
# h264 and its rtx both should change pt
325+
# h264 and its rtx both should change pt (but to the second h264 from sdp as this is the one with matching fmtp)
305326
# vp8 should stay as it is but its rtx should change pt as it conflicts with the new h264
306327
# vp9 should just change pt
328+
# av1 should stay as it is but its rtx should change pt as it conflicts with the second h264's rtx from sdp
307329
sdp =
308330
"""
309-
m=audio 9 UDP/TLS/RTP/SAVPF 0
331+
m=audio 9 UDP/TLS/RTP/SAVPF 115
310332
a=rtpmap:115 opus/48000/2
311-
m=video 9 UDP/TLS/RTP/SAVPF 1
333+
m=video 9 UDP/TLS/RTP/SAVPF 112 113 100 101 96 110 111
334+
a=rtpmap:112 H264/90000
335+
a=fmtp:112 profile-level-id=42e01f;packetization-mode=0;level-asymmetry-allowed=1
336+
a=rtpmap:113 rtx/90000
337+
a=fmtp:113 apt=112
312338
a=rtpmap:100 H264/90000
339+
a=fmtp:100 profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1
313340
a=rtpmap:101 rtx/90000
314341
a=fmtp:101 apt=100
315342
a=rtpmap:96 VP8/90000
@@ -326,15 +353,25 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
326353
video_codecs: video_codecs
327354
} = config
328355

329-
[h264, vp8, vp9] = Enum.reject(video_codecs, &String.ends_with?(&1.mime_type, "/rtx"))
356+
[h264, vp8, vp9, av1] = Enum.reject(video_codecs, &String.ends_with?(&1.mime_type, "/rtx"))
330357
assert %{mime_type: "video/H264", payload_type: 100} = h264
331358
assert %{mime_type: "video/VP8", payload_type: 96} = vp8
332359
assert %{mime_type: "video/VP9", payload_type: 110} = vp9
360+
assert %{mime_type: "video/AV1", payload_type: 102} = av1
361+
362+
[h264_rtx, vp8_rtx, av1_rtx] =
363+
Enum.filter(video_codecs, &String.ends_with?(&1.mime_type, "/rtx"))
333364

334-
[h264_rtx, vp8_rtx] = Enum.filter(video_codecs, &String.ends_with?(&1.mime_type, "/rtx"))
335365
assert %{mime_type: "video/rtx", payload_type: 101, sdp_fmtp_line: %{apt: 100}} = h264_rtx
336-
assert %{mime_type: "video/rtx", payload_type: pt, sdp_fmtp_line: %{apt: 96}} = vp8_rtx
337-
assert pt not in [100, 101, 96, 110]
366+
367+
assert %{mime_type: "video/rtx", payload_type: vp8_rtx_pt, sdp_fmtp_line: %{apt: 96}} =
368+
vp8_rtx
369+
370+
assert %{mime_type: "video/rtx", payload_type: av1_rtx_pt, sdp_fmtp_line: %{apt: 102}} =
371+
av1_rtx
372+
373+
assert vp8_rtx_pt not in [100, 101, 112, 113, 96, 110, 111]
374+
assert av1_rtx_pt not in [100, 101, 112, 113, 96, 110, 111]
338375
end
339376

340377
test "does not update anything, when there are no common codecs" do
@@ -367,65 +404,6 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
367404
String.ends_with?(codec.mime_type, "/rtx")
368405
end)
369406
end
370-
371-
test "does not update codec payload type when FMTP does not match" do
372-
h264_codec = %RTPCodecParameters{
373-
payload_type: 98,
374-
mime_type: "video/H264",
375-
clock_rate: 90_000,
376-
sdp_fmtp_line: %FMTP{
377-
pt: 98,
378-
level_asymmetry_allowed: true,
379-
packetization_mode: 1,
380-
profile_level_id: 0x42E01F
381-
}
382-
}
383-
384-
og_config =
385-
Configuration.from_options!(
386-
controlling_process: self(),
387-
video_codecs: [h264_codec]
388-
)
389-
390-
# packetization mode in fmtp differs
391-
sdp =
392-
"""
393-
m=video 58712 UDP/TLS/RTP/SAVPF 127
394-
a=rtpmap:127 H264/90000
395-
a=rtcp-fb:127 nack
396-
a=rtcp-fb:127 nack pli
397-
a=fmtp:127 profile-level-id=42e01f;packetization-mode=0;level-asymmetry-allowed=1
398-
"""
399-
|> ExSDP.parse!()
400-
401-
assert Configuration.update(og_config, sdp) == og_config
402-
end
403-
404-
test "updates codec payload type when there is no local FMTP" do
405-
og_config =
406-
Configuration.from_options!(controlling_process: self(), video_codecs: [@h264_codec])
407-
408-
assert @h264_codec.sdp_fmtp_line == nil
409-
assert @h264_codec.payload_type != 96
410-
411-
sdp =
412-
"""
413-
m=video 58712 UDP/TLS/RTP/SAVPF 96
414-
a=rtpmap:96 H264/90000
415-
a=rtcp-fb:96 nack
416-
a=rtcp-fb:96 nack pli
417-
a=fmtp:96 profile-level-id=42e01f;packetization-mode=0;level-asymmetry-allowed=1
418-
"""
419-
|> ExSDP.parse!()
420-
421-
config = Configuration.update(og_config, sdp)
422-
423-
assert [h264, rtx] = config.video_codecs
424-
assert h264.payload_type == 96
425-
assert h264.sdp_fmtp_line == nil
426-
assert rtx.payload_type != 96
427-
assert rtx.sdp_fmtp_line.apt == 96
428-
end
429407
end
430408

431409
test "intersect_codecs/2" do
@@ -440,15 +418,20 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
440418

441419
sdp =
442420
"""
443-
m=audio 9 UDP/TLS/RTP/SAVPF 0
421+
m=audio 9 UDP/TLS/RTP/SAVPF 111
444422
a=rtpmap:111 opus/48000/2
445423
a=rtcp-fb:111 transport-cc
446-
m=video 9 UDP/TLS/RTP/SAVPF 1
424+
m=video 9 UDP/TLS/RTP/SAVPF 112 115 120 121 113 117 119
447425
a=rtpmap:112 H264/90000
448-
a=rtcp-fb:112 transport-cc
449-
a=rtcp-fb:112 nack pli
426+
a=fmtp:112 profile-level-id=42e01f;packetization-mode=0;level-asymmetry-allowed=1
450427
a=rtpmap:115 rtx/90000
451428
a=fmtp:115 apt=112
429+
a=rtpmap:120 H264/90000
430+
a=fmtp:120 profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1
431+
a=rtcp-fb:120 transport-cc
432+
a=rtcp-fb:120 nack pli
433+
a=rtpmap:121 rtx/90000
434+
a=fmtp:121 apt=120
452435
a=rtpmap:113 VP8/90000
453436
a=rtcp-fb:113 transport-cc
454437
a=rtpmap:117 VP9/90000
@@ -477,15 +460,15 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
477460

478461
assert %RTPCodecParameters{
479462
mime_type: "video/H264",
480-
payload_type: 112,
481-
rtcp_fbs: [%RTCPFeedback{pt: 112, feedback_type: :pli}]
463+
payload_type: 120,
464+
rtcp_fbs: [%RTCPFeedback{pt: 120, feedback_type: :pli}]
482465
} = h264
483466

484467
assert %RTPCodecParameters{
485468
mime_type: "video/rtx",
486-
payload_type: 115,
469+
payload_type: 121,
487470
rtcp_fbs: [],
488-
sdp_fmtp_line: %FMTP{pt: 115, apt: 112}
471+
sdp_fmtp_line: %FMTP{pt: 121, apt: 120}
489472
} = h264_rtx
490473
end
491474

@@ -507,6 +490,7 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
507490
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
508491
a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
509492
a=rtpmap:112 H264/90000
493+
a=fmtp:112 profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1
510494
"""
511495
|> ExSDP.parse!()
512496

0 commit comments

Comments
 (0)