blob: 7400d7d032b6f1607a83f7264467efb0967c3761 [file] [log] [blame]
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +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 * Usage: this class will register multiple RtcpBitrateObserver's one at each
11 * RTCP module. It will aggregate the results and run one bandwidth estimation
12 * and push the result to the encoders via BitrateObserver(s).
13 */
14
15#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
16#define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
17
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000018#include <map>
19
stefanfd0d4262016-09-29 02:44:31 -070020#include "webrtc/modules/congestion_controller/delay_based_bwe.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/include/module.h"
perkjec81bcd2016-05-11 06:01:13 -070022#include "webrtc/modules/pacing/paced_sender.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010023#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000024
25namespace webrtc {
26
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000027class CriticalSectionWrapper;
terelius006d93d2015-11-05 12:02:15 -080028class RtcEventLog;
sprang867fb522015-08-03 04:38:41 -070029struct PacketInfo;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000030
perkjec81bcd2016-05-11 06:01:13 -070031// Deprecated
32// TODO(perkj): Remove BitrateObserver when no implementations use it.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000033class BitrateObserver {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000034 // Observer class for bitrate changes announced due to change in bandwidth
35 // estimate or due to bitrate allocation changes. Fraction loss and rtt is
36 // also part of this callback to allow the obsevrer to optimize its settings
37 // for different types of network environments. The bitrate does not include
38 // packet headers and is measured in bits per second.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000039 public:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000040 virtual void OnNetworkChanged(uint32_t bitrate_bps,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000041 uint8_t fraction_loss, // 0 - 255.
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000042 int64_t rtt_ms) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000043
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000044 virtual ~BitrateObserver() {}
45};
46
stefanfd0d4262016-09-29 02:44:31 -070047class BitrateController : public Module {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000048 // This class collects feedback from all streams sent to a peer (via
49 // RTCPBandwidthObservers). It does one aggregated send side bandwidth
50 // estimation and divide the available bitrate between all its registered
51 // BitrateObservers.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000052 public:
perkjec81bcd2016-05-11 06:01:13 -070053 static const int kDefaultStartBitratebps = 300000;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000054
perkjec81bcd2016-05-11 06:01:13 -070055 // Deprecated:
56 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC.
57 // Remove this method once other other projects does not use it.
andresp@webrtc.org44caf012014-03-26 21:00:21 +000058 static BitrateController* CreateBitrateController(Clock* clock,
ivoc14d5dbe2016-07-04 07:06:55 -070059 BitrateObserver* observer,
60 RtcEventLog* event_log);
61
62 static BitrateController* CreateBitrateController(Clock* clock,
63 RtcEventLog* event_log);
perkjec81bcd2016-05-11 06:01:13 -070064
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000065 virtual ~BitrateController() {}
66
67 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
68
philipelc6957c72016-04-28 15:52:49 +020069 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000070 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020071 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000072 virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020073 virtual void SetBitrates(int start_bitrate_bps,
74 int min_bitrate_bps,
75 int max_bitrate_bps) = 0;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000076
honghaiz059e1832016-06-24 11:03:55 -070077 virtual void ResetBitrates(int bitrate_bps,
78 int min_bitrate_bps,
79 int max_bitrate_bps) = 0;
80
stefanfd0d4262016-09-29 02:44:31 -070081 virtual void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) = 0;
82
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000083 // Gets the available payload bandwidth in bits per second. Note that
84 // this bandwidth excludes packet headers.
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000085 virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
86
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000087 virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0;
perkjec81bcd2016-05-11 06:01:13 -070088
89 virtual bool GetNetworkParameters(uint32_t* bitrate,
90 uint8_t* fraction_loss,
91 int64_t* rtt) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000092};
93} // namespace webrtc
94#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_