• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/scoped_ptr.h"
19 #include "webrtc/common_types.h"
20 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
21 #include "webrtc/typedefs.h"
22 
23 namespace webrtc {
24 
25 class Clock;
26 class CriticalSectionWrapper;
27 
28 class Bitrate {
29  public:
30   class Observer;
31   Bitrate(Clock* clock, Observer* observer);
32   virtual ~Bitrate();
33 
34   // Calculates rates.
35   void Process();
36 
37   // Update with a packet.
38   void Update(const size_t bytes);
39 
40   // Packet rate last second, updated roughly every 100 ms.
41   uint32_t PacketRate() const;
42 
43   // Bitrate last second, updated roughly every 100 ms.
44   uint32_t BitrateLast() const;
45 
46   // Bitrate last second, updated now.
47   uint32_t BitrateNow() const;
48 
49   int64_t time_last_rate_update() const;
50 
51   class Observer {
52    public:
Observer()53     Observer() {}
~Observer()54     virtual ~Observer() {}
55 
56     virtual void BitrateUpdated(const BitrateStatistics& stats) = 0;
57   };
58 
59  protected:
60   Clock* clock_;
61 
62  private:
63   rtc::scoped_ptr<CriticalSectionWrapper> crit_;
64   uint32_t packet_rate_;
65   uint32_t bitrate_;
66   uint8_t bitrate_next_idx_;
67   int64_t packet_rate_array_[10];
68   int64_t bitrate_array_[10];
69   int64_t bitrate_diff_ms_[10];
70   int64_t time_last_rate_update_;
71   size_t bytes_count_;
72   uint32_t packet_count_;
73   Observer* const observer_;
74 };
75 
76 }  // namespace webrtc
77 
78 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_
79