blob: a61cf6a7a74f139ae972170c968be7e07a1a8ad5 [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 encoders via BitrateObserver(s).
13 */
14
15#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
16#define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
17
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000018#include <map>
19
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020#include "webrtc/modules/include/module.h"
Per28a44562016-05-04 17:12:51 +020021#include "webrtc/modules/pacing/paced_sender.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010022#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000023
24namespace webrtc {
25
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000026class CriticalSectionWrapper;
terelius006d93d2015-11-05 12:02:15 -080027class RtcEventLog;
sprang867fb522015-08-03 04:38:41 -070028struct PacketInfo;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000029
Per28a44562016-05-04 17:12:51 +020030// Deprecated
31// TODO(perkj): Remove BitrateObserver when no implementations use it.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000032class BitrateObserver {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000033 // Observer class for bitrate changes announced due to change in bandwidth
34 // estimate or due to bitrate allocation changes. Fraction loss and rtt is
35 // also part of this callback to allow the obsevrer to optimize its settings
36 // for different types of network environments. The bitrate does not include
37 // packet headers and is measured in bits per second.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000038 public:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000039 virtual void OnNetworkChanged(uint32_t bitrate_bps,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000040 uint8_t fraction_loss, // 0 - 255.
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000041 int64_t rtt_ms) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000042
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000043 virtual ~BitrateObserver() {}
44};
45
andresp@webrtc.org44caf012014-03-26 21:00:21 +000046class BitrateController : public Module {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000047 // This class collects feedback from all streams sent to a peer (via
48 // RTCPBandwidthObservers). It does one aggregated send side bandwidth
49 // estimation and divide the available bitrate between all its registered
50 // BitrateObservers.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000051 public:
Per28a44562016-05-04 17:12:51 +020052 static const int kDefaultStartBitratebps = 300000;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000053
Per28a44562016-05-04 17:12:51 +020054 // Deprecated:
55 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC.
56 // Remove this method once other other projects does not use it.
andresp@webrtc.org44caf012014-03-26 21:00:21 +000057 static BitrateController* CreateBitrateController(Clock* clock,
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000058 BitrateObserver* observer);
Per28a44562016-05-04 17:12:51 +020059 static BitrateController* CreateBitrateController(Clock* clock);
60
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000061 virtual ~BitrateController() {}
62
63 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
64
philipelc6957c72016-04-28 15:52:49 +020065 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000066 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020067 // Deprecated
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000068 virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
philipelc6957c72016-04-28 15:52:49 +020069 virtual void SetBitrates(int start_bitrate_bps,
70 int min_bitrate_bps,
71 int max_bitrate_bps) = 0;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000072
stefan32f81542016-01-20 07:13:58 -080073 virtual void UpdateDelayBasedEstimate(uint32_t bitrate_bps) = 0;
74
terelius006d93d2015-11-05 12:02:15 -080075 virtual void SetEventLog(RtcEventLog* event_log) = 0;
76
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000077 // Gets the available payload bandwidth in bits per second. Note that
78 // this bandwidth excludes packet headers.
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000079 virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
80
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000081 virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0;
Per28a44562016-05-04 17:12:51 +020082
83 virtual bool GetNetworkParameters(uint32_t* bitrate,
84 uint8_t* fraction_loss,
85 int64_t* rtt) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000086};
87} // namespace webrtc
88#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_