2012-04-19 12:13:52 +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.
|
|
|
|
|
*
|
|
|
|
|
* FEC and NACK added bitrate is handled outside class
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
|
|
|
|
|
#define MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
2014-03-26 21:00:21 +00:00
|
|
|
#include <deque>
|
2016-01-24 23:05:21 -08:00
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
2014-03-26 21:00:21 +00:00
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
#include "absl/types/optional.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "api/transport/network_types.h"
|
|
|
|
|
#include "api/units/data_rate.h"
|
|
|
|
|
#include "api/units/time_delta.h"
|
|
|
|
|
#include "api/units/timestamp.h"
|
2018-11-19 15:30:23 +01:00
|
|
|
#include "modules/bitrate_controller/loss_based_bandwidth_estimation.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
2018-10-08 12:49:53 +02:00
|
|
|
#include "rtc_base/experiments/field_trial_parser.h"
|
2012-04-19 12:13:52 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2015-11-05 12:02:15 -08:00
|
|
|
|
|
|
|
|
class RtcEventLog;
|
|
|
|
|
|
2018-11-23 14:49:18 +01:00
|
|
|
class LinkCapacityTracker {
|
|
|
|
|
public:
|
|
|
|
|
LinkCapacityTracker();
|
|
|
|
|
~LinkCapacityTracker();
|
|
|
|
|
void OnOveruse(DataRate acknowledged_rate, Timestamp at_time);
|
|
|
|
|
void OnStartingRate(DataRate start_rate);
|
|
|
|
|
void OnRateUpdate(DataRate acknowledged, Timestamp at_time);
|
|
|
|
|
void OnRttBackoff(DataRate backoff_rate, Timestamp at_time);
|
|
|
|
|
DataRate estimate() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FieldTrialParameter<TimeDelta> tracking_rate;
|
|
|
|
|
double capacity_estimate_bps_ = 0;
|
|
|
|
|
Timestamp last_link_capacity_update_ = Timestamp::MinusInfinity();
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-14 14:19:45 +01:00
|
|
|
class RttBasedBackoff {
|
|
|
|
|
public:
|
|
|
|
|
RttBasedBackoff();
|
|
|
|
|
~RttBasedBackoff();
|
|
|
|
|
void OnRouteChange();
|
|
|
|
|
void UpdatePropagationRtt(Timestamp at_time, TimeDelta propagation_rtt);
|
2019-02-08 11:00:10 +01:00
|
|
|
TimeDelta CorrectedRtt(Timestamp at_time) const;
|
2018-11-14 14:19:45 +01:00
|
|
|
|
|
|
|
|
FieldTrialParameter<TimeDelta> rtt_limit_;
|
|
|
|
|
FieldTrialParameter<double> drop_fraction_;
|
|
|
|
|
FieldTrialParameter<TimeDelta> drop_interval_;
|
|
|
|
|
FieldTrialFlag persist_on_route_change_;
|
2019-02-08 11:00:10 +01:00
|
|
|
FieldTrialParameter<bool> safe_timeout_;
|
2018-11-14 14:19:45 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Timestamp last_propagation_rtt_update_;
|
|
|
|
|
TimeDelta last_propagation_rtt_;
|
2019-02-08 11:00:10 +01:00
|
|
|
Timestamp last_packet_sent_;
|
2018-10-08 12:49:53 +02:00
|
|
|
};
|
|
|
|
|
|
2012-04-19 12:13:52 +00:00
|
|
|
class SendSideBandwidthEstimation {
|
|
|
|
|
public:
|
2016-07-04 07:06:55 -07:00
|
|
|
SendSideBandwidthEstimation() = delete;
|
|
|
|
|
explicit SendSideBandwidthEstimation(RtcEventLog* event_log);
|
2018-10-08 12:49:53 +02:00
|
|
|
~SendSideBandwidthEstimation();
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2018-11-14 14:19:45 +01:00
|
|
|
void OnRouteChange();
|
2015-03-26 11:11:06 +01:00
|
|
|
void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const;
|
2018-11-23 14:49:18 +01:00
|
|
|
DataRate GetEstimatedLinkCapacity() const;
|
2014-03-26 21:00:21 +00:00
|
|
|
// Call periodically to update estimate.
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateEstimate(Timestamp at_time);
|
2019-02-08 11:00:10 +01:00
|
|
|
void OnSentPacket(const SentPacket& sent_packet);
|
2018-11-14 14:19:45 +01:00
|
|
|
void UpdatePropagationRtt(Timestamp at_time, TimeDelta propagation_rtt);
|
2014-03-26 21:00:21 +00:00
|
|
|
|
2014-03-21 16:51:01 +00:00
|
|
|
// Call when we receive a RTCP message with TMMBR or REMB.
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateReceiverEstimate(Timestamp at_time, DataRate bandwidth);
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2016-01-20 07:13:58 -08:00
|
|
|
// Call when a new delay-based estimate is available.
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateDelayBasedEstimate(Timestamp at_time, DataRate bitrate);
|
2016-01-20 07:13:58 -08:00
|
|
|
|
2014-03-21 16:51:01 +00:00
|
|
|
// Call when we receive a RTCP message with a ReceiveBlock.
|
|
|
|
|
void UpdateReceiverBlock(uint8_t fraction_loss,
|
2018-10-08 11:00:50 +02:00
|
|
|
TimeDelta rtt_ms,
|
2014-03-21 16:51:01 +00:00
|
|
|
int number_of_packets,
|
2018-10-08 11:00:50 +02:00
|
|
|
Timestamp at_time);
|
2014-03-21 16:51:01 +00:00
|
|
|
|
2018-02-20 10:46:39 +01:00
|
|
|
// Call when we receive a RTCP message with a ReceiveBlock.
|
|
|
|
|
void UpdatePacketsLost(int packets_lost,
|
|
|
|
|
int number_of_packets,
|
2018-10-08 11:00:50 +02:00
|
|
|
Timestamp at_time);
|
2018-02-20 10:46:39 +01:00
|
|
|
|
|
|
|
|
// Call when we receive a RTCP message with a ReceiveBlock.
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateRtt(TimeDelta rtt, Timestamp at_time);
|
|
|
|
|
|
|
|
|
|
void SetBitrates(absl::optional<DataRate> send_bitrate,
|
|
|
|
|
DataRate min_bitrate,
|
|
|
|
|
DataRate max_bitrate,
|
|
|
|
|
Timestamp at_time);
|
|
|
|
|
void SetSendBitrate(DataRate bitrate, Timestamp at_time);
|
|
|
|
|
void SetMinMaxBitrate(DataRate min_bitrate, DataRate max_bitrate);
|
2015-03-26 11:11:06 +01:00
|
|
|
int GetMinBitrate() const;
|
2018-11-23 14:49:18 +01:00
|
|
|
void SetAcknowledgedRate(absl::optional<DataRate> acknowledged_rate,
|
|
|
|
|
Timestamp at_time);
|
|
|
|
|
void IncomingPacketFeedbackVector(const TransportPacketsFeedback& report);
|
2012-04-19 12:13:52 +00:00
|
|
|
|
|
|
|
|
private:
|
2014-11-04 19:32:10 +00:00
|
|
|
enum UmaState { kNoUpdate, kFirstDone, kDone };
|
|
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
bool IsInStartPhase(Timestamp at_time) const;
|
2014-11-03 14:42:43 +00:00
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateUmaStatsPacketsLost(Timestamp at_time, int packets_lost);
|
2014-11-04 19:32:10 +00:00
|
|
|
|
2014-03-26 21:00:21 +00:00
|
|
|
// Updates history of min bitrates.
|
|
|
|
|
// After this method returns min_bitrate_history_.front().second contains the
|
|
|
|
|
// min bitrate used during last kBweIncreaseIntervalMs.
|
2018-10-08 11:00:50 +02:00
|
|
|
void UpdateMinHistory(Timestamp at_time);
|
2014-03-26 21:00:21 +00:00
|
|
|
|
2018-11-19 15:30:23 +01:00
|
|
|
DataRate MaybeRampupOrBackoff(DataRate new_bitrate, Timestamp at_time);
|
|
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
// Cap |bitrate| to [min_bitrate_configured_, max_bitrate_configured_] and
|
|
|
|
|
// set |current_bitrate_| to the capped value and updates the event log.
|
|
|
|
|
void CapBitrateToThresholds(Timestamp at_time, DataRate bitrate);
|
2017-04-18 06:55:32 -07:00
|
|
|
|
2018-11-14 14:19:45 +01:00
|
|
|
RttBasedBackoff rtt_backoff_;
|
2018-11-23 14:49:18 +01:00
|
|
|
LinkCapacityTracker link_capacity_;
|
2018-10-08 12:49:53 +02:00
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
std::deque<std::pair<Timestamp, DataRate> > min_bitrate_history_;
|
2014-03-26 21:00:21 +00:00
|
|
|
|
2012-04-19 12:13:52 +00:00
|
|
|
// incoming filters
|
2018-02-20 10:46:39 +01:00
|
|
|
int lost_packets_since_last_loss_update_;
|
2015-10-22 08:52:20 -07:00
|
|
|
int expected_packets_since_last_loss_update_;
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2018-11-23 14:49:18 +01:00
|
|
|
absl::optional<DataRate> acknowledged_rate_;
|
2018-10-08 11:00:50 +02:00
|
|
|
DataRate current_bitrate_;
|
|
|
|
|
DataRate min_bitrate_configured_;
|
|
|
|
|
DataRate max_bitrate_configured_;
|
|
|
|
|
Timestamp last_low_bitrate_log_;
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2015-10-22 08:52:20 -07:00
|
|
|
bool has_decreased_since_last_fraction_loss_;
|
2018-10-08 11:00:50 +02:00
|
|
|
Timestamp last_loss_feedback_;
|
|
|
|
|
Timestamp last_loss_packet_report_;
|
|
|
|
|
Timestamp last_timeout_;
|
2012-04-19 12:13:52 +00:00
|
|
|
uint8_t last_fraction_loss_;
|
2016-09-04 05:07:26 -07:00
|
|
|
uint8_t last_logged_fraction_loss_;
|
2018-10-08 11:00:50 +02:00
|
|
|
TimeDelta last_round_trip_time_;
|
2012-04-19 12:13:52 +00:00
|
|
|
|
2018-10-08 11:00:50 +02:00
|
|
|
DataRate bwe_incoming_;
|
|
|
|
|
DataRate delay_based_bitrate_;
|
|
|
|
|
Timestamp time_last_decrease_;
|
|
|
|
|
Timestamp first_report_time_;
|
2014-11-03 14:42:43 +00:00
|
|
|
int initially_lost_packets_;
|
2018-10-08 11:00:50 +02:00
|
|
|
DataRate bitrate_at_2_seconds_;
|
2014-11-04 19:32:10 +00:00
|
|
|
UmaState uma_update_state_;
|
2018-02-20 10:46:39 +01:00
|
|
|
UmaState uma_rtt_state_;
|
2015-01-19 15:44:47 +00:00
|
|
|
std::vector<bool> rampup_uma_stats_updated_;
|
2015-11-05 12:02:15 -08:00
|
|
|
RtcEventLog* event_log_;
|
2018-10-08 11:00:50 +02:00
|
|
|
Timestamp last_rtc_event_log_;
|
2016-09-20 14:14:23 +02:00
|
|
|
bool in_timeout_experiment_;
|
2017-03-31 15:53:27 +02:00
|
|
|
float low_loss_threshold_;
|
|
|
|
|
float high_loss_threshold_;
|
2018-10-08 11:00:50 +02:00
|
|
|
DataRate bitrate_threshold_;
|
2018-11-19 15:30:23 +01:00
|
|
|
LossBasedBandwidthEstimation loss_based_bandwidth_estimation_;
|
2012-04-19 12:13:52 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
|