Skip to content

Commit

Permalink
Support different RIDs per direction
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Jan 10, 2025
1 parent bfc2740 commit 36ac2bb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/change/sdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,14 @@ fn update_media(
media.set_direction(new_dir);
}

for rid in m.rids().iter() {
media.expect_rid_rx(*rid);
if new_dir.is_sending() {
// The other side has declared how it EXPECTING to receive. We must only send
// the RIDs declared in the answer.
media.set_rid_tx(m.rids().into());
}
if new_dir.is_receiving() {
// The other side has declared what it proposes to send. We are accepting it.
media.set_rid_rx(m.rids().into());
}

// Narrowing/ordering of of PT
Expand Down
35 changes: 34 additions & 1 deletion src/media/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub struct Media {
/// RTP level.
rids_rx: Rids,

/// Rid that we can send using the [`Writer`].
///
/// RTP level.
rids_tx: Rids,

// ========================================= SDP level =========================================
//
/// The index of this media line in the Session::media Vec.
Expand Down Expand Up @@ -120,8 +125,10 @@ pub struct Media {
}

#[derive(Debug)]
/// Config value for [`Media::rids_rx()`]
/// Config value for [`Media::rids_rx()`] and [`Media::rids_tx()`]
pub enum Rids {
/// No rid is allowed.
None,
/// Any Rid is allowed.
///
/// This is the default value for direct API.
Expand All @@ -135,6 +142,7 @@ pub enum Rids {
impl Rids {
pub(crate) fn contains(&self, rid: Rid) -> bool {
match self {
Rids::None => false,
Rids::Any => true,
Rids::Specific(v) => v.contains(&rid),
}
Expand All @@ -145,6 +153,12 @@ impl Rids {
}
}

impl<I: AsRef<[Rid]>> From<I> for Rids {
fn from(value: I) -> Self {
Rids::Specific(value.as_ref().to_vec())
}
}

#[derive(Debug)]
pub(crate) struct ToPayload {
pub pt: Pt,
Expand Down Expand Up @@ -200,6 +214,16 @@ impl Media {
&self.rids_rx
}

/// Rids we are can send via the [`Writer`].
///
/// By default this is set to [`Rids::None`], which changes to [`Rids::Specific`] via SDP negotiation
/// that configures Simulcast where specific rids are expected.
///
/// RTP level.
pub fn rids_tx(&self) -> &Rids {
&self.rids_tx
}

pub(crate) fn index(&self) -> usize {
self.index
}
Expand Down Expand Up @@ -467,6 +491,14 @@ impl Media {
// Simply remove the depayloader, it will be re-created on the next RTP packet.
self.depayloaders.remove(&(payload_type, rid));
}

pub(crate) fn set_rid_rx(&mut self, rids: Rids) {
self.rids_rx = rids;
}

pub(crate) fn set_rid_tx(&mut self, rids: Rids) {
self.rids_tx = rids;
}
}

impl Default for Media {
Expand All @@ -484,6 +516,7 @@ impl Default for Media {
dir: Direction::SendRecv,
simulcast: None,
rids_rx: Rids::Any,
rids_tx: Rids::None,
payloaders: HashMap::new(),
depayloaders: HashMap::new(),
to_payload: VecDeque::default(),
Expand Down

0 comments on commit 36ac2bb

Please sign in to comment.