diff --git a/webrtc/api/mediastreaminterface.h b/webrtc/api/mediastreaminterface.h index 71cbbb7b10..cc660e1be2 100644 --- a/webrtc/api/mediastreaminterface.h +++ b/webrtc/api/mediastreaminterface.h @@ -111,11 +111,6 @@ class MediaStreamTrackInterface : public rtc::RefCountInterface, // VideoTrackSourceInterface is a reference counted source used for // VideoTracks. The same source can be used by multiple VideoTracks. -// VideoTrackSourceInterface is designed to be invoked on the signaling thread -// except for rtc::VideoSourceInterface methods that will be invoked -// on the worker thread via a VideoTrack. A custom implementation of a source -// can inherit AdaptedVideoTrackSource instead of directly implementing this -// interface. class VideoTrackSourceInterface : public MediaSourceInterface, public rtc::VideoSourceInterface { @@ -150,12 +145,6 @@ class VideoTrackSourceInterface virtual ~VideoTrackSourceInterface() {} }; -// VideoTrackInterface is designed to be invoked on the signaling thread except -// for rtc::VideoSourceInterface methods that must be invoked -// on the worker thread. -// PeerConnectionFactory::CreateVideoTrack can be used for creating a VideoTrack -// that ensures thread safety and that all methods are called on the right -// thread. class VideoTrackInterface : public MediaStreamTrackInterface, public rtc::VideoSourceInterface { @@ -165,6 +154,12 @@ class VideoTrackInterface // See https://crbug.com/653531 and https://github.com/WICG/mst-content-hint. enum class ContentHint { kNone, kFluid, kDetailed }; + // Register a video sink for this track. Used to connect the track to the + // underlying video engine. + void AddOrUpdateSink(rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants) override {} + void RemoveSink(rtc::VideoSinkInterface* sink) override {} + virtual VideoTrackSourceInterface* GetSource() const = 0; virtual ContentHint content_hint() const { return ContentHint::kNone; } diff --git a/webrtc/ortc/ortcfactory.cc b/webrtc/ortc/ortcfactory.cc index be1c4c7a76..1d968738cd 100644 --- a/webrtc/ortc/ortcfactory.cc +++ b/webrtc/ortc/ortcfactory.cc @@ -479,8 +479,7 @@ rtc::scoped_refptr OrtcFactory::CreateVideoTrack( const std::string& id, VideoTrackSourceInterface* source) { RTC_DCHECK_RUN_ON(signaling_thread_); - rtc::scoped_refptr track( - VideoTrack::Create(id, source, worker_thread_.get())); + rtc::scoped_refptr track(VideoTrack::Create(id, source)); return VideoTrackProxy::Create(signaling_thread_, worker_thread_.get(), track); } diff --git a/webrtc/pc/mediastream_unittest.cc b/webrtc/pc/mediastream_unittest.cc index 1a96a56f97..01a547bbc5 100644 --- a/webrtc/pc/mediastream_unittest.cc +++ b/webrtc/pc/mediastream_unittest.cc @@ -56,8 +56,8 @@ class MediaStreamTest: public testing::Test { stream_ = MediaStream::Create(kStreamLabel1); ASSERT_TRUE(stream_.get() != NULL); - video_track_ = VideoTrack::Create( - kVideoTrackId, FakeVideoTrackSource::Create(), rtc::Thread::Current()); + video_track_ = + VideoTrack::Create(kVideoTrackId, FakeVideoTrackSource::Create()); ASSERT_TRUE(video_track_.get() != NULL); EXPECT_EQ(MediaStreamTrackInterface::kLive, video_track_->state()); diff --git a/webrtc/pc/peerconnectionfactory.cc b/webrtc/pc/peerconnectionfactory.cc index be083c26b7..15e36f094a 100644 --- a/webrtc/pc/peerconnectionfactory.cc +++ b/webrtc/pc/peerconnectionfactory.cc @@ -292,7 +292,7 @@ rtc::scoped_refptr PeerConnectionFactory::CreateVideoTrack( VideoTrackSourceInterface* source) { RTC_DCHECK(signaling_thread_->IsCurrent()); rtc::scoped_refptr track( - VideoTrack::Create(id, source, worker_thread_)); + VideoTrack::Create(id, source)); return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track); } diff --git a/webrtc/pc/peerconnectioninterface_unittest.cc b/webrtc/pc/peerconnectioninterface_unittest.cc index 30567b95d3..c10324a94b 100644 --- a/webrtc/pc/peerconnectioninterface_unittest.cc +++ b/webrtc/pc/peerconnectioninterface_unittest.cc @@ -460,8 +460,7 @@ rtc::scoped_refptr CreateStreamCollection( // Add a local video track. rtc::scoped_refptr video_track( webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], - webrtc::FakeVideoTrackSource::Create(), - rtc::Thread::Current())); + webrtc::FakeVideoTrackSource::Create())); stream->AddTrack(video_track); } @@ -1140,8 +1139,7 @@ class PeerConnectionInterfaceTest : public testing::Test { MediaStreamInterface* stream) { rtc::scoped_refptr video_track( webrtc::VideoTrack::Create(track_id, - webrtc::FakeVideoTrackSource::Create(), - rtc::Thread::Current())); + webrtc::FakeVideoTrackSource::Create())); ASSERT_TRUE(stream->AddTrack(video_track)); } diff --git a/webrtc/pc/rtcstatscollector_unittest.cc b/webrtc/pc/rtcstatscollector_unittest.cc index a8755570cc..43c94efe62 100644 --- a/webrtc/pc/rtcstatscollector_unittest.cc +++ b/webrtc/pc/rtcstatscollector_unittest.cc @@ -218,11 +218,6 @@ class FakeVideoTrackForStats std::string kind() const override { return MediaStreamTrackInterface::kVideoKind; } - - void AddOrUpdateSink(rtc::VideoSinkInterface* sink, - const rtc::VideoSinkWants& wants) override{}; - void RemoveSink(rtc::VideoSinkInterface* sink) override{}; - VideoTrackSourceInterface* GetSource() const override { return nullptr; } }; diff --git a/webrtc/pc/rtpreceiver.cc b/webrtc/pc/rtpreceiver.cc index c6a2128dfb..f3eef5a9a9 100644 --- a/webrtc/pc/rtpreceiver.cc +++ b/webrtc/pc/rtpreceiver.cc @@ -155,8 +155,7 @@ VideoRtpReceiver::VideoRtpReceiver(const std::string& track_id, track_id, VideoTrackSourceProxy::Create(rtc::Thread::Current(), worker_thread, - source_), - worker_thread))) { + source_)))) { source_->SetState(MediaSourceInterface::kLive); if (!channel_) { LOG(LS_ERROR) diff --git a/webrtc/pc/rtpsenderreceiver_unittest.cc b/webrtc/pc/rtpsenderreceiver_unittest.cc index 9779eb6f56..bf413e411d 100644 --- a/webrtc/pc/rtpsenderreceiver_unittest.cc +++ b/webrtc/pc/rtpsenderreceiver_unittest.cc @@ -124,8 +124,7 @@ class RtpSenderReceiverTest : public testing::Test, void AddVideoTrack(bool is_screencast) { rtc::scoped_refptr source( FakeVideoTrackSource::Create(is_screencast)); - video_track_ = - VideoTrack::Create(kVideoTrackId, source, rtc::Thread::Current()); + video_track_ = VideoTrack::Create(kVideoTrackId, source); EXPECT_TRUE(local_stream_->AddTrack(video_track_)); } diff --git a/webrtc/pc/statscollector_unittest.cc b/webrtc/pc/statscollector_unittest.cc index 0fad6adead..9b62b81d33 100644 --- a/webrtc/pc/statscollector_unittest.cc +++ b/webrtc/pc/statscollector_unittest.cc @@ -545,8 +545,7 @@ class StatsCollectorTest : public testing::Test { void AddOutgoingVideoTrackStats() { stream_ = webrtc::MediaStream::Create("streamlabel"); track_ = webrtc::VideoTrack::Create(kLocalTrackId, - webrtc::FakeVideoTrackSource::Create(), - rtc::Thread::Current()); + webrtc::FakeVideoTrackSource::Create()); stream_->AddTrack(track_); EXPECT_CALL(session_, GetLocalTrackIdBySsrc(kSsrcOfTrack, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(kLocalTrackId), Return(true))); @@ -556,8 +555,7 @@ class StatsCollectorTest : public testing::Test { void AddIncomingVideoTrackStats() { stream_ = webrtc::MediaStream::Create("streamlabel"); track_ = webrtc::VideoTrack::Create(kRemoteTrackId, - webrtc::FakeVideoTrackSource::Create(), - rtc::Thread::Current()); + webrtc::FakeVideoTrackSource::Create()); stream_->AddTrack(track_); EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true))); diff --git a/webrtc/pc/trackmediainfomap_unittest.cc b/webrtc/pc/trackmediainfomap_unittest.cc index f0a3f1ad73..b380cc4184 100644 --- a/webrtc/pc/trackmediainfomap_unittest.cc +++ b/webrtc/pc/trackmediainfomap_unittest.cc @@ -85,12 +85,10 @@ class TrackMediaInfoMapTest : public testing::Test { remote_audio_track_(AudioTrack::Create("RemoteAudioTrack", nullptr)), local_video_track_( VideoTrack::Create("LocalVideoTrack", - FakeVideoTrackSource::Create(false), - rtc::Thread::Current())), + FakeVideoTrackSource::Create(false))), remote_video_track_( VideoTrack::Create("RemoteVideoTrack", - FakeVideoTrackSource::Create(false), - rtc::Thread::Current())) {} + FakeVideoTrackSource::Create(false))) {} ~TrackMediaInfoMapTest() { // If we have a map the ownership has been passed to the map, only delete if diff --git a/webrtc/pc/videotrack.cc b/webrtc/pc/videotrack.cc index f106460164..494d728b1e 100644 --- a/webrtc/pc/videotrack.cc +++ b/webrtc/pc/videotrack.cc @@ -15,12 +15,11 @@ namespace webrtc { VideoTrack::VideoTrack(const std::string& label, - VideoTrackSourceInterface* video_source, - rtc::Thread* worker_thread) + VideoTrackSourceInterface* video_source) : MediaStreamTrack(label), - worker_thread_(worker_thread), video_source_(video_source), content_hint_(ContentHint::kNone) { + worker_thread_checker_.DetachFromThread(); video_source_->RegisterObserver(this); } @@ -36,7 +35,7 @@ std::string VideoTrack::kind() const { // thread. void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) { - RTC_DCHECK(worker_thread_->IsCurrent()); + RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); VideoSourceBase::AddOrUpdateSink(sink, wants); rtc::VideoSinkWants modified_wants = wants; modified_wants.black_frames = !enabled(); @@ -44,7 +43,7 @@ void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface* sink, } void VideoTrack::RemoveSink(rtc::VideoSinkInterface* sink) { - RTC_DCHECK(worker_thread_->IsCurrent()); + RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); VideoSourceBase::RemoveSink(sink); video_source_->RemoveSink(sink); } @@ -64,14 +63,13 @@ void VideoTrack::set_content_hint(ContentHint hint) { bool VideoTrack::set_enabled(bool enable) { RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); - worker_thread_->Invoke(RTC_FROM_HERE, [enable, this] { - RTC_DCHECK(worker_thread_->IsCurrent()); - for (auto& sink_pair : sink_pairs()) { - rtc::VideoSinkWants modified_wants = sink_pair.wants; - modified_wants.black_frames = !enable; - video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); - } - }); + for (auto& sink_pair : sink_pairs()) { + rtc::VideoSinkWants modified_wants = sink_pair.wants; + modified_wants.black_frames = !enable; + // video_source_ is a proxy object, marshalling the call to the + // worker thread. + video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); + } return MediaStreamTrack::set_enabled(enable); } @@ -86,10 +84,9 @@ void VideoTrack::OnChanged() { rtc::scoped_refptr VideoTrack::Create( const std::string& id, - VideoTrackSourceInterface* source, - rtc::Thread* worker_thread) { + VideoTrackSourceInterface* source) { rtc::RefCountedObject* track = - new rtc::RefCountedObject(id, source, worker_thread); + new rtc::RefCountedObject(id, source); return track; } diff --git a/webrtc/pc/videotrack.h b/webrtc/pc/videotrack.h index 6e20e978b9..f251797155 100644 --- a/webrtc/pc/videotrack.h +++ b/webrtc/pc/videotrack.h @@ -27,8 +27,7 @@ class VideoTrack : public MediaStreamTrack, public: static rtc::scoped_refptr Create( const std::string& label, - VideoTrackSourceInterface* source, - rtc::Thread* worker_thread); + VideoTrackSourceInterface* source); void AddOrUpdateSink(rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) override; @@ -43,17 +42,15 @@ class VideoTrack : public MediaStreamTrack, std::string kind() const override; protected: - VideoTrack(const std::string& id, - VideoTrackSourceInterface* video_source, - rtc::Thread* worker_thread); + VideoTrack(const std::string& id, VideoTrackSourceInterface* video_source); ~VideoTrack(); private: // Implements ObserverInterface. Observes |video_source_| state. void OnChanged() override; - rtc::Thread* const worker_thread_; rtc::ThreadChecker signaling_thread_checker_; + rtc::ThreadChecker worker_thread_checker_; rtc::scoped_refptr video_source_; ContentHint content_hint_ GUARDED_BY(signaling_thread_checker_); }; diff --git a/webrtc/pc/videotrack_unittest.cc b/webrtc/pc/videotrack_unittest.cc index 1f569ebd59..d033efe632 100644 --- a/webrtc/pc/videotrack_unittest.cc +++ b/webrtc/pc/videotrack_unittest.cc @@ -31,8 +31,7 @@ class VideoTrackTest : public testing::Test { static const char kVideoTrackId[] = "track_id"; video_track_source_ = new rtc::RefCountedObject( &capturer_, true /* remote */); - video_track_ = VideoTrack::Create(kVideoTrackId, video_track_source_, - rtc::Thread::Current()); + video_track_ = VideoTrack::Create(kVideoTrackId, video_track_source_); capturer_.Start( cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));