|
| 1 | +use super::*; |
1 | 2 |
|
| 3 | +fn decoded_packet() -> ExtendedReport { |
| 4 | + ExtendedReport { |
| 5 | + sender_ssrc: 0x01020304, |
| 6 | + reports: vec![ |
| 7 | + Box::new(LossRLEReportBlock { |
| 8 | + is_loss_rle: true, |
| 9 | + t: 12, |
| 10 | + |
| 11 | + ssrc: 0x12345689, |
| 12 | + begin_seq: 5, |
| 13 | + end_seq: 12, |
| 14 | + chunks: vec![Chunk(0x4006), Chunk(0x0006), Chunk(0x8765), Chunk(0x0000)], |
| 15 | + }), |
| 16 | + Box::new(DuplicateRLEReportBlock { |
| 17 | + is_loss_rle: false, |
| 18 | + t: 6, |
| 19 | + |
| 20 | + ssrc: 0x12345689, |
| 21 | + begin_seq: 5, |
| 22 | + end_seq: 12, |
| 23 | + chunks: vec![Chunk(0x4123), Chunk(0x3FFF), Chunk(0xFFFF), Chunk(0x0000)], |
| 24 | + }), |
| 25 | + Box::new(PacketReceiptTimesReportBlock { |
| 26 | + t: 3, |
| 27 | + |
| 28 | + ssrc: 0x98765432, |
| 29 | + begin_seq: 15432, |
| 30 | + end_seq: 15577, |
| 31 | + receipt_time: vec![0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555], |
| 32 | + }), |
| 33 | + Box::new(ReceiverReferenceTimeReportBlock { |
| 34 | + ntp_timestamp: 0x0102030405060708, |
| 35 | + }), |
| 36 | + Box::new(DLRRReportBlock { |
| 37 | + reports: vec![ |
| 38 | + DLRRReport { |
| 39 | + ssrc: 0x88888888, |
| 40 | + last_rr: 0x12345678, |
| 41 | + dlrr: 0x99999999, |
| 42 | + }, |
| 43 | + DLRRReport { |
| 44 | + ssrc: 0x09090909, |
| 45 | + last_rr: 0x12345678, |
| 46 | + dlrr: 0x99999999, |
| 47 | + }, |
| 48 | + DLRRReport { |
| 49 | + ssrc: 0x11223344, |
| 50 | + last_rr: 0x12345678, |
| 51 | + dlrr: 0x99999999, |
| 52 | + }, |
| 53 | + ], |
| 54 | + }), |
| 55 | + Box::new(StatisticsSummaryReportBlock { |
| 56 | + loss_reports: true, |
| 57 | + duplicate_reports: true, |
| 58 | + jitter_reports: true, |
| 59 | + ttl_or_hop_limit: TTLorHopLimitType::IPv4, |
| 60 | + |
| 61 | + ssrc: 0xFEDCBA98, |
| 62 | + begin_seq: 0x1234, |
| 63 | + end_seq: 0x5678, |
| 64 | + lost_packets: 0x11111111, |
| 65 | + dup_packets: 0x22222222, |
| 66 | + min_jitter: 0x33333333, |
| 67 | + max_jitter: 0x44444444, |
| 68 | + mean_jitter: 0x55555555, |
| 69 | + dev_jitter: 0x66666666, |
| 70 | + min_ttl_or_hl: 0x01, |
| 71 | + max_ttl_or_hl: 0x02, |
| 72 | + mean_ttl_or_hl: 0x03, |
| 73 | + dev_ttl_or_hl: 0x04, |
| 74 | + }), |
| 75 | + Box::new(VoIPMetricsReportBlock { |
| 76 | + ssrc: 0x89ABCDEF, |
| 77 | + loss_rate: 0x05, |
| 78 | + discard_rate: 0x06, |
| 79 | + burst_density: 0x07, |
| 80 | + gap_density: 0x08, |
| 81 | + burst_duration: 0x1111, |
| 82 | + gap_duration: 0x2222, |
| 83 | + round_trip_delay: 0x3333, |
| 84 | + end_system_delay: 0x4444, |
| 85 | + signal_level: 0x11, |
| 86 | + noise_level: 0x22, |
| 87 | + rerl: 0x33, |
| 88 | + gmin: 0x44, |
| 89 | + rfactor: 0x55, |
| 90 | + ext_rfactor: 0x66, |
| 91 | + mos_lq: 0x77, |
| 92 | + mos_cq: 0x88, |
| 93 | + rx_config: 0x99, |
| 94 | + reserved: 0x00, |
| 95 | + jb_nominal: 0x1122, |
| 96 | + jb_maximum: 0x3344, |
| 97 | + jb_abs_max: 0x5566, |
| 98 | + }), |
| 99 | + ], |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +fn encoded_packet() -> Bytes { |
| 104 | + Bytes::from_static(&[ |
| 105 | + // RTP Header |
| 106 | + 0x80, 0xCF, 0x00, 0x33, // byte 0 - 3 |
| 107 | + // Sender SSRC |
| 108 | + 0x01, 0x02, 0x03, 0x04, // Loss RLE Report Block |
| 109 | + 0x01, 0x0C, 0x00, 0x04, // byte 8 - 11 |
| 110 | + // Source SSRC |
| 111 | + 0x12, 0x34, 0x56, 0x89, // Begin & End Seq |
| 112 | + 0x00, 0x05, 0x00, 0x0C, // byte 16 - 19 |
| 113 | + // Chunks |
| 114 | + 0x40, 0x06, 0x00, 0x06, 0x87, 0x65, 0x00, 0x00, // byte 24 - 27 |
| 115 | + // Duplicate RLE Report Block |
| 116 | + 0x02, 0x06, 0x00, 0x04, // Source SSRC |
| 117 | + 0x12, 0x34, 0x56, 0x89, // byte 32 - 35 |
| 118 | + // Begin & End Seq |
| 119 | + 0x00, 0x05, 0x00, 0x0C, // Chunks |
| 120 | + 0x41, 0x23, 0x3F, 0xFF, // byte 40 - 43 |
| 121 | + 0xFF, 0xFF, 0x00, 0x00, // Packet Receipt Times Report Block |
| 122 | + 0x03, 0x03, 0x00, 0x07, // byte 48 - 51 |
| 123 | + // Source SSRC |
| 124 | + 0x98, 0x76, 0x54, 0x32, // Begin & End Seq |
| 125 | + 0x3C, 0x48, 0x3C, 0xD9, // byte 56 - 59 |
| 126 | + // Receipt times |
| 127 | + 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x22, // byte 64 - 67 |
| 128 | + 0x33, 0x33, 0x33, 0x33, 0x44, 0x44, 0x44, 0x44, // byte 72 - 75 |
| 129 | + 0x55, 0x55, 0x55, 0x55, // Receiver Reference Time Report |
| 130 | + 0x04, 0x00, 0x00, 0x02, // byte 80 - 83 |
| 131 | + // Timestamp |
| 132 | + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // byte 88 - 91 |
| 133 | + // DLRR Report |
| 134 | + 0x05, 0x00, 0x00, 0x09, // SSRC 1 |
| 135 | + 0x88, 0x88, 0x88, 0x88, // byte 96 - 99 |
| 136 | + // LastRR 1 |
| 137 | + 0x12, 0x34, 0x56, 0x78, // DLRR 1 |
| 138 | + 0x99, 0x99, 0x99, 0x99, // byte 104 - 107 |
| 139 | + // SSRC 2 |
| 140 | + 0x09, 0x09, 0x09, 0x09, // LastRR 2 |
| 141 | + 0x12, 0x34, 0x56, 0x78, // byte 112 - 115 |
| 142 | + // DLRR 2 |
| 143 | + 0x99, 0x99, 0x99, 0x99, // SSRC 3 |
| 144 | + 0x11, 0x22, 0x33, 0x44, // byte 120 - 123 |
| 145 | + // LastRR 3 |
| 146 | + 0x12, 0x34, 0x56, 0x78, // DLRR 3 |
| 147 | + 0x99, 0x99, 0x99, 0x99, // byte 128 - 131 |
| 148 | + // Statistics Summary Report |
| 149 | + 0x06, 0xE8, 0x00, 0x09, // SSRC |
| 150 | + 0xFE, 0xDC, 0xBA, 0x98, // byte 136 - 139 |
| 151 | + // Various statistics |
| 152 | + 0x12, 0x34, 0x56, 0x78, 0x11, 0x11, 0x11, 0x11, // byte 144 - 147 |
| 153 | + 0x22, 0x22, 0x22, 0x22, 0x33, 0x33, 0x33, 0x33, // byte 152 - 155 |
| 154 | + 0x44, 0x44, 0x44, 0x44, 0x55, 0x55, 0x55, 0x55, // byte 160 - 163 |
| 155 | + 0x66, 0x66, 0x66, 0x66, 0x01, 0x02, 0x03, 0x04, // byte 168 - 171 |
| 156 | + // VoIP Metrics Report |
| 157 | + 0x07, 0x00, 0x00, 0x08, // SSRC |
| 158 | + 0x89, 0xAB, 0xCD, 0xEF, // byte 176 - 179 |
| 159 | + // Various statistics |
| 160 | + 0x05, 0x06, 0x07, 0x08, 0x11, 0x11, 0x22, 0x22, // byte 184 - 187 |
| 161 | + 0x33, 0x33, 0x44, 0x44, 0x11, 0x22, 0x33, 0x44, // byte 192 - 195 |
| 162 | + 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, // byte 200 - 203 |
| 163 | + 0x33, 0x44, 0x55, 0x66, // byte 204 - 207 |
| 164 | + ]) |
| 165 | +} |
| 166 | + |
| 167 | +#[test] |
| 168 | +fn test_encode() -> Result<()> { |
| 169 | + let expected = encoded_packet(); |
| 170 | + let packet = decoded_packet(); |
| 171 | + let actual = packet.marshal()?; |
| 172 | + assert_eq!(actual, expected); |
| 173 | + Ok(()) |
| 174 | +} |
| 175 | + |
| 176 | +#[test] |
| 177 | +fn test_decode() -> Result<()> { |
| 178 | + let mut encoded = encoded_packet(); |
| 179 | + let expected = decoded_packet(); |
| 180 | + let actual = ExtendedReport::unmarshal(&mut encoded)?; |
| 181 | + assert_eq!(actual, expected); |
| 182 | + assert_eq!(actual.to_string(), expected.to_string()); |
| 183 | + Ok(()) |
| 184 | +} |
0 commit comments