Skip to content

Commit

Permalink
feat: added bwe reset
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm committed Apr 26, 2024
1 parent 897ce43 commit 8097815
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bwe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ impl<'a> Bwe<'a> {
pub fn set_desired_bitrate(&mut self, desired_bitrate: Bitrate) {
self.0.session.set_bwe_desired_bitrate(desired_bitrate);
}

/// Reset the BWE with a new init_bitrate
///
/// # Example
///
/// This method is useful when you initially start with only an audio stream. In this case, the BWE will report a very low estimated bitrate.
/// Later, when you start a video stream, the estimated bitrate will be affected by the previous low bitrate, resulting in a very low estimated bitrate, which can cause poor video stream quality.
/// To avoid this, you need to warm up the video stream for a while then calling reset with a provided init_bitrate.
///
pub fn reset(&mut self, init_bitrate: Bitrate) {
self.0.session.reset_bwe(init_bitrate);
}
}
10 changes: 10 additions & 0 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,12 @@ impl Session {
}
}

pub fn reset_bwe(&mut self, init_bitrate: Bitrate) {
if let Some(bwe) = self.bwe.as_mut() {
bwe.reset(init_bitrate);
}
}

pub fn line_count(&self) -> usize {
self.medias.len() + if self.app.is_some() { 1 } else { 0 }
}
Expand Down Expand Up @@ -898,6 +904,10 @@ impl Bwe {
self.bwe.handle_timeout(now);
}

pub fn reset(&mut self, init_bitrate: Bitrate) {
self.bwe = SendSideBandwithEstimator::new(init_bitrate);
}

pub fn update<'t>(
&mut self,
records: impl Iterator<Item = &'t crate::rtp_::TwccSendRecord>,
Expand Down

0 comments on commit 8097815

Please sign in to comment.