use bytes::Bytes;
use rtp::codec::av1::Av1Depacketizer;
use rtp::codec::vp8::Vp8Packet;
use rtp::packetizer::Depacketizer;
use rtp::{Header, Packet};
use std::time::Instant;
use super::*;
fn packet(sequence_number: u16, timestamp: u32, marker: bool, payload: &'static [u8]) -> Packet {
Packet {
header: Header {
sequence_number,
timestamp,
marker,
..Default::default()
},
payload: Bytes::from_static(payload),
}
}
fn sample_timestamps<T: Depacketizer>(depacketizer: T, packets: Vec<Packet>) -> Vec<u32> {
let now = Instant::now();
let mut builder = SampleBuilder::new(2, depacketizer, 90000);
let mut out = vec![];
for p in packets {
builder.push(now, p);
while let Some((_, timestamp)) = builder.pop_with_timestamp(now) {
out.push(timestamp);
}
}
out
}
#[test]
fn a_vp8_frame_without_its_first_partition_is_dropped() {
let timestamps = sample_timestamps(
Vp8Packet::default(),
vec![
packet(1, 1000, true, &[0x10, 0x01, 0x02, 0x03]),
packet(3, 2000, false, &[0x11, 0x04, 0x05, 0x06]),
packet(4, 2000, true, &[0x12, 0x07, 0x08, 0x09]),
packet(5, 3000, true, &[0x10, 0x0A, 0x0B, 0x0C]),
packet(6, 4000, true, &[0x10, 0x0D, 0x0E, 0x0F]),
packet(7, 5000, true, &[0x10, 0x10, 0x11, 0x12]),
packet(8, 6000, true, &[0x10, 0x13, 0x14, 0x15]),
],
);
assert!(
!timestamps.contains(&2000),
"the frame at 2000 lacks its first partition: {timestamps:?}"
);
assert!(timestamps.contains(&1000) && timestamps.contains(&3000));
}
#[test]
fn an_av1_temporal_unit_without_its_frame_header_is_dropped() {
let timestamps = sample_timestamps(
Av1Depacketizer::new(),
vec![
packet(1, 1000, true, &[0x10, 0x30, 0x01]),
packet(3, 2000, false, &[0x10, 0x20, 0xAA]),
packet(4, 2000, true, &[0x10, 0x20, 0xBB]),
packet(5, 3000, true, &[0x10, 0x30, 0x02]),
packet(6, 4000, true, &[0x10, 0x30, 0x03]),
packet(7, 5000, true, &[0x10, 0x30, 0x04]),
packet(8, 6000, true, &[0x10, 0x30, 0x05]),
],
);
assert!(
!timestamps.contains(&2000),
"the unit at 2000 lacks its frame header: {timestamps:?}"
);
assert!(timestamps.contains(&1000) && timestamps.contains(&3000));
}