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