niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_CODEC_TIMER_H_ |
| 12 | #define MODULES_VIDEO_CODING_CODEC_TIMER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 14 | #include <queue> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/include/module_common_types.h" |
| 17 | #include "rtc_base/numerics/percentile_filter.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 18 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 22 | class VCMCodecTimer { |
| 23 | public: |
| 24 | VCMCodecTimer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 26 | // Add a new decode time to the filter. |
| 27 | void AddTiming(int64_t new_decode_time_ms, int64_t now_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 29 | // Get the required decode time in ms. It is the 95th percentile observed |
| 30 | // decode time within a time window. |
| 31 | int64_t RequiredDecodeTimeMs() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 33 | private: |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 34 | struct Sample { |
| 35 | Sample(int64_t decode_time_ms, int64_t sample_time_ms); |
| 36 | int64_t decode_time_ms; |
| 37 | int64_t sample_time_ms; |
| 38 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 40 | // The number of samples ignored so far. |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 41 | int ignored_sample_count_; |
| 42 | // Queue with history of latest decode time values. |
| 43 | std::queue<Sample> history_; |
| 44 | // |filter_| contains the same values as |history_|, but in a data structure |
| 45 | // that allows efficient retrieval of the percentile value. |
terelius | cb861e0 | 2016-11-30 06:51:57 -0800 | [diff] [blame] | 46 | PercentileFilter<int64_t> filter_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 49 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 51 | #endif // MODULES_VIDEO_CODING_CODEC_TIMER_H_ |