blob: 1a46834f738febaa5faceda5aeda613ff4c5f1d0 [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();
Niels Möllerbe682d42018-03-27 08:31:45 +020025 ~VCMCodecTimer();
niklase@google.com470e71d2011-07-07 08:21:25 +000026
magjed2943f012016-03-22 05:12:09 -070027 // Add a new decode time to the filter.
28 void AddTiming(int64_t new_decode_time_ms, int64_t now_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000029
magjed2943f012016-03-22 05:12:09 -070030 // Get the required decode time in ms. It is the 95th percentile observed
31 // decode time within a time window.
32 int64_t RequiredDecodeTimeMs() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
philipelcce46fc2015-12-21 03:04:49 -080034 private:
magjed2943f012016-03-22 05:12:09 -070035 struct Sample {
36 Sample(int64_t decode_time_ms, int64_t sample_time_ms);
37 int64_t decode_time_ms;
38 int64_t sample_time_ms;
39 };
niklase@google.com470e71d2011-07-07 08:21:25 +000040
philipelcce46fc2015-12-21 03:04:49 -080041 // The number of samples ignored so far.
magjed2943f012016-03-22 05:12:09 -070042 int ignored_sample_count_;
43 // Queue with history of latest decode time values.
44 std::queue<Sample> history_;
45 // |filter_| contains the same values as |history_|, but in a data structure
46 // that allows efficient retrieval of the percentile value.
tereliuscb861e02016-11-30 06:51:57 -080047 PercentileFilter<int64_t> filter_;
niklase@google.com470e71d2011-07-07 08:21:25 +000048};
49
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000050} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000051
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#endif // MODULES_VIDEO_CODING_CODEC_TIMER_H_