Refactor NetEq delay manager logic.
- Removes dependence on sequence number for calculating target delay. - Changes target delay unit to milliseconds instead of number of packets. - Moves acceleration/preemptive expand thresholds to decision logic. Tests for this will be added in a follow up cl. Bug: webrtc:10333 Change-Id: If690aae4abf41ef1d9353f0ff01fb7d121cf8a26 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186265 Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Reviewed-by: Ivo Creusen <ivoc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32326}
This commit is contained in:
committed by
Commit Bot
parent
76d3e7a8d1
commit
f8e62fcb14
@ -25,10 +25,9 @@ namespace webrtc {
|
||||
|
||||
class DelayManager {
|
||||
public:
|
||||
DelayManager(size_t max_packets_in_buffer,
|
||||
DelayManager(int max_packets_in_buffer,
|
||||
int base_minimum_delay_ms,
|
||||
int histogram_quantile,
|
||||
bool enable_rtx_handling,
|
||||
const TickTimer* tick_timer,
|
||||
std::unique_ptr<Histogram> histogram);
|
||||
|
||||
@ -37,58 +36,29 @@ class DelayManager {
|
||||
// is the number of packet slots in the buffer) and that the target delay
|
||||
// should be greater than or equal to |base_minimum_delay_ms|. Supply a
|
||||
// PeakDetector object to the DelayManager.
|
||||
static std::unique_ptr<DelayManager> Create(size_t max_packets_in_buffer,
|
||||
static std::unique_ptr<DelayManager> Create(int max_packets_in_buffer,
|
||||
int base_minimum_delay_ms,
|
||||
bool enable_rtx_handling,
|
||||
const TickTimer* tick_timer);
|
||||
|
||||
virtual ~DelayManager();
|
||||
|
||||
// Updates the delay manager with a new incoming packet, with
|
||||
// |sequence_number| and |timestamp| from the RTP header. This updates the
|
||||
// inter-arrival time histogram and other statistics, as well as the
|
||||
// associated DelayPeakDetector. A new target buffer level is calculated.
|
||||
// Returns the relative delay if it can be calculated.
|
||||
virtual absl::optional<int> Update(uint16_t sequence_number,
|
||||
uint32_t timestamp,
|
||||
int sample_rate_hz);
|
||||
// Updates the delay manager with a new incoming packet, with |timestamp| from
|
||||
// the RTP header. This updates the statistics and a new target buffer level
|
||||
// is calculated. Returns the relative delay if it can be calculated. If
|
||||
// |reset| is true, restarts the relative arrival delay calculation from this
|
||||
// packet.
|
||||
virtual absl::optional<int> Update(uint32_t timestamp,
|
||||
int sample_rate_hz,
|
||||
bool reset = false);
|
||||
|
||||
// Calculates a new target buffer level. Called from the Update() method.
|
||||
// Sets target_level_ (in Q8) and returns the same value. Also calculates
|
||||
// and updates base_target_level_, which is the target buffer level before
|
||||
// taking delay peaks into account.
|
||||
virtual int CalculateTargetLevel();
|
||||
|
||||
// Notifies the DelayManager of how much audio data is carried in each packet.
|
||||
// The method updates the DelayPeakDetector too, and resets the inter-arrival
|
||||
// time counter. Returns 0 on success, -1 on failure.
|
||||
virtual int SetPacketAudioLength(int length_ms);
|
||||
|
||||
// Resets the DelayManager and the associated DelayPeakDetector.
|
||||
// Resets all state.
|
||||
virtual void Reset();
|
||||
|
||||
// Reset the inter-arrival time counter to 0.
|
||||
virtual void ResetPacketIatCount();
|
||||
// Gets the target buffer level in milliseconds.
|
||||
virtual int TargetDelayMs() const;
|
||||
|
||||
// Writes the lower and higher limits which the buffer level should stay
|
||||
// within to the corresponding pointers. The values are in (fractions of)
|
||||
// packets in Q8.
|
||||
virtual void BufferLimits(int* lower_limit, int* higher_limit) const;
|
||||
virtual void BufferLimits(int target_level,
|
||||
int* lower_limit,
|
||||
int* higher_limit) const;
|
||||
|
||||
// Gets the target buffer level, in (fractions of) packets in Q8.
|
||||
virtual int TargetLevel() const;
|
||||
|
||||
// Informs the delay manager whether or not the last decoded packet contained
|
||||
// speech.
|
||||
virtual void LastDecodedWasCngOrDtmf(bool it_was);
|
||||
|
||||
// Notify the delay manager that empty packets have been received. These are
|
||||
// packets that are part of the sequence number series, so that an empty
|
||||
// packet will shift the sequence numbers for the following packets.
|
||||
virtual void RegisterEmptyPacket();
|
||||
// Notifies the DelayManager of how much audio data is carried in each packet.
|
||||
virtual int SetPacketAudioLength(int length_ms);
|
||||
|
||||
// Accessors and mutators.
|
||||
// Assuming |delay| is in valid range.
|
||||
@ -96,16 +66,11 @@ class DelayManager {
|
||||
virtual bool SetMaximumDelay(int delay_ms);
|
||||
virtual bool SetBaseMinimumDelay(int delay_ms);
|
||||
virtual int GetBaseMinimumDelay() const;
|
||||
virtual int base_target_level() const;
|
||||
virtual int last_pack_cng_or_dtmf() const;
|
||||
virtual void set_last_pack_cng_or_dtmf(int value);
|
||||
|
||||
// This accessor is only intended for testing purposes.
|
||||
// These accessors are only intended for testing purposes.
|
||||
int effective_minimum_delay_ms_for_test() const {
|
||||
return effective_minimum_delay_ms_;
|
||||
}
|
||||
|
||||
// These accessors are only intended for testing purposes.
|
||||
int histogram_quantile() const { return histogram_quantile_; }
|
||||
Histogram* histogram() const { return histogram_.get(); }
|
||||
|
||||
@ -114,9 +79,6 @@ class DelayManager {
|
||||
// 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;
|
||||
|
||||
// Updates |delay_history_|.
|
||||
void UpdateDelayHistory(int iat_delay_ms,
|
||||
uint32_t timestamp,
|
||||
@ -130,10 +92,6 @@ class DelayManager {
|
||||
// and buffer size.
|
||||
void UpdateEffectiveMinimumDelay();
|
||||
|
||||
// Makes sure that |target_level_| is not too large, taking
|
||||
// |max_packets_in_buffer_| into account. This method is called by Update().
|
||||
void LimitTargetLevel();
|
||||
|
||||
// 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_|.
|
||||
@ -142,31 +100,21 @@ class DelayManager {
|
||||
bool IsValidBaseMinimumDelay(int delay_ms) const;
|
||||
|
||||
bool first_packet_received_;
|
||||
const size_t max_packets_in_buffer_; // Capacity of the packet buffer.
|
||||
// TODO(jakobi): set maximum buffer delay instead of number of packets.
|
||||
const int max_packets_in_buffer_;
|
||||
std::unique_ptr<Histogram> histogram_;
|
||||
const int histogram_quantile_;
|
||||
const TickTimer* tick_timer_;
|
||||
int base_minimum_delay_ms_;
|
||||
// Provides delay which is used by LimitTargetLevel as lower bound on target
|
||||
// delay.
|
||||
int effective_minimum_delay_ms_;
|
||||
int effective_minimum_delay_ms_; // Used as lower bound for target delay.
|
||||
int minimum_delay_ms_; // Externally set minimum delay.
|
||||
int maximum_delay_ms_; // Externally set maximum allowed delay.
|
||||
|
||||
// Time elapsed since last packet.
|
||||
std::unique_ptr<TickTimer::Stopwatch> packet_iat_stopwatch_;
|
||||
int base_target_level_; // Currently preferred buffer level before peak
|
||||
// detection and streaming mode (Q0).
|
||||
// TODO(turajs) change the comment according to the implementation of
|
||||
// minimum-delay.
|
||||
int target_level_; // Currently preferred buffer level in (fractions)
|
||||
// of packets (Q8), before adding any extra delay.
|
||||
int packet_len_ms_; // Length of audio in each incoming packet [ms].
|
||||
uint16_t last_seq_no_; // Sequence number for last received packet.
|
||||
uint32_t last_timestamp_; // Timestamp for the last received packet.
|
||||
int minimum_delay_ms_; // Externally set minimum delay.
|
||||
int maximum_delay_ms_; // Externally set maximum allowed delay.
|
||||
int last_pack_cng_or_dtmf_;
|
||||
const bool enable_rtx_handling_;
|
||||
int num_reordered_packets_ = 0; // Number of consecutive reordered packets.
|
||||
int packet_len_ms_ = 0;
|
||||
std::unique_ptr<TickTimer::Stopwatch>
|
||||
packet_iat_stopwatch_; // Time elapsed since last packet.
|
||||
int target_level_ms_; // Currently preferred buffer level.
|
||||
uint32_t last_timestamp_; // Timestamp for the last received packet.
|
||||
|
||||
struct PacketDelay {
|
||||
int iat_delay_ms;
|
||||
|
||||
Reference in New Issue
Block a user