Skip to content

Commit

Permalink
Revert "TaskQueue: unexpose delayed task convenience methods."
Browse files Browse the repository at this point in the history
This reverts commit 08bb629.

Reason for revert: Breaks downstream tests

Original change's description:
> TaskQueue: unexpose delayed task convenience methods.
>
> Bug: webrtc:14165
> Change-Id: Ieb8580670e9e521580afd68cca6ff631fb6df3f8
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265400
> Reviewed-by: Harald Alvestrand <[email protected]>
> Auto-Submit: Markus Handell <[email protected]>
> Commit-Queue: Harald Alvestrand <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#37166}

Bug: webrtc:14165
Change-Id: Ia7368cf205622be448ec0ead5d22f211aa071a29
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265411
Bot-Commit: [email protected] <[email protected]>
Owners-Override: Björn Terelius <[email protected]>
Auto-Submit: Björn Terelius <[email protected]>
Commit-Queue: Björn Terelius <[email protected]>
Cr-Commit-Position: refs/heads/main@{#37167}
  • Loading branch information
Björn Terelius authored and WebRTC LUCI CQ committed Jun 9, 2022
1 parent 08bb629 commit 4cd3a0d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 29 deletions.
4 changes: 2 additions & 2 deletions common_video/incoming_video_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void IncomingVideoStream::Dequeue() {

if (render_buffers_.HasPendingFrames()) {
uint32_t wait_time = render_buffers_.TimeToNextFrameRelease();
incoming_render_queue_.PostDelayedHighPrecisionTask(
ToQueuedTask([this]() { Dequeue(); }), wait_time);
incoming_render_queue_.PostDelayedHighPrecisionTask([this]() { Dequeue(); },
wait_time);
}
}

Expand Down
2 changes: 1 addition & 1 deletion logging/rtc_event_log/rtc_event_log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void RtcEventLogImpl::ScheduleOutput() {
const int64_t time_since_output_ms = now_ms - last_output_ms_;
const uint32_t delay = rtc::SafeClamp(
*output_period_ms_ - time_since_output_ms, 0, *output_period_ms_);
task_queue_->PostDelayedTask(ToQueuedTask(std::move(output_task)), delay);
task_queue_->PostDelayedTask(output_task, delay);
}
}

Expand Down
4 changes: 1 addition & 3 deletions modules/audio_device/audio_device_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,7 @@ void AudioDeviceBuffer::LogStats(LogState state) {

// Keep posting new (delayed) tasks until state is changed to kLogStop.
task_queue_.PostDelayedTask(
ToQueuedTask([this] {
AudioDeviceBuffer::LogStats(AudioDeviceBuffer::LOG_ACTIVE);
}),
[this] { AudioDeviceBuffer::LogStats(AudioDeviceBuffer::LOG_ACTIVE); },
time_to_wait_ms);
}

Expand Down
5 changes: 2 additions & 3 deletions modules/pacing/task_queue_paced_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ void TaskQueuePacedSender::MaybeProcessPackets(
}

task_queue_.PostDelayedTaskWithPrecision(
precision, ToQueuedTask([this, next_send_time]() {
MaybeProcessPackets(next_send_time);
}),
precision,
[this, next_send_time]() { MaybeProcessPackets(next_send_time); },
time_to_next_process.RoundUpTo(TimeDelta::Millis(1)).ms<uint32_t>());
next_process_time_ = next_send_time;
}
Expand Down
28 changes: 28 additions & 0 deletions rtc_base/task_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue {
void PostTask(Closure&& closure) {
PostTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)));
}
template <class Closure,
typename std::enable_if<!std::is_convertible<
Closure,
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
void PostDelayedTask(Closure&& closure, uint32_t milliseconds) {
PostDelayedTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)),
milliseconds);
}
template <class Closure,
typename std::enable_if<!std::is_convertible<
Closure,
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
void PostDelayedHighPrecisionTask(Closure&& closure, uint32_t milliseconds) {
PostDelayedHighPrecisionTask(
webrtc::ToQueuedTask(std::forward<Closure>(closure)), milliseconds);
}
template <class Closure,
typename std::enable_if<!std::is_convertible<
Closure,
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
void PostDelayedTaskWithPrecision(
webrtc::TaskQueueBase::DelayPrecision precision,
Closure&& closure,
uint32_t milliseconds) {
PostDelayedTaskWithPrecision(
precision, webrtc::ToQueuedTask(std::forward<Closure>(closure)),
milliseconds);
}

