Avoid DEPRECATED_SingleThreadedTaskQueueForTesting::CancelTask in VideoAnalyzer

Bug: webrtc:10933
Change-Id: Iba24100b092df7306ee77f6592ad5469c541099a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157901
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29559}
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 5aa64e9..de35ec9 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -293,6 +293,7 @@
       "../rtc_base:rtc_base_tests_utils",
       "../rtc_base:rtc_numerics",
       "../rtc_base:task_queue_for_test",
+      "../rtc_base/task_utils:repeating_task",
       "../system_wrappers",
       "../test:fake_video_codecs",
       "../test:fileutils",
diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc
index 0430faa..018ec8b 100644
--- a/video/video_analyzer.cc
+++ b/video/video_analyzer.cc
@@ -21,6 +21,8 @@
 #include "rtc_base/cpu_time.h"
 #include "rtc_base/format_macros.h"
 #include "rtc_base/memory_usage.h"
+#include "rtc_base/task_queue_for_test.h"
+#include "rtc_base/task_utils/repeating_task.h"
 #include "system_wrappers/include/cpu_info.h"
 #include "test/call_test.h"
 #include "test/testsupport/file_utils.h"
@@ -36,7 +38,7 @@
 
 namespace webrtc {
 namespace {
-constexpr int kSendStatsPollingIntervalMs = 1000;
+constexpr TimeDelta kSendStatsPollingInterval = TimeDelta::Seconds<1>();
 constexpr size_t kMaxComparisons = 10;
 // How often is keep alive message printed.
 constexpr int kKeepAliveIntervalSeconds = 30;
@@ -50,23 +52,22 @@
 }
 }  // namespace
 
-VideoAnalyzer::VideoAnalyzer(
-    test::LayerFilteringTransport* transport,
-    const std::string& test_label,
-    double avg_psnr_threshold,
-    double avg_ssim_threshold,
-    int duration_frames,
-    FILE* graph_data_output_file,
-    const std::string& graph_title,
-    uint32_t ssrc_to_analyze,
-    uint32_t rtx_ssrc_to_analyze,
-    size_t selected_stream,
-    int selected_sl,
-    int selected_tl,
-    bool is_quick_test_enabled,
-    Clock* clock,
-    std::string rtp_dump_name,
-    test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue)
+VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport,
+                             const std::string& test_label,
+                             double avg_psnr_threshold,
+                             double avg_ssim_threshold,
+                             int duration_frames,
+                             FILE* graph_data_output_file,
+                             const std::string& graph_title,
+                             uint32_t ssrc_to_analyze,
+                             uint32_t rtx_ssrc_to_analyze,
+                             size_t selected_stream,
+                             int selected_sl,
+                             int selected_tl,
+                             bool is_quick_test_enabled,
+                             Clock* clock,
+                             std::string rtp_dump_name,
+                             TaskQueueBase* task_queue)
     : transport_(transport),
       receiver_(nullptr),
       call_(nullptr),
@@ -343,12 +344,11 @@
   // at time-out check if frames_processed is going up. If so, give it more
   // time, otherwise fail. Hopefully this will reduce test flakiness.
 
-  {
-    rtc::CritScope lock(&comparison_lock_);
-    stop_stats_poller_ = false;
-    stats_polling_task_id_ = task_queue_->PostDelayedTask(
-        [this]() { PollStats(); }, kSendStatsPollingIntervalMs);
-  }
+  RepeatingTaskHandle stats_polling_task = RepeatingTaskHandle::DelayedStart(
+      task_queue_, kSendStatsPollingInterval, [this] {
+        PollStats();
+        return kSendStatsPollingInterval;
+      });
 
   int last_frames_processed = -1;
   int last_frames_captured = -1;
@@ -393,11 +393,7 @@
   if (iteration > 0)
     printf("- Farewell, sweet Concorde!\n");
 
-  {
-    rtc::CritScope lock(&comparison_lock_);
-    stop_stats_poller_ = true;
-    task_queue_->CancelTask(stats_polling_task_id_);
-  }
+  SendTask(RTC_FROM_HERE, task_queue_, [&] { stats_polling_task.Stop(); });
 
   PrintResults();
   if (graph_data_output_file_)
@@ -474,9 +470,6 @@
 
 void VideoAnalyzer::PollStats() {
   rtc::CritScope crit(&comparison_lock_);
-  if (stop_stats_poller_) {
-    return;
-  }
 
   Call::Stats call_stats = call_->GetStats();
   send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps);
@@ -543,9 +536,6 @@
   }
 
   memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes());
-
-  stats_polling_task_id_ = task_queue_->PostDelayedTask(
-      [this]() { PollStats(); }, kSendStatsPollingIntervalMs);
 }
 
 void VideoAnalyzer::FrameComparisonThread(void* obj) {
diff --git a/video/video_analyzer.h b/video/video_analyzer.h
index 03ee87e..be771f4 100644
--- a/video/video_analyzer.h
+++ b/video/video_analyzer.h
@@ -16,6 +16,7 @@
 #include <string>
 #include <vector>
 
+#include "api/task_queue/task_queue_base.h"
 #include "api/video/video_source_interface.h"
 #include "rtc_base/numerics/running_statistics.h"
 #include "rtc_base/time_utils.h"
@@ -46,7 +47,7 @@
                 bool is_quick_test_enabled,
                 Clock* clock,
                 std::string rtp_dump_name,
-                test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue);
+                TaskQueueBase* task_queue);
   ~VideoAnalyzer();
 
   virtual void SetReceiver(PacketReceiver* receiver);
@@ -292,14 +293,11 @@
   std::deque<FrameComparison> comparisons_ RTC_GUARDED_BY(comparison_lock_);
   bool quit_ RTC_GUARDED_BY(comparison_lock_);
   rtc::Event done_;
-  test::DEPRECATED_SingleThreadedTaskQueueForTesting::TaskId
-      stats_polling_task_id_ RTC_GUARDED_BY(comparison_lock_);
-  bool stop_stats_poller_ RTC_GUARDED_BY(comparison_lock_);
 
   std::unique_ptr<test::RtpFileWriter> rtp_file_writer_;
   Clock* const clock_;
   const int64_t start_ms_;
-  test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue_;
+  TaskQueueBase* task_queue_;
 };
 
 }  // namespace webrtc