2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 // This class estimates the incoming available bandwidth.
13 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
14 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
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"
28 enum RateControlType {
33 // RemoteBitrateObserver is used to signal changes in bitrate estimates for
34 // the incoming streams.
35 class RemoteBitrateObserver {
37 // Called when a receive channel group has a new bitrate estimate for the
39 virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
40 unsigned int bitrate) = 0;
42 virtual ~RemoteBitrateObserver() {}
45 struct ReceiveBandwidthEstimatorStats {
46 ReceiveBandwidthEstimatorStats() : total_propagation_time_delta_ms(0) {}
48 // The "propagation_time_delta" of a frame is defined as (d_arrival - d_sent),
49 // where d_arrival is the delta of the arrival times of the frame and the
50 // previous frame, d_sent is the delta of the sent times of the frame and
51 // the previous frame. The sent time is calculated from the RTP timestamp.
53 // |total_propagation_time_delta_ms| is the sum of the propagation_time_deltas
54 // of all received frames, except that it's is adjusted to 0 when it becomes
56 int total_propagation_time_delta_ms;
57 // The propagation_time_deltas for the frames arrived in the last
58 // kProcessIntervalMs using the clock passed to
59 // RemoteBitrateEstimatorFactory::Create.
60 std::vector<int> recent_propagation_time_delta_ms;
61 // The arrival times for the frames arrived in the last kProcessIntervalMs
62 // using the clock passed to RemoteBitrateEstimatorFactory::Create.
63 std::vector<int64_t> recent_arrival_time_ms;
66 class RemoteBitrateEstimator : public CallStatsObserver, public Module {
68 virtual ~RemoteBitrateEstimator() {}
70 // Called for each incoming packet. Updates the incoming payload bitrate
71 // estimate and the over-use detector. If an over-use is detected the
72 // remote bitrate estimate will be updated. Note that |payload_size| is the
73 // packet size excluding headers.
74 virtual void IncomingPacket(int64_t arrival_time_ms,
76 const RTPHeader& header) = 0;
78 // Removes all data for |ssrc|.
79 virtual void RemoveStream(unsigned int ssrc) = 0;
81 // Returns true if a valid estimate exists and sets |bitrate_bps| to the
82 // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
83 // currently being received and of which the bitrate estimate is based upon.
84 virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
85 unsigned int* bitrate_bps) const = 0;
87 // Returns true if the statistics are available.
88 virtual bool GetStats(ReceiveBandwidthEstimatorStats* output) const = 0;
91 static const int kProcessIntervalMs = 1000;
92 static const int kStreamTimeOutMs = 2000;
95 struct RemoteBitrateEstimatorFactory {
96 RemoteBitrateEstimatorFactory() {}
97 virtual ~RemoteBitrateEstimatorFactory() {}
99 virtual RemoteBitrateEstimator* Create(
100 RemoteBitrateObserver* observer,
102 RateControlType control_type,
103 uint32_t min_bitrate_bps) const;
106 struct AbsoluteSendTimeRemoteBitrateEstimatorFactory
107 : public RemoteBitrateEstimatorFactory {
108 AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
109 virtual ~AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
111 virtual RemoteBitrateEstimator* Create(
112 RemoteBitrateObserver* observer,
114 RateControlType control_type,
115 uint32_t min_bitrate_bps) const;
117 } // namespace webrtc
119 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_