pub type MatchFunc = Box<dyn (Fn(&[u8]) -> bool) + Send + Sync>;
pub fn match_all(_b: &[u8]) -> bool {
true
}
pub fn match_range(lower: u8, upper: u8) -> MatchFunc {
Box::new(move |buf: &[u8]| -> bool {
if buf.is_empty() {
return false;
}
let b = buf[0];
b >= lower && b <= upper
})
}
pub fn match_dtls(b: &[u8]) -> bool {
match_range(20, 63)(b)
}
pub fn match_srtp_or_srtcp(b: &[u8]) -> bool {
match_range(128, 191)(b)
}
pub(crate) fn is_rtcp(buf: &[u8]) -> bool {
if buf.len() < 4 {
return false;
}
let rtcp_packet_type = buf[1];
(192..=223).contains(&rtcp_packet_type)
}
pub fn match_srtp(buf: &[u8]) -> bool {
match_srtp_or_srtcp(buf) && !is_rtcp(buf)
}
pub fn match_srtcp(buf: &[u8]) -> bool {
match_srtp_or_srtcp(buf) && is_rtcp(buf)
}