blob: 412e4cc8b15071774364a9bc1ba76ddf6a36539d [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 "rtc_base/numerics/percentile_filter.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
philipelcce46fc2015-12-21 03:04:49 -080018namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000019
philipelcce46fc2015-12-21 03:04:49 -080020class VCMCodecTimer {
21 public:
22 VCMCodecTimer();
Niels Möllerbe682d42018-03-27 08:31:45 +020023 ~VCMCodecTimer();
niklase@google.com470e71d2011-07-07 08:21:25 +000024
magjed2943f012016-03-22 05:12:09 -070025 // Add a new decode time to the filter.
26 void AddTiming(int64_t new_decode_time_ms, int64_t now_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000027
magjed2943f012016-03-22 05:12:09 -070028 // Get the required decode time in ms. It is the 95th percentile observed
29 // decode time within a time window.
30 int64_t RequiredDecodeTimeMs() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
philipelcce46fc2015-12-21 03:04:49 -080032 private:
magjed2943f012016-03-22 05:12:09 -070033 struct Sample {
34 Sample(int64_t decode_time_ms, int64_t sample_time_ms);
35 int64_t decode_time_ms;
36 int64_t sample_time_ms;
37 };
niklase@google.com470e71d2011-07-07 08:21:25 +000038
philipelcce46fc2015-12-21 03:04:49 -080039 // The number of samples ignored so far.
magjed2943f012016-03-22 05:12:09 -070040 int ignored_sample_count_;
41 // Queue with history of latest decode time values.
42 std::queue<Sample> history_;
43 // |filter_| contains the same values as |history_|, but in a data structure
44 // that allows efficient retrieval of the percentile value.
tereliuscb861e02016-11-30 06:51:57 -080045 PercentileFilter<int64_t> filter_;
niklase@google.com470e71d2011-07-07 08:21:25 +000046};
47
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000048} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000049
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020050#endif // MODULES_VIDEO_CODING_CODEC_TIMER_H_