Skip to content

Commit 6cfb302

Browse files
committed
Address feedback
1 parent 1b5b973 commit 6cfb302

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

webrtc/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Added more stats to `RemoteInboundRTPStats` and `RemoteOutboundRTPStats` [#282](https://github.com/webrtc-rs/webrtc/pull/282) by [@k0nserv](https://github.com/k0nserv).
66
* Don't register `video/rtx` codecs in `MediaEngine::register_default_codecs`. These weren't actually support and prevented RTX in the existing RTP stream from being used. Long term we should support RTX via this method, this is tracked in [#295](https://github.com/webrtc-rs/webrtc/issues/295). [#294 Remove video/rtx codecs](https://github.com/webrtc-rs/webrtc/pull/294) contributed by [k0nserv](https://github.com/k0nserv)
77
* Add IP filter to WebRTC `SettingEngine` [#306](https://github.com/webrtc-rs/webrtc/pull/306)
8-
8+
* Stop sequence numbers from increasing in `TrackLocalStaticSample` while the bound `RTCRtpSender` have
9+
directions that should not send. [#316](https://github.com/webrtc-rs/webrtc/pull/316)
910

1011
## 0.5.1
1112

webrtc/src/track/track_local/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@ pub(crate) struct TrackBinding {
105105
ssrc: SSRC,
106106
payload_type: PayloadType,
107107
write_stream: Option<Arc<dyn TrackLocalWriter + Send + Sync>>,
108-
paused: Arc<AtomicBool>,
108+
sender_paused: Arc<AtomicBool>,
109109
}
110110

111111
impl TrackBinding {
112-
pub fn is_paused(&self) -> bool {
113-
self.paused.load(Ordering::SeqCst)
112+
pub fn is_sender_paused(&self) -> bool {
113+
self.sender_paused.load(Ordering::SeqCst)
114114
}
115115
}
116116

117117
pub(crate) struct InterceptorToTrackLocalWriter {
118118
pub(crate) interceptor_rtp_writer: Mutex<Option<Arc<dyn RTPWriter + Send + Sync>>>,
119-
paused: Arc<AtomicBool>,
119+
sender_paused: Arc<AtomicBool>,
120120
}
121121

122122
impl InterceptorToTrackLocalWriter {
123123
pub(crate) fn new(paused: Arc<AtomicBool>) -> Self {
124124
InterceptorToTrackLocalWriter {
125125
interceptor_rtp_writer: Mutex::new(None),
126-
paused,
126+
sender_paused: paused,
127127
}
128128
}
129129

130-
fn is_paused(&self) -> bool {
131-
self.paused.load(Ordering::SeqCst)
130+
fn is_sender_paused(&self) -> bool {
131+
self.sender_paused.load(Ordering::SeqCst)
132132
}
133133
}
134134

@@ -141,7 +141,7 @@ impl std::fmt::Debug for InterceptorToTrackLocalWriter {
141141
#[async_trait]
142142
impl TrackLocalWriter for InterceptorToTrackLocalWriter {
143143
async fn write_rtp(&self, pkt: &rtp::packet::Packet) -> Result<usize> {
144-
if self.is_paused() {
144+
if self.is_sender_paused() {
145145
return Ok(0);
146146
}
147147

webrtc/src/track/track_local/track_local_static_rtp.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ impl TrackLocalStaticRTP {
3131

3232
pub async fn any_binding_paused(&self) -> bool {
3333
let bindings = self.bindings.lock().await;
34-
bindings.iter().any(|b| b.paused.load(Ordering::SeqCst))
34+
bindings
35+
.iter()
36+
.any(|b| b.sender_paused.load(Ordering::SeqCst))
3537
}
3638

3739
pub async fn all_binding_paused(&self) -> bool {
3840
let bindings = self.bindings.lock().await;
39-
bindings.iter().all(|b| b.paused.load(Ordering::SeqCst))
41+
bindings
42+
.iter()
43+
.all(|b| b.sender_paused.load(Ordering::SeqCst))
4044
}
4145
}
4246

@@ -60,7 +64,7 @@ impl TrackLocal for TrackLocalStaticRTP {
6064
payload_type: codec.payload_type,
6165
write_stream: t.write_stream(),
6266
id: t.id(),
63-
paused: t.paused.clone(),
67+
sender_paused: t.paused.clone(),
6468
}));
6569
}
6670

@@ -123,6 +127,11 @@ impl TrackLocalWriter for TrackLocalStaticRTP {
123127
/// If one PeerConnection fails the packets will still be sent to
124128
/// all PeerConnections. The error message will contain the ID of the failed
125129
/// PeerConnections so you can remove them
130+
///
131+
/// If the RTCRtpSender direction is such that no packets should be sent, any call to this
132+
/// function are blocked internally. Care must be taken to not increase the sequence number
133+
/// while the sender is paused. While the actual _sending_ is blocked, the receiver will
134+
/// miss out when the sequence number "rolls over", which in turn will break SRTP.
126135
async fn write_rtp(&self, p: &rtp::packet::Packet) -> Result<usize> {
127136
let mut n = 0;
128137
let mut write_errs = vec![];
@@ -133,7 +142,8 @@ impl TrackLocalWriter for TrackLocalStaticRTP {
133142
bindings.clone()
134143
};
135144
for b in bindings {
136-
if b.is_paused() {
145+
if b.is_sender_paused() {
146+
// See caveat in function doc.
137147
continue;
138148
}
139149
pkt.header.ssrc = b.ssrc;

webrtc/src/track/track_local/track_local_static_sample.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl TrackLocalStaticSample {
7171
// the packet. I.e. we get the same sequence number per multiple SSRC, which is not good
7272
// for SRTP, but that's how it works.
7373
//
74-
// Chrome has further a problem with regards to jumps in sequence number. Consider this:
74+
// SRTP has a further problem with regards to jumps in sequence number. Consider this:
7575
//
7676
// 1. Create track local
7777
// 2. Bind track local to track 1.
@@ -80,9 +80,11 @@ impl TrackLocalStaticSample {
8080
// 5. Keep sending...
8181
//
8282
// At this point, the track local will keep incrementing the sequence number, because we have
83-
// one binding that is still active. However Chrome can only accept a relatively small jump
84-
// in SRTP key deriving, which means if this pause state of one binding persists for a longer
85-
// time, the track can never be resumed (against Chrome).
83+
// one binding that is still active. However SRTP hmac verifying (tag), can only accept a
84+
// relatively small jump in sequence numbers since it uses the ROC (i.e. how many times the
85+
// sequence number has rolled over), which means if this pause state of one binding persists
86+
// for a longer time, the track can never be resumed since the receiver would have missed
87+
// the rollovers.
8688
if !internal.did_warn_about_wonky_pause {
8789
internal.did_warn_about_wonky_pause = true;
8890
warn!("Detected multiple track bindings where only one was paused");

0 commit comments

Comments
 (0)