Skip to content

Commit

Permalink
add rtp header extensions support
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jan 21, 2024
1 parent fdd6d5b commit bea1789
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
21 changes: 12 additions & 9 deletions src/server/session/description/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) mod sdp_type;
use crate::server::certificate::RTCDtlsFingerprint;
use crate::server::endpoint::candidate::RTCIceParameters;
use crate::server::session::description::rtp_codec::{
RTCRtpCodecCapability, RTCRtpCodecParameters, RTCRtpParameters,
RTCRtpCodecCapability, RTCRtpCodecParameters, RTCRtpHeaderExtensionParameters,
};
use crate::server::session::description::rtp_transceiver::{
PayloadType, RTCPFeedback, RTCRtpTransceiver,
Expand Down Expand Up @@ -271,7 +271,7 @@ pub(crate) fn add_transceiver_sdp(
.with_property_attribute(ATTR_KEY_RTCPMUX.to_owned())
.with_property_attribute(ATTR_KEY_RTCPRSIZE.to_owned());

let codecs = &transceiver.get_codecs();
let codecs = transceiver.get_codecs();
for codec in codecs {
let name = codec
.capability
Expand Down Expand Up @@ -340,10 +340,10 @@ pub(crate) fn add_transceiver_sdp(
return Ok((d, false));
}

let parameters = RTCRtpParameters::default(); //TODO: media_engine.get_rtp_parameters_by_kind(t.kind, t.direction());
for rtp_extension in &parameters.header_extensions {
let header_extensions = transceiver.get_header_extensions();
for rtp_extension in header_extensions {
let ext_url = Url::parse(rtp_extension.uri.as_str())?;
media = media.with_extmap(sdp::extmap::ExtMap {
media = media.with_extmap(ExtMap {
value: rtp_extension.id,
uri: Some(ext_url),
..Default::default()
Expand Down Expand Up @@ -754,7 +754,7 @@ pub(crate) fn codecs_from_media_description(
rtcp_feedbacks: feedback,
},
payload_type,
stats_id: String::new(),
//stats_id: String::new(),
})
}

Expand All @@ -763,8 +763,8 @@ pub(crate) fn codecs_from_media_description(

pub(crate) fn rtp_extensions_from_media_description(
m: &MediaDescription,
) -> Result<HashMap<String, isize>> {
let mut out = HashMap::new();
) -> Result<Vec<RTCRtpHeaderExtensionParameters>> {
let mut out = vec![];

for a in &m.attributes {
if a.key == ATTR_KEY_EXT_MAP {
Expand All @@ -774,7 +774,10 @@ pub(crate) fn rtp_extensions_from_media_description(
ExtMap::unmarshal(&mut reader).map_err(|err| Error::Other(format!("{}", err)))?;

if let Some(uri) = e.uri {
out.insert(uri.to_string(), e.value);
out.push(RTCRtpHeaderExtensionParameters {
uri: uri.to_string(),
id: e.value,
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/session/description/rtp_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub struct RTCRtpHeaderExtensionParameters {
pub struct RTCRtpCodecParameters {
pub capability: RTCRtpCodecCapability,
pub payload_type: PayloadType,
pub stats_id: String,
//pub stats_id: String,
}

/// RTPParameters is a list of negotiated codecs and header extensions
Expand Down
19 changes: 12 additions & 7 deletions src/server/session/description/rtp_transceiver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::server::session::description::rtp_codec::{RTCRtpCodecParameters, RTPCodecType};
use crate::server::session::description::rtp_codec::{
RTCRtpCodecParameters, RTCRtpHeaderExtensionParameters, RTCRtpParameters, RTPCodecType,
};
use crate::server::session::description::rtp_sender::RTCRtpSender;
use crate::server::session::description::rtp_transceiver_direction::RTCRtpTransceiverDirection;
use log::{debug, trace};
Expand Down Expand Up @@ -55,7 +57,7 @@ pub struct RTCRtpTransceiver {
//pub(crate) receiver: RTCRtpReceiver,
pub(crate) direction: RTCRtpTransceiverDirection,
current_direction: RTCRtpTransceiverDirection,
codecs: Vec<RTCRtpCodecParameters>, // User provided codecs via set_codec_preferences
rtp_params: RTCRtpParameters,
pub(crate) stopped: bool,
pub(crate) kind: RTPCodecType,
//media_engine: Arc<MediaEngine>,
Expand All @@ -67,14 +69,14 @@ impl RTCRtpTransceiver {
pub(crate) fn new(
sender: RTCRtpSender,
direction: RTCRtpTransceiverDirection,
codecs: Vec<RTCRtpCodecParameters>,
rtp_params: RTCRtpParameters,
kind: RTPCodecType,
) -> Self {
Self {
sender,
direction,
current_direction: RTCRtpTransceiverDirection::Unspecified,
codecs,
rtp_params,
stopped: false,
kind,
}
Expand Down Expand Up @@ -143,8 +145,11 @@ impl RTCRtpTransceiver {
Ok(())
}

pub(crate) fn get_codecs(&self) -> Vec<RTCRtpCodecParameters> {
//TODO:
self.codecs.clone()
pub(crate) fn get_codecs(&self) -> &Vec<RTCRtpCodecParameters> {
&self.rtp_params.codecs
}

pub(crate) fn get_header_extensions(&self) -> &Vec<RTCRtpHeaderExtensionParameters> {
&self.rtp_params.header_extensions
}
}
14 changes: 10 additions & 4 deletions src/server/session/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use log::debug;
use retty::transport::TransportContext;
use sdp::description::session::Origin;
use sdp::util::ConnectionRole;
Expand All @@ -14,14 +13,15 @@ use crate::server::config::SessionConfig;
use crate::server::endpoint::candidate::{Candidate, DTLSRole, RTCIceParameters};
use crate::server::endpoint::transport::Transport;
use crate::server::endpoint::Endpoint;
use crate::server::session::description::rtp_codec::RTPCodecType;
use crate::server::session::description::rtp_codec::{RTCRtpParameters, RTPCodecType};
use crate::server::session::description::rtp_sender::RTCRtpSender;
use crate::server::session::description::rtp_transceiver::RTCRtpTransceiver;
use crate::server::session::description::rtp_transceiver_direction::RTCRtpTransceiverDirection;
use crate::server::session::description::sdp_type::RTCSdpType;
use crate::server::session::description::{
codecs_from_media_description, get_mid_value, get_peer_direction, get_rids, populate_sdp,
update_sdp_origin, MediaSection, RTCSessionDescription, MEDIA_SECTION_APPLICATION,
rtp_extensions_from_media_description, update_sdp_origin, MediaSection, RTCSessionDescription,
MEDIA_SECTION_APPLICATION,
};
use crate::types::{EndpointId, Mid, SessionId};

Expand Down Expand Up @@ -145,7 +145,13 @@ impl Session {

let sender = RTCRtpSender::new();
let codecs = codecs_from_media_description(media)?;
let transceiver = RTCRtpTransceiver::new(sender, local_direction, codecs, kind);
let header_extensions = rtp_extensions_from_media_description(media)?;
let rtp_params = RTCRtpParameters {
header_extensions,
codecs,
};
let transceiver =
RTCRtpTransceiver::new(sender, local_direction, rtp_params, kind);
local_transceivers.insert(mid_value.to_string(), transceiver);
}
}
Expand Down

0 comments on commit bea1789

Please sign in to comment.