|
| 1 | +use std::borrow::Cow; |
| 2 | +use std::fmt; |
| 3 | + |
| 4 | +use util::{Marshal, MarshalSize}; |
| 5 | + |
1 | 6 | pub mod abs_send_time_extension;
|
2 | 7 | pub mod audio_level_extension;
|
3 | 8 | pub mod transport_cc_extension;
|
4 | 9 | pub mod video_orientation_extension;
|
| 10 | + |
| 11 | +/// A generic RTP header extension. |
| 12 | +pub enum HeaderExtension { |
| 13 | + AbsSendTime(abs_send_time_extension::AbsSendTimeExtension), |
| 14 | + AudioLevel(audio_level_extension::AudioLevelExtension), |
| 15 | + TransportCc(transport_cc_extension::TransportCcExtension), |
| 16 | + VideoOrientation(video_orientation_extension::VideoOrientationExtension), |
| 17 | + |
| 18 | + /// A custom extension |
| 19 | + Custom { |
| 20 | + uri: Cow<'static, str>, |
| 21 | + extension: Box<dyn Marshal + Send + Sync + 'static>, |
| 22 | + }, |
| 23 | +} |
| 24 | + |
| 25 | +impl HeaderExtension { |
| 26 | + pub fn uri(&self) -> Cow<'static, str> { |
| 27 | + use HeaderExtension::*; |
| 28 | + |
| 29 | + match self { |
| 30 | + AbsSendTime(_) => "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time".into(), |
| 31 | + AudioLevel(_) => "urn:ietf:params:rtp-hdrext:ssrc-audio-level".into(), |
| 32 | + TransportCc(_) => { |
| 33 | + "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01".into() |
| 34 | + } |
| 35 | + VideoOrientation(_) => "urn:3gpp:video-orientation".into(), |
| 36 | + Custom { uri, .. } => uri.clone(), |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +impl MarshalSize for HeaderExtension { |
| 42 | + fn marshal_size(&self) -> usize { |
| 43 | + use HeaderExtension::*; |
| 44 | + match self { |
| 45 | + AbsSendTime(ext) => ext.marshal_size(), |
| 46 | + AudioLevel(ext) => ext.marshal_size(), |
| 47 | + TransportCc(ext) => ext.marshal_size(), |
| 48 | + VideoOrientation(ext) => ext.marshal_size(), |
| 49 | + Custom { extension: ext, .. } => ext.marshal_size(), |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +impl Marshal for HeaderExtension { |
| 55 | + fn marshal_to(&self, buf: &mut [u8]) -> util::Result<usize> { |
| 56 | + use HeaderExtension::*; |
| 57 | + match self { |
| 58 | + AbsSendTime(ext) => ext.marshal_to(buf), |
| 59 | + AudioLevel(ext) => ext.marshal_to(buf), |
| 60 | + TransportCc(ext) => ext.marshal_to(buf), |
| 61 | + VideoOrientation(ext) => ext.marshal_to(buf), |
| 62 | + Custom { extension: ext, .. } => ext.marshal_to(buf), |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +impl fmt::Debug for HeaderExtension { |
| 68 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 69 | + use HeaderExtension::*; |
| 70 | + |
| 71 | + match self { |
| 72 | + AbsSendTime(ext) => f.debug_tuple("AbsSendTime").field(ext).finish(), |
| 73 | + AudioLevel(ext) => f.debug_tuple("AudioLevel").field(ext).finish(), |
| 74 | + TransportCc(ext) => f.debug_tuple("TransportCc").field(ext).finish(), |
| 75 | + VideoOrientation(ext) => f.debug_tuple("VideoOrientation").field(ext).finish(), |
| 76 | + Custom { uri, extension: _ } => f.debug_struct("Custom").field("uri", uri).finish(), |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments