msf_rtp/
lib.rs

1//! RTP packet serialization/de-serialization + utilities as defined in RFC
2//! 3550.
3
4mod rtp;
5
6pub mod depacketizer;
7pub mod packetizer;
8pub mod rtcp;
9pub mod utils;
10
11#[cfg(feature = "h264")]
12pub mod h264;
13
14#[cfg(feature = "pcm")]
15pub mod pcm;
16
17use std::fmt::{self, Display, Formatter};
18
19pub use self::{
20    depacketizer::{Depacketizer, MediaStream},
21    packetizer::{MediaSink, Packetizer},
22    rtcp::{CompoundRtcpPacket, RtcpHeader, RtcpPacket, RtcpPacketType},
23    rtp::{RtpHeader, RtpHeaderExtension, RtpPacket},
24};
25
26/// Invalid input.
27#[derive(Debug, Copy, Clone)]
28pub struct InvalidInput;
29
30impl Display for InvalidInput {
31    #[inline]
32    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
33        f.write_str("invalid input")
34    }
35}
36
37impl std::error::Error for InvalidInput {}
38
39/// RTP or RTCP packet.
40///
41/// This is useful when RTP and RTCP packets can be multiplexed in a single
42/// channel. See RFC 5761 for more info.
43#[derive(Clone)]
44pub enum PacketMux {
45    Rtp(RtpPacket),
46    Rtcp(CompoundRtcpPacket),
47}
48
49impl From<RtpPacket> for PacketMux {
50    #[inline]
51    fn from(packet: RtpPacket) -> Self {
52        Self::Rtp(packet)
53    }
54}
55
56impl From<RtcpPacket> for PacketMux {
57    #[inline]
58    fn from(packet: RtcpPacket) -> Self {
59        Self::Rtcp(packet.into())
60    }
61}
62
63impl From<CompoundRtcpPacket> for PacketMux {
64    #[inline]
65    fn from(packet: CompoundRtcpPacket) -> Self {
66        Self::Rtcp(packet)
67    }
68}