Skip to content

Commit 83ef82a

Browse files
committed
combine timers
1 parent 278df4d commit 83ef82a

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

pulsebeam/src/participant/actor.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ impl actor::Actor<ParticipantMessageSet> for ParticipantActor {
8080
gateway_tx,
8181
))
8282
.await;
83-
let mut stats_interval = tokio::time::interval(Duration::from_millis(200));
8483
let mut maybe_deadline = self.core.poll();
8584
let sleep = tokio::time::sleep(MIN_QUANTA);
8685
tokio::pin!(sleep);
@@ -165,11 +164,8 @@ impl actor::Actor<ParticipantMessageSet> for ParticipantActor {
165164
},
166165

167166
// Priority 4: Background tasks
168-
now = stats_interval.tick() => {
169-
self.core.poll_slow(now);
170-
}
171167
_ = &mut sleep => {
172-
maybe_deadline = self.core.handle_timeout();
168+
maybe_deadline = self.core.handle_tick();
173169
},
174170
}
175171
}

pulsebeam/src/participant/core.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use pulsebeam_proto::namespace;
33
use pulsebeam_runtime::net::{self, Transport};
44
use std::collections::HashMap;
55
use std::sync::Arc;
6+
use std::time::Duration;
67
use str0m::bwe::BweKind;
78
use str0m::channel::ChannelConfig;
89
use str0m::media::{KeyframeRequest, MediaKind, Mid};
@@ -22,6 +23,7 @@ use crate::rtp::RtpPacket;
2223
use crate::track::{self, TrackReceiver};
2324

2425
const RESERVED_DATA_CHANNEL_COUNT: u16 = 32;
26+
const SLOW_POLL_INTERVAL: Duration = Duration::from_millis(200);
2527

2628
pub struct TrackMapping {
2729
pub mid: Mid,
@@ -58,6 +60,7 @@ pub struct ParticipantCore {
5860
pub events: Vec<CoreEvent>,
5961
disconnect_reason: Option<DisconnectReason>,
6062
signaling: Signaling,
63+
last_slow_poll: Instant,
6164
}
6265

6366
impl ParticipantCore {
@@ -97,6 +100,7 @@ impl ParticipantCore {
97100
disconnect_reason: None,
98101
events: Vec::with_capacity(32),
99102
signaling: Signaling::new(cid),
103+
last_slow_poll: Instant::now(),
100104
}
101105
}
102106

@@ -141,7 +145,7 @@ impl ParticipantCore {
141145
last_deadline
142146
}
143147

144-
pub fn handle_timeout(&mut self) -> Option<Instant> {
148+
pub fn handle_tick(&mut self) -> Option<Instant> {
145149
let _ = self.rtc.handle_input(Input::Timeout(Instant::now().into()));
146150
self.poll()
147151
}
@@ -178,21 +182,26 @@ impl ParticipantCore {
178182
/// The Main Orchestrator.
179183
/// Drives the feedback loop between the RTC Engine and the Signaling Logic.
180184
pub fn poll(&mut self) -> Option<Instant> {
181-
if self.disconnect_reason.is_some() {
182-
return None;
185+
let now = Instant::now();
186+
187+
if now >= self.last_slow_poll + SLOW_POLL_INTERVAL {
188+
self.poll_slow(now);
189+
self.last_slow_poll = now;
183190
}
184191

185192
loop {
186-
let deadline = self.poll_rtc()?;
193+
let rtc_deadline = self.poll_rtc()?;
187194
let did_work = self.signaling.poll(&mut self.rtc, &self.downstream);
188195
if did_work {
189196
// Signaling wrote data. The RTC engine is now "dirty" (has output to send).
190197
// We loop back to `poll_rtc` immediately to flush `Output::Transmit`.
191198
continue;
192199
}
193200

201+
let next_slow_poll = self.last_slow_poll + SLOW_POLL_INTERVAL;
202+
194203
// No new work generated. We are synced. Return the RTC deadline.
195-
return Some(deadline);
204+
return Some(rtc_deadline.min(next_slow_poll));
196205
}
197206
}
198207

pulsebeam/src/participant/downstream/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::task::{Context, Poll};
1212
use str0m::bwe::Bitrate;
1313
use str0m::media::{KeyframeRequest, MediaKind, Mid};
1414
use tokio::time::Instant;
15-
pub use video::{Intent, SlotAssignment};
15+
pub use video::Intent;
1616

1717
pub struct DownstreamAllocator {
1818
available_bandwidth: BitrateController,

pulsebeam/src/participant/signaling.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::{HashMap, HashSet};
22

3-
use crate::participant::downstream::SlotAssignment;
43
use crate::participant::downstream::{DownstreamAllocator, Intent};
54
use pulsebeam_proto::prelude::*;
65
use pulsebeam_proto::signaling;

0 commit comments

Comments
 (0)