Allow SynchronizedFrameDecodeScheduler::Stop to be run multiple times 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 <eshr@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39452}
diff --git a/video/decode_synchronizer.cc b/video/decode_synchronizer.cc index 7d4da3d..e676acf 100644 --- a/video/decode_synchronizer.cc +++ b/video/decode_synchronizer.cc
@@ -66,6 +66,7 @@ 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 @@ 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::Stop() { + if (stopped_) { + return; + } CancelOutstanding(); stopped_ = true; sync_->RemoveFrameScheduler(this); @@ -107,7 +112,7 @@ DecodeSynchronizer::~DecodeSynchronizer() { RTC_DCHECK_RUN_ON(worker_queue_); - RTC_DCHECK(schedulers_.empty()); + RTC_CHECK(schedulers_.empty()); } std::unique_ptr<FrameDecodeScheduler>