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