blob: 0f7436765816cf1b9a30da2af7fd170393a26ab9 [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
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000019
20namespace webrtc {
21
22class BitrateObserver {
23 /*
24 * Observer class for the encoders, each encoder should implement this class
25 * to get the target bitrate. It also get the fraction loss and rtt to
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000026 * optimize its settings for this type of network. |target_bitrate| is the
27 * target media/payload bitrate excluding packet headers, measured in bits
28 * per second.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000029 */
30 public:
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000031 virtual void OnNetworkChanged(const uint32_t target_bitrate,
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000032 const uint8_t fraction_loss, // 0 - 255.
33 const uint32_t rtt) = 0;
34
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000035 virtual ~BitrateObserver() {}
36};
37
andrew@webrtc.org6cd201c2014-03-25 19:42:39 +000038class BitrateController {
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000039/*
40 * This class collects feedback from all streams sent to a peer (via
41 * RTCPBandwidthObservers). It does one aggregated send side bandwidth
42 * estimation and divide the available bitrate between all its registered
43 * BitrateObservers.
44 */
45 public:
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000046 // The argument |enforce_min_bitrate| controls the behavior when the available
47 // bitrate is lower than the minimum bitrate, or the sum of minimum bitrates.
48 // When true, the bitrate will never be set lower than the minimum bitrate(s).
49 // When false, the bitrate observers will be allocated rates up to their
50 // respective minimum bitrate, satisfying one observer after the other.
andrew@webrtc.org6cd201c2014-03-25 19:42:39 +000051 static BitrateController* CreateBitrateController(bool enforce_min_bitrate);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000052 virtual ~BitrateController() {}
53
54 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
55
stefan@webrtc.org42aa10e2012-11-13 15:02:13 +000056 // Gets the available payload bandwidth in bits per second. Note that
57 // this bandwidth excludes packet headers.
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000058 virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
59
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000060 /*
61 * Set the start and max send bitrate used by the bandwidth management.
62 *
63 * observer, updates bitrates if already in use.
64 * min_bitrate_kbit = 0 equals no min bitrate.
65 * max_bitrate_kit = 0 equals no max bitrate.
66 */
67 virtual void SetBitrateObserver(BitrateObserver* observer,
68 const uint32_t start_bitrate,
69 const uint32_t min_bitrate,
70 const uint32_t max_bitrate) = 0;
71
72 virtual void RemoveBitrateObserver(BitrateObserver* observer) = 0;
henrik.lundin@webrtc.orgb56d0e32013-10-24 09:24:06 +000073
74 // Changes the mode that was set in the constructor.
75 virtual void EnforceMinBitrate(bool enforce_min_bitrate) = 0;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000076};
77} // namespace webrtc
78#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_