songbird/events/context/data/
rtp.rs

1use discortp::rtp::RtpPacket;
2
3use super::*;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
6#[non_exhaustive]
7/// Opus audio packet, received from another stream
8///
9/// `payload_offset` contains the true payload location within the raw packet's `payload()`,
10/// if extensions or raw packet data are required.
11pub struct RtpData {
12    /// Raw RTP packet data.
13    ///
14    /// Includes the SSRC (i.e., sender) of this packet.
15    pub packet: Bytes,
16    /// Byte index into the packet body (after headers) for where the payload begins.
17    pub payload_offset: usize,
18    /// Number of bytes at the end of the packet to discard.
19    pub payload_end_pad: usize,
20}
21
22impl RtpData {
23    /// Create a zero-copy view of the inner RTP packet.
24    ///
25    /// This allows easy access to packet header fields, taking them from the underlying
26    /// `Bytes` as needed while handling endianness etc.
27    pub fn rtp(&'_ self) -> RtpPacket<'_> {
28        RtpPacket::new(&self.packet)
29            .expect("FATAL: leaked illegally small RTP packet from UDP Rx task.")
30    }
31}