2012-03-05 17:12:41 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-23 13:30:42 +01:00
|
|
|
#ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
|
|
|
|
|
#define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
|
2012-03-05 17:12:41 +00:00
|
|
|
|
2016-04-27 01:19:58 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2016-04-26 08:14:39 -07:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
2016-05-01 20:18:34 -07:00
|
|
|
#include "webrtc/common_types.h"
|
2016-02-17 15:52:17 +01:00
|
|
|
#include "webrtc/modules/include/module.h"
|
|
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
|
|
|
|
#include "webrtc/modules/pacing/packet_router.h"
|
2016-05-11 06:01:13 -07:00
|
|
|
#include "webrtc/modules/pacing/paced_sender.h"
|
2016-02-17 15:52:17 +01:00
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
|
|
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
|
2012-03-05 17:12:41 +00:00
|
|
|
|
2016-02-08 14:31:30 +01:00
|
|
|
namespace rtc {
|
|
|
|
|
struct SentPacket;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-05 17:12:41 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-11-12 21:02:42 -08:00
|
|
|
class BitrateController;
|
2016-02-08 14:31:30 +01:00
|
|
|
class Clock;
|
2012-03-05 17:12:41 +00:00
|
|
|
class ProcessThread;
|
2016-07-13 09:11:28 -07:00
|
|
|
class RateLimiter;
|
2013-05-14 12:10:58 +00:00
|
|
|
class RemoteBitrateEstimator;
|
2016-02-08 14:31:30 +01:00
|
|
|
class RemoteBitrateObserver;
|
2016-07-04 07:06:55 -07:00
|
|
|
class RtcEventLog;
|
2015-11-12 21:02:42 -08:00
|
|
|
class TransportFeedbackObserver;
|
2015-03-09 10:06:40 +00:00
|
|
|
|
2016-02-17 15:52:17 +01:00
|
|
|
class CongestionController : public CallStatsObserver, public Module {
|
2012-03-05 17:12:41 +00:00
|
|
|
public:
|
2016-05-11 06:01:13 -07:00
|
|
|
// Observer class for bitrate changes announced due to change in bandwidth
|
|
|
|
|
// estimate or due to that the send pacer is full. Fraction loss and rtt is
|
|
|
|
|
// also part of this callback to allow the observer to optimize its settings
|
|
|
|
|
// for different types of network environments. The bitrate does not include
|
|
|
|
|
// packet headers and is measured in bits per second.
|
|
|
|
|
class Observer {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnNetworkChanged(uint32_t bitrate_bps,
|
|
|
|
|
uint8_t fraction_loss, // 0 - 255.
|
|
|
|
|
int64_t rtt_ms) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~Observer() {}
|
|
|
|
|
};
|
|
|
|
|
CongestionController(Clock* clock,
|
|
|
|
|
Observer* observer,
|
2016-07-04 07:06:55 -07:00
|
|
|
RemoteBitrateObserver* remote_bitrate_observer,
|
|
|
|
|
RtcEventLog* event_log);
|
2016-05-11 06:01:13 -07:00
|
|
|
CongestionController(Clock* clock,
|
|
|
|
|
Observer* observer,
|
|
|
|
|
RemoteBitrateObserver* remote_bitrate_observer,
|
2016-07-04 07:06:55 -07:00
|
|
|
RtcEventLog* event_log,
|
2016-05-11 06:01:13 -07:00
|
|
|
std::unique_ptr<PacketRouter> packet_router,
|
|
|
|
|
std::unique_ptr<PacedSender> pacer);
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual ~CongestionController();
|
2016-02-17 15:52:17 +01:00
|
|
|
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual void SetBweBitrates(int min_bitrate_bps,
|
|
|
|
|
int start_bitrate_bps,
|
|
|
|
|
int max_bitrate_bps);
|
2016-06-24 11:03:55 -07:00
|
|
|
// Resets both the BWE state and the bitrate estimator. Note the first
|
|
|
|
|
// argument is the bitrate_bps.
|
|
|
|
|
virtual void ResetBweAndBitrates(int bitrate_bps,
|
|
|
|
|
int min_bitrate_bps,
|
|
|
|
|
int max_bitrate_bps);
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual void SignalNetworkState(NetworkState state);
|
|
|
|
|
virtual BitrateController* GetBitrateController() const;
|
|
|
|
|
virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
|
2016-02-17 15:52:17 +01:00
|
|
|
bool send_side_bwe);
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual int64_t GetPacerQueuingDelayMs() const;
|
2016-02-17 15:52:17 +01:00
|
|
|
virtual PacedSender* pacer() { return pacer_.get(); }
|
2016-05-11 06:01:13 -07:00
|
|
|
virtual PacketRouter* packet_router() { return packet_router_.get(); }
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
|
2016-07-13 09:11:28 -07:00
|
|
|
RateLimiter* GetRetransmissionRateLimiter();
|
2012-04-27 05:25:53 +00:00
|
|
|
|
2016-06-15 00:47:53 -07:00
|
|
|
// SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec
|
|
|
|
|
// settings.
|
|
|
|
|
// |min_send_bitrate_bps| is the total minimum send bitrate required by all
|
|
|
|
|
// sending streams. This is the minimum bitrate the PacedSender will use.
|
|
|
|
|
// Note that CongestionController::OnNetworkChanged can still be called with
|
|
|
|
|
// a lower bitrate estimate.
|
|
|
|
|
// |max_padding_bitrate_bps| is the max bitrate the send streams request for
|
|
|
|
|
// padding. This can be higher than the current network estimate and tells
|
|
|
|
|
// the PacedSender how much it should max pad unless there is real packets to
|
|
|
|
|
// send.
|
|
|
|
|
void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps,
|
|
|
|
|
int max_padding_bitrate_bps);
|
2015-03-04 12:24:26 +00:00
|
|
|
|
2016-01-12 13:55:00 +01:00
|
|
|
virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
|
2015-10-15 07:26:07 -07:00
|
|
|
|
2016-02-17 15:52:17 +01:00
|
|
|
// Implements CallStatsObserver.
|
|
|
|
|
void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
|
2015-10-21 13:24:28 +02:00
|
|
|
|
2016-02-17 15:52:17 +01:00
|
|
|
// Implements Module.
|
|
|
|
|
int64_t TimeUntilNextProcess() override;
|
2016-02-25 04:50:01 -08:00
|
|
|
void Process() override;
|
2015-03-26 11:11:06 +01:00
|
|
|
|
2016-02-17 15:52:17 +01:00
|
|
|
private:
|
2016-05-11 06:01:13 -07:00
|
|
|
void Init();
|
|
|
|
|
void MaybeTriggerOnNetworkChanged();
|
|
|
|
|
|
2016-05-14 00:58:48 -07:00
|
|
|
bool IsSendQueueFull() const;
|
|
|
|
|
bool IsNetworkDown() const;
|
|
|
|
|
bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps,
|
|
|
|
|
uint8_t fraction_loss,
|
|
|
|
|
int64_t rtt);
|
2016-02-17 15:52:17 +01:00
|
|
|
Clock* const clock_;
|
2016-05-11 06:01:13 -07:00
|
|
|
Observer* const observer_;
|
|
|
|
|
const std::unique_ptr<PacketRouter> packet_router_;
|
2016-04-27 01:19:58 -07:00
|
|
|
const std::unique_ptr<PacedSender> pacer_;
|
|
|
|
|
const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
|
|
|
|
|
const std::unique_ptr<BitrateController> bitrate_controller_;
|
2016-07-13 09:11:28 -07:00
|
|
|
const std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
|
2016-02-17 15:52:17 +01:00
|
|
|
RemoteEstimatorProxy remote_estimator_proxy_;
|
|
|
|
|
TransportFeedbackAdapter transport_feedback_adapter_;
|
2015-09-28 03:57:14 -07:00
|
|
|
int min_bitrate_bps_;
|
2016-05-11 06:01:13 -07:00
|
|
|
rtc::CriticalSection critsect_;
|
2016-05-14 00:58:48 -07:00
|
|
|
uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_);
|
|
|
|
|
uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_);
|
|
|
|
|
int64_t last_reported_rtt_ GUARDED_BY(critsect_);
|
|
|
|
|
NetworkState network_state_ GUARDED_BY(critsect_);
|
2016-01-12 13:55:00 +01:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
|
2012-03-05 17:12:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-02-23 13:30:42 +01:00
|
|
|
#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
|