From 1aa75817018764e004eaac703f80635ec06654d7 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Tue, 5 Mar 2019 11:11:35 +0100 Subject: [PATCH] Replace all usage of rtc::NewClosure with webrtc::ToQueuedTask Bug: webrtc:10191 Change-Id: I795c8a6f281ccdf60031500a4fb5a411f2afdb70 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125400 Commit-Queue: Danil Chapovalov Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#26975} --- modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/source/rtcp_transceiver.cc | 8 ++-- rtc_base/BUILD.gn | 1 + rtc_base/task_queue.h | 25 ++---------- rtc_base/task_queue_for_test.h | 6 ++- video/BUILD.gn | 42 ++++++++++----------- video/call_stats.cc | 4 +- video/call_stats_unittest.cc | 4 +- video/video_send_stream.cc | 3 +- 9 files changed, 41 insertions(+), 53 deletions(-) diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index bf8e69f635..d66d437dd7 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -259,6 +259,7 @@ rtc_source_set("rtcp_transceiver") { "../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_task_queue", "../../rtc_base/task_utils:repeating_task", + "../../rtc_base/task_utils:to_queued_task", "../../system_wrappers", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/types:optional", diff --git a/modules/rtp_rtcp/source/rtcp_transceiver.cc b/modules/rtp_rtcp/source/rtcp_transceiver.cc index 6c0e0b74f5..cec6da9f3b 100644 --- a/modules/rtp_rtcp/source/rtcp_transceiver.cc +++ b/modules/rtp_rtcp/source/rtcp_transceiver.cc @@ -16,6 +16,7 @@ #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" #include "rtc_base/checks.h" #include "rtc_base/event.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "rtc_base/time_utils.h" namespace webrtc { @@ -41,8 +42,8 @@ RtcpTransceiver::~RtcpTransceiver() { void RtcpTransceiver::Stop(std::function on_destroyed) { RTC_DCHECK(rtcp_transceiver_); - task_queue_->PostTask(rtc::NewClosure( - Destructor{std::move(rtcp_transceiver_)}, std::move(on_destroyed))); + task_queue_->PostTask(ToQueuedTask(Destructor{std::move(rtcp_transceiver_)}, + std::move(on_destroyed))); RTC_DCHECK(!rtcp_transceiver_); } @@ -65,8 +66,7 @@ void RtcpTransceiver::RemoveMediaReceiverRtcpObserver( auto remove = [ptr, remote_ssrc, observer] { ptr->RemoveMediaReceiverRtcpObserver(remote_ssrc, observer); }; - task_queue_->PostTask( - rtc::NewClosure(std::move(remove), std::move(on_removed))); + task_queue_->PostTask(ToQueuedTask(std::move(remove), std::move(on_removed))); } void RtcpTransceiver::SetReadyToSend(bool ready) { diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 0759fde15d..bb4a256211 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1147,6 +1147,7 @@ rtc_source_set("rtc_task_queue_for_test") { ":checks", ":rtc_base_approved", ":rtc_task_queue", + "task_utils:to_queued_task", ] } diff --git a/rtc_base/task_queue.h b/rtc_base/task_queue.h index ffb7a11589..1c0ae297ee 100644 --- a/rtc_base/task_queue.h +++ b/rtc_base/task_queue.h @@ -29,12 +29,6 @@ namespace rtc { // TODO(danilchap): Remove the alias when all of webrtc is updated to use // webrtc::QueuedTask directly. using ::webrtc::QueuedTask; -// TODO(danilchap): Remove the alias when all of webrtc is updated to use -// webrtc::ToQueuedTask directly. -template -std::unique_ptr NewClosure(Args&&... args) { - return webrtc::ToQueuedTask(std::forward(args)...); -} // Implements a task queue that asynchronously executes tasks in a way that // guarantees that they're executed in FIFO order and that tasks never overlap. @@ -54,19 +48,7 @@ std::unique_ptr NewClosure(Args&&... args) { // queue_.PostTask([]() { Work(); }); // ... // -// 2) Doing work asynchronously on a worker queue and providing a notification -// callback on the current queue, when the work has been done: -// -// void MyClass::StartWorkAndLetMeKnowWhenDone( -// std::unique_ptr callback) { -// DCHECK(TaskQueue::Current()) << "Need to be running on a queue"; -// queue_.PostTaskAndReply([]() { Work(); }, std::move(callback)); -// } -// ... -// my_class->StartWorkAndLetMeKnowWhenDone( -// NewClosure([]() { RTC_LOG(INFO) << "The work is done!";})); -// -// 3) Posting a custom task on a timer. The task posts itself again after +// 2) Posting a custom task on a timer. The task posts itself again after // every running: // // class TimerTask : public QueuedTask { @@ -136,7 +118,7 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue { Closure, std::unique_ptr>::value>::type* = nullptr> void PostTask(Closure&& closure) { - PostTask(NewClosure(std::forward(closure))); + PostTask(webrtc::ToQueuedTask(std::forward(closure))); } // See documentation above for performance expectations. @@ -145,7 +127,8 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue { Closure, std::unique_ptr>::value>::type* = nullptr> void PostDelayedTask(Closure&& closure, uint32_t milliseconds) { - PostDelayedTask(NewClosure(std::forward(closure)), milliseconds); + PostDelayedTask(webrtc::ToQueuedTask(std::forward(closure)), + milliseconds); } private: diff --git a/rtc_base/task_queue_for_test.h b/rtc_base/task_queue_for_test.h index dd27f64409..0becc80975 100644 --- a/rtc_base/task_queue_for_test.h +++ b/rtc_base/task_queue_for_test.h @@ -15,6 +15,7 @@ #include "rtc_base/constructor_magic.h" #include "rtc_base/event.h" #include "rtc_base/task_queue.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "rtc_base/thread_annotations.h" namespace rtc { @@ -34,7 +35,7 @@ class RTC_LOCKABLE TaskQueueForTest : public TaskQueue { void SendTask(Closure* task) { RTC_DCHECK(!IsCurrent()); rtc::Event event; - PostTask(rtc::NewClosure( + PostTask(webrtc::ToQueuedTask( [&task]() { RTC_CHECK_EQ(false, static_cast(task)->Run()); }, @@ -48,7 +49,8 @@ class RTC_LOCKABLE TaskQueueForTest : public TaskQueue { void SendTask(Closure&& task) { RTC_DCHECK(!IsCurrent()); rtc::Event event; - PostTask(rtc::NewClosure(std::move(task), [&event]() { event.Set(); })); + PostTask(webrtc::ToQueuedTask(std::forward(task), + [&event] { event.Set(); })); event.Wait(rtc::Event::kForever); } diff --git a/video/BUILD.gn b/video/BUILD.gn index 268aeab640..de139918a4 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -68,49 +68,48 @@ rtc_static_library("video") { "../call:bitrate_allocator", "../call:call_interfaces", "../call:rtp_interfaces", + "../call:rtp_receiver", # For RtxReceiveStream. "../call:rtp_sender", "../call:video_stream_api", + "../common_video", + "../logging:rtc_event_log_api", "../media:rtc_h264_profile_id", + "../modules:module_api", "../modules:module_api_public", + "../modules/bitrate_controller", + "../modules/pacing", + "../modules/remote_bitrate_estimator", + "../modules/rtp_rtcp", "../modules/rtp_rtcp:rtp_rtcp_format", "../modules/rtp_rtcp:rtp_video_header", + "../modules/utility", + "../modules/video_coding", "../modules/video_coding:codec_globals_headers", "../modules/video_coding:nack_module", "../modules/video_coding:packet", "../modules/video_coding:video_codec_interface", + "../modules/video_coding:video_coding_utility", + "../modules/video_processing", "../rtc_base:checks", "../rtc_base:rate_limiter", + "../rtc_base:rtc_base_approved", + "../rtc_base:rtc_numerics", + "../rtc_base:rtc_task_queue", + "../rtc_base:sequenced_task_checker", "../rtc_base:stringutils", + "../rtc_base:weak_ptr", "../rtc_base/experiments:alr_experiment", "../rtc_base/experiments:quality_scaling_experiment", "../rtc_base/experiments:rate_control_settings", "../rtc_base/system:fallthrough", "../rtc_base/task_utils:repeating_task", + "../rtc_base/task_utils:to_queued_task", + "../rtc_base/time:timestamp_extrapolator", + "../system_wrappers", "../system_wrappers:field_trial", "../system_wrappers:metrics", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/types:optional", - - # For RtxReceiveStream. - "../call:rtp_receiver", - "../common_video", - "../logging:rtc_event_log_api", - "../modules:module_api", - "../modules/bitrate_controller", - "../modules/pacing", - "../modules/remote_bitrate_estimator", - "../modules/rtp_rtcp", - "../modules/utility", - "../modules/video_coding", - "../modules/video_coding:video_coding_utility", - "../modules/video_processing", - "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_numerics", - "../rtc_base:rtc_task_queue", - "../rtc_base:sequenced_task_checker", - "../rtc_base:weak_ptr", - "../rtc_base/time:timestamp_extrapolator", - "../system_wrappers", ] if (!build_with_mozilla) { @@ -532,6 +531,7 @@ if (rtc_include_tests) { "../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue_for_test", "../rtc_base/experiments:alr_experiment", + "../rtc_base/task_utils:to_queued_task", "../system_wrappers", "../system_wrappers:field_trial", "../system_wrappers:metrics", diff --git a/video/call_stats.cc b/video/call_stats.cc index 3c833ff8dd..cfa066fbab 100644 --- a/video/call_stats.cc +++ b/video/call_stats.cc @@ -16,7 +16,7 @@ #include "modules/utility/include/process_thread.h" #include "rtc_base/checks.h" #include "rtc_base/location.h" -#include "rtc_base/task_queue.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "system_wrappers/include/metrics.h" namespace webrtc { @@ -177,7 +177,7 @@ int64_t CallStats::LastProcessedRtt() const { void CallStats::OnRttUpdate(int64_t rtt) { int64_t now_ms = clock_->TimeInMilliseconds(); - process_thread_->PostTask(rtc::NewClosure([rtt, now_ms, this]() { + process_thread_->PostTask(ToQueuedTask([rtt, now_ms, this]() { RTC_DCHECK_RUN_ON(&process_thread_checker_); reports_.push_back(RttTime(rtt, now_ms)); if (time_of_first_rtt_ms_ == -1) diff --git a/video/call_stats_unittest.cc b/video/call_stats_unittest.cc index dc6c69af9e..c31d33664d 100644 --- a/video/call_stats_unittest.cc +++ b/video/call_stats_unittest.cc @@ -16,7 +16,7 @@ #include "modules/utility/include/process_thread.h" #include "rtc_base/event.h" #include "rtc_base/location.h" -#include "rtc_base/task_queue.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "system_wrappers/include/metrics.h" #include "test/gmock.h" #include "test/gtest.h" @@ -168,7 +168,7 @@ TEST_F(CallStatsTest, MultipleObservers) { // Flush the queue on the process thread to make sure we return after // Process() has been called. rtc::Event event; - process_thread_->PostTask(rtc::NewClosure([&event]() { event.Set(); })); + process_thread_->PostTask(ToQueuedTask([&event] { event.Set(); })); event.Wait(rtc::Event::kForever); } diff --git a/video/video_send_stream.cc b/video/video_send_stream.cc index 978558d5d7..e78a6990c0 100644 --- a/video/video_send_stream.cc +++ b/video/video_send_stream.cc @@ -19,6 +19,7 @@ #include "modules/rtp_rtcp/source/rtp_sender.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "system_wrappers/include/clock.h" #include "system_wrappers/include/field_trial.h" #include "video/video_send_stream_impl.h" @@ -93,7 +94,7 @@ VideoSendStream::VideoSendStream( // TODO(srte): Initialization should not be done posted on a task queue. // Note that the posted task must not outlive this scope since the closure // references local variables. - worker_queue_->PostTask(rtc::NewClosure( + worker_queue_->PostTask(ToQueuedTask( [this, clock, call_stats, transport, bitrate_allocator, send_delay_stats, event_log, &suspended_ssrcs, &encoder_config, &suspended_payload_states, &fec_controller]() {