2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-05-25 10:12:42 +02:00
|
|
|
#ifndef MODULES_VIDEO_CODING_TIMING_JITTER_ESTIMATOR_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_TIMING_JITTER_ESTIMATOR_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-03-07 13:21:51 +01:00
|
|
|
#include "absl/types/optional.h"
|
2022-03-29 11:04:48 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2022-03-07 13:21:51 +01:00
|
|
|
#include "api/units/data_size.h"
|
|
|
|
|
#include "api/units/frequency.h"
|
|
|
|
|
#include "api/units/time_delta.h"
|
|
|
|
|
#include "api/units/timestamp.h"
|
2022-09-02 16:12:22 +02:00
|
|
|
#include "modules/video_coding/timing/frame_delay_variation_kalman_filter.h"
|
2022-05-23 09:53:15 +02:00
|
|
|
#include "modules/video_coding/timing/rtt_filter.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/rolling_accumulator.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-09-24 14:06:56 +00:00
|
|
|
class Clock;
|
|
|
|
|
|
2022-05-25 10:12:42 +02:00
|
|
|
class JitterEstimator {
|
2015-12-21 04:12:39 -08:00
|
|
|
public:
|
2022-05-25 10:12:42 +02:00
|
|
|
explicit JitterEstimator(Clock* clock, const FieldTrialsView& field_trials);
|
2022-08-12 16:39:25 +02:00
|
|
|
~JitterEstimator();
|
2022-05-25 10:12:42 +02:00
|
|
|
JitterEstimator(const JitterEstimator&) = delete;
|
|
|
|
|
JitterEstimator& operator=(const JitterEstimator&) = delete;
|
2015-12-21 04:12:39 -08:00
|
|
|
|
2019-04-04 09:40:27 +02:00
|
|
|
// Resets the estimate to the initial state.
|
2015-12-21 04:12:39 -08:00
|
|
|
void Reset();
|
|
|
|
|
|
|
|
|
|
// Updates the jitter estimate with the new data.
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
2022-03-07 13:21:51 +01:00
|
|
|
// - frame_delay : Delay-delta calculated by UTILDelayEstimate.
|
|
|
|
|
// - frame_size : Frame size of the current frame.
|
2022-07-05 14:03:25 +02:00
|
|
|
void UpdateEstimate(TimeDelta frame_delay, DataSize frame_size);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
2022-03-07 13:21:51 +01:00
|
|
|
// Returns the current jitter estimate and adds an RTT dependent term in cases
|
|
|
|
|
// of retransmission.
|
2015-12-21 04:12:39 -08:00
|
|
|
// Input:
|
2022-03-07 13:21:51 +01:00
|
|
|
// - rtt_multiplier : RTT param multiplier (when applicable).
|
|
|
|
|
// - rtt_mult_add_cap : Multiplier cap from the RTTMultExperiment.
|
2015-12-21 04:12:39 -08:00
|
|
|
//
|
2022-03-07 13:21:51 +01:00
|
|
|
// Return value : Jitter estimate.
|
2022-08-12 16:39:25 +02:00
|
|
|
TimeDelta GetJitterEstimate(double rtt_multiplier,
|
|
|
|
|
absl::optional<TimeDelta> rtt_mult_add_cap);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
// Updates the nack counter.
|
|
|
|
|
void FrameNacked();
|
|
|
|
|
|
|
|
|
|
// Updates the RTT filter.
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
2022-03-07 13:21:51 +01:00
|
|
|
// - rtt : Round trip time.
|
|
|
|
|
void UpdateRtt(TimeDelta rtt);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
private:
|
2019-04-04 09:40:27 +02:00
|
|
|
// Updates the random jitter estimate, i.e. the variance of the time
|
|
|
|
|
// deviations from the line given by the Kalman filter.
|
2015-12-21 04:12:39 -08:00
|
|
|
//
|
|
|
|
|
// Input:
|
2019-04-04 09:40:27 +02:00
|
|
|
// - d_dT : The deviation from the kalman estimate.
|
2022-07-05 14:03:25 +02:00
|
|
|
void EstimateRandomJitter(double d_dT);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
double NoiseThreshold() const;
|
|
|
|
|
|
|
|
|
|
// Calculates the current jitter estimate.
|
|
|
|
|
//
|
2022-03-07 13:21:51 +01:00
|
|
|
// Return value : The current jitter estimate.
|
|
|
|
|
TimeDelta CalculateEstimate();
|
2015-12-21 04:12:39 -08:00
|
|
|
|
2019-04-04 09:40:27 +02:00
|
|
|
// Post process the calculated estimate.
|
2015-12-21 04:12:39 -08:00
|
|
|
void PostProcessEstimate();
|
|
|
|
|
|
2022-09-05 09:37:58 +02:00
|
|
|
// Returns the estimated incoming frame rate.
|
2022-03-07 13:21:51 +01:00
|
|
|
Frequency GetFrameRate() const;
|
|
|
|
|
|
2022-08-09 14:40:05 +02:00
|
|
|
// Filters the {frame_delay_delta, frame_size_delta} measurements through
|
|
|
|
|
// a linear Kalman filter.
|
2022-09-02 16:12:22 +02:00
|
|
|
FrameDelayVariationKalmanFilter kalman_filter_;
|
2022-03-07 13:21:51 +01:00
|
|
|
|
2022-08-19 13:23:26 +02:00
|
|
|
// TODO(bugs.webrtc.org/14381): Update `avg_frame_size_bytes_` to DataSize
|
|
|
|
|
// when api/units have sufficient precision.
|
|
|
|
|
double avg_frame_size_bytes_; // Average frame size
|
2022-09-05 09:37:58 +02:00
|
|
|
double var_frame_size_bytes2_; // Frame size variance. Unit is bytes^2.
|
2022-03-07 13:21:51 +01:00
|
|
|
// Largest frame size received (descending with a factor kPsi)
|
2022-08-19 13:23:26 +02:00
|
|
|
// TODO(bugs.webrtc.org/14381): Update `max_frame_size_bytes_` to DataSize
|
|
|
|
|
// when api/units have sufficient precision.
|
|
|
|
|
double max_frame_size_bytes_;
|
2022-09-05 09:37:58 +02:00
|
|
|
// TODO(bugs.webrtc.org/14381): Update `startup_frame_size_sum_bytes_` to
|
|
|
|
|
// DataSize when api/units have sufficient precision.
|
|
|
|
|
double startup_frame_size_sum_bytes_;
|
|
|
|
|
size_t startup_frame_size_count_;
|
2022-03-07 13:21:51 +01:00
|
|
|
|
|
|
|
|
absl::optional<Timestamp> last_update_time_;
|
|
|
|
|
// The previously returned jitter estimate
|
|
|
|
|
absl::optional<TimeDelta> prev_estimate_;
|
|
|
|
|
// Frame size of the previous frame
|
|
|
|
|
absl::optional<DataSize> prev_frame_size_;
|
2022-09-05 09:37:58 +02:00
|
|
|
// Average of the random jitter. Unit is milliseconds.
|
|
|
|
|
double avg_noise_ms_;
|
|
|
|
|
// Variance of the time-deviation from the line. Unit is milliseconds^2.
|
|
|
|
|
double var_noise_ms2_;
|
|
|
|
|
size_t alpha_count_;
|
2022-03-07 13:21:51 +01:00
|
|
|
// The filtered sum of jitter estimates
|
|
|
|
|
TimeDelta filter_jitter_estimate_ = TimeDelta::Zero();
|
|
|
|
|
|
2022-09-05 09:37:58 +02:00
|
|
|
size_t startup_count_;
|
2022-03-07 13:21:51 +01:00
|
|
|
// Time when the latest nack was seen
|
|
|
|
|
Timestamp latest_nack_ = Timestamp::Zero();
|
|
|
|
|
// Keeps track of the number of nacks received, but never goes above
|
|
|
|
|
// kNackLimit.
|
2022-09-05 09:37:58 +02:00
|
|
|
size_t nack_count_;
|
2022-05-23 09:53:15 +02:00
|
|
|
RttFilter rtt_filter_;
|
2022-03-07 13:21:51 +01:00
|
|
|
|
|
|
|
|
// Tracks frame rates in microseconds.
|
2015-12-21 04:12:39 -08:00
|
|
|
rtc::RollingAccumulator<uint64_t> fps_counter_;
|
2019-01-30 11:28:59 +01:00
|
|
|
Clock* clock_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-05-25 10:12:42 +02:00
|
|
|
#endif // MODULES_VIDEO_CODING_TIMING_JITTER_ESTIMATOR_H_
|