Delete rtc::TaskQueue::Current in favor of webrtc::TaskQueueBase::Current

Bug: webrtc:10191
Change-Id: I506cc50a90c73a6a4f6a3de36de0999cca72f5ba
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126230
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27035}
This commit is contained in:
Danil Chapovalov 2019-03-07 17:41:37 +01:00 committed by Commit Bot
parent 37d4f91db3
commit 304e9d2df3
14 changed files with 38 additions and 49 deletions

View File

@ -15,12 +15,6 @@
#include "api/task_queue/queued_task.h" #include "api/task_queue/queued_task.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
// TODO(bugs.webrtc.org/10191): Remove when
// rtc::TaskQueue* rtc::TaskQueue::Current() is unused.
namespace rtc {
class TaskQueue;
} // namespace rtc
namespace webrtc { namespace webrtc {
// Asynchronously executes tasks in a way that guarantees that they're executed // Asynchronously executes tasks in a way that guarantees that they're executed
@ -77,10 +71,6 @@ class RTC_LOCKABLE TaskQueueBase {
// Users of the TaskQueue should call Delete instead of directly deleting // Users of the TaskQueue should call Delete instead of directly deleting
// this object. // this object.
virtual ~TaskQueueBase() = default; virtual ~TaskQueueBase() = default;
private:
friend class rtc::TaskQueue;
rtc::TaskQueue* task_queue_ = nullptr;
}; };
struct TaskQueueDeleter { struct TaskQueueDeleter {

View File

@ -248,6 +248,7 @@ if (rtc_include_tests) {
] ]
deps = [ deps = [
"../api:simulated_network_api", "../api:simulated_network_api",
"../api/task_queue",
"../call:fake_network", "../call:fake_network",
"../call:simulated_network", "../call:simulated_network",
"../common_audio", "../common_audio",

View File

@ -11,6 +11,7 @@
#include "audio/test/audio_bwe_integration_test.h" #include "audio/test/audio_bwe_integration_test.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/task_queue/task_queue_base.h"
#include "call/fake_network_pipe.h" #include "call/fake_network_pipe.h"
#include "call/simulated_network.h" #include "call/simulated_network.h"
#include "common_audio/wav_file.h" #include "common_audio/wav_file.h"
@ -89,8 +90,8 @@ class StatsPollTask : public rtc::QueuedTask {
RTC_CHECK(sender_call_); RTC_CHECK(sender_call_);
Call::Stats call_stats = sender_call_->GetStats(); Call::Stats call_stats = sender_call_->GetStats();
EXPECT_GT(call_stats.send_bandwidth_bps, 25000); EXPECT_GT(call_stats.send_bandwidth_bps, 25000);
rtc::TaskQueue::Current()->PostDelayedTask( TaskQueueBase::Current()->PostDelayedTask(std::unique_ptr<QueuedTask>(this),
std::unique_ptr<QueuedTask>(this), 100); 100);
return false; return false;
} }
Call* sender_call_; Call* sender_call_;

View File

@ -572,6 +572,7 @@ if (rtc_include_tests) {
"../..:webrtc_common", "../..:webrtc_common",
"../../api:scoped_refptr", "../../api:scoped_refptr",
"../../api:videocodec_test_fixture_api", "../../api:videocodec_test_fixture_api",
"../../api/task_queue",
"../../api/video:builtin_video_bitrate_allocator_factory", "../../api/video:builtin_video_bitrate_allocator_factory",
"../../api/video:encoded_image", "../../api/video:encoded_image",
"../../api/video:video_bitrate_allocation", "../../api/video:video_bitrate_allocation",
@ -586,6 +587,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_task_queue", "../../rtc_base:rtc_task_queue",
"../../rtc_base:rtc_task_queue_for_test", "../../rtc_base:rtc_task_queue_for_test",
"../../rtc_base:sequenced_task_checker", "../../rtc_base:sequenced_task_checker",
"../../rtc_base/task_utils:to_queued_task",
"../../test:test_support", "../../test:test_support",
"../../test:video_test_common", "../../test:video_test_common",
"../../test:video_test_support", "../../test:video_test_support",

View File

@ -31,6 +31,7 @@
#include "modules/video_coding/codecs/interface/common_constants.h" #include "modules/video_coding/codecs/interface/common_constants.h"
#include "modules/video_coding/include/video_error_codes.h" #include "modules/video_coding/include/video_error_codes.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "third_party/libyuv/include/libyuv/compare.h" #include "third_party/libyuv/include/libyuv/compare.h"
@ -191,7 +192,7 @@ VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder,
decoded_frame_buffer_(num_simulcast_or_spatial_layers_), decoded_frame_buffer_(num_simulcast_or_spatial_layers_),
post_encode_time_ns_(0) { post_encode_time_ns_(0) {
// Sanity checks. // Sanity checks.
RTC_CHECK(rtc::TaskQueue::Current()) RTC_CHECK(TaskQueueBase::Current())
<< "VideoProcessor must be run on a task queue."; << "VideoProcessor must be run on a task queue.";
RTC_CHECK(encoder); RTC_CHECK(encoder);
RTC_CHECK(decoders); RTC_CHECK(decoders);
@ -321,9 +322,9 @@ int32_t VideoProcessor::VideoProcessorDecodeCompleteCallback::Decoded(
.build(); .build();
copy.set_timestamp(image.timestamp()); copy.set_timestamp(image.timestamp());
task_queue_->PostTask([this, copy]() { task_queue_->PostTask(ToQueuedTask([this, copy]() {
video_processor_->FrameDecoded(copy, simulcast_svc_idx_); video_processor_->FrameDecoded(copy, simulcast_svc_idx_);
}); }));
return 0; return 0;
} }
video_processor_->FrameDecoded(image, simulcast_svc_idx_); video_processor_->FrameDecoded(image, simulcast_svc_idx_);

View File

@ -18,6 +18,7 @@
#include <vector> #include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/task_queue/task_queue_base.h"
#include "api/test/videocodec_test_fixture.h" #include "api/test/videocodec_test_fixture.h"
#include "api/test/videocodec_test_stats.h" #include "api/test/videocodec_test_stats.h"
#include "api/video/encoded_image.h" #include "api/video/encoded_image.h"
@ -79,7 +80,7 @@ class VideoProcessor {
explicit VideoProcessorEncodeCompleteCallback( explicit VideoProcessorEncodeCompleteCallback(
VideoProcessor* video_processor) VideoProcessor* video_processor)
: video_processor_(video_processor), : video_processor_(video_processor),
task_queue_(rtc::TaskQueue::Current()) { task_queue_(TaskQueueBase::Current()) {
RTC_DCHECK(video_processor_); RTC_DCHECK(video_processor_);
RTC_DCHECK(task_queue_); RTC_DCHECK(task_queue_);
} }
@ -126,7 +127,7 @@ class VideoProcessor {
}; };
VideoProcessor* const video_processor_; VideoProcessor* const video_processor_;
rtc::TaskQueue* const task_queue_; TaskQueueBase* const task_queue_;
}; };
class VideoProcessorDecodeCompleteCallback class VideoProcessorDecodeCompleteCallback
@ -137,7 +138,7 @@ class VideoProcessor {
size_t simulcast_svc_idx) size_t simulcast_svc_idx)
: video_processor_(video_processor), : video_processor_(video_processor),
simulcast_svc_idx_(simulcast_svc_idx), simulcast_svc_idx_(simulcast_svc_idx),
task_queue_(rtc::TaskQueue::Current()) { task_queue_(TaskQueueBase::Current()) {
RTC_DCHECK(video_processor_); RTC_DCHECK(video_processor_);
RTC_DCHECK(task_queue_); RTC_DCHECK(task_queue_);
} }
@ -158,7 +159,7 @@ class VideoProcessor {
private: private:
VideoProcessor* const video_processor_; VideoProcessor* const video_processor_;
const size_t simulcast_svc_idx_; const size_t simulcast_svc_idx_;
rtc::TaskQueue* const task_queue_; TaskQueueBase* const task_queue_;
}; };
// Invoked by the callback adapter when a frame has completed encoding. // Invoked by the callback adapter when a frame has completed encoding.

View File

@ -16,9 +16,7 @@ namespace rtc {
TaskQueue::TaskQueue( TaskQueue::TaskQueue(
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter> task_queue) std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter> task_queue)
: impl_(task_queue.release()) { : impl_(task_queue.release()) {}
impl_->task_queue_ = this;
}
TaskQueue::TaskQueue(const char* queue_name, Priority priority) TaskQueue::TaskQueue(const char* queue_name, Priority priority)
: TaskQueue(webrtc::GlobalTaskQueueFactory().CreateTaskQueue(queue_name, : TaskQueue(webrtc::GlobalTaskQueueFactory().CreateTaskQueue(queue_name,
@ -32,17 +30,8 @@ TaskQueue::~TaskQueue() {
impl_->Delete(); impl_->Delete();
} }
// static
TaskQueue* TaskQueue::Current() {
webrtc::TaskQueueBase* impl = webrtc::TaskQueueBase::Current();
if (impl == nullptr) {
return nullptr;
}
return impl->task_queue_;
}
bool TaskQueue::IsCurrent() const { bool TaskQueue::IsCurrent() const {
return Current() == this; return impl_->IsCurrent();
} }
void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) { void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) {

View File

@ -57,8 +57,8 @@ using ::webrtc::QueuedTask;
// private: // private:
// bool Run() override { // bool Run() override {
// ++count_; // ++count_;
// TaskQueue::Current()->PostDelayedTask( // TaskQueueBase::Current()->PostDelayedTask(
// std::unique_ptr<QueuedTask>(this), 1000); // absl::WrapUnique(this), 1000);
// // Ownership has been transferred to the next occurance, // // Ownership has been transferred to the next occurance,
// // so return false to prevent from being deleted now. // // so return false to prevent from being deleted now.
// return false; // return false;
@ -66,8 +66,7 @@ using ::webrtc::QueuedTask;
// int count_ = 0; // int count_ = 0;
// }; // };
// ... // ...
// queue_.PostDelayedTask( // queue_.PostDelayedTask(absl::make_unique<TimerTask>(), 1000);
// std::unique_ptr<QueuedTask>(new TimerTask()), 1000);
// //
// For more examples, see task_queue_unittests.cc. // For more examples, see task_queue_unittests.cc.
// //
@ -90,8 +89,6 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue {
Priority priority = Priority::NORMAL); Priority priority = Priority::NORMAL);
~TaskQueue(); ~TaskQueue();
static TaskQueue* Current();
// Used for DCHECKing the current queue. // Used for DCHECKing the current queue.
bool IsCurrent() const; bool IsCurrent() const;

View File

@ -43,6 +43,7 @@ if (rtc_enable_protobuf) {
deps = [ deps = [
":network_tester_config_proto", ":network_tester_config_proto",
":network_tester_packet_proto", ":network_tester_packet_proto",
"../../api/task_queue",
"../../p2p", "../../p2p",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:protobuf_utils", "../../rtc_base:protobuf_utils",

View File

@ -16,6 +16,7 @@
#include <utility> #include <utility>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/task_queue/task_queue_base.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "rtc_tools/network_tester/config_reader.h" #include "rtc_tools/network_tester/config_reader.h"
#include "rtc_tools/network_tester/test_controller.h" #include "rtc_tools/network_tester/test_controller.h"
@ -36,7 +37,7 @@ class SendPacketTask : public rtc::QueuedTask {
target_time_ms_ += packet_sender_->GetSendIntervalMs(); target_time_ms_ += packet_sender_->GetSendIntervalMs();
int64_t delay_ms = std::max(static_cast<int64_t>(0), int64_t delay_ms = std::max(static_cast<int64_t>(0),
target_time_ms_ - rtc::TimeMillis()); target_time_ms_ - rtc::TimeMillis());
rtc::TaskQueue::Current()->PostDelayedTask( TaskQueueBase::Current()->PostDelayedTask(
std::unique_ptr<QueuedTask>(this), delay_ms); std::unique_ptr<QueuedTask>(this), delay_ms);
return false; return false;
} else { } else {
@ -60,7 +61,7 @@ class UpdateTestSettingTask : public rtc::QueuedTask {
if (config) { if (config) {
packet_sender_->UpdateTestSetting((*config).packet_size, packet_sender_->UpdateTestSetting((*config).packet_size,
(*config).packet_send_interval_ms); (*config).packet_send_interval_ms);
rtc::TaskQueue::Current()->PostDelayedTask( TaskQueueBase::Current()->PostDelayedTask(
std::unique_ptr<QueuedTask>(this), (*config).execution_time_ms); std::unique_ptr<QueuedTask>(this), (*config).execution_time_ms);
return false; return false;
} else { } else {

View File

@ -621,6 +621,7 @@ if (is_android) {
":videoframe_jni", ":videoframe_jni",
"../..:webrtc_common", "../..:webrtc_common",
"../../api:scoped_refptr", "../../api:scoped_refptr",
"../../api/task_queue",
"../../api/video_codecs:video_codecs_api", "../../api/video_codecs:video_codecs_api",
"../../common_video:common_video", "../../common_video:common_video",
"../../media:rtc_internal_video_codecs", "../../media:rtc_internal_video_codecs",
@ -679,6 +680,7 @@ if (is_android) {
":videoframe_jni", ":videoframe_jni",
"../..:webrtc_common", "../..:webrtc_common",
"../../api:libjingle_peerconnection_api", "../../api:libjingle_peerconnection_api",
"../../api/task_queue",
"../../api/video:encoded_image", "../../api/video:encoded_image",
"../../api/video:video_frame", "../../api/video:video_frame",
"../../api/video_codecs:rtc_software_fallback_wrappers", "../../api/video_codecs:rtc_software_fallback_wrappers",
@ -691,6 +693,7 @@ if (is_android) {
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:rtc_base", "../../rtc_base:rtc_base",
"../../rtc_base:rtc_task_queue", "../../rtc_base:rtc_task_queue",
"../../rtc_base/task_utils:to_queued_task",
"//third_party/libyuv", "//third_party/libyuv",
] ]
} }

View File

@ -14,6 +14,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "api/task_queue/task_queue_base.h"
#include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder.h"
#include "common_types.h" // NOLINT(build/include) #include "common_types.h" // NOLINT(build/include)
@ -416,10 +417,10 @@ bool MediaCodecVideoEncoder::EncodeTask::Run() {
// If there aren't more frames to deliver, we can start polling at lower rate. // If there aren't more frames to deliver, we can start polling at lower rate.
if (encoder_->input_frame_infos_.empty()) { if (encoder_->input_frame_infos_.empty()) {
rtc::TaskQueue::Current()->PostDelayedTask( TaskQueueBase::Current()->PostDelayedTask(
std::unique_ptr<rtc::QueuedTask>(this), kMediaCodecPollNoFramesMs); std::unique_ptr<rtc::QueuedTask>(this), kMediaCodecPollNoFramesMs);
} else { } else {
rtc::TaskQueue::Current()->PostDelayedTask( TaskQueueBase::Current()->PostDelayedTask(
std::unique_ptr<rtc::QueuedTask>(this), kMediaCodecPollMs); std::unique_ptr<rtc::QueuedTask>(this), kMediaCodecPollMs);
} }
@ -741,8 +742,8 @@ int32_t MediaCodecVideoEncoder::Encode(
// Start the polling loop if it is not started. // Start the polling loop if it is not started.
if (encode_task_) { if (encode_task_) {
rtc::TaskQueue::Current()->PostDelayedTask(std::move(encode_task_), TaskQueueBase::Current()->PostDelayedTask(std::move(encode_task_),
kMediaCodecPollMs); kMediaCodecPollMs);
} }
if (!DeliverPendingOutputs(jni)) { if (!DeliverPendingOutputs(jni)) {

View File

@ -18,6 +18,7 @@
#include "modules/video_coding/utility/vp8_header_parser.h" #include "modules/video_coding/utility/vp8_header_parser.h"
#include "modules/video_coding/utility/vp9_uncompressed_header_parser.h" #include "modules/video_coding/utility/vp9_uncompressed_header_parser.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "sdk/android/generated_video_jni/jni/VideoEncoderWrapper_jni.h" #include "sdk/android/generated_video_jni/jni/VideoEncoderWrapper_jni.h"
#include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h" #include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h"
@ -47,7 +48,7 @@ int32_t VideoEncoderWrapper::InitEncode(const VideoCodec* codec_settings,
num_resets_ = 0; num_resets_ = 0;
{ {
rtc::CritScope lock(&encoder_queue_crit_); rtc::CritScope lock(&encoder_queue_crit_);
encoder_queue_ = rtc::TaskQueue::Current(); encoder_queue_ = TaskQueueBase::Current();
} }
return InitEncodeInternal(jni); return InitEncodeInternal(jni);
@ -293,10 +294,10 @@ void VideoEncoderWrapper::OnEncodedFrame(JNIEnv* jni,
{ {
rtc::CritScope lock(&encoder_queue_crit_); rtc::CritScope lock(&encoder_queue_crit_);
if (encoder_queue_ != nullptr) { if (encoder_queue_ != nullptr) {
encoder_queue_->PostTask( encoder_queue_->PostTask(ToQueuedTask(
Lambda{this, std::move(buffer_copy), qp, encoded_width, Lambda{this, std::move(buffer_copy), qp, encoded_width,
encoded_height, capture_time_ns, frame_type, rotation, encoded_height, capture_time_ns, frame_type, rotation,
complete_frame, &frame_extra_infos_, callback_}); complete_frame, &frame_extra_infos_, callback_}));
} }
} }
} }

View File

@ -16,10 +16,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/task_queue/task_queue_base.h"
#include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder.h"
#include "common_video/h264/h264_bitstream_parser.h" #include "common_video/h264/h264_bitstream_parser.h"
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h" #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
#include "rtc_base/task_queue.h"
#include "sdk/android/src/jni/jni_helpers.h" #include "sdk/android/src/jni/jni_helpers.h"
#include "sdk/android/src/jni/video_frame.h" #include "sdk/android/src/jni/video_frame.h"
@ -92,7 +92,7 @@ class VideoEncoderWrapper : public VideoEncoder {
const ScopedJavaGlobalRef<jclass> int_array_class_; const ScopedJavaGlobalRef<jclass> int_array_class_;
rtc::CriticalSection encoder_queue_crit_; rtc::CriticalSection encoder_queue_crit_;
rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(encoder_queue_crit_); TaskQueueBase* encoder_queue_ RTC_GUARDED_BY(encoder_queue_crit_);
std::deque<FrameExtraInfo> frame_extra_infos_; std::deque<FrameExtraInfo> frame_extra_infos_;
EncodedImageCallback* callback_; EncodedImageCallback* callback_;
bool initialized_; bool initialized_;