Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / remote_bitrate_estimator / include / remote_bitrate_estimator.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
11 // This class estimates the incoming available bandwidth.
12
13 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
14 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
15
16 #include <map>
17 #include <vector>
18
19 #include "webrtc/common_types.h"
20 #include "webrtc/modules/interface/module.h"
21 #include "webrtc/modules/interface/module_common_types.h"
22 #include "webrtc/typedefs.h"
23
24 namespace webrtc {
25
26 class Clock;
27
28 // RemoteBitrateObserver is used to signal changes in bitrate estimates for
29 // the incoming streams.
30 class RemoteBitrateObserver {
31  public:
32   // Called when a receive channel group has a new bitrate estimate for the
33   // incoming streams.
34   virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
35                                        unsigned int bitrate) = 0;
36
37   virtual ~RemoteBitrateObserver() {}
38 };
39
40 struct ReceiveBandwidthEstimatorStats {
41   ReceiveBandwidthEstimatorStats() : total_propagation_time_delta_ms(0) {}
42
43   // The "propagation_time_delta" of a frame is defined as (d_arrival - d_sent),
44   // where d_arrival is the delta of the arrival times of the frame and the
45   // previous frame, d_sent is the delta of the sent times of the frame and
46   // the previous frame. The sent time is calculated from the RTP timestamp.
47
48   // |total_propagation_time_delta_ms| is the sum of the propagation_time_deltas
49   // of all received frames, except that it's is adjusted to 0 when it becomes
50   // negative.
51   int total_propagation_time_delta_ms;
52   // The propagation_time_deltas for the frames arrived in the last
53   // kProcessIntervalMs using the clock passed to
54   // RemoteBitrateEstimatorFactory::Create.
55   std::vector<int> recent_propagation_time_delta_ms;
56   // The arrival times for the frames arrived in the last kProcessIntervalMs
57   // using the clock passed to RemoteBitrateEstimatorFactory::Create.
58   std::vector<int64_t> recent_arrival_time_ms;
59 };
60
61 class RemoteBitrateEstimator : public CallStatsObserver, public Module {
62  public:
63   virtual ~RemoteBitrateEstimator() {}
64
65   // Called for each incoming packet. Updates the incoming payload bitrate
66   // estimate and the over-use detector. If an over-use is detected the
67   // remote bitrate estimate will be updated. Note that |payload_size| is the
68   // packet size excluding headers.
69   virtual void IncomingPacket(int64_t arrival_time_ms,
70                               int payload_size,
71                               const RTPHeader& header) = 0;
72
73   // Removes all data for |ssrc|.
74   virtual void RemoveStream(unsigned int ssrc) = 0;
75
76   // Returns true if a valid estimate exists and sets |bitrate_bps| to the
77   // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
78   // currently being received and of which the bitrate estimate is based upon.
79   virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
80                               unsigned int* bitrate_bps) const = 0;
81
82   // Returns true if the statistics are available.
83   virtual bool GetStats(ReceiveBandwidthEstimatorStats* output) const = 0;
84
85  protected:
86   static const int kProcessIntervalMs = 1000;
87   static const int kStreamTimeOutMs = 2000;
88 };
89
90 struct RemoteBitrateEstimatorFactory {
91   RemoteBitrateEstimatorFactory() {}
92   virtual ~RemoteBitrateEstimatorFactory() {}
93
94   virtual RemoteBitrateEstimator* Create(
95       RemoteBitrateObserver* observer,
96       Clock* clock,
97       uint32_t min_bitrate_bps) const;
98 };
99
100 struct AbsoluteSendTimeRemoteBitrateEstimatorFactory
101     : public RemoteBitrateEstimatorFactory {
102   AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
103   virtual ~AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
104
105   virtual RemoteBitrateEstimator* Create(
106       RemoteBitrateObserver* observer,
107       Clock* clock,
108       uint32_t min_bitrate_bps) const;
109 };
110 }  // namespace webrtc
111
112 #endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_