webrtc_m130/video/quality_limitation_reason_tracker.h
Henrik Boström ce33b6a4cf Implement QualityLimitationReasonTracker and expose "reason".
This CL implements the logic behind qualityLimitationReason[1] and
qualityLimitationDurations[2]

This CL also exposes qualityLimitationReason in the standard getStats()
API, but does not expose qualityLimitationDurations because that is
blocked on supporting the "record<>" type in RTCStatsMember[3].

[1] https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
[2] https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
[3] https://crbug.com/webrtc/10685

TBR=stefan@webrtc.org

Bug: webrtc:10451, webrtc:10686
Change-Id: Ifff0be4ddd64eaec23d59c02af99fdbb1feb3841
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/138825
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28090}
2019-05-28 16:23:55 +00:00

54 lines
2.1 KiB
C++

/*
* Copyright 2019 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
#define VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
#include <map>
#include "common_video/include/quality_limitation_reason.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
// A tracker of quality limitation reasons. The quality limitation reason is the
// primary reason for limiting resolution and/or framerate (such as CPU or
// bandwidth limitations). The tracker keeps track of the current reason and the
// duration of time spent in each reason. See qualityLimitationReason[1] and
// qualityLimitationDurations[2] in the webrtc-stats spec.
// [1]
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
// [2]
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
class QualityLimitationReasonTracker {
public:
// The caller is responsible for making sure |clock| outlives the tracker.
explicit QualityLimitationReasonTracker(Clock* clock);
// The current reason defaults to QualityLimitationReason::kNone.
QualityLimitationReason current_reason() const;
void SetReason(QualityLimitationReason reason);
std::map<QualityLimitationReason, int64_t> DurationsMs() const;
private:
Clock* const clock_;
QualityLimitationReason current_reason_;
int64_t current_reason_updated_timestamp_ms_;
// The total amount of time spent in each reason at time
// |current_reason_updated_timestamp_ms_|. To get the total amount duration
// so-far, including the time spent in |current_reason_| elapsed since the
// last time |current_reason_| was updated, see DurationsMs().
std::map<QualityLimitationReason, int64_t> durations_ms_;
};
} // namespace webrtc
#endif // VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_