You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2011 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. #include "modules/video_coding/codec_timer.h"
  11. #include <cstdint>
  12. namespace webrtc {
  13. namespace {
  14. // The first kIgnoredSampleCount samples will be ignored.
  15. const int kIgnoredSampleCount = 5;
  16. // Return the |kPercentile| value in RequiredDecodeTimeMs().
  17. const float kPercentile = 0.95f;
  18. // The window size in ms.
  19. const int64_t kTimeLimitMs = 10000;
  20. } // anonymous namespace
  21. VCMCodecTimer::VCMCodecTimer()
  22. : ignored_sample_count_(0), filter_(kPercentile) {}
  23. VCMCodecTimer::~VCMCodecTimer() = default;
  24. void VCMCodecTimer::AddTiming(int64_t decode_time_ms, int64_t now_ms) {
  25. // Ignore the first |kIgnoredSampleCount| samples.
  26. if (ignored_sample_count_ < kIgnoredSampleCount) {
  27. ++ignored_sample_count_;
  28. return;
  29. }
  30. // Insert new decode time value.
  31. filter_.Insert(decode_time_ms);
  32. history_.emplace(decode_time_ms, now_ms);
  33. // Pop old decode time values.
  34. while (!history_.empty() &&
  35. now_ms - history_.front().sample_time_ms > kTimeLimitMs) {
  36. filter_.Erase(history_.front().decode_time_ms);
  37. history_.pop();
  38. }
  39. }
  40. // Get the 95th percentile observed decode time within a time window.
  41. int64_t VCMCodecTimer::RequiredDecodeTimeMs() const {
  42. return filter_.GetPercentileValue();
  43. }
  44. VCMCodecTimer::Sample::Sample(int64_t decode_time_ms, int64_t sample_time_ms)
  45. : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {}
  46. } // namespace webrtc