blob: 5a9b6e4e786c1f8b783b26f799c61594657839c3 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/codec_timer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
philipelcce46fc2015-12-21 03:04:49 -080013namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000014
magjed2943f012016-03-22 05:12:09 -070015namespace {
16
wuchengli@chromium.org30377c72013-09-28 06:06:18 +000017// The first kIgnoredSampleCount samples will be ignored.
magjed2943f012016-03-22 05:12:09 -070018const int kIgnoredSampleCount = 5;
19// Return the |kPercentile| value in RequiredDecodeTimeMs().
20const float kPercentile = 0.95f;
21// The window size in ms.
22const int64_t kTimeLimitMs = 10000;
23
24} // anonymous namespace
wuchengli@chromium.org30377c72013-09-28 06:06:18 +000025
niklase@google.com470e71d2011-07-07 08:21:25 +000026VCMCodecTimer::VCMCodecTimer()
magjed2943f012016-03-22 05:12:09 -070027 : ignored_sample_count_(0), filter_(kPercentile) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000028
magjed2943f012016-03-22 05:12:09 -070029void VCMCodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) {
30 // Ignore the first |kIgnoredSampleCount| samples.
31 if (ignored_sample_count_ < kIgnoredSampleCount) {
32 ++ignored_sample_count_;
philipelcce46fc2015-12-21 03:04:49 -080033 return;
34 }
magjed2943f012016-03-22 05:12:09 -070035
36 // Insert new decode time value.
37 filter_.Insert(decode_time_ms);
38 history_.emplace(decode_time_ms, now_ms);
39
40 // Pop old decode time values.
41 while (!history_.empty() &&
42 now_ms - history_.front().sample_time_ms > kTimeLimitMs) {
43 filter_.Erase(history_.front().decode_time_ms);
44 history_.pop();
philipelcce46fc2015-12-21 03:04:49 -080045 }
niklase@google.com470e71d2011-07-07 08:21:25 +000046}
47
magjed2943f012016-03-22 05:12:09 -070048// Get the 95th percentile observed decode time within a time window.
49int64_t VCMCodecTimer::RequiredDecodeTimeMs() const {
50 return filter_.GetPercentileValue();
niklase@google.com470e71d2011-07-07 08:21:25 +000051}
magjed2943f012016-03-22 05:12:09 -070052
53VCMCodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms)
54 : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {}
55
philipelcce46fc2015-12-21 03:04:49 -080056} // namespace webrtc