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 <hta@webrtc.org> Auto-Submit: Markus Handell <handellm@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37166}
This commit is contained in:
parent
fd0f6b9bf5
commit
08bb6295ea
@ -57,8 +57,8 @@ void IncomingVideoStream::Dequeue() {
|
|||||||
|
|
||||||
if (render_buffers_.HasPendingFrames()) {
|
if (render_buffers_.HasPendingFrames()) {
|
||||||
uint32_t wait_time = render_buffers_.TimeToNextFrameRelease();
|
uint32_t wait_time = render_buffers_.TimeToNextFrameRelease();
|
||||||
incoming_render_queue_.PostDelayedHighPrecisionTask([this]() { Dequeue(); },
|
incoming_render_queue_.PostDelayedHighPrecisionTask(
|
||||||
wait_time);
|
ToQueuedTask([this]() { Dequeue(); }), wait_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -181,7 +181,7 @@ void RtcEventLogImpl::ScheduleOutput() {
|
|||||||
const int64_t time_since_output_ms = now_ms - last_output_ms_;
|
const int64_t time_since_output_ms = now_ms - last_output_ms_;
|
||||||
const uint32_t delay = rtc::SafeClamp(
|
const uint32_t delay = rtc::SafeClamp(
|
||||||
*output_period_ms_ - time_since_output_ms, 0, *output_period_ms_);
|
*output_period_ms_ - time_since_output_ms, 0, *output_period_ms_);
|
||||||
task_queue_->PostDelayedTask(output_task, delay);
|
task_queue_->PostDelayedTask(ToQueuedTask(std::move(output_task)), delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -477,7 +477,9 @@ void AudioDeviceBuffer::LogStats(LogState state) {
|
|||||||
|
|
||||||
// Keep posting new (delayed) tasks until state is changed to kLogStop.
|
// Keep posting new (delayed) tasks until state is changed to kLogStop.
|
||||||
task_queue_.PostDelayedTask(
|
task_queue_.PostDelayedTask(
|
||||||
[this] { AudioDeviceBuffer::LogStats(AudioDeviceBuffer::LOG_ACTIVE); },
|
ToQueuedTask([this] {
|
||||||
|
AudioDeviceBuffer::LogStats(AudioDeviceBuffer::LOG_ACTIVE);
|
||||||
|
}),
|
||||||
time_to_wait_ms);
|
time_to_wait_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -317,8 +317,9 @@ void TaskQueuePacedSender::MaybeProcessPackets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
task_queue_.PostDelayedTaskWithPrecision(
|
task_queue_.PostDelayedTaskWithPrecision(
|
||||||
precision,
|
precision, ToQueuedTask([this, next_send_time]() {
|
||||||
[this, next_send_time]() { MaybeProcessPackets(next_send_time); },
|
MaybeProcessPackets(next_send_time);
|
||||||
|
}),
|
||||||
time_to_next_process.RoundUpTo(TimeDelta::Millis(1)).ms<uint32_t>());
|
time_to_next_process.RoundUpTo(TimeDelta::Millis(1)).ms<uint32_t>());
|
||||||
next_process_time_ = next_send_time;
|
next_process_time_ = next_send_time;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,34 +115,6 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue {
|
|||||||
void PostTask(Closure&& closure) {
|
void PostTask(Closure&& closure) {
|
||||||
PostTask(webrtc::ToQueuedTask(std::forward<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:
|
private:
|
||||||
webrtc::TaskQueueBase* const impl_;
|
webrtc::TaskQueueBase* const impl_;
|
||||||
|
|||||||
@ -66,7 +66,9 @@ TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
|
|||||||
webrtc::TaskQueueForTest queue(kQueueName, TaskQueue::Priority::HIGH);
|
webrtc::TaskQueueForTest queue(kQueueName, TaskQueue::Priority::HIGH);
|
||||||
|
|
||||||
uint32_t start = Time();
|
uint32_t start = Time();
|
||||||
queue.PostDelayedTask([&event, &queue] { CheckCurrent(&event, &queue); }, 3);
|
queue.PostDelayedTask(
|
||||||
|
webrtc::ToQueuedTask([&event, &queue] { CheckCurrent(&event, &queue); }),
|
||||||
|
3);
|
||||||
EXPECT_TRUE(event.Wait(1000));
|
EXPECT_TRUE(event.Wait(1000));
|
||||||
uint32_t end = TimeMillis();
|
uint32_t end = TimeMillis();
|
||||||
// These tests are a little relaxed due to how "powerful" our test bots can
|
// These tests are a little relaxed due to how "powerful" our test bots can
|
||||||
|
|||||||
@ -61,12 +61,11 @@ int32_t FakeDecoder::Decode(const EncodedImage& input,
|
|||||||
if (decode_delay_ms_ == 0 || !task_queue_) {
|
if (decode_delay_ms_ == 0 || !task_queue_) {
|
||||||
callback_->Decoded(frame);
|
callback_->Decoded(frame);
|
||||||
} else {
|
} else {
|
||||||
task_queue_->PostDelayedHighPrecisionTask(
|
task_queue_->PostDelayedHighPrecisionTask(ToQueuedTask([frame, this]() {
|
||||||
[frame, this]() {
|
VideoFrame copy = frame;
|
||||||
VideoFrame copy = frame;
|
callback_->Decoded(copy);
|
||||||
callback_->Decoded(copy);
|
}),
|
||||||
},
|
decode_delay_ms_);
|
||||||
decode_delay_ms_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
|
|||||||
@ -103,9 +103,10 @@ void TestActivitiesExecutor::PostActivity(ScheduledActivity activity) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
task_queue_->PostDelayedTask(
|
task_queue_->PostDelayedTask(ToQueuedTask([activity, start_time, this]() {
|
||||||
[activity, start_time, this]() { activity.func(Now() - start_time); },
|
activity.func(Now() - start_time);
|
||||||
remaining_delay.ms());
|
}),
|
||||||
|
remaining_delay.ms());
|
||||||
}
|
}
|
||||||
|
|
||||||
Timestamp TestActivitiesExecutor::Now() const {
|
Timestamp TestActivitiesExecutor::Now() const {
|
||||||
|
|||||||
@ -266,7 +266,8 @@ void Scenario::Post(std::function<void()> function) {
|
|||||||
|
|
||||||
void Scenario::At(TimeDelta offset, std::function<void()> function) {
|
void Scenario::At(TimeDelta offset, std::function<void()> function) {
|
||||||
RTC_DCHECK_GT(offset, TimeSinceStart());
|
RTC_DCHECK_GT(offset, TimeSinceStart());
|
||||||
task_queue_.PostDelayedTask(function, TimeUntilTarget(offset).ms());
|
task_queue_.PostDelayedTask(ToQueuedTask(std::move(function)),
|
||||||
|
TimeUntilTarget(offset).ms());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenario::RunFor(TimeDelta duration) {
|
void Scenario::RunFor(TimeDelta duration) {
|
||||||
|
|||||||
@ -120,7 +120,8 @@ TEST(SimulatedTimeControllerTest, DelayTaskRunOnTime) {
|
|||||||
"TestQueue", TaskQueueFactory::Priority::NORMAL));
|
"TestQueue", TaskQueueFactory::Priority::NORMAL));
|
||||||
|
|
||||||
bool delay_task_executed = false;
|
bool delay_task_executed = false;
|
||||||
task_queue.PostDelayedTask([&] { delay_task_executed = true; }, 10);
|
task_queue.PostDelayedTask(ToQueuedTask([&] { delay_task_executed = true; }),
|
||||||
|
10);
|
||||||
|
|
||||||
time_simulation.AdvanceTime(TimeDelta::Millis(10));
|
time_simulation.AdvanceTime(TimeDelta::Millis(10));
|
||||||
EXPECT_TRUE(delay_task_executed);
|
EXPECT_TRUE(delay_task_executed);
|
||||||
|
|||||||
@ -867,13 +867,13 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
|
|||||||
|
|
||||||
rtc::Event done;
|
rtc::Event done;
|
||||||
test_queue_.PostDelayedTask(
|
test_queue_.PostDelayedTask(
|
||||||
[&] {
|
ToQueuedTask([&] {
|
||||||
// No padding supposed to be sent for paused observer
|
// No padding supposed to be sent for paused observer
|
||||||
EXPECT_EQ(0, padding_bitrate);
|
EXPECT_EQ(0, padding_bitrate);
|
||||||
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||||
vss_impl->Stop();
|
vss_impl->Stop();
|
||||||
done.Set();
|
done.Set();
|
||||||
},
|
}),
|
||||||
5000);
|
5000);
|
||||||
|
|
||||||
// Pause the test suite so that the last delayed task executes.
|
// Pause the test suite so that the last delayed task executes.
|
||||||
@ -905,11 +905,11 @@ TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {
|
|||||||
|
|
||||||
rtc::Event done;
|
rtc::Event done;
|
||||||
test_queue_.PostDelayedTask(
|
test_queue_.PostDelayedTask(
|
||||||
[&] {
|
ToQueuedTask([&] {
|
||||||
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||||
vss_impl->Stop();
|
vss_impl->Stop();
|
||||||
done.Set();
|
done.Set();
|
||||||
},
|
}),
|
||||||
2000);
|
2000);
|
||||||
ASSERT_TRUE(done.Wait(5000));
|
ASSERT_TRUE(done.Wait(5000));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user