pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #ifndef MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |
| 16 | #define MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 17 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
gnish | a36165c | 2017-08-20 09:19:58 -0700 | [diff] [blame] | 20 | |
Sebastian Jansson | 04b18cb | 2018-07-02 09:25:25 +0200 | [diff] [blame] | 21 | #include "modules/congestion_controller/goog_cc/delay_based_bwe.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/include/module.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 24 | #include "rtc_base/deprecation.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 28 | class Clock; |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 29 | class RtcEventLog; |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 30 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 31 | // Deprecated |
| 32 | // TODO(perkj): Remove BitrateObserver when no implementations use it. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 33 | class BitrateObserver { |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 34 | // 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.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 39 | public: |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 40 | virtual void OnNetworkChanged(uint32_t bitrate_bps, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 41 | uint8_t fraction_loss, // 0 - 255. |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 42 | int64_t rtt_ms) = 0; |
gnish | a36165c | 2017-08-20 09:19:58 -0700 | [diff] [blame] | 43 | // 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 Bonadei | 64f813e | 2018-07-18 15:37:01 +0200 | [diff] [blame] | 50 | virtual size_t pacer_queue_size_in_bytes(); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 51 | virtual ~BitrateObserver() {} |
| 52 | }; |
| 53 | |
gnish | a36165c | 2017-08-20 09:19:58 -0700 | [diff] [blame] | 54 | class BitrateController : public Module, public RtcpBandwidthObserver { |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 55 | // 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.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 59 | public: |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 60 | static const int kDefaultStartBitratebps = 300000; |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 61 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 62 | // 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.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 65 | static BitrateController* CreateBitrateController(const Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 66 | BitrateObserver* observer, |
| 67 | RtcEventLog* event_log); |
| 68 | |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 69 | static BitrateController* CreateBitrateController(const Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 70 | RtcEventLog* event_log); |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 71 | |
Mirko Bonadei | 64f813e | 2018-07-18 15:37:01 +0200 | [diff] [blame] | 72 | ~BitrateController() override {} |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 73 | |
Sebastian Jansson | 8d9c540 | 2017-11-15 17:22:16 +0100 | [diff] [blame] | 74 | // Deprecated, use raw pointer to BitrateController instance instead. |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame] | 75 | // Creates RtcpBandwidthObserver caller responsible to delete. |
Sebastian Jansson | 8d9c540 | 2017-11-15 17:22:16 +0100 | [diff] [blame] | 76 | RTC_DEPRECATED virtual RtcpBandwidthObserver* |
| 77 | CreateRtcpBandwidthObserver() = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 78 | |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 79 | // Deprecated |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 80 | virtual void SetStartBitrate(int start_bitrate_bps) = 0; |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 81 | // Deprecated |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 82 | virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0; |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 83 | virtual void SetBitrates(int start_bitrate_bps, |
| 84 | int min_bitrate_bps, |
| 85 | int max_bitrate_bps) = 0; |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 86 | |
honghaiz | 059e183 | 2016-06-24 11:03:55 -0700 | [diff] [blame] | 87 | virtual void ResetBitrates(int bitrate_bps, |
| 88 | int min_bitrate_bps, |
| 89 | int max_bitrate_bps) = 0; |
| 90 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 91 | virtual void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) = 0; |
| 92 | |
stefan@webrtc.org | 42aa10e | 2012-11-13 15:02:13 +0000 | [diff] [blame] | 93 | // Gets the available payload bandwidth in bits per second. Note that |
| 94 | // this bandwidth excludes packet headers. |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 +0000 | [diff] [blame] | 95 | virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0; |
| 96 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 97 | virtual bool GetNetworkParameters(uint32_t* bitrate, |
| 98 | uint8_t* fraction_loss, |
| 99 | int64_t* rtt) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 100 | }; |
| 101 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 102 | #endif // MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |