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