blob: a33a0e6f0402e240f566df37c57be4e1c4d782e6 [file] [log] [blame]
pwestin@webrtc.org1cd11622012-04-19 12:13:521/*
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:5318#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:5219
stefan@webrtc.org1281dc02012-08-13 16:13:0920#include <list>
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:0121#include <utility>
pwestin@webrtc.org1cd11622012-04-19 12:13:5222
sprang867fb522015-08-03 11:38:4123#include "webrtc/base/criticalsection.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:5524#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org2e10b8e2013-07-16 12:54:5325#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:5226
27namespace webrtc {
28
pwestin@webrtc.org1cd11622012-04-19 12:13:5229class BitrateControllerImpl : public BitrateController {
30 public:
stefan@webrtc.org792f1a12015-03-04 12:24:2631 BitrateControllerImpl(Clock* clock, BitrateObserver* observer);
Stefan Holmere5904162015-03-26 10:11:0632 virtual ~BitrateControllerImpl() {}
andresp@webrtc.org16b75c22014-03-21 14:00:5133
kjellander@webrtc.org14665ff2015-03-04 12:58:3534 bool AvailableBandwidth(uint32_t* bandwidth) const override;
andresp@webrtc.org16b75c22014-03-21 14:00:5135
kjellander@webrtc.org14665ff2015-03-04 12:58:3536 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override;
andresp@webrtc.org16b75c22014-03-21 14:00:5137
kjellander@webrtc.org14665ff2015-03-04 12:58:3538 void SetStartBitrate(int start_bitrate_bps) override;
39 void SetMinMaxBitrate(int min_bitrate_bps,
stefan@webrtc.org792f1a12015-03-04 12:24:2640 int max_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:5141
kjellander@webrtc.org14665ff2015-03-04 12:58:3542 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override;
andresp@webrtc.org16b75c22014-03-21 14:00:5143
kjellander@webrtc.org14665ff2015-03-04 12:58:3544 int64_t TimeUntilNextProcess() override;
45 int32_t Process() override;
andresp@webrtc.org44caf012014-03-26 21:00:2146
andresp@webrtc.org16b75c22014-03-21 14:00:5147 private:
48 class RtcpBandwidthObserverImpl;
pwestin@webrtc.org1cd11622012-04-19 12:13:5249
pwestin@webrtc.org1cd11622012-04-19 12:13:5250 // Called by BitrateObserver's direct from the RTCP module.
stefan@webrtc.orgedeea912014-12-08 19:46:2351 void OnReceivedEstimatedBitrate(uint32_t bitrate);
pwestin@webrtc.org1cd11622012-04-19 12:13:5252
stefan@webrtc.orgedeea912014-12-08 19:46:2353 void OnReceivedRtcpReceiverReport(uint8_t fraction_loss,
pkasting@chromium.org16825b12015-01-12 21:51:2154 int64_t rtt,
stefan@webrtc.orgedeea912014-12-08 19:46:2355 int number_of_packets,
56 int64_t now_ms);
pwestin@webrtc.org1cd11622012-04-19 12:13:5257
stefan@webrtc.org792f1a12015-03-04 12:24:2658 void MaybeTriggerOnNetworkChanged();
andresp@webrtc.org07bc7342014-03-21 16:51:0159
Stefan Holmere5904162015-03-26 10:11:0660 // 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);
64
stefan@webrtc.orgedeea912014-12-08 19:46:2365 void OnNetworkChanged(uint32_t bitrate,
66 uint8_t fraction_loss, // 0 - 255.
sprang867fb522015-08-03 11:38:4167 int64_t rtt) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
andresp@webrtc.org16b75c22014-03-21 14:00:5168
andresp@webrtc.org44caf012014-03-26 21:00:2169 // Used by process thread.
70 Clock* clock_;
stefan@webrtc.org792f1a12015-03-04 12:24:2671 BitrateObserver* observer_;
stefan@webrtc.orgedeea912014-12-08 19:46:2372 int64_t last_bitrate_update_ms_;
andresp@webrtc.org44caf012014-03-26 21:00:2173
sprang867fb522015-08-03 11:38:4174 mutable rtc::CriticalSection critsect_;
75 SendSideBandwidthEstimation bandwidth_estimation_ GUARDED_BY(critsect_);
76 uint32_t reserved_bitrate_bps_ GUARDED_BY(critsect_);
andresp@webrtc.org44caf012014-03-26 21:00:2177
sprang867fb522015-08-03 11:38:4178 uint32_t last_bitrate_bps_ GUARDED_BY(critsect_);
79 uint8_t last_fraction_loss_ GUARDED_BY(critsect_);
80 int64_t last_rtt_ms_ GUARDED_BY(critsect_);
81 uint32_t last_reserved_bitrate_bps_ GUARDED_BY(critsect_);
solenberg@webrtc.org4e656022014-03-26 14:32:4782
henrikg3c089d72015-09-16 12:37:4483 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl);
pwestin@webrtc.org1cd11622012-04-19 12:13:5284};
85} // namespace webrtc
86#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_