2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-05-23 09:53:15 +02:00
|
|
|
#include "modules/video_coding/timing/codec_timer.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
2016-03-16 07:51:44 -07:00
|
|
|
namespace webrtc {
|
2016-03-11 02:15:07 -08:00
|
|
|
|
2016-03-22 05:12:09 -07:00
|
|
|
namespace {
|
|
|
|
|
|
2013-09-28 06:06:18 +00:00
|
|
|
// The first kIgnoredSampleCount samples will be ignored.
|
2016-03-22 05:12:09 -07:00
|
|
|
const int kIgnoredSampleCount = 5;
|
2021-08-09 13:02:57 +02:00
|
|
|
// Return the `kPercentile` value in RequiredDecodeTimeMs().
|
2016-03-22 05:12:09 -07:00
|
|
|
const float kPercentile = 0.95f;
|
|
|
|
|
// The window size in ms.
|
|
|
|
|
const int64_t kTimeLimitMs = 10000;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 05:12:09 -07:00
|
|
|
} // anonymous namespace
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-05-23 09:53:15 +02:00
|
|
|
CodecTimer::CodecTimer() : ignored_sample_count_(0), filter_(kPercentile) {}
|
|
|
|
|
CodecTimer::~CodecTimer() = default;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-05-23 09:53:15 +02:00
|
|
|
void CodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) {
|
2021-08-09 13:02:57 +02:00
|
|
|
// Ignore the first `kIgnoredSampleCount` samples.
|
2016-03-22 05:12:09 -07:00
|
|
|
if (ignored_sample_count_ < kIgnoredSampleCount) {
|
|
|
|
|
++ignored_sample_count_;
|
|
|
|
|
return;
|
2015-12-21 03:04:49 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 05:12:09 -07:00
|
|
|
// Insert new decode time value.
|
|
|
|
|
filter_.Insert(decode_time_ms);
|
|
|
|
|
history_.emplace(decode_time_ms, now_ms);
|
2016-03-16 07:51:44 -07:00
|
|
|
|
2016-03-22 05:12:09 -07:00
|
|
|
// Pop old decode time values.
|
|
|
|
|
while (!history_.empty() &&
|
|
|
|
|
now_ms - history_.front().sample_time_ms > kTimeLimitMs) {
|
|
|
|
|
filter_.Erase(history_.front().decode_time_ms);
|
|
|
|
|
history_.pop();
|
2016-03-16 07:51:44 -07:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 05:12:09 -07:00
|
|
|
// Get the 95th percentile observed decode time within a time window.
|
2022-05-23 09:53:15 +02:00
|
|
|
int64_t CodecTimer::RequiredDecodeTimeMs() const {
|
2016-03-22 05:12:09 -07:00
|
|
|
return filter_.GetPercentileValue();
|
2016-03-16 07:51:44 -07:00
|
|
|
}
|
2016-03-11 02:15:07 -08:00
|
|
|
|
2022-05-23 09:53:15 +02:00
|
|
|
CodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms)
|
2016-03-22 05:12:09 -07:00
|
|
|
: decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {}
|
|
|
|
|
|
2015-12-21 03:04:49 -08:00
|
|
|
} // namespace webrtc
|