blob: 84c18a4ae199c2a41b01f4863223e65e6a709318 [file] [log] [blame]
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Stefan Holmer80e12072016-02-23 13:30:42 +010011#ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
12#define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000013
kwiberg84be5112016-04-27 01:19:58 -070014#include <memory>
15
kwiberg4485ffb2016-04-26 08:14:39 -070016#include "webrtc/base/constructormagic.h"
kwiberg6ab3db22016-05-11 05:07:26 -070017#include "webrtc/base/scoped_ptr.h"
pbos1ba8d392016-05-01 20:18:34 -070018#include "webrtc/common_types.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010019#include "webrtc/modules/include/module.h"
20#include "webrtc/modules/include/module_common_types.h"
21#include "webrtc/modules/pacing/packet_router.h"
perkjec81bcd2016-05-11 06:01:13 -070022#include "webrtc/modules/pacing/paced_sender.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010023#include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
24#include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000025
Stefan Holmer58c664c2016-02-08 14:31:30 +010026namespace rtc {
27struct SentPacket;
28}
29
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000030namespace webrtc {
31
mflodman0e7e2592015-11-12 21:02:42 -080032class BitrateController;
33class BitrateObserver;
Stefan Holmer58c664c2016-02-08 14:31:30 +010034class Clock;
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000035class ProcessThread;
andresp@webrtc.org29b22192013-05-14 12:10:58 +000036class RemoteBitrateEstimator;
Stefan Holmer58c664c2016-02-08 14:31:30 +010037class RemoteBitrateObserver;
mflodman0e7e2592015-11-12 21:02:42 -080038class TransportFeedbackObserver;
stefan@webrtc.orga50e6f02015-03-09 10:06:40 +000039
Stefan Holmer789ba922016-02-17 15:52:17 +010040class CongestionController : public CallStatsObserver, public Module {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000041 public:
perkjec81bcd2016-05-11 06:01:13 -070042 // Observer class for bitrate changes announced due to change in bandwidth
43 // estimate or due to that the send pacer is full. Fraction loss and rtt is
44 // also part of this callback to allow the observer to optimize its settings
45 // for different types of network environments. The bitrate does not include
46 // packet headers and is measured in bits per second.
47 class Observer {
48 public:
49 virtual void OnNetworkChanged(uint32_t bitrate_bps,
50 uint8_t fraction_loss, // 0 - 255.
51 int64_t rtt_ms) = 0;
52
53 protected:
54 virtual ~Observer() {}
55 };
56 // Deprecated
57 // TODO(perkj): Remove once no other clients use this ctor.
Stefan Holmer58c664c2016-02-08 14:31:30 +010058 CongestionController(Clock* clock,
perkj825eb582016-05-04 01:08:05 -070059 BitrateObserver* bitrate_observer,
Stefan Holmer58c664c2016-02-08 14:31:30 +010060 RemoteBitrateObserver* remote_bitrate_observer);
perkjec81bcd2016-05-11 06:01:13 -070061 CongestionController(Clock* clock,
62 Observer* observer,
63 RemoteBitrateObserver* remote_bitrate_observer);
64 CongestionController(Clock* clock,
65 Observer* observer,
66 RemoteBitrateObserver* remote_bitrate_observer,
67 std::unique_ptr<PacketRouter> packet_router,
68 std::unique_ptr<PacedSender> pacer);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010069 virtual ~CongestionController();
Stefan Holmer789ba922016-02-17 15:52:17 +010070
Stefan Holmer3842c5c2016-01-12 13:55:00 +010071 virtual void SetBweBitrates(int min_bitrate_bps,
72 int start_bitrate_bps,
73 int max_bitrate_bps);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010074 virtual void SignalNetworkState(NetworkState state);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010075 virtual BitrateController* GetBitrateController() const;
76 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
Stefan Holmer789ba922016-02-17 15:52:17 +010077 bool send_side_bwe);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010078 virtual int64_t GetPacerQueuingDelayMs() const;
Stefan Holmer789ba922016-02-17 15:52:17 +010079 virtual PacedSender* pacer() { return pacer_.get(); }
perkjec81bcd2016-05-11 06:01:13 -070080 virtual PacketRouter* packet_router() { return packet_router_.get(); }
Stefan Holmer3842c5c2016-01-12 13:55:00 +010081 virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000082
perkjec81bcd2016-05-11 06:01:13 -070083 void SetAllocatedSendBitrate(int allocated_bitrate_bps,
84 int padding_bitrate_bps);
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000085
Stefan Holmer3842c5c2016-01-12 13:55:00 +010086 virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
stefanc1aeaf02015-10-15 07:26:07 -070087
Stefan Holmer789ba922016-02-17 15:52:17 +010088 // Implements CallStatsObserver.
89 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
90
91 // Implements Module.
92 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -080093 void Process() override;
Stefan Holmer789ba922016-02-17 15:52:17 +010094
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000095 private:
perkjec81bcd2016-05-11 06:01:13 -070096 void Init();
97 void MaybeTriggerOnNetworkChanged();
perkjec81bcd2016-05-11 06:01:13 -070098
perkjfea93092016-05-14 00:58:48 -070099 bool IsSendQueueFull() const;
100 bool IsNetworkDown() const;
101 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps,
102 uint8_t fraction_loss,
103 int64_t rtt);
Stefan Holmer58c664c2016-02-08 14:31:30 +0100104 Clock* const clock_;
perkjec81bcd2016-05-11 06:01:13 -0700105 Observer* const observer_;
106 const std::unique_ptr<PacketRouter> packet_router_;
kwiberg84be5112016-04-27 01:19:58 -0700107 const std::unique_ptr<PacedSender> pacer_;
108 const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
109 const std::unique_ptr<BitrateController> bitrate_controller_;
Stefan Holmer789ba922016-02-17 15:52:17 +0100110 RemoteEstimatorProxy remote_estimator_proxy_;
111 TransportFeedbackAdapter transport_feedback_adapter_;
stefan4fbd1452015-09-28 03:57:14 -0700112 int min_bitrate_bps_;
perkjec81bcd2016-05-11 06:01:13 -0700113 rtc::CriticalSection critsect_;
perkjfea93092016-05-14 00:58:48 -0700114 uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_);
115 uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_);
116 int64_t last_reported_rtt_ GUARDED_BY(critsect_);
117 NetworkState network_state_ GUARDED_BY(critsect_);
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100118
119 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000120};
121
122} // namespace webrtc
123
Stefan Holmer80e12072016-02-23 13:30:42 +0100124#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_