blob: 1646f750224d4b29a5c3ecf4701169cfffe2c0eb [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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000023#include "webrtc/base/scoped_ptr.h"
sprang@webrtc.org9b791972014-12-18 11:53:59 +000024#include "webrtc/modules/bitrate_controller/remb_suppressor.h"
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000025#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
26#include "webrtc/system_wrappers/interface/critical_section_wrapper.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:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000032 BitrateControllerImpl(Clock* clock, BitrateObserver* observer);
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000033 virtual ~BitrateControllerImpl();
34
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000035 virtual bool AvailableBandwidth(uint32_t* bandwidth) const override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000036
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000037 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000038
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000039 virtual void SetStartBitrate(int start_bitrate_bps) override;
40 virtual void SetMinMaxBitrate(int min_bitrate_bps,
41 int max_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000042
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000043 virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000044
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000045 virtual int64_t TimeUntilNextProcess() override;
46 virtual int32_t Process() override;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000047
sprang@webrtc.org9b791972014-12-18 11:53:59 +000048 // Current bitrate actually being sent.
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000049 virtual void SetBitrateSent(uint32_t bitrate_sent_bps) override;
sprang@webrtc.org9b791972014-12-18 11:53:59 +000050
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000051 virtual void SetCodecMode(webrtc::VideoCodecMode mode) override;
sprang@webrtc.org9b791972014-12-18 11:53:59 +000052
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000053 private:
54 class RtcpBandwidthObserverImpl;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000055
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000056 // Called by BitrateObserver's direct from the RTCP module.
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000057 void OnReceivedEstimatedBitrate(uint32_t bitrate);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000058
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000059 void OnReceivedRtcpReceiverReport(uint8_t fraction_loss,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000060 int64_t rtt,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000061 int number_of_packets,
62 int64_t now_ms);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000063
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000064 void MaybeTriggerOnNetworkChanged();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000065
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000066 void OnNetworkChanged(uint32_t bitrate,
67 uint8_t fraction_loss, // 0 - 255.
pkasting@chromium.org16825b12015-01-12 21:51:21 +000068 int64_t rtt)
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000069 EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
70
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
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000076 CriticalSectionWrapper* critsect_;
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000077 SendSideBandwidthEstimation bandwidth_estimation_ GUARDED_BY(*critsect_);
andresp@webrtc.org16b75c22014-03-21 14:00:51 +000078 bool enforce_min_bitrate_ GUARDED_BY(*critsect_);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000079 uint32_t reserved_bitrate_bps_ GUARDED_BY(*critsect_);
80
81 uint32_t last_bitrate_bps_ GUARDED_BY(*critsect_);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000082 uint8_t last_fraction_loss_ GUARDED_BY(*critsect_);
pkasting@chromium.org16825b12015-01-12 21:51:21 +000083 int64_t last_rtt_ms_ GUARDED_BY(*critsect_);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000084 bool last_enforce_min_bitrate_ GUARDED_BY(*critsect_);
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000085 uint32_t last_reserved_bitrate_bps_ GUARDED_BY(*critsect_);
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000086 rtc::scoped_ptr<RembSuppressor> remb_suppressor_ GUARDED_BY(*critsect_);
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000087
88 DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000089};
90} // namespace webrtc
91#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_