private:
webrtc::TaskQueueBase* const impl_;
Expand Down
4 changes: 1 addition & 3 deletions rtc_base/task_queue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
webrtc::TaskQueueForTest queue(kQueueName, TaskQueue::Priority::HIGH);

uint32_t start = Time();
queue.PostDelayedTask(
webrtc::ToQueuedTask([&event, &queue] { CheckCurrent(&event, &queue); }),
3);
queue.PostDelayedTask([&event, &queue] { CheckCurrent(&event, &queue); }, 3);
EXPECT_TRUE(event.Wait(1000));
uint32_t end = TimeMillis();
// These tests are a little relaxed due to how "powerful" our test bots can
Expand Down
11 changes: 6 additions & 5 deletions test/fake_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ int32_t FakeDecoder::Decode(const EncodedImage& input,
if (decode_delay_ms_ == 0 || !task_queue_) {
callback_->Decoded(frame);
} else {
task_queue_->PostDelayedHighPrecisionTask(ToQueuedTask([frame, this]() {
VideoFrame copy = frame;
callback_->Decoded(copy);
}),
decode_delay_ms_);
task_queue_->PostDelayedHighPrecisionTask(
[frame, this]() {
VideoFrame copy = frame;
callback_->Decoded(copy);
},
decode_delay_ms_);
}

return WEBRTC_VIDEO_CODEC_OK;
Expand Down
7 changes: 3 additions & 4 deletions test/pc/e2e/test_activities_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ void TestActivitiesExecutor::PostActivity(ScheduledActivity activity) {
return;
}

task_queue_->PostDelayedTask(ToQueuedTask([activity, start_time, this]() {
activity.func(Now() - start_time);
}),
remaining_delay.ms());
task_queue_->PostDelayedTask(
[activity, start_time, this]() { activity.func(Now() - start_time); },
remaining_delay.ms());
}

Timestamp TestActivitiesExecutor::Now() const {
Expand Down
3 changes: 1 addition & 2 deletions test/scenario/scenario.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ void Scenario::Post(std::function<void()> function) {

void Scenario::At(TimeDelta offset, std::function<void()> function) {
RTC_DCHECK_GT(offset, TimeSinceStart());
task_queue_.PostDelayedTask(ToQueuedTask(std::move(function)),
TimeUntilTarget(offset).ms());
task_queue_.PostDelayedTask(function, TimeUntilTarget(offset).ms());
}

void Scenario::RunFor(TimeDelta duration) {
Expand Down
3 changes: 1 addition & 2 deletions test/time_controller/simulated_time_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ TEST(SimulatedTimeControllerTest, DelayTaskRunOnTime) {
"TestQueue", TaskQueueFactory::Priority::NORMAL));

bool delay_task_executed = false;
task_queue.PostDelayedTask(ToQueuedTask([&] { delay_task_executed = true; }),
10);
task_queue.PostDelayedTask([&] { delay_task_executed = true; }, 10);

time_simulation.AdvanceTime(TimeDelta::Millis(10));
EXPECT_TRUE(delay_task_executed);
Expand Down
8 changes: 4 additions & 4 deletions video/video_send_stream_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,13 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {

rtc::Event done;
test_queue_.PostDelayedTask(
ToQueuedTask([&] {
[&] {
// No padding supposed to be sent for paused observer
EXPECT_EQ(0, padding_bitrate);
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
vss_impl->Stop();
done.Set();
}),
},
5000);

// Pause the test suite so that the last delayed task executes.
Expand Down Expand Up @@ -905,11 +905,11 @@ TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {

rtc::Event done;
test_queue_.PostDelayedTask(
ToQueuedTask([&] {
[&] {
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
vss_impl->Stop();
done.Set();
}),
},
2000);
ASSERT_TRUE(done.Wait(5000));
}
Expand Down

0 comments on commit 4cd3a0d

Please sign in to comment.