send_side_bandwidth_estimation.h revision 4e69f782b0e67ade5b68657c6f22b8c5b61f3a4d
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 *  FEC and NACK added bitrate is handled outside class
11 */
12
13#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
14#define WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
15
16#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
17#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18
19namespace webrtc {
20class SendSideBandwidthEstimation {
21 public:
22  SendSideBandwidthEstimation();
23  virtual ~SendSideBandwidthEstimation();
24
25  // Call when we receive a RTCP message with TMMBR or REMB
26  // Return true if new_bitrate is valid.
27  bool UpdateBandwidthEstimate(const uint32_t bandwidth,
28                               uint32_t* new_bitrate,
29                               uint8_t* fraction_lost,
30                               uint16_t* rtt);
31
32  // Call when we receive a RTCP message with a ReceiveBlock
33  // Return true if new_bitrate is valid.
34  bool UpdatePacketLoss(const int number_of_packets,
35                        const uint32_t rtt,
36                        const uint32_t now_ms,
37                        uint8_t* loss,
38                        uint32_t* new_bitrate);
39
40  // Return false if no bandwidth estimate is available
41  bool AvailableBandwidth(uint32_t* bandwidth) const;
42  void SetSendBitrate(const uint32_t bitrate);
43  void SetMinMaxBitrate(const uint32_t min_bitrate, const uint32_t max_bitrate);
44  void SetMinBitrate(uint32_t min_bitrate);
45
46 private:
47  bool ShapeSimple(const uint8_t loss, const uint32_t rtt,
48                   const uint32_t now_ms, uint32_t* bitrate);
49
50  void CapBitrateToThresholds(uint32_t* bitrate);
51
52  uint32_t CalcTFRCbps(uint16_t rtt, uint8_t loss);
53
54  enum { kBWEIncreaseIntervalMs = 1000 };
55  enum { kBWEDecreaseIntervalMs = 300 };
56  enum { kLimitNumPackets = 20 };
57  enum { kAvgPacketSizeBytes = 1000 };
58
59  CriticalSectionWrapper* critsect_;
60
61  // incoming filters
62  int accumulate_lost_packets_Q8_;
63  int accumulate_expected_packets_;
64
65  uint32_t bitrate_;
66  uint32_t min_bitrate_configured_;
67  uint32_t max_bitrate_configured_;
68
69  uint8_t last_fraction_loss_;
70  uint16_t last_round_trip_time_;
71
72  uint32_t bwe_incoming_;
73  uint32_t time_last_increase_;
74  uint32_t time_last_decrease_;
75};
76}  // namespace webrtc
77#endif  // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
78