bitrate.h revision 66b2e5c05a3f2a93d634d1dbbcbb283fb218ca4f
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#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_
13
14#include <stdio.h>
15
16#include <list>
17
18#include "webrtc/common_types.h"
19#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
20#include "webrtc/typedefs.h"
21
22namespace webrtc {
23
24class Clock;
25
26class Bitrate {
27 public:
28  explicit Bitrate(Clock* clock);
29
30  // Calculates rates.
31  void Process();
32
33  // Update with a packet.
34  void Update(const int32_t bytes);
35
36  // Packet rate last second, updated roughly every 100 ms.
37  uint32_t PacketRate() const;
38
39  // Bitrate last second, updated roughly every 100 ms.
40  uint32_t BitrateLast() const;
41
42  // Bitrate last second, updated now.
43  uint32_t BitrateNow() const;
44
45  int64_t time_last_rate_update() const;
46
47 protected:
48  Clock* clock_;
49
50 private:
51  uint32_t packet_rate_;
52  uint32_t bitrate_;
53  uint8_t bitrate_next_idx_;
54  int64_t packet_rate_array_[10];
55  int64_t bitrate_array_[10];
56  int64_t bitrate_diff_ms_[10];
57  int64_t time_last_rate_update_;
58  uint32_t bytes_count_;
59  uint32_t packet_count_;
60};
61
62}  // namespace webrtc
63
64#endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_
65