bitrate.h revision a048d7cb0a5bad5ca49bbcc5273cb4cca28c1710
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 protected: 46 Clock* clock_; 47 48 private: 49 uint32_t packet_rate_; 50 uint32_t bitrate_; 51 uint8_t bitrate_next_idx_; 52 int64_t packet_rate_array_[10]; 53 int64_t bitrate_array_[10]; 54 int64_t bitrate_diff_ms_[10]; 55 int64_t time_last_rate_update_; 56 uint32_t bytes_count_; 57 uint32_t packet_count_; 58}; 59 60} // namespace webrtc 61 62#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ 63