remote_bitrate_estimator.h revision 821510637147d6e4ea358db8f0415dd756bb14af
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  // Called for each incoming packet. Updates the incoming payload bitrate
45  // estimate and the over-use detector. If an over-use is detected the
46  // remote bitrate estimate will be updated. Note that |payload_size| is the
47  // packet size excluding headers.
48  virtual void IncomingPacket(int64_t arrival_time_ms,
49                              int payload_size,
50                              const RTPHeader& header) = 0;
51
52  // Removes all data for |ssrc|.
53  virtual void RemoveStream(unsigned int ssrc) = 0;
54
55  // Returns true if a valid estimate exists and sets |bitrate_bps| to the
56  // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
57  // currently being received and of which the bitrate estimate is based upon.
58  virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
59                              unsigned int* bitrate_bps) const = 0;
60
61 protected:
62  static const int kProcessIntervalMs = 1000;
63  static const int kStreamTimeOutMs = 2000;
64};
65
66struct RemoteBitrateEstimatorFactory {
67  RemoteBitrateEstimatorFactory() {}
68  virtual ~RemoteBitrateEstimatorFactory() {}
69
70  virtual RemoteBitrateEstimator* Create(
71      RemoteBitrateObserver* observer,
72      Clock* clock) const;
73};
74
75struct AbsoluteSendTimeRemoteBitrateEstimatorFactory
76    : public RemoteBitrateEstimatorFactory {
77  AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
78  virtual ~AbsoluteSendTimeRemoteBitrateEstimatorFactory() {}
79
80  virtual RemoteBitrateEstimator* Create(
81      RemoteBitrateObserver* observer,
82      Clock* clock) const;
83};
84}  // namespace webrtc
85
86#endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_REMOTE_BITRATE_ESTIMATOR_H_
87