blob: 0d4099ba9d20a8eaefbaf2d290adb4ed43afe754 [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
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <cstdint>
14
philipelcce46fc2015-12-21 03:04:49 -080015namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000016
magjed2943f012016-03-22 05:12:09 -070017namespace {
18
wuchengli@chromium.org30377c72013-09-28 06:06:18 +000019// The first kIgnoredSampleCount samples will be ignored.
magjed2943f012016-03-22 05:12:09 -070020const int kIgnoredSampleCount = 5;
21// Return the |kPercentile| value in RequiredDecodeTimeMs().
22const float kPercentile = 0.95f;
23// The window size in ms.
24const int64_t kTimeLimitMs = 10000;
25
26} // anonymous namespace
wuchengli@chromium.org30377c72013-09-28 06:06:18 +000027
niklase@google.com470e71d2011-07-07 08:21:25 +000028VCMCodecTimer::VCMCodecTimer()
magjed2943f012016-03-22 05:12:09 -070029 : ignored_sample_count_(0), filter_(kPercentile) {}
Niels Möllerbe682d42018-03-27 08:31:45 +020030VCMCodecTimer::~VCMCodecTimer() = default;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
magjed2943f012016-03-22 05:12:09 -070032void 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_;
philipelcce46fc2015-12-21 03:04:49 -080036 return;
37 }
magjed2943f012016-03-22 05:12:09 -070038
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();
philipelcce46fc2015-12-21 03:04:49 -080048 }
niklase@google.com470e71d2011-07-07 08:21:25 +000049}
50
magjed2943f012016-03-22 05:12:09 -070051// Get the 95th percentile observed decode time within a time window.
52int64_t VCMCodecTimer::RequiredDecodeTimeMs() const {
53 return filter_.GetPercentileValue();
niklase@google.com470e71d2011-07-07 08:21:25 +000054}
magjed2943f012016-03-22 05:12:09 -070055
56VCMCodecTimer::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
philipelcce46fc2015-12-21 03:04:49 -080059} // namespace webrtc