2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_
|
|
|
|
|
#define MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <string.h> // Provide access to size_t.
|
|
|
|
|
|
2019-02-27 10:08:09 +01:00
|
|
|
#include <deque>
|
2016-04-28 23:19:20 -07:00
|
|
|
#include <memory>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-10-04 11:31:03 +02:00
|
|
|
#include "absl/types/optional.h"
|
2024-08-13 15:28:50 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2019-10-31 14:38:11 +01:00
|
|
|
#include "api/neteq/tick_timer.h"
|
2019-02-21 15:42:31 +01:00
|
|
|
#include "modules/audio_coding/neteq/histogram.h"
|
2021-09-08 16:35:50 +02:00
|
|
|
#include "modules/audio_coding/neteq/reorder_optimizer.h"
|
2021-09-07 14:24:56 +02:00
|
|
|
#include "modules/audio_coding/neteq/underrun_optimizer.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class DelayManager {
|
|
|
|
|
public:
|
2021-09-07 14:24:56 +02:00
|
|
|
struct Config {
|
2024-08-13 15:28:50 +02:00
|
|
|
explicit Config(const FieldTrialsView& field_trials);
|
2021-09-07 14:24:56 +02:00
|
|
|
void Log();
|
|
|
|
|
|
|
|
|
|
// Options that can be configured via field trial.
|
2021-11-09 12:58:45 +01:00
|
|
|
double quantile = 0.95;
|
|
|
|
|
double forget_factor = 0.983;
|
2021-09-07 14:24:56 +02:00
|
|
|
absl::optional<double> start_forget_weight = 2;
|
2021-11-09 12:58:45 +01:00
|
|
|
absl::optional<int> resample_interval_ms = 500;
|
2021-09-07 14:24:56 +02:00
|
|
|
|
2021-09-08 16:35:50 +02:00
|
|
|
bool use_reorder_optimizer = true;
|
|
|
|
|
double reorder_forget_factor = 0.9993;
|
|
|
|
|
int ms_per_loss_percent = 20;
|
|
|
|
|
|
2021-09-07 14:24:56 +02:00
|
|
|
// Options that are externally populated.
|
|
|
|
|
int max_packets_in_buffer = 200;
|
|
|
|
|
int base_minimum_delay_ms = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DelayManager(const Config& config, const TickTimer* tick_timer);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2013-07-31 15:54:00 +00:00
|
|
|
virtual ~DelayManager();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
DelayManager(const DelayManager&) = delete;
|
|
|
|
|
DelayManager& operator=(const DelayManager&) = delete;
|
|
|
|
|
|
2022-05-25 21:06:14 +02:00
|
|
|
// Updates the delay manager that a new packet arrived with delay
|
|
|
|
|
// `arrival_delay_ms`. This updates the statistics and a new target buffer
|
|
|
|
|
// level is calculated. The `reordered` flag indicates if the packet was
|
|
|
|
|
// reordered.
|
|
|
|
|
virtual void Update(int arrival_delay_ms, bool reordered);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2020-10-09 13:41:06 +02:00
|
|
|
// Resets all state.
|
2013-01-29 12:09:21 +00:00
|
|
|
virtual void Reset();
|
|
|
|
|
|
2022-07-19 16:33:10 +02:00
|
|
|
// Gets the target buffer level in milliseconds. If a minimum or maximum delay
|
|
|
|
|
// has been set, the target delay reported here also respects the configured
|
|
|
|
|
// min/max delay.
|
2020-10-09 13:41:06 +02:00
|
|
|
virtual int TargetDelayMs() const;
|
2020-10-07 12:46:42 +00:00
|
|
|
|
2022-07-19 16:33:10 +02:00
|
|
|
// Reports the target delay that would be used if no minimum/maximum delay
|
|
|
|
|
// would be set.
|
|
|
|
|
virtual int UnlimitedTargetLevelMs() const;
|
|
|
|
|
|
2020-10-09 13:41:06 +02:00
|
|
|
// Notifies the DelayManager of how much audio data is carried in each packet.
|
|
|
|
|
virtual int SetPacketAudioLength(int length_ms);
|
Handle padded audio packets correctly
RTP packets can be padded with extra data at the end of the payload. The usable
payload length of the packet should then be reduced with the padding length,
since the padding must be discarded. This was not the case; instead, the entire
payload, including padding data, was forwarded to the audio channel and in the
end to the decoder.
A special case of padding is packets which are empty except for the padding.
That is, they carry no usable payload. These packets are sometimes used for
probing the network and were discarded in
RTPReceiverAudio::ParseAudioCodecSpecific. The result is that NetEq never sees
those empty packets, just the holes in the sequence number series; this can
throw off the target buffer calculations.
With this change, the empty (after removing the padding) packets are let through,
all the way down to NetEq, to a new method called NetEq::InsertEmptyPacket. This
method notifies the DelayManager that an empty packet was received.
BUG=webrtc:7610, webrtc:7625
Review-Url: https://codereview.webrtc.org/2870043003
Cr-Commit-Position: refs/heads/master@{#18083}
2017-05-10 07:38:01 -07:00
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Accessors and mutators.
|
2021-07-28 20:00:17 +02:00
|
|
|
// Assuming `delay` is in valid range.
|
2013-08-16 23:44:24 +00:00
|
|
|
virtual bool SetMinimumDelay(int delay_ms);
|
|
|
|
|
virtual bool SetMaximumDelay(int delay_ms);
|
2019-02-04 16:17:31 +01:00
|
|
|
virtual bool SetBaseMinimumDelay(int delay_ms);
|
|
|
|
|
virtual int GetBaseMinimumDelay() const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2020-10-09 13:41:06 +02:00
|
|
|
// These accessors are only intended for testing purposes.
|
2019-02-13 14:25:39 +01:00
|
|
|
int effective_minimum_delay_ms_for_test() const {
|
|
|
|
|
return effective_minimum_delay_ms_;
|
|
|
|
|
}
|
2019-02-27 10:08:09 +01:00
|
|
|
|
2018-10-04 11:31:03 +02:00
|
|
|
private:
|
2019-02-13 14:25:39 +01:00
|
|
|
// Provides value which minimum delay can't exceed based on current buffer
|
2021-07-28 20:00:17 +02:00
|
|
|
// size and given `maximum_delay_ms_`. Lower bound is a constant 0.
|
2019-02-13 14:25:39 +01:00
|
|
|
int MinimumDelayUpperBound() const;
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Updates `effective_minimum_delay_ms_` delay based on current
|
|
|
|
|
// `minimum_delay_ms_`, `base_minimum_delay_ms_` and `maximum_delay_ms_`
|
2019-02-13 14:25:39 +01:00
|
|
|
// and buffer size.
|
|
|
|
|
void UpdateEffectiveMinimumDelay();
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// 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_`.
|
2019-02-13 14:25:39 +01:00
|
|
|
bool IsValidMinimumDelay(int delay_ms) const;
|
|
|
|
|
|
|
|
|
|
bool IsValidBaseMinimumDelay(int delay_ms) const;
|
2019-02-04 16:17:31 +01:00
|
|
|
|
2020-10-09 13:41:06 +02:00
|
|
|
// TODO(jakobi): set maximum buffer delay instead of number of packets.
|
|
|
|
|
const int max_packets_in_buffer_;
|
2021-09-07 14:24:56 +02:00
|
|
|
UnderrunOptimizer underrun_optimizer_;
|
2021-09-08 16:35:50 +02:00
|
|
|
std::unique_ptr<ReorderOptimizer> reorder_optimizer_;
|
2020-11-11 15:26:10 +01:00
|
|
|
|
2019-02-13 14:25:39 +01:00
|
|
|
int base_minimum_delay_ms_;
|
2020-10-09 13:41:06 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
int packet_len_ms_ = 0;
|
2022-07-19 16:33:10 +02:00
|
|
|
int target_level_ms_ = 0; // Currently preferred buffer level.
|
|
|
|
|
int unlimited_target_level_ms_ = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_
|