Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support getting stream_id and track_id of Media #550

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/media/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ impl Media {
pub(crate) fn msid(&self) -> &Msid {
&self.msid
}
/// Identifier for the group this Media belongs to.
pub fn stream_id(&self) -> &str {
&self.msid().stream_id
}
algesten marked this conversation as resolved.
Show resolved Hide resolved
/// Identifier for this Media. Should be unique for the given stream id.
pub fn track_id(&self) -> &str {
&self.msid().track_id
}

/// Whether this media is audio or video.
///
Expand Down Expand Up @@ -462,10 +470,7 @@ impl Default for Media {
index: 0,
app_tmp: false,
cname: Id::<20>::random().to_string(),
msid: Msid {
stream_id: Id::<30>::random().to_string(),
track_id: Id::<30>::random().to_string(),
},
msid: Msid::random(),
kind: MediaKind::Video,
remote_pts: vec![],
remote_exts: ExtensionMap::empty(),
Expand All @@ -491,9 +496,9 @@ impl Media {
Media {
mid: l.mid(),
index,
// These two are not reflected back, and thus added by add_pending_changes().
// This is not reflected back, and thus added by add_pending_changes().
// cname,
// msid,
msid: l.msid().unwrap_or(Msid::random()),
kind: l.typ.clone().into(),
dir: l.direction().invert(), // remote direction is reverse.
remote_created,
Expand Down
18 changes: 18 additions & 0 deletions src/sdp/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::format::Codec;
use crate::format::CodecSpec;
use crate::format::FormatParams;
use crate::format::PayloadParams;
use crate::io::Id;
use crate::rtp_::{Direction, Extension, Frequency, Mid, Pt, Rid, SessionId, Ssrc};
use crate::{Candidate, IceCreds, VERSION};

Expand Down Expand Up @@ -242,6 +243,15 @@ impl MediaLine {
// a mid line. This is checked by `check_consistent`.
.expect("missing a=mid")
}
pub fn msid(&self) -> Option<Msid> {
algesten marked this conversation as resolved.
Show resolved Hide resolved
self.attrs.iter().find_map(|a| {
if let MediaAttribute::Msid(m) = a {
Some(m.clone())
} else {
None
}
})
}

pub fn direction(&self) -> Direction {
for a in &self.attrs {
Expand Down Expand Up @@ -1116,6 +1126,14 @@ pub struct Msid {
pub stream_id: String,
pub track_id: String,
}
impl Msid {
algesten marked this conversation as resolved.
Show resolved Hide resolved
pub fn random() -> Self {
Msid {
stream_id: Id::<30>::random().to_string(),
track_id: Id::<30>::random().to_string(),
}
}
}

impl fmt::Display for SimulcastGroups {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
Loading