blob: 1fbd71ffc4767da9223fcda1556ade847f63207c [file] [log] [blame]
Henrik Boströmce33b6a2019-05-28 17:42:38 +02001/*
2 * Copyright 2019 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#ifndef VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
12#define VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
13
14#include <map>
15
16#include "common_video/include/quality_limitation_reason.h"
17#include "system_wrappers/include/clock.h"
18
19namespace webrtc {
20
21// A tracker of quality limitation reasons. The quality limitation reason is the
22// primary reason for limiting resolution and/or framerate (such as CPU or
23// bandwidth limitations). The tracker keeps track of the current reason and the
Evan Shrubsolecc62b162019-09-09 11:26:45 +020024// duration of time spent in each reason. See qualityLimitationReason[1],
25// qualityLimitationDurations[2], and qualityLimitationResolutionChanges[3] in
26// the webrtc-stats spec.
Henrik Boströmce33b6a2019-05-28 17:42:38 +020027// [1]
28// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
29// [2]
30// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
Evan Shrubsolecc62b162019-09-09 11:26:45 +020031// [3]
32// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
Henrik Boströmce33b6a2019-05-28 17:42:38 +020033class QualityLimitationReasonTracker {
34 public:
35 // The caller is responsible for making sure |clock| outlives the tracker.
36 explicit QualityLimitationReasonTracker(Clock* clock);
37
38 // The current reason defaults to QualityLimitationReason::kNone.
39 QualityLimitationReason current_reason() const;
40 void SetReason(QualityLimitationReason reason);
41 std::map<QualityLimitationReason, int64_t> DurationsMs() const;
42
43 private:
44 Clock* const clock_;
45 QualityLimitationReason current_reason_;
46 int64_t current_reason_updated_timestamp_ms_;
47 // The total amount of time spent in each reason at time
48 // |current_reason_updated_timestamp_ms_|. To get the total amount duration
49 // so-far, including the time spent in |current_reason_| elapsed since the
50 // last time |current_reason_| was updated, see DurationsMs().
51 std::map<QualityLimitationReason, int64_t> durations_ms_;
52};
53
54} // namespace webrtc
55
56#endif // VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_