blob: 3e11fa76a3241de6089e8e2a3410c0c865f09d61 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#ifndef MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
16#define MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000017
Yves Gerey988cc082018-10-23 12:03:01 +020018#include <stddef.h>
19#include <stdint.h>
gnisha36165c2017-08-20 09:19:58 -070020
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020021#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/include/module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Yves Gerey988cc082018-10-23 12:03:01 +020024#include "rtc_base/deprecation.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000025
26namespace webrtc {
27
Yves Gerey988cc082018-10-23 12:03:01 +020028class Clock;
terelius006d93d2015-11-05 12:02:15 -080029class RtcEventLog;
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;
gnisha36165c2017-08-20 09:19:58 -070043 // TODO(gnish): Merge these two into one function.
44 virtual void OnNetworkChanged(uint32_t bitrate_for_encoder_bps,
45 uint32_t bitrate_for_pacer_bps,
46 bool in_probe_rtt,
47 int64_t target_set_time,
48 uint64_t congestion_window) {}
49 virtual void OnBytesAcked(size_t bytes) {}
Mirko Bonadei64f813e2018-07-18 15:37:01 +020050 virtual size_t pacer_queue_size_in_bytes();
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000051 virtual ~BitrateObserver() {}
52};
53
gnisha36165c2017-08-20 09:19:58 -070054class BitrateController : public Module, public RtcpBandwidthObserver {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000055 // This class collects feedback from all streams sent to a peer (via
56 // RTCPBandwidthObservers). It does one aggregated send side bandwidth
57 // estimation and divide the available bitrate between all its registered
58 // BitrateObservers.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000059 public:
perkjec81bcd2016-05-11 06:01:13 -070060 static const int kDefaultStartBitratebps = 300000;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000061
perkjec81bcd2016-05-11 06:01:13 -070062 // Deprecated:
63 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC.
64 // Remove this method once other other projects does not use it.
elad.alon61ce37e2017-03-09 07:09:31 -080065 static BitrateController* CreateBitrateController(const Clock* clock,
ivoc14d5dbe2016-07-04 07:06:55 -070066 BitrateObserver* observer,
67 RtcEventLog* event_log);
68
elad.alon61ce37e2017-03-09 07:09:31 -080069 static BitrateController* CreateBitrateController(const Clock* clock,
ivoc14d5dbe2016-07-04 07:06:55 -070070 RtcEventLog* event_log);
perkjec81bcd2016-05-11 06:01:13 -070071
Mirko Bonadei64f813e2018-07-18 15:37:01 +020072 ~BitrateController() override {}
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000073
Sebastian Jansson8d9c5402017-11-15 17:22:16 +010074 // Deprecated, use raw pointer to BitrateController instance instead.
Danil Chapovalov38018ba2017-06-12 16:29:45 +020075 // Creates RtcpBandwidthObserver caller responsible to delete.
Sebastian Jansson8d9c5402017-11-15 17:22:16 +010076 RTC_DEPRECATED virtual RtcpBandwidthObserver*
77 CreateRtcpBandwidthObserver() = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000078
philipelc6957c72016-04-28 15:52:49 +020079 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000080 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020081 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000082 virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020083 virtual void SetBitrates(int start_bitrate_bps,
84 int min_bitrate_bps,
85 int max_bitrate_bps) = 0;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000086
honghaiz059e1832016-06-24 11:03:55 -070087 virtual void ResetBitrates(int bitrate_bps,
88 int min_bitrate_bps,
89 int max_bitrate_bps) = 0;
90
Stefan Holmer280de9e2016-09-30 10:06:51 +020091 virtual void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) = 0;
92
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000093 // Gets the available payload bandwidth in bits per second. Note that
94 // this bandwidth excludes packet headers.
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000095 virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
96
perkjec81bcd2016-05-11 06:01:13 -070097 virtual bool GetNetworkParameters(uint32_t* bitrate,
98 uint8_t* fraction_loss,
99 int64_t* rtt) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000100};
101} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200102#endif // MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_