Propagate clock into VP8Decoder::QpSmoother

Bug: webrtc:42223992
Change-Id: I6b8f3023b4b6d2489549488515d789344404b1c5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/404240
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45326}
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index 2ef666d..ef3d60e 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -618,7 +618,6 @@
     "../../rtc_base:logging",
     "../../rtc_base:rtc_numerics",
     "../../rtc_base:safe_conversions",
-    "../../rtc_base:timeutils",
     "../../rtc_base/experiments:encoder_info_settings",
     "../../rtc_base/experiments:field_trial_parser",
     "../../rtc_base/experiments:rate_control_settings",
diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_decoder.cc b/modules/video_coding/codecs/vp8/libvpx_vp8_decoder.cc
index 13e7b32..5e51c31 100644
--- a/modules/video_coding/codecs/vp8/libvpx_vp8_decoder.cc
+++ b/modules/video_coding/codecs/vp8/libvpx_vp8_decoder.cc
@@ -21,6 +21,7 @@
 #include "api/environment/environment.h"
 #include "api/field_trials_view.h"
 #include "api/scoped_refptr.h"
+#include "api/units/timestamp.h"
 #include "api/video/color_space.h"
 #include "api/video/encoded_image.h"
 #include "api/video/i420_buffer.h"
@@ -32,7 +33,6 @@
 #include "modules/video_coding/include/video_error_codes.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/numerics/exp_filter.h"
-#include "rtc_base/time_utils.h"
 #include "system_wrappers/include/metrics.h"
 #include "third_party/libvpx/source/libvpx/vpx/vp8.h"
 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h"
@@ -96,7 +96,10 @@
 
 class LibvpxVp8Decoder::QpSmoother {
  public:
-  QpSmoother() : last_sample_ms_(TimeMillis()), smoother_(kAlpha) {}
+  explicit QpSmoother(const Environment& env)
+      : env_(env),
+        last_sample_(env_.clock().CurrentTime()),
+        smoother_(kAlpha) {}
 
   int GetAvg() const {
     float value = smoother_.filtered();
@@ -104,16 +107,18 @@
   }
 
   void Add(float sample) {
-    int64_t now_ms = TimeMillis();
-    smoother_.Apply(static_cast<float>(now_ms - last_sample_ms_), sample);
-    last_sample_ms_ = now_ms;
+    Timestamp now = env_.clock().CurrentTime();
+    smoother_.Apply((now - last_sample_).ms<float>(), sample);
+    last_sample_ = now;
   }
 
   void Reset() { smoother_.Reset(kAlpha); }
 
  private:
-  const float kAlpha = 0.95f;
-  int64_t last_sample_ms_;
+  static constexpr float kAlpha = 0.95f;
+
+  const Environment env_;
+  Timestamp last_sample_;
   ExpFilter smoother_;
 };
 
@@ -131,7 +136,8 @@
       deblock_params_(use_postproc_ ? GetPostProcParamsFromFieldTrialGroup(
                                           env.field_trials())
                                     : std::nullopt),
-      qp_smoother_(use_postproc_ ? new QpSmoother() : nullptr) {}
+      qp_smoother_(use_postproc_ ? std::make_unique<QpSmoother>(env)
+                                 : nullptr) {}
 
 LibvpxVp8Decoder::~LibvpxVp8Decoder() {
   inited_ = true;  // in order to do the actual release