str0m/rtp/rtcp/
fmt.rs

1/// Number of _something_ in the RTCP packet.
2///
3/// PacketType determines how to interpret the count field.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum FeedbackMessageType {
6    /// When packet type SenderReport or ReceiverReport.
7    ///
8    /// The contained u8 is number of receiver reports.
9    ReceptionReport(u8),
10
11    /// When packet type SourceDescription (SDES) or Goodbye
12    ///
13    /// The contained u8 is number of contained SDES or Goodbyes.
14    SourceCount(u8),
15
16    /// When packet type ApplicationDefined
17    ///
18    /// The contained u8 is a subtype which is upp to the application.
19    Subtype(u8),
20
21    /// When packet type is TransportLayerFeedback.
22    TransportFeedback(TransportType),
23
24    /// When packet type is PayloadSpecificFeedback.
25    PayloadFeedback(PayloadType),
26
27    /// When the packet type is ExtendedReport
28    NotUsed,
29}
30
31impl FeedbackMessageType {
32    pub fn count(&self) -> u8 {
33        match self {
34            FeedbackMessageType::ReceptionReport(v) => *v,
35            FeedbackMessageType::SourceCount(v) => *v,
36            _ => panic!("Not a count"),
37        }
38    }
39}
40
41impl From<FeedbackMessageType> for u8 {
42    fn from(val: FeedbackMessageType) -> Self {
43        use FeedbackMessageType::*;
44        match val {
45            ReceptionReport(v) | SourceCount(v) | Subtype(v) => {
46                assert!(v <= 31, "rtcp fmt when count must be <= 31");
47                v
48            }
49            TransportFeedback(v) => v as u8,
50            PayloadFeedback(v) => v as u8,
51            NotUsed => 0,
52        }
53    }
54}
55
56/// Subtypes of [`FeedbackMessageType::TransportFeedback`].
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum TransportType {
59    /// Nack RTCP packet.
60    ///
61    /// Definition: <https://www.rfc-editor.org/rfc/rfc4585#section-6.2.1>
62    Nack = 1,
63
64    /// Transportwide congestion control packet.
65    ///
66    /// Definition: <https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01>
67    TransportWide = 15,
68}
69
70impl TryFrom<u8> for TransportType {
71    type Error = &'static str;
72
73    fn try_from(v: u8) -> Result<Self, Self::Error> {
74        use TransportType::*;
75        match v {
76            1 => Ok(Nack),
77            15 => Ok(TransportWide),
78            _ => {
79                trace!("Uknown TransportType: {}", v);
80                Err("Uknown TransportType")
81            }
82        }
83    }
84}
85
86/// Subtypes of [`FeedbackMessageType::PayloadFeedback`].
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum PayloadType {
89    /// PLI packet type.
90    ///
91    /// Definition: <https://www.rfc-editor.org/rfc/rfc4585#section-6.3.1>
92    PictureLossIndication = 1,
93
94    /// SLI packet type.
95    ///
96    /// Definition: <https://www.rfc-editor.org/rfc/rfc4585#section-6.3.2>
97    SliceLossIndication = 2,
98
99    /// RPSI packet type.
100    ///
101    /// Definition: <https://www.rfc-editor.org/rfc/rfc4585#section-6.3.3>
102    ReferencePictureSelectionIndication = 3,
103
104    /// FIR packet type.
105    ///
106    /// Definition: <https://www.rfc-editor.org/rfc/rfc5104.html#section-4.3.1>
107    FullIntraRequest = 4,
108
109    /// Application specific type.
110    ///
111    /// Definition: <https://www.rfc-editor.org/rfc/rfc4585#section-6.4>
112    ApplicationLayer = 15,
113}
114
115impl TryFrom<u8> for PayloadType {
116    type Error = &'static str;
117
118    fn try_from(v: u8) -> Result<Self, Self::Error> {
119        use PayloadType::*;
120        match v {
121            1 => Ok(PictureLossIndication),
122            2 => Ok(SliceLossIndication),
123            3 => Ok(ReferencePictureSelectionIndication),
124            4 => Ok(FullIntraRequest),
125            15 => Ok(ApplicationLayer),
126            _ => {
127                trace!("Uknown PayloadType: {}", v);
128                Err("Uknown PayloadType")
129            }
130        }
131    }
132}