From 3cbdb78878bfd4551b7419eefffe7a02e67323a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 8 May 2018 13:55:43 +0200 Subject: [PATCH] Add method FakePeriodicVideoSource::Stop() Fixes potential race at test shutdown, introduced in cl https://webrtc-review.googlesource.com/49220. Bug: webrtc:6353 Change-Id: Ifaf9e736681b87073a489d75bf1375aa95ee92bb Reviewed-on: https://webrtc-review.googlesource.com/75124 Reviewed-by: Taylor Brandstetter Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#23200} --- ortc/ortcfactory_integrationtest.cc | 1 + pc/test/fakeperiodicvideosource.h | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ortc/ortcfactory_integrationtest.cc b/ortc/ortcfactory_integrationtest.cc index 52dccdd368..6a697cd7e2 100644 --- a/ortc/ortcfactory_integrationtest.cc +++ b/ortc/ortcfactory_integrationtest.cc @@ -465,6 +465,7 @@ TEST_F(OrtcFactoryIntegrationTest, SetTrackWhileSending) { // Destroy old source, set a new track, and verify new frames are received // from the new track. The VideoTrackSource is reference counted and may live // a little longer, so tell it that its source is going away now. + fake_video_sources_[0]->Stop(); fake_video_track_sources_[0]->OnSourceDestroyed(); fake_video_track_sources_[0] = nullptr; fake_video_sources_[0].reset(); diff --git a/pc/test/fakeperiodicvideosource.h b/pc/test/fakeperiodicvideosource.h index 98ed4c2b3a..fd5a3da308 100644 --- a/pc/test/fakeperiodicvideosource.h +++ b/pc/test/fakeperiodicvideosource.h @@ -11,9 +11,12 @@ #ifndef PC_TEST_FAKEPERIODICVIDEOSOURCE_H_ #define PC_TEST_FAKEPERIODICVIDEOSOURCE_H_ +#include + #include "api/videosourceinterface.h" #include "media/base/fakeframesource.h" #include "media/base/videobroadcaster.h" +#include "rtc_base/ptr_util.h" #include "rtc_base/task_queue.h" namespace webrtc { @@ -25,9 +28,11 @@ class FakePeriodicVideoSource final static constexpr int kWidth = 640; static constexpr int kHeight = 480; - FakePeriodicVideoSource() { + FakePeriodicVideoSource() + : task_queue_( + rtc::MakeUnique("FakePeriodicVideoTrackSource")) { thread_checker_.DetachFromThread(); - task_queue_.PostTask(rtc::MakeUnique(&broadcaster_)); + task_queue_->PostTask(rtc::MakeUnique(&broadcaster_)); } void RemoveSink(rtc::VideoSinkInterface* sink) override { @@ -41,6 +46,11 @@ class FakePeriodicVideoSource final broadcaster_.AddOrUpdateSink(sink, wants); } + void Stop() { + RTC_DCHECK(task_queue_); + task_queue_.reset(); + } + private: class FrameTask : public rtc::QueuedTask { public: @@ -65,8 +75,7 @@ class FakePeriodicVideoSource final rtc::VideoBroadcaster broadcaster_; - // Last member, depend on detruction order. - rtc::TaskQueue task_queue_{"FakePeriodicVideoTrackSource"}; + std::unique_ptr task_queue_; }; } // namespace webrtc