blob: 725f02501d2d00909d0d063d750163c58dbae240 [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) {}
Niels Möllerbe682d42018-03-27 08:31:45 +020028VCMCodecTimer::~VCMCodecTimer() = default;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
magjed2943f012016-03-22 05:12:09 -070030void VCMCodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) {
31 // Ignore the first |kIgnoredSampleCount| samples.
32 if (ignored_sample_count_ < kIgnoredSampleCount) {
33 ++ignored_sample_count_;
philipelcce46fc2015-12-21 03:04:49 -080034 return;
35 }
magjed2943f012016-03-22 05:12:09 -070036
37 // Insert new decode time value.
38 filter_.Insert(decode_time_ms);
39 history_.emplace(decode_time_ms, now_ms);
40
41 // Pop old decode time values.
42 while (!history_.empty() &&
43 now_ms - history_.front().sample_time_ms > kTimeLimitMs) {
44 filter_.Erase(history_.front().decode_time_ms);
45 history_.pop();
philipelcce46fc2015-12-21 03:04:49 -080046 }
niklase@google.com470e71d2011-07-07 08:21:25 +000047}
48
magjed2943f012016-03-22 05:12:09 -070049// Get the 95th percentile observed decode time within a time window.
50int64_t VCMCodecTimer::RequiredDecodeTimeMs() const {
51 return filter_.GetPercentileValue();
niklase@google.com470e71d2011-07-07 08:21:25 +000052}
magjed2943f012016-03-22 05:12:09 -070053
54VCMCodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms)
55 : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {}
56
philipelcce46fc2015-12-21 03:04:49 -080057} // namespace webrtc