blob: c8bb10282be5677e0ee9976d1038a0f04c2abe0f [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
15#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_
16#define WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_
17
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000018#include "webrtc/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>
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000021#include <utility>
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070022#include <vector>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000023
kwiberg4485ffb2016-04-26 08:14:39 -070024#include "webrtc/base/constructormagic.h"
sprang867fb522015-08-03 04:38:41 -070025#include "webrtc/base/criticalsection.h"
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000026#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000027
28namespace webrtc {
29
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000030class BitrateControllerImpl : public BitrateController {
31 public:
perkjec81bcd2016-05-11 06:01:13 -070032 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC.
33 // |observer| is left for project that is not yet updated.
ivoc14d5dbe2016-07-04 07:06:55 -070034 BitrateControllerImpl(Clock* clock,
35 BitrateObserver* observer,
36 RtcEventLog* event_log);
Stefan Holmere5904162015-03-26 11:11:06 +010037 virtual ~BitrateControllerImpl() {}
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000038
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000039 bool AvailableBandwidth(uint32_t* bandwidth) const override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000040
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000041 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000042
philipelc6957c72016-04-28 15:52:49 +020043 // Deprecated
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000044 void SetStartBitrate(int start_bitrate_bps) override;
philipelc6957c72016-04-28 15:52:49 +020045 // Deprecated
stefan32f81542016-01-20 07:13:58 -080046 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override;
47
philipelc6957c72016-04-28 15:52:49 +020048 void SetBitrates(int start_bitrate_bps,
49 int min_bitrate_bps,
50 int max_bitrate_bps) override;
51
honghaiz059e1832016-06-24 11:03:55 -070052 void ResetBitrates(int bitrate_bps,
53 int min_bitrate_bps,
54 int max_bitrate_bps) override;
55
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000056
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
stefan5ec85fb2016-09-29 04:19:38 -070064 // RemoteBitrateObserver overrides.
65 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
66 uint32_t bitrate_bps) override;
67 void OnProbeBitrate(uint32_t bitrate_bps) override;
philipel0aa9d182016-08-24 02:45:35 -070068
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000069 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -080070 void Process() override;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000071
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000072 private:
73 class RtcpBandwidthObserverImpl;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000074
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000075 // Called by BitrateObserver's direct from the RTCP module.
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070076 void OnReceiverEstimatedBitrate(uint32_t bitrate);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000077
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000078 void OnReceivedRtcpReceiverReport(uint8_t fraction_loss,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000079 int64_t rtt,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000080 int number_of_packets,
81 int64_t now_ms);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000082
perkjec81bcd2016-05-11 06:01:13 -070083 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000084 void MaybeTriggerOnNetworkChanged();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000085
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000086 void OnNetworkChanged(uint32_t bitrate,
87 uint8_t fraction_loss, // 0 - 255.
sprang867fb522015-08-03 04:38:41 -070088 int64_t rtt) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000089
andresp@webrtc.org44caf012014-03-26 21:00:21 +000090 // Used by process thread.
perkjec81bcd2016-05-11 06:01:13 -070091 Clock* const clock_;
92 BitrateObserver* const observer_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000093 int64_t last_bitrate_update_ms_;
ivoc14d5dbe2016-07-04 07:06:55 -070094 RtcEventLog* const event_log_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000095
pbos5ad935c2016-01-25 03:52:44 -080096 rtc::CriticalSection critsect_;
sprang867fb522015-08-03 04:38:41 -070097 SendSideBandwidthEstimation bandwidth_estimation_ GUARDED_BY(critsect_);
98 uint32_t reserved_bitrate_bps_ GUARDED_BY(critsect_);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000099
sprang867fb522015-08-03 04:38:41 -0700100 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.org4e656022014-03-26 14:32:47 +0000104
henrikg3c089d72015-09-16 05:37:44 -0700105 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000106};
107} // namespace webrtc
108#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_