- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / bitrate_controller / send_side_bandwidth_estimation.h
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
19 namespace webrtc {
20 class 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
45  private:
46   bool ShapeSimple(const uint8_t loss, const uint32_t rtt,
47                    const uint32_t now_ms, uint32_t* bitrate);
48
49   uint32_t CalcTFRCbps(uint16_t rtt, uint8_t loss);
50
51   enum { kBWEIncreaseIntervalMs = 1000 };
52   enum { kBWEDecreaseIntervalMs = 300 };
53   enum { kLimitNumPackets = 20 };
54   enum { kAvgPacketSizeBytes = 1000 };
55
56   CriticalSectionWrapper* critsect_;
57
58   // incoming filters
59   int accumulate_lost_packets_Q8_;
60   int accumulate_expected_packets_;
61
62   uint32_t bitrate_;
63   uint32_t min_bitrate_configured_;
64   uint32_t max_bitrate_configured_;
65
66   uint8_t last_fraction_loss_;
67   uint16_t last_round_trip_time_;
68
69   uint32_t bwe_incoming_;
70   uint32_t time_last_increase_;
71   uint32_t time_last_decrease_;
72 };
73 }  // namespace webrtc
74 #endif  // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_