Change VideoStreamEncoder::Stop() to handle stopped TQ

In case the encoder TQ has been stopped and doesn't accept more tasks,
we could end up in a hung state during Stop(). This is a hypothetical
situation, but can be simulated in a test and avoided.

Bug: webrtc:14063
Change-Id: I20f48b11b6266f6875ed5e69de3529212505e439
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258125
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36964}
This commit is contained in:
Tommi 2022-05-23 09:34:41 +02:00 committed by WebRTC LUCI CQ
parent c3fa7c38b2
commit 4d6dd17153
2 changed files with 31 additions and 25 deletions

View File

@ -731,7 +731,8 @@ void VideoStreamEncoder::Stop() {
rtc::Event shutdown_event;
encoder_queue_.PostTask([this, &shutdown_event] {
encoder_queue_.PostTask(webrtc::ToQueuedTask(
[this] {
RTC_DCHECK_RUN_ON(&encoder_queue_);
if (resource_adaptation_processor_) {
stream_resource_manager_.StopManagedResources();
@ -754,8 +755,8 @@ void VideoStreamEncoder::Stop() {
ReleaseEncoder();
encoder_ = nullptr;
frame_cadence_adapter_ = nullptr;
shutdown_event.Set();
});
},
[&shutdown_event]() { shutdown_event.Set(); }));
shutdown_event.Wait(rtc::Event::kForever);
}

View File

@ -9108,6 +9108,11 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) {
VideoStreamEncoder::BitrateAllocationCallbackType::
kVideoBitrateAllocation,
field_trials);
// Stop the encoder explicitly. This additional step tests if we could
// hang when calling stop and the TQ has been stopped and/or isn't accepting
// any more tasks.
encoder->Stop();
}
TEST(VideoStreamEncoderFrameCadenceTest, ActivatesFrameCadenceOnContentType) {