1 use super::*;
2 use crate::description::common::*;
3 use crate::description::media::*;
4 use crate::description::session::*;
5
get_test_session_description() -> SessionDescription6 fn get_test_session_description() -> SessionDescription {
7 SessionDescription{
8 media_descriptions: vec![
9 MediaDescription {
10 media_name: MediaName {
11 media: "video".to_string(),
12 port: RangedPort {
13 value: 51372,
14 range: None,
15 },
16 protos: vec!["RTP".to_string(), "AVP".to_string()],
17 formats: vec!["120".to_string(), "121".to_string(), "126".to_string(), "97".to_string()],
18 },
19 attributes: vec![
20 Attribute::new("fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1".to_string(), None),
21 Attribute::new("fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1".to_string(), None),
22 Attribute::new("fmtp:120 max-fs=12288;max-fr=60".to_string(), None),
23 Attribute::new("fmtp:121 max-fs=12288;max-fr=60".to_string(), None),
24 Attribute::new("rtpmap:120 VP8/90000".to_string(), None),
25 Attribute::new("rtpmap:121 VP9/90000".to_string(), None),
26 Attribute::new("rtpmap:126 H264/90000".to_string(), None),
27 Attribute::new("rtpmap:97 H264/90000".to_string(), None),
28 Attribute::new("rtcp-fb:97 ccm fir".to_string(), None),
29 Attribute::new("rtcp-fb:97 nack".to_string(), None),
30 Attribute::new("rtcp-fb:97 nack pli".to_string(), None),
31 ],
32 ..Default::default()
33 },
34 ],
35 ..Default::default()
36 }
37 }
38
39 #[test]
test_get_payload_type_for_vp8() -> Result<()>40 fn test_get_payload_type_for_vp8() -> Result<()> {
41 let tests = vec![
42 (
43 Codec {
44 name: "VP8".to_string(),
45 ..Default::default()
46 },
47 120,
48 ),
49 (
50 Codec {
51 name: "VP9".to_string(),
52 ..Default::default()
53 },
54 121,
55 ),
56 (
57 Codec {
58 name: "H264".to_string(),
59 fmtp: "profile-level-id=42e01f;level-asymmetry-allowed=1".to_string(),
60 ..Default::default()
61 },
62 97,
63 ),
64 (
65 Codec {
66 name: "H264".to_string(),
67 fmtp: "level-asymmetry-allowed=1;profile-level-id=42e01f".to_string(),
68 ..Default::default()
69 },
70 97,
71 ),
72 (
73 Codec {
74 name: "H264".to_string(),
75 fmtp: "profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1"
76 .to_string(),
77 ..Default::default()
78 },
79 126,
80 ),
81 ];
82
83 for (codec, expected) in tests {
84 let sdp = get_test_session_description();
85 let actual = sdp.get_payload_type_for_codec(&codec)?;
86 assert_eq!(actual, expected);
87 }
88
89 Ok(())
90 }
91
92 #[test]
test_get_codec_for_payload_type() -> Result<()>93 fn test_get_codec_for_payload_type() -> Result<()> {
94 let tests: Vec<(u8, Codec)> = vec![
95 (
96 120,
97 Codec {
98 payload_type: 120,
99 name: "VP8".to_string(),
100 clock_rate: 90000,
101 fmtp: "max-fs=12288;max-fr=60".to_string(),
102 ..Default::default()
103 },
104 ),
105 (
106 121,
107 Codec {
108 payload_type: 121,
109 name: "VP9".to_string(),
110 clock_rate: 90000,
111 fmtp: "max-fs=12288;max-fr=60".to_string(),
112 ..Default::default()
113 },
114 ),
115 (
116 126,
117 Codec {
118 payload_type: 126,
119 name: "H264".to_string(),
120 clock_rate: 90000,
121 fmtp: "profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1"
122 .to_string(),
123 ..Default::default()
124 },
125 ),
126 (
127 97,
128 Codec {
129 payload_type: 97,
130 name: "H264".to_string(),
131 clock_rate: 90000,
132 fmtp: "profile-level-id=42e01f;level-asymmetry-allowed=1".to_string(),
133 rtcp_feedback: vec![
134 "ccm fir".to_string(),
135 "nack".to_string(),
136 "nack pli".to_string(),
137 ],
138 ..Default::default()
139 },
140 ),
141 ];
142
143 for (payload_type, expected) in &tests {
144 let sdp = get_test_session_description();
145 let actual = sdp.get_codec_for_payload_type(*payload_type)?;
146 assert_eq!(actual, *expected);
147 }
148
149 Ok(())
150 }
151
152 #[test]
test_new_session_id() -> Result<()>153 fn test_new_session_id() -> Result<()> {
154 let mut min = 0x7FFFFFFFFFFFFFFFu64;
155 let mut max = 0u64;
156 for _ in 0..10000 {
157 let r = new_session_id();
158
159 if r > (1 << 63) - 1 {
160 panic!("Session ID must be less than 2**64-1, got {r}")
161 }
162 if r < min {
163 min = r
164 }
165 if r > max {
166 max = r
167 }
168 }
169 if min > 0x1000000000000000 {
170 panic!("Value around lower boundary was not generated")
171 }
172 if max < 0x7000000000000000 {
173 panic!("Value around upper boundary was not generated")
174 }
175
176 Ok(())
177 }
178