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}
This commit is contained in:
Danil Chapovalov 2019-10-21 13:36:59 +02:00 committed by Commit Bot
parent e34fb878b9
commit 9cd53b4910
3 changed files with 29 additions and 40 deletions

View File

@ -293,6 +293,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_base_tests_utils", "../rtc_base:rtc_base_tests_utils",
"../rtc_base:rtc_numerics", "../rtc_base:rtc_numerics",
"../rtc_base:task_queue_for_test", "../rtc_base:task_queue_for_test",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers", "../system_wrappers",
"../test:fake_video_codecs", "../test:fake_video_codecs",
"../test:fileutils", "../test:fileutils",

View File

@ -21,6 +21,8 @@
#include "rtc_base/cpu_time.h" #include "rtc_base/cpu_time.h"
#include "rtc_base/format_macros.h" #include "rtc_base/format_macros.h"
#include "rtc_base/memory_usage.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 "system_wrappers/include/cpu_info.h"
#include "test/call_test.h" #include "test/call_test.h"
#include "test/testsupport/file_utils.h" #include "test/testsupport/file_utils.h"
@ -36,7 +38,7 @@ ABSL_FLAG(bool,
namespace webrtc { namespace webrtc {
namespace { namespace {
constexpr int kSendStatsPollingIntervalMs = 1000; constexpr TimeDelta kSendStatsPollingInterval = TimeDelta::Seconds<1>();
constexpr size_t kMaxComparisons = 10; constexpr size_t kMaxComparisons = 10;
// How often is keep alive message printed. // How often is keep alive message printed.
constexpr int kKeepAliveIntervalSeconds = 30; constexpr int kKeepAliveIntervalSeconds = 30;
@ -50,23 +52,22 @@ bool IsFlexfec(int payload_type) {
} }
} // namespace } // namespace
VideoAnalyzer::VideoAnalyzer( VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport,
test::LayerFilteringTransport* transport, const std::string& test_label,
const std::string& test_label, double avg_psnr_threshold,
double avg_psnr_threshold, double avg_ssim_threshold,
double avg_ssim_threshold, int duration_frames,
int duration_frames, FILE* graph_data_output_file,
FILE* graph_data_output_file, const std::string& graph_title,
const std::string& graph_title, uint32_t ssrc_to_analyze,
uint32_t ssrc_to_analyze, uint32_t rtx_ssrc_to_analyze,
uint32_t rtx_ssrc_to_analyze, size_t selected_stream,
size_t selected_stream, int selected_sl,
int selected_sl, int selected_tl,
int selected_tl, bool is_quick_test_enabled,
bool is_quick_test_enabled, Clock* clock,
Clock* clock, std::string rtp_dump_name,
std::string rtp_dump_name, TaskQueueBase* task_queue)
test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue)
: transport_(transport), : transport_(transport),
receiver_(nullptr), receiver_(nullptr),
call_(nullptr), call_(nullptr),
@ -343,12 +344,11 @@ void VideoAnalyzer::Wait() {
// at time-out check if frames_processed is going up. If so, give it more // at time-out check if frames_processed is going up. If so, give it more
// time, otherwise fail. Hopefully this will reduce test flakiness. // time, otherwise fail. Hopefully this will reduce test flakiness.
{ RepeatingTaskHandle stats_polling_task = RepeatingTaskHandle::DelayedStart(
rtc::CritScope lock(&comparison_lock_); task_queue_, kSendStatsPollingInterval, [this] {
stop_stats_poller_ = false; PollStats();
stats_polling_task_id_ = task_queue_->PostDelayedTask( return kSendStatsPollingInterval;
[this]() { PollStats(); }, kSendStatsPollingIntervalMs); });
}
int last_frames_processed = -1; int last_frames_processed = -1;
int last_frames_captured = -1; int last_frames_captured = -1;
@ -393,11 +393,7 @@ void VideoAnalyzer::Wait() {
if (iteration > 0) if (iteration > 0)
printf("- Farewell, sweet Concorde!\n"); printf("- Farewell, sweet Concorde!\n");
{ SendTask(RTC_FROM_HERE, task_queue_, [&] { stats_polling_task.Stop(); });
rtc::CritScope lock(&comparison_lock_);
stop_stats_poller_ = true;
task_queue_->CancelTask(stats_polling_task_id_);
}
PrintResults(); PrintResults();
if (graph_data_output_file_) if (graph_data_output_file_)
@ -474,9 +470,6 @@ bool VideoAnalyzer::IsInSelectedSpatialAndTemporalLayer(
void VideoAnalyzer::PollStats() { void VideoAnalyzer::PollStats() {
rtc::CritScope crit(&comparison_lock_); rtc::CritScope crit(&comparison_lock_);
if (stop_stats_poller_) {
return;
}
Call::Stats call_stats = call_->GetStats(); Call::Stats call_stats = call_->GetStats();
send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps); send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps);
@ -543,9 +536,6 @@ void VideoAnalyzer::PollStats() {
} }
memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes()); memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes());
stats_polling_task_id_ = task_queue_->PostDelayedTask(
[this]() { PollStats(); }, kSendStatsPollingIntervalMs);
} }
void VideoAnalyzer::FrameComparisonThread(void* obj) { void VideoAnalyzer::FrameComparisonThread(void* obj) {

View File

@ -16,6 +16,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/task_queue/task_queue_base.h"
#include "api/video/video_source_interface.h" #include "api/video/video_source_interface.h"
#include "rtc_base/numerics/running_statistics.h" #include "rtc_base/numerics/running_statistics.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -46,7 +47,7 @@ class VideoAnalyzer : public PacketReceiver,
bool is_quick_test_enabled, bool is_quick_test_enabled,
Clock* clock, Clock* clock,
std::string rtp_dump_name, std::string rtp_dump_name,
test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue); TaskQueueBase* task_queue);
~VideoAnalyzer(); ~VideoAnalyzer();
virtual void SetReceiver(PacketReceiver* receiver); virtual void SetReceiver(PacketReceiver* receiver);
@ -292,14 +293,11 @@ class VideoAnalyzer : public PacketReceiver,
std::deque<FrameComparison> comparisons_ RTC_GUARDED_BY(comparison_lock_); std::deque<FrameComparison> comparisons_ RTC_GUARDED_BY(comparison_lock_);
bool quit_ RTC_GUARDED_BY(comparison_lock_); bool quit_ RTC_GUARDED_BY(comparison_lock_);
rtc::Event done_; 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_; std::unique_ptr<test::RtpFileWriter> rtp_file_writer_;
Clock* const clock_; Clock* const clock_;
const int64_t start_ms_; const int64_t start_ms_;
test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue_; TaskQueueBase* task_queue_;
}; };
} // namespace webrtc } // namespace webrtc