• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 namespace 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
24 // duration of time spent in each reason. See qualityLimitationReason[1],
25 // qualityLimitationDurations[2], and qualityLimitationResolutionChanges[3] in
26 // the webrtc-stats spec.
27 // [1]
28 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
29 // [2]
30 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
31 // [3]
32 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
33 class 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_
57