niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/codec_timer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <cstdint> |
| 14 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 15 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | |
wuchengli@chromium.org | 30377c7 | 2013-09-28 06:06:18 +0000 | [diff] [blame] | 19 | // The first kIgnoredSampleCount samples will be ignored. |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 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 |
wuchengli@chromium.org | 30377c7 | 2013-09-28 06:06:18 +0000 | [diff] [blame] | 27 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | VCMCodecTimer::VCMCodecTimer() |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 29 | : ignored_sample_count_(0), filter_(kPercentile) {} |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 30 | VCMCodecTimer::~VCMCodecTimer() = default; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 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_; |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 36 | return; |
| 37 | } |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 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(); |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 48 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | } |
| 50 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 51 | // Get the 95th percentile observed decode time within a time window. |
| 52 | int64_t VCMCodecTimer::RequiredDecodeTimeMs() const { |
| 53 | return filter_.GetPercentileValue(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | } |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 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 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 59 | } // namespace webrtc |