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

Tentative first pass at making simulcast egest possible #312

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2742632
Tentative first pass at making simulcast egest possible
robashton Oct 7, 2022
d4160e1
Fix the tests (for now)
robashton Oct 7, 2022
9fdf70b
clippy warnings (I guess I need to update/downgrade my rust)
robashton Oct 7, 2022
ec670b4
Re-instate changes from #217
robashton Oct 10, 2022
4974cf4
Replace the mutex on track_encodings with a RwLock
robashton Oct 10, 2022
379f403
Initial feedback from PR
robashton Oct 10, 2022
21607ac
Make Rid an Option<String> and see how that falls out
robashton Oct 11, 2022
a3c2a20
revert change to log (that I did when I was debugging my own stuff\!)
robashton Oct 11, 2022
d6ff71d
unique track ids in stats
robashton Oct 11, 2022
d4c27fc
debug impl for TrackLocalContext
robashton Oct 11, 2022
19fc8e9
ensure we only do simulcast send directives if we're doing a send on …
robashton Oct 11, 2022
acef0fd
apparently format! is a thing
robashton Oct 11, 2022
ac59df1
a few things in rtp_sender that we didn't ike
robashton Oct 11, 2022
4b04180
unnecessary clone now it's an option
robashton Oct 11, 2022
246044e
typo (got vimmed)
robashton Oct 11, 2022
850fcb5
Tentative first pass at making simulcast egest possible
robashton Oct 7, 2022
e20c15d
Fix the tests (for now)
robashton Oct 7, 2022
866965e
clippy warnings (I guess I need to update/downgrade my rust)
robashton Oct 7, 2022
25cedc0
Re-instate changes from #217
robashton Oct 10, 2022
2972dd5
Replace the mutex on track_encodings with a RwLock
robashton Oct 10, 2022
55bc75c
Initial feedback from PR
robashton Oct 10, 2022
8a59116
Make Rid an Option<String> and see how that falls out
robashton Oct 11, 2022
f780884
revert change to log (that I did when I was debugging my own stuff\!)
robashton Oct 11, 2022
9707863
unique track ids in stats
robashton Oct 11, 2022
ffad0b5
debug impl for TrackLocalContext
robashton Oct 11, 2022
6b23661
ensure we only do simulcast send directives if we're doing a send on …
robashton Oct 11, 2022
7853a8d
apparently format! is a thing
robashton Oct 11, 2022
afe4dcb
a few things in rtp_sender that we didn't ike
robashton Oct 11, 2022
b64f163
unnecessary clone now it's an option
robashton Oct 11, 2022
6a24250
typo (got vimmed)
robashton Oct 11, 2022
fd84deb
don't hold onto that lock, or we hang
robashton Oct 13, 2022
f5857dd
some more tweaks
robashton Oct 13, 2022
5aa6864
merge from upstream
robashton Oct 13, 2022
6996968
Merge branch 'simulcast-egest' of github.com:robashton/webrtc into si…
robashton Oct 13, 2022
7da6936
removed comments
robashton Oct 13, 2022
5007093
revert method order
robashton Oct 13, 2022
7114d5e
remove read_simulcast_rtcp as we can't see a reason why it needs to e…
robashton Oct 13, 2022
7c03a11
Option<String> on structs, Option<&str> on traits (for rid anyway)
robashton Oct 17, 2022
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
1 change: 1 addition & 0 deletions interceptor/src/stream_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct RTPHeaderExtension {
#[derive(Default, Debug, Clone)]
pub struct StreamInfo {
pub id: String,
pub rid: String,
robashton marked this conversation as resolved.
Show resolved Hide resolved
pub attributes: Attributes,
pub ssrc: u32,
pub payload_type: u8,
Expand Down
17 changes: 17 additions & 0 deletions webrtc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ pub enum Error {
#[error("new track must be of the same kind as previous")]
ErrRTPSenderNewTrackHasIncorrectKind,

#[error("Sender cannot encoding due to RID collision")]
robashton marked this conversation as resolved.
Show resolved Hide resolved
ErrRTPSenderRIDCollision,

#[error("Sender cannot add encoding as provided track does not match base track")]
ErrRTPSenderBaseEncodingMismatch,

/// ErrRTPSenderStopped indicates the sender was already stopped
#[error("Sender has already been stopped")]
ErrRTPSenderStopped,

/// ErrRTPSenderRidNil indicates that the track RID was empty
#[error("Sender cannot add encoding as rid is empty")]
ErrRTPSenderRidNil,

#[error("Sender cannot add encoding as there is no base track")]
ErrRTPSenderNoBaseEncoding,

/// ErrUnbindFailed indicates that a TrackLocal was not able to be unbind
#[error("failed to unbind TrackLocal from PeerConnection")]
ErrUnbindFailed,
Expand Down
23 changes: 12 additions & 11 deletions webrtc/src/peer_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ impl RTCPeerConnection {
if let Some(m) = m {
// Step 5.3.1
if t.direction().has_send() {
let dmsid = match m.attribute(ATTR_KEY_MSID).and_then(|o| o) {
let _dmsid = match m.attribute(ATTR_KEY_MSID).and_then(|o| o) {
Some(m) => m,
None => return true, // doesn't contain a single a=msid line
};

let sender = match t.sender().await {
Some(s) => s.clone(),
let _sender = match t.sender().await {
Some(s) => s,
None => {
log::warn!(
"RtpSender missing for transeceiver with sending direction {} for mid {}",
Expand All @@ -490,16 +490,17 @@ impl RTCPeerConnection {
// local description so we can compare all of them. For no we only
// consider the first one.

let stream_ids = sender.associated_media_stream_ids();
robashton marked this conversation as resolved.
Show resolved Hide resolved
// Different number of lines, 1 vs 0
if stream_ids.is_empty() {
return true;
}
// TODO: Go and see what Pion does these days here
// let stream_ids = sender.associated_media_stream_ids();
// // Different number of lines, 1 vs 0
// if stream_ids.is_empty() {
return true;
// }

// different stream id
if dmsid.split_whitespace().next() != Some(&stream_ids[0]) {
return true;
}
// if dmsid.split_whitespace().next() != Some(&stream_ids[0]) {
// return true;
// }
}
match local_desc.sdp_type {
RTCSdpType::Offer => {
Expand Down
20 changes: 12 additions & 8 deletions webrtc/src/peer_connection/peer_connection_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ impl PeerConnectionInternal {
let stream_info = create_stream_info(
"".to_owned(),
ssrc,
"".to_owned(),
params.codecs[0].payload_type,
params.codecs[0].capability.clone(),
&params.header_extensions,
Expand Down Expand Up @@ -1535,20 +1536,23 @@ impl PeerConnectionInternal {
None => continue,
};

let track_id = track.id().to_string();
let kind = match track.kind() {
RTPCodecType::Unspecified => continue,
RTPCodecType::Audio => "audio",
RTPCodecType::Video => "video",
};

track_infos.push(TrackInfo {
track_id,
ssrc: sender.ssrc,
mid: mid.clone(),
rid: None,
kind,
});
let encodings = sender.track_encodings.lock().await;
for e in encodings.iter() {
let track_id = track.id().to_string();
robashton marked this conversation as resolved.
Show resolved Hide resolved
track_infos.push(TrackInfo {
track_id,
ssrc: e.ssrc,
mid: mid.clone(),
rid: Some(track.rid().to_owned()),
kind,
});
}
}

let stream_stats = self
Expand Down
80 changes: 41 additions & 39 deletions webrtc/src/peer_connection/sdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,55 +540,57 @@ pub(crate) async fn add_transceiver_sdp(
);
}

// This is equivalent to addSenderSDP in Pion (now)
robashton marked this conversation as resolved.
Show resolved Hide resolved
for mt in transceivers {
if let Some(sender) = mt.sender().await {
let send_parameters = sender.get_parameters().await;
robashton marked this conversation as resolved.
Show resolved Hide resolved
if let Some(track) = sender.track().await {
media = media.with_media_source(
sender.ssrc,
track.stream_id().to_owned(), /* cname */
track.stream_id().to_owned(), /* streamLabel */
track.id().to_owned(),
);

// Send msid based on the configured track if we haven't already
// sent on this sender. If we have sent we must keep the msid line consistent, this
// is handled below.
if !is_plan_b && sender.initial_track_id().is_none() {
for stream_id in sender.associated_media_stream_ids() {
media = media.with_property_attribute(format!(
"msid:{} {}",
stream_id,
track.id()
));
for encoding in send_parameters.encodings.iter() {
k0nserv marked this conversation as resolved.
Show resolved Hide resolved
media = media.with_media_source(
encoding.ssrc,
track.stream_id().to_owned(), /* cname */
track.stream_id().to_owned(), /* streamLabel */
track.id().to_owned(),
);

// Send msid based on the configured track if we haven't already
// sent on this sender. If we have sent we must keep the msid line consistent, this
// is handled below.
if !is_plan_b {
// We need this?
// related streams don't exist any more in pion (and nor should they?)

// I this should become obsolete
if sender.initial_track_id().is_none() {
media = media.with_property_attribute(format!(
robashton marked this conversation as resolved.
Show resolved Hide resolved
"msid:{} {}",
track.stream_id(),
track.id()
));
sender.set_initial_track_id(track.id().to_string())?;
}
}

sender.set_initial_track_id(track.id().to_string())?;
break;
}
}

if !is_plan_b {
if let Some(track_id) = sender.initial_track_id() {
// After we have include an msid attribute in an offer it must stay the same for
// all subsequent offer even if the track or transceiver direction changes.
//
// [RFC 8829 Section 5.2.2](https://datatracker.ietf.org/doc/html/rfc8829#section-5.2.2)
//
// For RtpTransceivers that are not stopped, the "a=msid" line or
// lines MUST stay the same if they are present in the current
// description, regardless of changes to the transceiver's direction
// or track. If no "a=msid" line is present in the current
// description, "a=msid" line(s) MUST be generated according to the
// same rules as for an initial offer.
for stream_id in sender.associated_media_stream_ids() {
media = media
.with_property_attribute(format!("msid:{} {}", stream_id, track_id));
}
if send_parameters.encodings.len() > 1 {
let mut send_rids: Vec<String> = vec![];

break;
for e in send_parameters.encodings.iter() {
let mut s: String = e.rid.clone();
s.push_str(" send");
media = media.with_value_attribute("rid".into(), s);
send_rids.push(e.rid.clone())
}
// Simulcast)
let mut s: String = "send ".to_owned();
s.push_str(send_rids.join(";").as_ref());
media = media.with_value_attribute("simulcast".into(), s);
}
}
}
if !is_plan_b {
break;
}
}

let direction = match params.offered_direction {
Expand Down
2 changes: 2 additions & 0 deletions webrtc/src/rtp_transceiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub struct RTCRtpTransceiverInit {
pub(crate) fn create_stream_info(
id: String,
ssrc: SSRC,
rid: String,
payload_type: PayloadType,
codec: RTCRtpCodecCapability,
webrtc_header_extensions: &[RTCRtpHeaderExtensionParameters],
Expand All @@ -154,6 +155,7 @@ pub(crate) fn create_stream_info(

StreamInfo {
id,
rid,
attributes: Attributes::new(),
ssrc,
payload_type,
Expand Down
2 changes: 2 additions & 0 deletions webrtc/src/rtp_transceiver/rtp_receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl RTCRtpReceiver {
let stream_info = create_stream_info(
"".to_owned(),
encoding.ssrc,
"".to_owned(),
0,
codec.clone(),
&global_params.header_extensions,
Expand Down Expand Up @@ -586,6 +587,7 @@ impl RTCRtpReceiver {
let stream_info = create_stream_info(
"".to_owned(),
rtx_ssrc,
"".to_owned(),
0,
codec.clone(),
&global_params.header_extensions,
Expand Down
Loading