diff --git a/webrtc/modules/remote_bitrate_estimator/test/estimators/nada.cc b/webrtc/modules/remote_bitrate_estimator/test/estimators/nada.cc index 2500679343..d77447f1ea 100644 --- a/webrtc/modules/remote_bitrate_estimator/test/estimators/nada.cc +++ b/webrtc/modules/remote_bitrate_estimator/test/estimators/nada.cc @@ -124,12 +124,20 @@ FeedbackPacket* NadaBweReceiver::GetFeedback(int64_t now_ms) { derivative, RecentKbps(), corrected_send_time_ms); } +// If size is even, the median is the average of the two middlemost numbers. int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) { - // Typically, size = 5. std::vector array_copy(last_delays_ms, last_delays_ms + size); std::nth_element(array_copy.begin(), array_copy.begin() + size / 2, array_copy.end()); - return array_copy.at(size / 2); + if (size % 2 == 1) { + // Typically, size = 5. For odd size values, right and left are equal. + return array_copy.at(size / 2); + } + int64_t right = array_copy.at(size / 2); + std::nth_element(array_copy.begin(), array_copy.begin() + (size - 1) / 2, + array_copy.end()); + int64_t left = array_copy.at((size - 1) / 2); + return (left + right + 1) / 2; } int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value, diff --git a/webrtc/modules/remote_bitrate_estimator/test/estimators/nada_unittest.cc b/webrtc/modules/remote_bitrate_estimator/test/estimators/nada_unittest.cc index 80768966b5..a0f56b73b7 100644 --- a/webrtc/modules/remote_bitrate_estimator/test/estimators/nada_unittest.cc +++ b/webrtc/modules/remote_bitrate_estimator/test/estimators/nada_unittest.cc @@ -356,7 +356,7 @@ TEST_F(NadaReceiverSideTest, FeedbackIncreasingDelay) { // Raw delays are = [10 20 30 40 50 60 70 80] ms. // Baseline delay will be 50 ms. // Delay signals should be: [0 10 20 30 40 50 60 70] ms. - const int64_t kMedianFilteredDelaysMs[] = {0, 10, 10, 20, 20, 30, 40, 50}; + const int64_t kMedianFilteredDelaysMs[] = {0, 5, 10, 15, 20, 30, 40, 50}; const int kNumPackets = ARRAY_SIZE(kMedianFilteredDelaysMs); const float kAlpha = 0.1f; // Used for exponential smoothing. @@ -425,7 +425,7 @@ TEST_F(NadaReceiverSideTest, FeedbackWarpedDelay) { // Baseline delay will be 50 ms. // Delay signals should be: [0 200 400 600 800 1000 1200 1400] ms. const int64_t kMedianFilteredDelaysMs[] = { - 0, 200, 200, 400, 400, 600, 800, 1000}; + 0, 100, 200, 300, 400, 600, 800, 1000}; const int kNumPackets = ARRAY_SIZE(kMedianFilteredDelaysMs); const float kAlpha = 0.1f; // Used for exponential smoothing.