Skip to main content

ezk_rtp/
rtp_packet.rs

1use core::fmt;
2
3/// Owned wrapper around [`rtp_types::RtpPacket`]
4#[derive(Clone)]
5pub struct RtpPacket(Vec<u8>);
6
7impl fmt::Debug for RtpPacket {
8    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9        self.get().fmt(f)
10    }
11}
12
13impl RtpPacket {
14    pub fn new(packet: &rtp_types::RtpPacketBuilder<&[u8], &[u8]>) -> Self {
15        Self(packet.write_vec_unchecked())
16    }
17
18    pub fn parse(i: &[u8]) -> Result<Self, rtp_types::RtpParseError> {
19        let _packet = rtp_types::RtpPacket::parse(i)?;
20
21        Ok(Self(i.to_vec()))
22    }
23
24    pub fn get(&self) -> rtp_types::RtpPacket<'_> {
25        rtp_types::RtpPacket::parse(&self.0)
26            .expect("internal buffer must contain a valid rtp packet")
27    }
28
29    pub fn get_mut(&mut self) -> rtp_types::RtpPacketMut<'_> {
30        rtp_types::RtpPacketMut::parse(&mut self.0[..])
31            .expect("internal buffer must contain a valid rtp packet")
32    }
33}