Skip to content

Commit

Permalink
fix(server): 🐛 Try fixing bitrate hikes
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Aug 31, 2023
1 parent 6e748ea commit 2cc89bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions alvr/common/src/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ impl<T> SlidingWindowAverage<T> {

self.history_buffer.push_back(sample);
}

pub fn retain(&mut self, count: usize) {
self.history_buffer
.drain(0..self.history_buffer.len().saturating_sub(count));
}
}

impl SlidingWindowAverage<f32> {
Expand Down
6 changes: 2 additions & 4 deletions alvr/server/src/bitrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const UPDATE_INTERVAL: Duration = Duration::from_secs(1);

pub struct BitrateManager {
nominal_frame_interval: Duration,
max_history_size: usize,
frame_interval_average: SlidingWindowAverage<Duration>,
// note: why packet_sizes_bits_history is a queue and not a sliding average? Because some
// network samples will be dropped but not any packet size sample
Expand All @@ -33,7 +32,6 @@ impl BitrateManager {
pub fn new(max_history_size: usize, initial_framerate: f32) -> Self {
Self {
nominal_frame_interval: Duration::from_secs_f32(1. / initial_framerate),
max_history_size,
frame_interval_average: SlidingWindowAverage::new(
Duration::from_millis(16),
max_history_size,
Expand Down Expand Up @@ -74,8 +72,8 @@ impl BitrateManager {
if interval_ratio > config.framerate_reset_threshold_multiplier
|| interval_ratio < 1.0 / config.framerate_reset_threshold_multiplier
{
self.frame_interval_average =
SlidingWindowAverage::new(interval, self.max_history_size);
// Clear most of the samples, keep some for stability
self.frame_interval_average.retain(5);
self.update_needed = true;
}
}
Expand Down

0 comments on commit 2cc89bc

Please sign in to comment.