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 | |
Rasmus Brandt | 2377226 | 2022-05-23 09:53:15 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/timing/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; |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 21 | // Return the `kPercentile` value in RequiredDecodeTimeMs(). |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 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 | |
Rasmus Brandt | 2377226 | 2022-05-23 09:53:15 +0200 | [diff] [blame] | 28 | CodecTimer::CodecTimer() : ignored_sample_count_(0), filter_(kPercentile) {} |
| 29 | CodecTimer::~CodecTimer() = default; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
Rasmus Brandt | 2377226 | 2022-05-23 09:53:15 +0200 | [diff] [blame] | 31 | void CodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) { |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 32 | // Ignore the first `kIgnoredSampleCount` samples. |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 33 | if (ignored_sample_count_ < kIgnoredSampleCount) { |
| 34 | ++ignored_sample_count_; |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 35 | return; |
| 36 | } |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 37 | |
| 38 | // Insert new decode time value. |
| 39 | filter_.Insert(decode_time_ms); |
| 40 | history_.emplace(decode_time_ms, now_ms); |
| 41 | |
| 42 | // Pop old decode time values. |
| 43 | while (!history_.empty() && |
| 44 | now_ms - history_.front().sample_time_ms > kTimeLimitMs) { |
| 45 | filter_.Erase(history_.front().decode_time_ms); |
| 46 | history_.pop(); |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 47 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | } |
| 49 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 50 | // Get the 95th percentile observed decode time within a time window. |
Rasmus Brandt | 2377226 | 2022-05-23 09:53:15 +0200 | [diff] [blame] | 51 | int64_t CodecTimer::RequiredDecodeTimeMs() const { |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 52 | return filter_.GetPercentileValue(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | } |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 54 | |
Rasmus Brandt | 2377226 | 2022-05-23 09:53:15 +0200 | [diff] [blame] | 55 | CodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms) |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 56 | : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {} |
| 57 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 58 | } // namespace webrtc |