use std::collections::VecDeque;
pub struct DTSSequenceBuilder {
rtp_timestamps: VecDeque<u64>,
last_rtp_timestamp: Option<u64>,
}
impl DTSSequenceBuilder {
pub fn new() -> Self {
Self {
rtp_timestamps: VecDeque::new(),
last_rtp_timestamp: None,
}
}
pub fn push_rtp_timestamp(&mut self, rtp_timestamp: u64) {
if Some(rtp_timestamp) == self.last_rtp_timestamp {
return;
}
self.last_rtp_timestamp = Some(rtp_timestamp);
self.rtp_timestamps.push_back(rtp_timestamp);
}
pub fn next_decoding_timestamp(&mut self) -> u64 {
self.rtp_timestamps
.pop_front()
.or(self.last_rtp_timestamp)
.unwrap_or(0)
}
pub fn available(&self) -> usize {
self.rtp_timestamps.len()
}
}