Skip to content

Commit c737c1e

Browse files
committed
correct gro receive
1 parent 480ff5c commit c737c1e

6 files changed

Lines changed: 58 additions & 18 deletions

File tree

media/rtc/src/rtp_session/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ impl RtpSession {
165165
self.rx.remove(&ssrc);
166166
}
167167

168+
/// Returns an iterator over all outbound streams
169+
pub fn tx_streams(&self) -> impl Iterator<Item = &RtpOutboundStream> {
170+
self.tx.values()
171+
}
172+
173+
/// Returns an iterator over all inbound streams (excluding rtx SSRCs as they're included in the original RtpInboundStream)
174+
pub fn rx_streams(&self) -> impl Iterator<Item = &RtpInboundStream> {
175+
self.rx.values().filter_map(|rx| match rx {
176+
RxStream::Original(rx) => Some(rx),
177+
RxStream::Rtx(..) => None,
178+
})
179+
}
180+
168181
/// Hand of the RTCP packet to the RTP session
169182
#[must_use]
170183
pub fn receive_rtcp(

media/rtc/src/rtp_session/outbound/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ impl RtpOutboundStream {
3535
stats: RtpOutboundStats {
3636
bytes_sent: 0,
3737
packets_sent: 0,
38+
rtx_packets_sent: 0,
39+
rtx_bytes_sent: 0,
3840
remote: None,
3941
},
4042
report_interval,
@@ -126,7 +128,10 @@ impl RtpOutboundStream {
126128
pub(crate) fn poll(&mut self, now: Instant) -> Option<RtpOutboundStreamEvent> {
127129
match self.queue.poll(now)? {
128130
RtpOutboundStreamEvent::SendRtpPacket { rtp_packet, is_rtx } => {
129-
if !is_rtx {
131+
if is_rtx {
132+
self.stats.rtx_packets_sent += 1;
133+
self.stats.rtx_bytes_sent += rtp_packet.payload.len() as u64;
134+
} else {
130135
self.stats.packets_sent += 1;
131136
self.stats.bytes_sent += rtp_packet.payload.len() as u64;
132137
}

media/rtc/src/rtp_session/outbound/queue.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct Rtx {
5252
pt: u8,
5353

5454
/// Queue of already sent RTP packets
55-
sent_packets: VecDeque<(RtpPacket, Instant)>,
55+
sent_packets: VecDeque<(RtpPacket, Instant, u32)>,
5656

5757
/// Determines how long a RTP packet is stored for retransmission before being dropped
5858
sent_packets_max_size: Duration,
@@ -190,10 +190,10 @@ impl OutboundQueue {
190190

191191
// Store packet in sent_packets if configured
192192
if let Some(rtx) = &mut self.rtx {
193-
rtx.sent_packets.push_back((rtp_packet.clone(), now));
193+
rtx.sent_packets.push_back((rtp_packet.clone(), now, 0));
194194

195195
// Remove old packets
196-
while let Some((_, sent_at)) = rtx.sent_packets.front()
196+
while let Some((_, sent_at, _)) = rtx.sent_packets.front()
197197
&& now.saturating_duration_since(*sent_at) > rtx.sent_packets_max_size
198198
{
199199
rtx.sent_packets.pop_front();
@@ -223,12 +223,16 @@ impl OutboundQueue {
223223
};
224224

225225
for entry in entries {
226-
if let Some((rtp_packet, _)) = rtx
226+
if let Some((rtp_packet, _, sent_counter)) = rtx
227227
.sent_packets
228-
.iter()
228+
.iter_mut()
229229
.find(|x| x.0.sequence_number.0 == entry)
230230
{
231-
rtx.retransmit_queue.push_back(rtp_packet.clone());
231+
// Limit the same RTP packet to being sent 5 times
232+
if *sent_counter < 5 {
233+
*sent_counter += 1;
234+
rtx.retransmit_queue.push_back(rtp_packet.clone());
235+
}
232236
}
233237
}
234238
}

media/rtc/src/rtp_session/outbound/stats.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct RtpOutboundStats {
99
/// Amount of RTP packets sent
1010
pub packets_sent: u64,
1111

12+
/// Amount of RTX packets sent
13+
pub rtx_packets_sent: u64,
14+
15+
/// Amount of RTX bytes sent
16+
pub rtx_bytes_sent: u64,
17+
1218
/// Stats that are dependent on the remote sending a receiver report block
1319
pub remote: Option<RtpOutboundRemoteStats>,
1420
}

media/rtc/src/sdp/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,13 @@ impl SdpSession {
20202020
Some(InboundMedia { media, stream })
20212021
}
20222022

2023+
/// Returns an iterator over all internal RTP transports and their corresponding transport id
2024+
pub fn rtp_sessions(&self) -> impl Iterator<Item = (TransportId, &RtpSession)> {
2025+
self.transports
2026+
.values()
2027+
.map(|x| (x.public_id, &x.rtp_session))
2028+
}
2029+
20232030
/// Returns the cumulative gathering state of all ice agents
20242031
pub fn ice_gathering_state(&self) -> Option<IceGatheringState> {
20252032
self.transports

media/rtc/src/tokio/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,22 @@ impl TokioIoState {
159159

160160
for i in 0..num_msg {
161161
let len = self.meta[i].len;
162-
163-
let pkt = ReceivedPkt {
164-
data: self.bufs[i][..len].to_vec(),
165-
source: self.meta[i].addr,
166-
destination: self.meta[i].dst_ip.map_or(socket.local_addr(), |ip| {
167-
(ip, socket.local_addr().port()).into()
168-
}),
169-
component: *component,
170-
};
171-
172-
session.receive(now, *transport_id, pkt);
162+
let stride = self.meta[i].stride;
163+
164+
let packet = &self.bufs[i][..len];
165+
166+
for packet in packet.chunks(stride) {
167+
let pkt = ReceivedPkt {
168+
data: packet.to_vec(),
169+
source: self.meta[i].addr,
170+
destination: self.meta[i].dst_ip.map_or(socket.local_addr(), |ip| {
171+
(ip, socket.local_addr().port()).into()
172+
}),
173+
component: *component,
174+
};
175+
176+
session.receive(now, *transport_id, pkt);
177+
}
173178

174179
received = true;
175180
}

0 commit comments

Comments
 (0)