remote_bitrate_estimator.h revision de98478965979e3de7578caae192c5110bc578ef
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
24namespace webrtc {
25
26class Clock;
27
28// RemoteBitrateObserver is used to signal changes in bitrate estimates for
29// the incoming streams.
30class 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
40class RemoteBitrateEstimator : public CallStatsObserver, public Module {
41 public:
42  virtual ~RemoteBitrateEstimator() {}
43
44  // Stores an RTCP SR (NTP, RTP timestamp) tuple for a specific SSRC to be used
45  // in future RTP timestamp to NTP time conversions. As soon as any SSRC has
46  // two tuples the RemoteBitrateEstimator will switch to multi-stream mode.
47  virtual void IncomingRtcp(unsigned int ssrc, uint32_t ntp_secs,
48                            uint32_t ntp_frac, uint32_t rtp_timestamp) = 0;
49
50  // Called for each incoming packet. Updates the incoming payload bitrate
51  // estimate and the over-use detector. If an over-use is detected the
52  // remote bitrate estimate will be updated. Note that |payload_size| is the
53  // packet size excluding headers. The estimator can only count on the
54  // "header" (an RTPHeader) and "extension" (an RTPHeaderExtension) fields of
55  // the WebRtcRTPHeader to be initialized.
56  virtual void IncomingPacket(int64_t arrival_time_ms,
57                              int payload_size,
58                              const RTPHeader& header) = 0;
59
60  // Removes all data for |ssrc|.
61  virtual void RemoveStream(unsigned int ssrc) = 0;
62
63  // Returns true if a valid estimate exists and sets |bitrate_bps| to the
64  // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
65  // currently being received and of which the bitrate estimate is based upon.
66  virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
67                              unsigned int* bitrate_bps) const = 0;
68
69 protected:
70  static const int kProcessIntervalMs = 1000;
71  static const int kStreamTimeOutMs = 2000;
72};
73
74struct RemoteBitrateEstimatorFactory {
75  RemoteBitrateEstimatorFactory() {}
76  virtual ~RemoteBitrateEstimatorFactory() {}
77
78  virtual RemoteBitrateEstimator* Create(
79      RemoteBitrateObserver* observer,
80      Clock* clock) const;
81};
82
83struct AbsoluteSendTimeRemoteBitrateEstimatorFactory {
84  AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
85  virtual ~AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
86
87  virtual RemoteBitrateEstimator* Create(
88      RemoteBitrateObserver* observer,
89      Clock* clock) const;
90};
91
92struct MultiStreamRemoteBitrateEstimatorFactory
93    : RemoteBitrateEstimatorFactory {
94  MultiStreamRemoteBitrateEstimatorFactory() {}
95  virtual ~MultiStreamRemoteBitrateEstimatorFactory() {}
96
97  virtual RemoteBitrateEstimator* Create(
98      RemoteBitrateObserver* observer,
99      Clock* clock) const;
100};
101}  // namespace webrtc
102
103#endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
104