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 "modules/video_coding/codec_timer.h" 12 13 #include <cstdint> 14 15 namespace webrtc { 16 17 namespace { 18 19 // The first kIgnoredSampleCount samples will be ignored. 20 const int kIgnoredSampleCount = 5; 21 // Return the |kPercentile| value in RequiredDecodeTimeMs(). 22 const float kPercentile = 0.95f; 23 // The window size in ms. 24 const int64_t kTimeLimitMs = 10000; 25 26 } // anonymous namespace 27 VCMCodecTimer()28VCMCodecTimer::VCMCodecTimer() 29 : ignored_sample_count_(0), filter_(kPercentile) {} 30 VCMCodecTimer::~VCMCodecTimer() = default; 31 AddTiming(int64_t decode_time_ms,int64_t now_ms)32void 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_; 36 return; 37 } 38 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(); 48 } 49 } 50 51 // Get the 95th percentile observed decode time within a time window. RequiredDecodeTimeMs() const52int64_t VCMCodecTimer::RequiredDecodeTimeMs() const { 53 return filter_.GetPercentileValue(); 54 } 55 Sample(int64_t decode_time_ms,int64_t sample_time_ms)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 59 } // namespace webrtc 60