@@ -3,6 +3,7 @@ use pulsebeam_proto::namespace;
33use pulsebeam_runtime:: net:: { self , Transport } ;
44use std:: collections:: HashMap ;
55use std:: sync:: Arc ;
6+ use std:: time:: Duration ;
67use str0m:: bwe:: BweKind ;
78use str0m:: channel:: ChannelConfig ;
89use str0m:: media:: { KeyframeRequest , MediaKind , Mid } ;
@@ -22,6 +23,7 @@ use crate::rtp::RtpPacket;
2223use crate :: track:: { self , TrackReceiver } ;
2324
2425const RESERVED_DATA_CHANNEL_COUNT : u16 = 32 ;
26+ const SLOW_POLL_INTERVAL : Duration = Duration :: from_millis ( 200 ) ;
2527
2628pub 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
6366impl 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
0 commit comments