blob: e315c5f9fd2e9b399bead812b560f118303525fa [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 encoder via VideoEncoderCallback.
13 */
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#ifndef MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_
16#define MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/bitrate_controller/include/bitrate_controller.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000019
stefan@webrtc.org1281dc02012-08-13 16:13:09 +000020#include <list>
Danil Chapovalov38018ba2017-06-12 16:29:45 +020021#include <map>
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000022#include <utility>
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070023#include <vector>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000024
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "modules/bitrate_controller/send_side_bandwidth_estimation.h"
26#include "rtc_base/constructormagic.h"
27#include "rtc_base/criticalsection.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000028
29namespace webrtc {
30
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000031class BitrateControllerImpl : public BitrateController {
32 public:
perkjec81bcd2016-05-11 06:01:13 -070033 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC.
34 // |observer| is left for project that is not yet updated.
elad.alon61ce37e2017-03-09 07:09:31 -080035 BitrateControllerImpl(const Clock* clock,
ivoc14d5dbe2016-07-04 07:06:55 -070036 BitrateObserver* observer,
37 RtcEventLog* event_log);
Stefan Holmere5904162015-03-26 11:11:06 +010038 virtual ~BitrateControllerImpl() {}
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000039
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000040 bool AvailableBandwidth(uint32_t* bandwidth) const override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000041
Sebastian Jansson8d9c5402017-11-15 17:22:16 +010042 RTC_DEPRECATED RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000043
philipelc6957c72016-04-28 15:52:49 +020044 // Deprecated
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000045 void SetStartBitrate(int start_bitrate_bps) override;
philipelc6957c72016-04-28 15:52:49 +020046 // Deprecated
stefan32f81542016-01-20 07:13:58 -080047 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override;
48
philipelc6957c72016-04-28 15:52:49 +020049 void SetBitrates(int start_bitrate_bps,
50 int min_bitrate_bps,
51 int max_bitrate_bps) override;
52
honghaiz059e1832016-06-24 11:03:55 -070053 void ResetBitrates(int bitrate_bps,
54 int min_bitrate_bps,
55 int max_bitrate_bps) override;
56
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000058
perkjec81bcd2016-05-11 06:01:13 -070059 // Returns true if the parameters have changed since the last call.
60 bool GetNetworkParameters(uint32_t* bitrate,
61 uint8_t* fraction_loss,
62 int64_t* rtt) override;
63
Stefan Holmer280de9e2016-09-30 10:06:51 +020064 void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override;
philipel0aa9d182016-08-24 02:45:35 -070065
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -080067 void Process() override;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000068
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000069 private:
70 class RtcpBandwidthObserverImpl;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000071
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000072 // Called by BitrateObserver's direct from the RTCP module.
Danil Chapovalov38018ba2017-06-12 16:29:45 +020073 // Implements RtcpBandwidthObserver.
74 void OnReceivedEstimatedBitrate(uint32_t bitrate) override;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000075
Danil Chapovalov38018ba2017-06-12 16:29:45 +020076 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000077 int64_t rtt,
Danil Chapovalov38018ba2017-06-12 16:29:45 +020078 int64_t now_ms) override;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000079
perkjec81bcd2016-05-11 06:01:13 -070080 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000081 void MaybeTriggerOnNetworkChanged();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000082
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000083 void OnNetworkChanged(uint32_t bitrate,
84 uint8_t fraction_loss, // 0 - 255.
danilchap56359be2017-09-07 07:53:45 -070085 int64_t rtt) RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000086
andresp@webrtc.org44caf012014-03-26 21:00:21 +000087 // Used by process thread.
elad.alon61ce37e2017-03-09 07:09:31 -080088 const Clock* const clock_;
perkjec81bcd2016-05-11 06:01:13 -070089 BitrateObserver* const observer_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000090 int64_t last_bitrate_update_ms_;
ivoc14d5dbe2016-07-04 07:06:55 -070091 RtcEventLog* const event_log_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000092
pbos5ad935c2016-01-25 03:52:44 -080093 rtc::CriticalSection critsect_;
Danil Chapovalov38018ba2017-06-12 16:29:45 +020094 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_
danilchap56359be2017-09-07 07:53:45 -070095 RTC_GUARDED_BY(critsect_);
96 SendSideBandwidthEstimation bandwidth_estimation_ RTC_GUARDED_BY(critsect_);
97 uint32_t reserved_bitrate_bps_ RTC_GUARDED_BY(critsect_);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000098
danilchap56359be2017-09-07 07:53:45 -070099 uint32_t last_bitrate_bps_ RTC_GUARDED_BY(critsect_);
100 uint8_t last_fraction_loss_ RTC_GUARDED_BY(critsect_);
101 int64_t last_rtt_ms_ RTC_GUARDED_BY(critsect_);
102 uint32_t last_reserved_bitrate_bps_ RTC_GUARDED_BY(critsect_);
solenberg@webrtc.org4e656022014-03-26 14:32:47 +0000103
henrikg3c089d72015-09-16 05:37:44 -0700104 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000105};
106} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200107#endif // MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_