blob: 6f776d758b491a760bc29c261123ffd56b410633 [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>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000022
sprang867fb522015-08-03 04:38:41 -070023#include "webrtc/base/criticalsection.h"
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000024#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000025
26namespace webrtc {
27
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000028class BitrateControllerImpl : public BitrateController {
29 public:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000030 BitrateControllerImpl(Clock* clock, BitrateObserver* observer);
Stefan Holmere5904162015-03-26 11:11:06 +010031 virtual ~BitrateControllerImpl() {}
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000032
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 bool AvailableBandwidth(uint32_t* bandwidth) const override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000034
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000035 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000036
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000037 void SetStartBitrate(int start_bitrate_bps) override;
stefan32f81542016-01-20 07:13:58 -080038 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override;
39
40 void UpdateDelayBasedEstimate(uint32_t bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000041
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000042 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000043
terelius006d93d2015-11-05 12:02:15 -080044 void SetEventLog(RtcEventLog* event_log) override;
45
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -080047 void Process() override;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000048
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000049 private:
50 class RtcpBandwidthObserverImpl;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000051
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000052 // Called by BitrateObserver's direct from the RTCP module.
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000053 void OnReceivedEstimatedBitrate(uint32_t bitrate);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000054
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000055 void OnReceivedRtcpReceiverReport(uint8_t fraction_loss,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000056 int64_t rtt,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000057 int number_of_packets,
58 int64_t now_ms);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000059
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000060 void MaybeTriggerOnNetworkChanged();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000061
Stefan Holmere5904162015-03-26 11:11:06 +010062 // Returns true if the parameters have changed since the last call.
63 bool GetNetworkParameters(uint32_t* bitrate,
64 uint8_t* fraction_loss,
65 int64_t* rtt);
66
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000067 void OnNetworkChanged(uint32_t bitrate,
68 uint8_t fraction_loss, // 0 - 255.
sprang867fb522015-08-03 04:38:41 -070069 int64_t rtt) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000070
andresp@webrtc.org44caf012014-03-26 21:00:21 +000071 // Used by process thread.
72 Clock* clock_;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000073 BitrateObserver* observer_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000074 int64_t last_bitrate_update_ms_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000075
pbos5ad935c2016-01-25 03:52:44 -080076 rtc::CriticalSection critsect_;
sprang867fb522015-08-03 04:38:41 -070077 SendSideBandwidthEstimation bandwidth_estimation_ GUARDED_BY(critsect_);
78 uint32_t reserved_bitrate_bps_ GUARDED_BY(critsect_);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000079
sprang867fb522015-08-03 04:38:41 -070080 uint32_t last_bitrate_bps_ GUARDED_BY(critsect_);
81 uint8_t last_fraction_loss_ GUARDED_BY(critsect_);
82 int64_t last_rtt_ms_ GUARDED_BY(critsect_);
83 uint32_t last_reserved_bitrate_bps_ GUARDED_BY(critsect_);
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000084
henrikg3c089d72015-09-16 05:37:44 -070085 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000086};
87} // namespace webrtc
88#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_