Henrik Boström | ce33b6a | 2019-05-28 15:42:38 | [diff] [blame] | 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 |
Evan Shrubsole | cc62b16 | 2019-09-09 09:26:45 | [diff] [blame] | 24 | // duration of time spent in each reason. See qualityLimitationReason[1], |
| 25 | // qualityLimitationDurations[2], and qualityLimitationResolutionChanges[3] in |
| 26 | // the webrtc-stats spec. |
Philipp Hancke | 3fd9cbc | 2022-01-10 16:41:43 | [diff] [blame] | 27 | // Note that the specification defines the durations in seconds while the |
| 28 | // internal data structures defines it in milliseconds. |
Henrik Boström | ce33b6a | 2019-05-28 15:42:38 | [diff] [blame] | 29 | // [1] |
| 30 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason |
| 31 | // [2] |
| 32 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations |
Evan Shrubsole | cc62b16 | 2019-09-09 09:26:45 | [diff] [blame] | 33 | // [3] |
| 34 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges |
Henrik Boström | ce33b6a | 2019-05-28 15:42:38 | [diff] [blame] | 35 | class QualityLimitationReasonTracker { |
| 36 | public: |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 37 | // The caller is responsible for making sure `clock` outlives the tracker. |
Henrik Boström | ce33b6a | 2019-05-28 15:42:38 | [diff] [blame] | 38 | explicit QualityLimitationReasonTracker(Clock* clock); |
| 39 | |
| 40 | // The current reason defaults to QualityLimitationReason::kNone. |
| 41 | QualityLimitationReason current_reason() const; |
| 42 | void SetReason(QualityLimitationReason reason); |
| 43 | std::map<QualityLimitationReason, int64_t> DurationsMs() const; |
| 44 | |
| 45 | private: |
| 46 | Clock* const clock_; |
| 47 | QualityLimitationReason current_reason_; |
| 48 | int64_t current_reason_updated_timestamp_ms_; |
| 49 | // The total amount of time spent in each reason at time |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 50 | // `current_reason_updated_timestamp_ms_`. To get the total amount duration |
| 51 | // so-far, including the time spent in `current_reason_` elapsed since the |
| 52 | // last time `current_reason_` was updated, see DurationsMs(). |
Henrik Boström | ce33b6a | 2019-05-28 15:42:38 | [diff] [blame] | 53 | std::map<QualityLimitationReason, int64_t> durations_ms_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace webrtc |
| 57 | |
| 58 | #endif // VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_ |