Line data Source code
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 :
11 : #include "webrtc/modules/video_coding/codec_timer.h"
12 :
13 : namespace webrtc {
14 :
15 : namespace {
16 :
17 : // The first kIgnoredSampleCount samples will be ignored.
18 : const int kIgnoredSampleCount = 5;
19 : // Return the |kPercentile| value in RequiredDecodeTimeMs().
20 : const float kPercentile = 0.95f;
21 : // The window size in ms.
22 : const int64_t kTimeLimitMs = 10000;
23 :
24 : } // anonymous namespace
25 :
26 0 : VCMCodecTimer::VCMCodecTimer()
27 0 : : ignored_sample_count_(0), filter_(kPercentile) {}
28 :
29 0 : void VCMCodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) {
30 : // Ignore the first |kIgnoredSampleCount| samples.
31 0 : if (ignored_sample_count_ < kIgnoredSampleCount) {
32 0 : ++ignored_sample_count_;
33 0 : return;
34 : }
35 :
36 : // Insert new decode time value.
37 0 : filter_.Insert(decode_time_ms);
38 0 : history_.emplace(decode_time_ms, now_ms);
39 :
40 : // Pop old decode time values.
41 0 : while (!history_.empty() &&
42 0 : now_ms - history_.front().sample_time_ms > kTimeLimitMs) {
43 0 : filter_.Erase(history_.front().decode_time_ms);
44 0 : history_.pop();
45 : }
46 : }
47 :
48 : // Get the 95th percentile observed decode time within a time window.
49 0 : int64_t VCMCodecTimer::RequiredDecodeTimeMs() const {
50 0 : return filter_.GetPercentileValue();
51 : }
52 :
53 0 : VCMCodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms)
54 0 : : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {}
55 :
56 : } // namespace webrtc
|