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 <deadbeef@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23200}
This commit is contained in:
Niels Möller
2018-05-08 13:55:43 +02:00
committed by Commit Bot
parent 73b36b582f
commit 3cbdb78878
2 changed files with 14 additions and 4 deletions

View File

@ -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();

View File

@ -11,9 +11,12 @@
#ifndef PC_TEST_FAKEPERIODICVIDEOSOURCE_H_
#define PC_TEST_FAKEPERIODICVIDEOSOURCE_H_
#include <memory>
#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<rtc::TaskQueue>("FakePeriodicVideoTrackSource")) {
thread_checker_.DetachFromThread();
task_queue_.PostTask(rtc::MakeUnique<FrameTask>(&broadcaster_));
task_queue_->PostTask(rtc::MakeUnique<FrameTask>(&broadcaster_));
}
void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* 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<rtc::TaskQueue> task_queue_;
};
} // namespace webrtc