blob: 8859fcd6e71814e8be619d2a1bbf3fbeed10e166 [file] [log] [blame]
niklase@google.com77ae29b2011-05-30 11:22:19 +00001/*
2 * Copyright (c) 2011 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 "typedefs.h"
15#include "rtp_rtcp_config.h" // misc. defines (e.g. MAX_PACKET_LENGTH)
16#include "common_types.h" // Transport
17#include "list_wrapper.h"
18
19namespace webrtc {
20class Bitrate
21{
22public:
23 Bitrate();
24
25 // initialize members
26 void Init();
27
28 // calculate rates
29 void Process();
30
31 // update with a packet
32 void Update(const WebRtc_Word32 bytes);
33
34 // packet rate last second, updated roughly every 100 ms
35 WebRtc_UWord32 PacketRate() const;
36
37 // bitrate last second, updated roughly every 100 ms
38 WebRtc_UWord32 BitrateLast() const;
39
40 // bitrate last second, updated now
41 WebRtc_UWord32 BitrateNow() const;
42
43private:
44 WebRtc_UWord32 _packetRate;
45 WebRtc_UWord32 _bitrate;
46 WebRtc_UWord8 _bitrateNextIdx;
47 WebRtc_UWord32 _packetRateArray[10];
48 WebRtc_UWord32 _bitrateArray[10];
49 WebRtc_UWord32 _bitrateDiffMS[10];
50 WebRtc_UWord32 _timeLastRateUpdate;
51 WebRtc_UWord32 _bytesCount;
52 WebRtc_UWord32 _packetCount;
53};
54
55struct DataTimeSizeTuple
56{
57 DataTimeSizeTuple(WebRtc_Word64 sizeBytes, WebRtc_Word64 timeCompleteMs) :
58 _sizeBytes(sizeBytes), _timeCompleteMs(timeCompleteMs) {}
59
60 WebRtc_Word64 _sizeBytes;
61 WebRtc_Word64 _timeCompleteMs;
62};
63
64class BitRateStats
65{
66public:
67 BitRateStats();
68 ~BitRateStats();
69
70 void Init();
71 void Update(WebRtc_Word64 packetSizeBytes, WebRtc_Word64 nowMs);
72 WebRtc_UWord32 BitRateNow();
73
74private:
75 ListWrapper _dataSamples;
76 WebRtc_UWord32 _avgSentBitRateBps;
77};
78} // namespace webrtc
79
80#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_