OLD | NEW |
(Empty) | |
| 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/criticalsection.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 |
| 27 class Bitrate { |
| 28 public: |
| 29 class Observer; |
| 30 Bitrate(Clock* clock, Observer* observer); |
| 31 virtual ~Bitrate(); |
| 32 |
| 33 // Calculates rates. |
| 34 void Process(); |
| 35 |
| 36 // Update with a packet. |
| 37 void Update(const size_t bytes); |
| 38 |
| 39 // Packet rate last second, updated roughly every 100 ms. |
| 40 uint32_t PacketRate() const; |
| 41 |
| 42 // Bitrate last second, updated roughly every 100 ms. |
| 43 uint32_t BitrateLast() const; |
| 44 |
| 45 // Bitrate last second, updated now. |
| 46 uint32_t BitrateNow() const; |
| 47 |
| 48 int64_t time_last_rate_update() const; |
| 49 |
| 50 class Observer { |
| 51 public: |
| 52 Observer() {} |
| 53 virtual ~Observer() {} |
| 54 |
| 55 virtual void BitrateUpdated(const BitrateStatistics& stats) = 0; |
| 56 }; |
| 57 |
| 58 protected: |
| 59 Clock* clock_; |
| 60 |
| 61 private: |
| 62 rtc::CriticalSection crit_; |
| 63 uint32_t packet_rate_; |
| 64 uint32_t bitrate_; |
| 65 uint8_t bitrate_next_idx_; |
| 66 int64_t packet_rate_array_[10]; |
| 67 int64_t bitrate_array_[10]; |
| 68 int64_t bitrate_diff_ms_[10]; |
| 69 int64_t time_last_rate_update_; |
| 70 size_t bytes_count_; |
| 71 uint32_t packet_count_; |
| 72 Observer* const observer_; |
| 73 }; |
| 74 |
| 75 } // namespace webrtc |
| 76 |
| 77 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ |
OLD | NEW |