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 <deque>
17
18#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
19#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
20
21namespace webrtc {
22class SendSideBandwidthEstimation {
23 public:
24  SendSideBandwidthEstimation();
25  virtual ~SendSideBandwidthEstimation();
26
27  void CurrentEstimate(uint32_t* bitrate, uint8_t* loss, uint32_t* rtt) const;
28
29  // Call periodically to update estimate.
30  void UpdateEstimate(uint32_t now_ms);
31
32  // Call when we receive a RTCP message with TMMBR or REMB.
33  void UpdateReceiverEstimate(uint32_t bandwidth);
34
35  // Call when we receive a RTCP message with a ReceiveBlock.
36  void UpdateReceiverBlock(uint8_t fraction_loss,
37                           uint32_t rtt,
38                           int number_of_packets,
39                           uint32_t now_ms);
40
41  void SetSendBitrate(uint32_t bitrate);
42  void SetMinMaxBitrate(uint32_t min_bitrate, uint32_t max_bitrate);
43  void SetMinBitrate(uint32_t min_bitrate);
44
45 private:
46  void CapBitrateToThresholds();
47
48  // Updates history of min bitrates.
49  // After this method returns min_bitrate_history_.front().second contains the
50  // min bitrate used during last kBweIncreaseIntervalMs.
51  void UpdateMinHistory(uint32_t now_ms);
52
53  std::deque<std::pair<uint32_t, uint32_t> > min_bitrate_history_;
54
55  // incoming filters
56  int accumulate_lost_packets_Q8_;
57  int accumulate_expected_packets_;
58
59  uint32_t bitrate_;
60  uint32_t min_bitrate_configured_;
61  uint32_t max_bitrate_configured_;
62
63  uint32_t time_last_receiver_block_ms_;
64  uint8_t last_fraction_loss_;
65  uint16_t last_round_trip_time_ms_;
66
67  uint32_t bwe_incoming_;
68  uint32_t time_last_decrease_ms_;
69};
70}  // namespace webrtc
71#endif  // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
72