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 encoder via VideoEncoderCallback. |
| 13 | */ |
| 14 | |
| 15 | #ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |
| 16 | #define WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |
| 17 | |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 19 | |
stefan@webrtc.org | 1281dc0 | 2012-08-13 16:13:09 +0000 | [diff] [blame] | 20 | #include <list> |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame^] | 21 | #include <map> |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 22 | #include <utility> |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 23 | #include <vector> |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 24 | |
kwiberg | 4485ffb | 2016-04-26 08:14:39 -0700 | [diff] [blame] | 25 | #include "webrtc/base/constructormagic.h" |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 26 | #include "webrtc/base/criticalsection.h" |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 27 | #include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 31 | class BitrateControllerImpl : public BitrateController { |
| 32 | public: |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 33 | // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC. |
| 34 | // |observer| is left for project that is not yet updated. |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 35 | BitrateControllerImpl(const Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 36 | BitrateObserver* observer, |
| 37 | RtcEventLog* event_log); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 38 | virtual ~BitrateControllerImpl() {} |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 39 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 40 | bool AvailableBandwidth(uint32_t* bandwidth) const override; |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 41 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 42 | RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override; |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 43 | |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 44 | // Deprecated |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 45 | void SetStartBitrate(int start_bitrate_bps) override; |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 46 | // Deprecated |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 47 | void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override; |
| 48 | |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 49 | void SetBitrates(int start_bitrate_bps, |
| 50 | int min_bitrate_bps, |
| 51 | int max_bitrate_bps) override; |
| 52 | |
honghaiz | 059e183 | 2016-06-24 11:03:55 -0700 | [diff] [blame] | 53 | void ResetBitrates(int bitrate_bps, |
| 54 | int min_bitrate_bps, |
| 55 | int max_bitrate_bps) override; |
| 56 | |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 57 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 58 | void SetReservedBitrate(uint32_t reserved_bitrate_bps) override; |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 59 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 60 | // Returns true if the parameters have changed since the last call. |
| 61 | bool GetNetworkParameters(uint32_t* bitrate, |
| 62 | uint8_t* fraction_loss, |
| 63 | int64_t* rtt) override; |
| 64 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 65 | void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override; |
philipel | 0aa9d18 | 2016-08-24 02:45:35 -0700 | [diff] [blame] | 66 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 67 | int64_t TimeUntilNextProcess() override; |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 68 | void Process() override; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 69 | |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 70 | private: |
| 71 | class RtcpBandwidthObserverImpl; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 72 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 73 | // Called by BitrateObserver's direct from the RTCP module. |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame^] | 74 | // Implements RtcpBandwidthObserver. |
| 75 | void OnReceivedEstimatedBitrate(uint32_t bitrate) override; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 76 | |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame^] | 77 | void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 78 | int64_t rtt, |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame^] | 79 | int64_t now_ms) override; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 80 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 81 | // Deprecated |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 82 | void MaybeTriggerOnNetworkChanged(); |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 83 | |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 84 | void OnNetworkChanged(uint32_t bitrate, |
| 85 | uint8_t fraction_loss, // 0 - 255. |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 86 | int64_t rtt) EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 +0000 | [diff] [blame] | 87 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 88 | // Used by process thread. |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 89 | const Clock* const clock_; |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 90 | BitrateObserver* const observer_; |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 91 | int64_t last_bitrate_update_ms_; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 92 | RtcEventLog* const event_log_; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 93 | |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 94 | rtc::CriticalSection critsect_; |
Danil Chapovalov | 38018ba | 2017-06-12 16:29:45 +0200 | [diff] [blame^] | 95 | std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_ |
| 96 | GUARDED_BY(critsect_); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 97 | SendSideBandwidthEstimation bandwidth_estimation_ GUARDED_BY(critsect_); |
| 98 | uint32_t reserved_bitrate_bps_ GUARDED_BY(critsect_); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 99 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 100 | uint32_t last_bitrate_bps_ GUARDED_BY(critsect_); |
| 101 | uint8_t last_fraction_loss_ GUARDED_BY(critsect_); |
| 102 | int64_t last_rtt_ms_ GUARDED_BY(critsect_); |
| 103 | uint32_t last_reserved_bitrate_bps_ GUARDED_BY(critsect_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 104 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 105 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 106 | }; |
| 107 | } // namespace webrtc |
| 108 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |