From 57fe5cd7db13254aa8b3c425c54bbde2ae8d2164 Mon Sep 17 00:00:00 2001 From: Evan Shrubsole Date: Tue, 28 Feb 2023 16:01:05 +0000 Subject: [PATCH] Allow SynchronizedFrameDecodeScheduler::Stop to be run multiple times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stop being called twice can happen in tests since the VideoReceiveStream destructor calls Stop so any test calling Stop may invoke it twice. This is a general problem that all things that the VideoReceiveStream have to able to be stopped multiple times. Bug: b/270932185 Change-Id: Ic25810d5ab73e8a07cf3b16685c578f4c0aa7fbd Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295580 Auto-Submit: Evan Shrubsole Reviewed-by: Erik Språng Commit-Queue: Evan Shrubsole Cr-Commit-Position: refs/heads/main@{#39452} --- video/decode_synchronizer.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/video/decode_synchronizer.cc b/video/decode_synchronizer.cc index 7d4da3d47a..e676acfcf0 100644 --- a/video/decode_synchronizer.cc +++ b/video/decode_synchronizer.cc @@ -66,6 +66,7 @@ DecodeSynchronizer::SynchronizedFrameDecodeScheduler::ScheduledRtpTimestamp() { DecodeSynchronizer::ScheduledFrame DecodeSynchronizer::SynchronizedFrameDecodeScheduler::ReleaseNextFrame() { + RTC_DCHECK(!stopped_); RTC_DCHECK(next_frame_); auto res = std::move(*next_frame_); next_frame_.reset(); @@ -82,6 +83,7 @@ void DecodeSynchronizer::SynchronizedFrameDecodeScheduler::ScheduleFrame( uint32_t rtp, FrameDecodeTiming::FrameSchedule schedule, FrameReleaseCallback cb) { + RTC_DCHECK(!stopped_); RTC_DCHECK(!next_frame_) << "Can not schedule two frames at once."; next_frame_ = ScheduledFrame(rtp, std::move(schedule), std::move(cb)); sync_->OnFrameScheduled(this); @@ -92,6 +94,9 @@ void DecodeSynchronizer::SynchronizedFrameDecodeScheduler::CancelOutstanding() { } void DecodeSynchronizer::SynchronizedFrameDecodeScheduler::Stop() { + if (stopped_) { + return; + } CancelOutstanding(); stopped_ = true; sync_->RemoveFrameScheduler(this); @@ -107,7 +112,7 @@ DecodeSynchronizer::DecodeSynchronizer(Clock* clock, DecodeSynchronizer::~DecodeSynchronizer() { RTC_DCHECK_RUN_ON(worker_queue_); - RTC_DCHECK(schedulers_.empty()); + RTC_CHECK(schedulers_.empty()); } std::unique_ptr