blob: d112959660ee739af639a1af4fe453efe026bb9a [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#ifndef MODULES_VIDEO_CODING_CODEC_TIMER_H_
12#define MODULES_VIDEO_CODING_CODEC_TIMER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
magjed2943f012016-03-22 05:12:09 -070014#include <queue>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/include/module_common_types.h"
17#include "rtc_base/numerics/percentile_filter.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000019
philipelcce46fc2015-12-21 03:04:49 -080020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
philipelcce46fc2015-12-21 03:04:49 -080022class VCMCodecTimer {
23 public:
24 VCMCodecTimer();
niklase@google.com470e71d2011-07-07 08:21:25 +000025
magjed2943f012016-03-22 05:12:09 -070026 // Add a new decode time to the filter.
27 void AddTiming(int64_t new_decode_time_ms, int64_t now_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000028
magjed2943f012016-03-22 05:12:09 -070029 // 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.com470e71d2011-07-07 08:21:25 +000032
philipelcce46fc2015-12-21 03:04:49 -080033 private:
magjed2943f012016-03-22 05:12:09 -070034 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.com470e71d2011-07-07 08:21:25 +000039
philipelcce46fc2015-12-21 03:04:49 -080040 // The number of samples ignored so far.
magjed2943f012016-03-22 05:12:09 -070041 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.
tereliuscb861e02016-11-30 06:51:57 -080046 PercentileFilter<int64_t> filter_;
niklase@google.com470e71d2011-07-07 08:21:25 +000047};
48
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000049} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#endif // MODULES_VIDEO_CODING_CODEC_TIMER_H_