quality_limitation_reason_tracker.h 2.3 KB

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