| 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 | #include "modules/video_coding/codec_timer.h" |
| 12 |
| 13 | #include <cstdint> |
| 14 |
| 15 | namespace webrtc { |
| 16 |
| 17 | namespace { |
| 18 |
| 19 | // The first kIgnoredSampleCount samples will be ignored. |
| 20 | const int kIgnoredSampleCount = 5; |
| 21 | // Return the |kPercentile| value in RequiredDecodeTimeMs(). |
| 22 | const float kPercentile = 0.95f; |
| 23 | // The window size in ms. |
| 24 | const int64_t kTimeLimitMs = 10000; |
| 25 |
| 26 | } // anonymous namespace |
| 27 |
| 28 | VCMCodecTimer::VCMCodecTimer() |
| 29 | : ignored_sample_count_(0), filter_(kPercentile) {} |
| 30 | VCMCodecTimer::~VCMCodecTimer() = default; |
| 31 |
| 32 | void VCMCodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) { |
| 33 | // Ignore the first |kIgnoredSampleCount| samples. |
| 34 | if (ignored_sample_count_ < kIgnoredSampleCount) { |
| 35 | ++ignored_sample_count_; |
| 36 | return; |
| 37 | } |
| 38 |
| 39 | // Insert new decode time value. |
| 40 | filter_.Insert(decode_time_ms); |
| 41 | history_.emplace(decode_time_ms, now_ms); |
| 42 |
| 43 | // Pop old decode time values. |
| 44 | while (!history_.empty() && |
| 45 | now_ms - history_.front().sample_time_ms > kTimeLimitMs) { |
| 46 | filter_.Erase(history_.front().decode_time_ms); |
| 47 | history_.pop(); |
| 48 | } |
| 49 | } |
| 50 |
| 51 | // Get the 95th percentile observed decode time within a time window. |
| 52 | int64_t VCMCodecTimer::RequiredDecodeTimeMs() const { |
| 53 | return filter_.GetPercentileValue(); |
| 54 | } |
| 55 |
| 56 | VCMCodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms) |
| 57 | : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {} |
| 58 |
| 59 | } // namespace webrtc |
| 60 |