simplify RTP parsing

This commit is contained in:
Emmanuel Gil Peyrot 2021-10-23 17:32:13 +02:00 committed by Jasper
parent e22cf34f42
commit 5db78b11bf
1 changed files with 75 additions and 106 deletions

View File

@ -128,114 +128,83 @@ impl JingleSession {
let mut video_hdrext_transport_cc = None; let mut video_hdrext_transport_cc = None;
if description.media == "audio" { if description.media == "audio" {
opus_payload_type = description for pt in description.payload_types.iter() {
.payload_types // We dont support any static codec, so name MUST be set.
.iter() if let Some(name) = &pt.name {
.find(|pt| pt.name.as_deref() == Some("opus")) match name.as_str() {
.map(|pt| pt.id); "opus" => {
opus_rtcp_fbs = description opus_payload_type = Some(pt.id);
.payload_types opus_rtcp_fbs = Some(pt.rtcp_fbs.clone());
.iter() }
.find(|pt| pt.name.as_deref() == Some("opus")) _ => (),
.map(|pt| pt.rtcp_fbs.clone()); }
audio_hdrext_ssrc_audio_level = description }
.hdrexts }
.iter() for hdrext in description.hdrexts.iter() {
.find(|hdrext| hdrext.uri == RTP_HDREXT_SSRC_AUDIO_LEVEL) // TODO: .parse::<u8>() wont be needed after updating xmpp-parsers, it is now a u16 as
.map(|hdrext| hdrext.id.parse::<u8>()) // defined in the XEP and related RFC.
.transpose()?; if hdrext.uri == RTP_HDREXT_SSRC_AUDIO_LEVEL {
audio_hdrext_transport_cc = description audio_hdrext_ssrc_audio_level = Some(hdrext.id.parse::<u8>()?);
.hdrexts }
.iter() else if hdrext.uri == RTP_HDREXT_TRANSPORT_CC {
.find(|hdrext| hdrext.uri == RTP_HDREXT_TRANSPORT_CC) audio_hdrext_transport_cc = Some(hdrext.id.parse::<u8>()?);
.map(|hdrext| hdrext.id.parse::<u8>()) }
.transpose()?; }
} }
else if description.media == "video" { else if description.media == "video" {
h264_payload_type = description for pt in description.payload_types.iter() {
.payload_types // We dont support any static codec, so name MUST be set.
.iter() if let Some(name) = &pt.name {
.find(|pt| pt.name.as_deref() == Some("H264")) match name.as_str() {
.map(|pt| pt.id); "H264" => {
h264_rtx_payload_type = description h264_payload_type = Some(pt.id);
.payload_types h264_rtcp_fbs = Some(pt.rtcp_fbs.clone());
.iter() }
.find(|pt| { "VP8" => {
pt.name.as_deref() == Some("rtx") vp8_payload_type = Some(pt.id);
&& pt.parameters.iter().any(|param| { vp8_rtcp_fbs = Some(pt.rtcp_fbs.clone());
param.name == "apt" }
&& param.value "VP9" => {
== h264_payload_type vp9_payload_type = Some(pt.id);
.map(|pt| pt.to_string()) vp9_rtcp_fbs = Some(pt.rtcp_fbs.clone());
.unwrap_or_default() }
}) _ => (),
}) }
.map(|pt| pt.id); }
h264_rtcp_fbs = description }
.payload_types for pt in description.payload_types.iter() {
.iter() if let Some(name) = &pt.name {
.find(|pt| pt.name.as_deref() == Some("H264")) if name == "rtx" {
.map(|pt| pt.rtcp_fbs.clone()); for param in pt.parameters.iter() {
vp8_payload_type = description if param.name == "apt" {
.payload_types let pt: u8 = param.value.parse()?;
.iter() if Some(pt) == h264_payload_type {
.find(|pt| pt.name.as_deref() == Some("VP8")) h264_rtx_payload_type = Some(pt);
.map(|pt| pt.id); }
vp8_rtx_payload_type = description else if Some(pt) == h264_payload_type {
.payload_types h264_rtx_payload_type = Some(pt);
.iter() }
.find(|pt| { else if Some(pt) == h264_payload_type {
pt.name.as_deref() == Some("rtx") h264_rtx_payload_type = Some(pt);
&& pt.parameters.iter().any(|param| { }
param.name == "apt" else {
&& param.value bail!("unknown rtx apt: {}", pt);
== vp8_payload_type }
.map(|pt| pt.to_string()) }
.unwrap_or_default() }
}) }
}) }
.map(|pt| pt.id); }
vp8_rtcp_fbs = description for hdrext in description.hdrexts.iter() {
.payload_types // TODO: .parse::<u8>() wont be needed after updating xmpp-parsers, it is now a u16 as
.iter() // defined in the XEP and related RFC.
.find(|pt| pt.name.as_deref() == Some("VP8")) if hdrext.uri == RTP_HDREXT_ABS_SEND_TIME {
.map(|pt| pt.rtcp_fbs.clone()); video_hdrext_abs_send_time = Some(hdrext.id.parse::<u8>()?);
vp9_payload_type = description }
.payload_types else if hdrext.uri == RTP_HDREXT_TRANSPORT_CC {
.iter() video_hdrext_transport_cc = Some(hdrext.id.parse::<u8>()?);
.find(|pt| pt.name.as_deref() == Some("VP9")) }
.map(|pt| pt.id); }
vp9_rtx_payload_type = description
.payload_types
.iter()
.find(|pt| {
pt.name.as_deref() == Some("rtx")
&& pt.parameters.iter().any(|param| {
param.name == "apt"
&& param.value
== vp9_payload_type
.map(|pt| pt.to_string())
.unwrap_or_default()
})
})
.map(|pt| pt.id);
vp9_rtcp_fbs = description
.payload_types
.iter()
.find(|pt| pt.name.as_deref() == Some("VP9"))
.map(|pt| pt.rtcp_fbs.clone());
video_hdrext_abs_send_time = description
.hdrexts
.iter()
.find(|hdrext| hdrext.uri == RTP_HDREXT_ABS_SEND_TIME)
.map(|hdrext| hdrext.id.parse::<u8>())
.transpose()?;
video_hdrext_transport_cc = description
.hdrexts
.iter()
.find(|hdrext| hdrext.uri == RTP_HDREXT_TRANSPORT_CC)
.map(|hdrext| hdrext.id.parse::<u8>())
.transpose()?;
} }
else { else {
debug!("skipping media: {}", description.media); debug!("skipping media: {}", description.media);