xref: /aosp_15_r20/external/webrtc/video/quality_limitation_reason_tracker.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2019 The WebRTC Project Authors. All rights reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
12*d9f75844SAndroid Build Coastguard Worker #define VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <map>
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #include "common_video/include/quality_limitation_reason.h"
17*d9f75844SAndroid Build Coastguard Worker #include "system_wrappers/include/clock.h"
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker // A tracker of quality limitation reasons. The quality limitation reason is the
22*d9f75844SAndroid Build Coastguard Worker // primary reason for limiting resolution and/or framerate (such as CPU or
23*d9f75844SAndroid Build Coastguard Worker // bandwidth limitations). The tracker keeps track of the current reason and the
24*d9f75844SAndroid Build Coastguard Worker // duration of time spent in each reason. See qualityLimitationReason[1],
25*d9f75844SAndroid Build Coastguard Worker // qualityLimitationDurations[2], and qualityLimitationResolutionChanges[3] in
26*d9f75844SAndroid Build Coastguard Worker // the webrtc-stats spec.
27*d9f75844SAndroid Build Coastguard Worker // Note that the specification defines the durations in seconds while the
28*d9f75844SAndroid Build Coastguard Worker // internal data structures defines it in milliseconds.
29*d9f75844SAndroid Build Coastguard Worker // [1]
30*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
31*d9f75844SAndroid Build Coastguard Worker // [2]
32*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
33*d9f75844SAndroid Build Coastguard Worker // [3]
34*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
35*d9f75844SAndroid Build Coastguard Worker class QualityLimitationReasonTracker {
36*d9f75844SAndroid Build Coastguard Worker  public:
37*d9f75844SAndroid Build Coastguard Worker   // The caller is responsible for making sure `clock` outlives the tracker.
38*d9f75844SAndroid Build Coastguard Worker   explicit QualityLimitationReasonTracker(Clock* clock);
39*d9f75844SAndroid Build Coastguard Worker 
40*d9f75844SAndroid Build Coastguard Worker   // The current reason defaults to QualityLimitationReason::kNone.
41*d9f75844SAndroid Build Coastguard Worker   QualityLimitationReason current_reason() const;
42*d9f75844SAndroid Build Coastguard Worker   void SetReason(QualityLimitationReason reason);
43*d9f75844SAndroid Build Coastguard Worker   std::map<QualityLimitationReason, int64_t> DurationsMs() const;
44*d9f75844SAndroid Build Coastguard Worker 
45*d9f75844SAndroid Build Coastguard Worker  private:
46*d9f75844SAndroid Build Coastguard Worker   Clock* const clock_;
47*d9f75844SAndroid Build Coastguard Worker   QualityLimitationReason current_reason_;
48*d9f75844SAndroid Build Coastguard Worker   int64_t current_reason_updated_timestamp_ms_;
49*d9f75844SAndroid Build Coastguard Worker   // The total amount of time spent in each reason at time
50*d9f75844SAndroid Build Coastguard Worker   // `current_reason_updated_timestamp_ms_`. To get the total amount duration
51*d9f75844SAndroid Build Coastguard Worker   // so-far, including the time spent in `current_reason_` elapsed since the
52*d9f75844SAndroid Build Coastguard Worker   // last time `current_reason_` was updated, see DurationsMs().
53*d9f75844SAndroid Build Coastguard Worker   std::map<QualityLimitationReason, int64_t> durations_ms_;
54*d9f75844SAndroid Build Coastguard Worker };
55*d9f75844SAndroid Build Coastguard Worker 
56*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
57*d9f75844SAndroid Build Coastguard Worker 
58*d9f75844SAndroid Build Coastguard Worker #endif  // VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
59