Separate base minimum delay and minimum delay.
On NetEq level latency corresponds to delay and two terms can be used interchangeably here.
In order to implement latency constraint we need to provide a range of possible values which should be constant. See getCapabilities() here:
https://www.w3.org/TR/mediacapture-streams/#dfn-applyconstraints-algorithm
Lowest possible value accepted value is constant and equals 0. But because |packet_len_ms_| and |maximum_delay_ms_| may be updated during live of DelayManager upper bound is not constant. Moreover, due to change in |packet_len_ms_| the |minimum_delay_ms_| which was valid when its was set may be considered invalid later on.
To circumvent that and provide constant range for capabilities we separate base minimum delay and minimum delay. ApplyConstraints algorithm will set base minimum delay. Base minimum delay will act as recommendation for lower bound of minimum delay and will be used to limit target delay. If user sets base minimum delay through ApplyConstraints which is bigger than currently
possible maximum (e.g. bigger than NetEq maximum buffer size in milliseconds) then base minimum delay will be clamped to currently possible maximum to match user's intentions as best as possible.
Note, that we keep original behavior when minimum_delay_ms_ (effective_minimum_delay_ms after this CL) in LimitTargetLevel method may be above upper bound due to changing packet audio length.
Bug: webrtc:10287
Change-Id: I06b8f5cd3fd1bc36800af0447f91f7c4dc21a766
Reviewed-on: https://webrtc-review.googlesource.com/c/121700
Commit-Queue: Ruslan Burakov <kuddai@google.com>
Reviewed-by: Minyue Li <minyue@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26666}
diff --git a/modules/audio_coding/neteq/delay_manager.h b/modules/audio_coding/neteq/delay_manager.h
index 652a773..59f9d37 100644
--- a/modules/audio_coding/neteq/delay_manager.h
+++ b/modules/audio_coding/neteq/delay_manager.h
@@ -32,10 +32,10 @@
// Create a DelayManager object. Notify the delay manager that the packet
// buffer can hold no more than |max_packets_in_buffer| packets (i.e., this
// is the number of packet slots in the buffer) and that the target delay
- // should be greater than or equal to |base_min_target_delay_ms|. Supply a
+ // should be greater than or equal to |base_minimum_delay_ms|. Supply a
// PeakDetector object to the DelayManager.
DelayManager(size_t max_packets_in_buffer,
- int base_min_target_delay_ms,
+ int base_minimum_delay_ms,
bool enable_rtx_handling,
DelayPeakDetector* peak_detector,
const TickTimer* tick_timer);
@@ -125,7 +125,19 @@
return forced_limit_probability_;
}
+ // This accessor is only intended for testing purposes.
+ int effective_minimum_delay_ms_for_test() const {
+ return effective_minimum_delay_ms_;
+ }
+
private:
+ // Provides value which minimum delay can't exceed based on current buffer
+ // size and given |maximum_delay_ms_|. Lower bound is a constant 0.
+ int MinimumDelayUpperBound() const;
+
+ // Provides 75% of currently possible maximum buffer size in milliseconds.
+ int MaxBufferTimeQ75() const;
+
// Sets |iat_vector_| to the default start distribution and sets the
// |base_target_level_| and |target_level_| to the corresponding values.
void ResetHistogram();
@@ -134,6 +146,11 @@
// used by the streaming mode.) This method is called by Update().
void UpdateCumulativeSums(int packet_len_ms, uint16_t sequence_number);
+ // Updates |effective_minimum_delay_ms_| delay based on current
+ // |minimum_delay_ms_|, |base_minimum_delay_ms_| and |maximum_delay_ms_|
+ // and buffer size.
+ void UpdateEffectiveMinimumDelay();
+
// Updates the histogram |iat_vector_|. The probability for inter-arrival time
// equal to |iat_packets| (in integer packets) is increased slightly, while
// all other entries are decreased. This method is called by Update().
@@ -147,15 +164,20 @@
// Makes sure that |delay_ms| is less than maximum delay, if any maximum
// is set. Also, if possible check |delay_ms| to be less than 75% of
// |max_packets_in_buffer_|.
- bool IsValidMinimumDelay(int delay_ms);
+ bool IsValidMinimumDelay(int delay_ms) const;
+
+ bool IsValidBaseMinimumDelay(int delay_ms) const;
bool first_packet_received_;
const size_t max_packets_in_buffer_; // Capacity of the packet buffer.
IATVector iat_vector_; // Histogram of inter-arrival times.
int iat_factor_; // Forgetting factor for updating the IAT histogram (Q15).
const TickTimer* tick_timer_;
- int base_min_target_delay_ms_; // Lower bound for target_level_ and
- // minimum_delay_ms_.
+ int base_minimum_delay_ms_;
+ // Provides delay which is used by LimitTargetLevel as lower bound on target
+ // delay.
+ int effective_minimum_delay_ms_;
+
// Time elapsed since last packet.
std::unique_ptr<TickTimer::Stopwatch> packet_iat_stopwatch_;
int base_target_level_; // Currently preferred buffer level before peak