From e1c707c40f666fe37b55576f66ffa849da3174d5 Mon Sep 17 00:00:00 2001 From: philipel Date: Tue, 5 Jul 2022 14:03:25 +0200 Subject: [PATCH] Remove unused incomplete_frame argument from JitterEstimator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14151 Change-Id: I6764315f0c10b304f50e4639a3e49e4ed013c41e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267842 Reviewed-by: Erik Språng Commit-Queue: Philip Eliasson Cr-Commit-Position: refs/heads/main@{#37443} --- modules/video_coding/jitter_buffer.cc | 5 +-- .../video_coding/timing/jitter_estimator.cc | 40 ++++++++----------- .../video_coding/timing/jitter_estimator.h | 11 +---- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/modules/video_coding/jitter_buffer.cc b/modules/video_coding/jitter_buffer.cc index a1866fac51..39553c9f3f 100644 --- a/modules/video_coding/jitter_buffer.cc +++ b/modules/video_coding/jitter_buffer.cc @@ -869,7 +869,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame, void VCMJitterBuffer::UpdateJitterEstimate(int64_t latest_packet_time_ms, uint32_t timestamp, unsigned int frame_size, - bool incomplete_frame) { + bool /*incomplete_frame*/) { if (latest_packet_time_ms == -1) { return; } @@ -880,8 +880,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(int64_t latest_packet_time_ms, // Filter out frames which have been reordered in time by the network if (not_reordered) { // Update the jitter estimate with the new samples - jitter_estimate_.UpdateEstimate(*frame_delay, DataSize::Bytes(frame_size), - incomplete_frame); + jitter_estimate_.UpdateEstimate(*frame_delay, DataSize::Bytes(frame_size)); } } diff --git a/modules/video_coding/timing/jitter_estimator.cc b/modules/video_coding/timing/jitter_estimator.cc index 8cc7d2b54c..168bfc2b4b 100644 --- a/modules/video_coding/timing/jitter_estimator.cc +++ b/modules/video_coding/timing/jitter_estimator.cc @@ -96,8 +96,7 @@ void JitterEstimator::Reset() { // Updates the estimates with the new measurements. void JitterEstimator::UpdateEstimate(TimeDelta frame_delay, - DataSize frame_size, - bool incomplete_frame /* = false */) { + DataSize frame_size) { if (frame_size.IsZero()) { return; } @@ -112,20 +111,18 @@ void JitterEstimator::UpdateEstimate(TimeDelta frame_delay, avg_frame_size_ = frame_size_sum_ / static_cast(frame_size_count_); frame_size_count_++; } - if (!incomplete_frame || frame_size > avg_frame_size_) { - DataSize avg_frame_size = kPhi * avg_frame_size_ + (1 - kPhi) * frame_size; - DataSize deviation_size = DataSize::Bytes(2 * sqrt(var_frame_size_)); - if (frame_size < avg_frame_size_ + deviation_size) { - // Only update the average frame size if this sample wasn't a key frame. - avg_frame_size_ = avg_frame_size; - } - // Update the variance anyway since we want to capture cases where we only - // get key frames. - double delta_bytes = frame_size.bytes() - avg_frame_size.bytes(); - var_frame_size_ = std::max( - kPhi * var_frame_size_ + (1 - kPhi) * (delta_bytes * delta_bytes), 1.0); + + DataSize avg_frame_size = kPhi * avg_frame_size_ + (1 - kPhi) * frame_size; + DataSize deviation_size = DataSize::Bytes(2 * sqrt(var_frame_size_)); + if (frame_size < avg_frame_size_ + deviation_size) { + // Only update the average frame size if this sample wasn't a key frame. + avg_frame_size_ = avg_frame_size; } + double delta_bytes = frame_size.bytes() - avg_frame_size.bytes(); + var_frame_size_ = std::max( + kPhi * var_frame_size_ + (1 - kPhi) * (delta_bytes * delta_bytes), 1.0); + // Update max_frame_size_ estimate. max_frame_size_ = std::max(kPsi * max_frame_size_, frame_size); @@ -152,22 +149,21 @@ void JitterEstimator::UpdateEstimate(TimeDelta frame_delay, kNumStdDevFrameSizeOutlier * sqrt(var_frame_size_)) { // Update the variance of the deviation from the line given by the Kalman // filter. - EstimateRandomJitter(deviation, incomplete_frame); + EstimateRandomJitter(deviation); // Prevent updating with frames which have been congested by a large frame, // and therefore arrives almost at the same time as that frame. // This can occur when we receive a large frame (key frame) which has been // delayed. The next frame is of normal size (delta frame), and thus deltaFS // will be << 0. This removes all frame samples which arrives after a key // frame. - if ((!incomplete_frame || deviation >= 0) && - delta_frame_bytes > -0.25 * max_frame_size_.bytes()) { + if (delta_frame_bytes > -0.25 * max_frame_size_.bytes()) { // Update the Kalman filter with the new data KalmanEstimateChannel(frame_delay, delta_frame_bytes); } } else { int nStdDev = (deviation >= 0) ? kNumStdDevDelayOutlier : -kNumStdDevDelayOutlier; - EstimateRandomJitter(nStdDev * sqrt(var_noise_), incomplete_frame); + EstimateRandomJitter(nStdDev * sqrt(var_noise_)); } // Post process the total estimated jitter if (startup_count_ >= kStartupDelaySamples) { @@ -273,7 +269,7 @@ double JitterEstimator::DeviationFromExpectedDelay( // Estimates the random jitter by calculating the variance of the sample // distance from the line given by theta. -void JitterEstimator::EstimateRandomJitter(double d_dT, bool incomplete_frame) { +void JitterEstimator::EstimateRandomJitter(double d_dT) { Timestamp now = clock_->CurrentTime(); if (last_update_time_.has_value()) { fps_counter_.AddSample((now - *last_update_time_).us()); @@ -310,10 +306,8 @@ void JitterEstimator::EstimateRandomJitter(double d_dT, bool incomplete_frame) { double avgNoise = alpha * avg_noise_ + (1 - alpha) * d_dT; double varNoise = alpha * var_noise_ + (1 - alpha) * (d_dT - avg_noise_) * (d_dT - avg_noise_); - if (!incomplete_frame || varNoise > var_noise_) { - avg_noise_ = avgNoise; - var_noise_ = varNoise; - } + avg_noise_ = avgNoise; + var_noise_ = varNoise; if (var_noise_ < 1.0) { // The variance should never be zero, since we might get stuck and consider // all samples as outliers. diff --git a/modules/video_coding/timing/jitter_estimator.h b/modules/video_coding/timing/jitter_estimator.h index 5e5a566c82..87a4f980e9 100644 --- a/modules/video_coding/timing/jitter_estimator.h +++ b/modules/video_coding/timing/jitter_estimator.h @@ -39,12 +39,7 @@ class JitterEstimator { // Input: // - frame_delay : Delay-delta calculated by UTILDelayEstimate. // - frame_size : Frame size of the current frame. - // - incomplete_frame : Flags if the frame is used to update the - // estimate before it was complete. - // Default is false. - void UpdateEstimate(TimeDelta frame_delay, - DataSize frame_size, - bool incomplete_frame = false); + void UpdateEstimate(TimeDelta frame_delay, DataSize frame_size); // Returns the current jitter estimate and adds an RTT dependent term in cases // of retransmission. @@ -94,9 +89,7 @@ class JitterEstimator { // // Input: // - d_dT : The deviation from the kalman estimate. - // - incomplete_frame : True if the frame used to update the - // estimate with was incomplete. - void EstimateRandomJitter(double d_dT, bool incomplete_frame); + void EstimateRandomJitter(double d_dT); double NoiseThreshold() const;