rtci_rtp/extension/
mod.rs1use std::borrow::Cow;
2use std::fmt;
3
4use shared::{
5 error::Result,
6 marshal::{Marshal, MarshalSize},
7};
8
9pub mod abs_capture_time_extension;
11pub mod abs_send_time_extension;
13pub mod audio_level_extension;
15pub mod corruption_detection_extension;
18pub mod csrc_audio_level_extension;
22pub mod ntp_timestamp_extension;
26pub mod playout_delay_extension;
28pub mod sdes_extension;
34pub mod transmission_offset_extension;
38pub mod transport_cc_extension;
40pub mod video_orientation_extension;
42
43pub const ABS_SEND_TIME_URI: &str = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
45pub const ABS_CAPTURE_TIME_URI: &str =
47 "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
48pub const CORRUPTION_DETECTION_URI: &str =
50 "http://www.webrtc.org/experiments/rtp-hdrext/corruption-detection";
51pub const AUDIO_LEVEL_URI: &str = "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
53pub const CSRC_AUDIO_LEVEL_URI: &str = "urn:ietf:params:rtp-hdrext:csrc-audio-level";
55pub const NTP_64_URI: &str = ntp_timestamp_extension::NTP_64_URI;
57pub const NTP_56_URI: &str = ntp_timestamp_extension::NTP_56_URI;
59pub const PLAYOUT_DELAY_URI: &str = "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
61pub const TRANSPORT_CC_URI: &str =
63 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
64pub const VIDEO_ORIENTATION_URI: &str = "urn:3gpp:video-orientation";
66pub const SDES_MID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:mid";
68pub const SDES_RTP_STREAM_ID_URI: &str = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
70pub const SDES_REPAIRED_RTP_STREAM_ID_URI: &str =
72 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
73pub const TRANSMISSION_OFFSET_URI: &str = "urn:ietf:params:rtp-hdrext:toffset";
75
76#[non_exhaustive]
78pub enum HeaderExtension {
79 AbsSendTime(abs_send_time_extension::AbsSendTimeExtension),
81 AudioLevel(audio_level_extension::AudioLevelExtension),
83 PlayoutDelay(playout_delay_extension::PlayoutDelayExtension),
85 TransportCc(transport_cc_extension::TransportCcExtension),
87 VideoOrientation(video_orientation_extension::VideoOrientationExtension),
89 AbsCaptureTime(abs_capture_time_extension::AbsCaptureTimeExtension),
91 CsrcAudioLevel(csrc_audio_level_extension::CsrcAudioLevelExtension),
93 Mid(sdes_extension::Mid),
95 RtpStreamId(sdes_extension::RtpStreamId),
97 RepairedRtpStreamId(sdes_extension::RepairedRtpStreamId),
99 TransmissionOffset(transmission_offset_extension::TransmissionOffsetExtension),
101
102 Custom {
104 uri: Cow<'static, str>,
106 extension: Box<dyn Marshal + 'static>,
108 },
109}
110
111impl HeaderExtension {
112 pub fn uri(&self) -> Cow<'static, str> {
114 use HeaderExtension::*;
115
116 match self {
117 AbsSendTime(_) => ABS_SEND_TIME_URI.into(),
118 AudioLevel(_) => AUDIO_LEVEL_URI.into(),
119 PlayoutDelay(_) => PLAYOUT_DELAY_URI.into(),
120 TransportCc(_) => TRANSPORT_CC_URI.into(),
121 VideoOrientation(_) => VIDEO_ORIENTATION_URI.into(),
122 AbsCaptureTime(_) => ABS_CAPTURE_TIME_URI.into(),
123 CsrcAudioLevel(_) => CSRC_AUDIO_LEVEL_URI.into(),
124 Mid(_) => SDES_MID_URI.into(),
125 RtpStreamId(_) => SDES_RTP_STREAM_ID_URI.into(),
126 RepairedRtpStreamId(_) => SDES_REPAIRED_RTP_STREAM_ID_URI.into(),
127 TransmissionOffset(_) => TRANSMISSION_OFFSET_URI.into(),
128 Custom { uri, .. } => uri.clone(),
129 }
130 }
131
132 pub fn is_same(&self, other: &Self) -> bool {
134 self.uri() == other.uri()
136 }
137}
138
139impl MarshalSize for HeaderExtension {
140 fn marshal_size(&self) -> usize {
141 use HeaderExtension::*;
142 match self {
143 AbsSendTime(ext) => ext.marshal_size(),
144 AudioLevel(ext) => ext.marshal_size(),
145 PlayoutDelay(ext) => ext.marshal_size(),
146 TransportCc(ext) => ext.marshal_size(),
147 VideoOrientation(ext) => ext.marshal_size(),
148 AbsCaptureTime(ext) => ext.marshal_size(),
149 CsrcAudioLevel(ext) => ext.marshal_size(),
150 Mid(ext) => ext.marshal_size(),
151 RtpStreamId(ext) => ext.marshal_size(),
152 RepairedRtpStreamId(ext) => ext.marshal_size(),
153 TransmissionOffset(ext) => ext.marshal_size(),
154 Custom { extension: ext, .. } => ext.marshal_size(),
155 }
156 }
157}
158
159impl Marshal for HeaderExtension {
160 fn marshal_to(&self, buf: &mut [u8]) -> Result<usize> {
161 use HeaderExtension::*;
162 match self {
163 AbsSendTime(ext) => ext.marshal_to(buf),
164 AudioLevel(ext) => ext.marshal_to(buf),
165 PlayoutDelay(ext) => ext.marshal_to(buf),
166 TransportCc(ext) => ext.marshal_to(buf),
167 VideoOrientation(ext) => ext.marshal_to(buf),
168 AbsCaptureTime(ext) => ext.marshal_to(buf),
169 CsrcAudioLevel(ext) => ext.marshal_to(buf),
170 Mid(ext) => ext.marshal_to(buf),
171 RtpStreamId(ext) => ext.marshal_to(buf),
172 RepairedRtpStreamId(ext) => ext.marshal_to(buf),
173 TransmissionOffset(ext) => ext.marshal_to(buf),
174 Custom { extension: ext, .. } => ext.marshal_to(buf),
175 }
176 }
177}
178
179impl fmt::Debug for HeaderExtension {
180 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
181 use HeaderExtension::*;
182
183 match self {
184 AbsSendTime(ext) => f.debug_tuple("AbsSendTime").field(ext).finish(),
185 AudioLevel(ext) => f.debug_tuple("AudioLevel").field(ext).finish(),
186 PlayoutDelay(ext) => f.debug_tuple("PlayoutDelay").field(ext).finish(),
187 TransportCc(ext) => f.debug_tuple("TransportCc").field(ext).finish(),
188 VideoOrientation(ext) => f.debug_tuple("VideoOrientation").field(ext).finish(),
189 AbsCaptureTime(ext) => f.debug_tuple("AbsCaptureTime").field(ext).finish(),
190 CsrcAudioLevel(ext) => f.debug_tuple("CsrcAudioLevel").field(ext).finish(),
191 Mid(ext) => f.debug_tuple("Mid").field(ext).finish(),
192 RtpStreamId(ext) => f.debug_tuple("RtpStreamId").field(ext).finish(),
193 RepairedRtpStreamId(ext) => f.debug_tuple("RepairedRtpStreamId").field(ext).finish(),
194 TransmissionOffset(ext) => f.debug_tuple("TransmissionOffset").field(ext).finish(),
195 Custom { uri, extension: _ } => f.debug_struct("Custom").field("uri", uri).finish(),
196 }
197 }
198}
199
200#[cfg(test)]
201mod extension_test;