1/*
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
18#include <map>
19
20#include "webrtc/modules/include/module.h"
21#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22
23namespace webrtc {
24
25class CriticalSectionWrapper;
26class RtcEventLog;
27struct PacketInfo;
28
29class BitrateObserver {
30  // 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.
35 public:
36  virtual void OnNetworkChanged(uint32_t bitrate_bps,
37                                uint8_t fraction_loss,  // 0 - 255.
38                                int64_t rtt_ms) = 0;
39
40  virtual ~BitrateObserver() {}
41};
42
43class BitrateController : public Module {
44  // 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.
48 public:
49  static const int kDefaultStartBitrateKbps = 300;
50
51  static BitrateController* CreateBitrateController(Clock* clock,
52                                                    BitrateObserver* observer);
53  virtual ~BitrateController() {}
54
55  virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
56
57  virtual void SetStartBitrate(int start_bitrate_bps) = 0;
58  virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
59
60  virtual void SetEventLog(RtcEventLog* event_log) = 0;
61
62  // Gets the available payload bandwidth in bits per second. Note that
63  // this bandwidth excludes packet headers.
64  virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
65
66  virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0;
67};
68}  // namespace webrtc
69#endif  // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
70