blob: a9c247acf179df5b7e087a286bfd98d31caec40b [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"
21#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000022
23namespace webrtc {
24
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000025class CriticalSectionWrapper;
terelius006d93d2015-11-05 12:02:15 -080026class RtcEventLog;
sprang867fb522015-08-03 04:38:41 -070027struct PacketInfo;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000028
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000029class BitrateObserver {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000030 // Observer class for bitrate changes announced due to change in bandwidth
31 // estimate or due to bitrate allocation changes. Fraction loss and rtt is
32 // also part of this callback to allow the obsevrer to optimize its settings
33 // for different types of network environments. The bitrate does not include
34 // packet headers and is measured in bits per second.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000035 public:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000036 virtual void OnNetworkChanged(uint32_t bitrate_bps,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000037 uint8_t fraction_loss, // 0 - 255.
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000038 int64_t rtt_ms) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000039
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000040 virtual ~BitrateObserver() {}
41};
42
andresp@webrtc.org44caf012014-03-26 21:00:21 +000043class BitrateController : public Module {
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000044 // This class collects feedback from all streams sent to a peer (via
45 // RTCPBandwidthObservers). It does one aggregated send side bandwidth
46 // estimation and divide the available bitrate between all its registered
47 // BitrateObservers.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000048 public:
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000049 static const int kDefaultStartBitrateKbps = 300;
50
andresp@webrtc.org44caf012014-03-26 21:00:21 +000051 static BitrateController* CreateBitrateController(Clock* clock,
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000052 BitrateObserver* observer);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000053 virtual ~BitrateController() {}
54
55 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
56
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000057 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
58 virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
59
stefan32f81542016-01-20 07:13:58 -080060 virtual void UpdateDelayBasedEstimate(uint32_t bitrate_bps) = 0;
61
terelius006d93d2015-11-05 12:02:15 -080062 virtual void SetEventLog(RtcEventLog* event_log) = 0;
63
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000064 // Gets the available payload bandwidth in bits per second. Note that
65 // this bandwidth excludes packet headers.
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000066 virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
67
solenberg@webrtc.org4e656022014-03-26 14:32:47 +000068 virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000069};
70} // namespace webrtc
71#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_