From f2880a0e04fdea1710976d1ae170379907028d1b Mon Sep 17 00:00:00 2001 From: perkj Date: Thu, 3 Mar 2016 01:51:52 -0800 Subject: [PATCH] Change webrtc::VideoSourceInterface to inherit rtc::VideoSourceInterface. Also introduce a typedef VideoTrackSourceInterface to be able to start changing clients such as Chrome to use the name VideoTrackSourceInterface. Document: https://docs.google.com/a/google.com/document/d/1mEIw_0uDzyHjL3l8a82WKp6AvgR8Tlwn9JGvhbUjVpY/edit?usp=sharing BUG=webrtc:5426 Review URL: https://codereview.webrtc.org/1758223002 Cr-Commit-Position: refs/heads/master@{#11854} --- webrtc/api/rtpsenderreceiver_unittest.cc | 21 +++++++++++---------- webrtc/api/videosource.cc | 9 ++++----- webrtc/api/videosource.h | 14 +++----------- webrtc/api/videosource_unittest.cc | 4 ++-- webrtc/api/videosourceinterface.h | 19 ++++++++----------- webrtc/api/videosourceproxy.h | 4 +++- webrtc/api/videotrack.cc | 2 +- webrtc/media/base/videosourceinterface.h | 1 - 8 files changed, 32 insertions(+), 42 deletions(-) diff --git a/webrtc/api/rtpsenderreceiver_unittest.cc b/webrtc/api/rtpsenderreceiver_unittest.cc index 60960fb5f0..ca88a3bc72 100644 --- a/webrtc/api/rtpsenderreceiver_unittest.cc +++ b/webrtc/api/rtpsenderreceiver_unittest.cc @@ -83,16 +83,17 @@ class FakeVideoSource : public Notifier { static rtc::scoped_refptr Create(bool remote) { return new rtc::RefCountedObject(remote); } - virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; } - virtual void Stop() {} - virtual void Restart() {} - virtual void AddSink(rtc::VideoSinkInterface* output) {} - virtual void RemoveSink( - rtc::VideoSinkInterface* output) {} - virtual SourceState state() const { return state_; } - virtual bool remote() const { return remote_; } - virtual const cricket::VideoOptions* options() const { return &options_; } - virtual cricket::VideoRenderer* FrameInput() { return NULL; } + cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; } + void Stop() override {} + void Restart() override {} + void AddOrUpdateSink( + rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants) override {} + void RemoveSink( + rtc::VideoSinkInterface* output) override {} + SourceState state() const override { return state_; } + bool remote() const override { return remote_; } + const cricket::VideoOptions* options() const override { return &options_; } protected: explicit FakeVideoSource(bool remote) : state_(kLive), remote_(remote) {} diff --git a/webrtc/api/videosource.cc b/webrtc/api/videosource.cc index 0178d1ec59..a15ed19ef2 100644 --- a/webrtc/api/videosource.cc +++ b/webrtc/api/videosource.cc @@ -394,13 +394,12 @@ void VideoSource::Restart() { started_ = true; } -void VideoSource::AddSink( - rtc::VideoSinkInterface* output) { - // TODO(perkj): Use fake rtc::VideoSinkWants for now. This will change once - // webrtc::VideoSourceInterface inherit rtc::VideoSourceInterface. +void VideoSource::AddOrUpdateSink( + rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants) { worker_thread_->Invoke( rtc::Bind(&cricket::VideoCapturer::AddOrUpdateSink, - video_capturer_.get(), output, rtc::VideoSinkWants())); + video_capturer_.get(), sink, wants)); } void VideoSource::RemoveSink( diff --git a/webrtc/api/videosource.h b/webrtc/api/videosource.h index 7ff479a45f..634c47ae37 100644 --- a/webrtc/api/videosource.h +++ b/webrtc/api/videosource.h @@ -30,13 +30,6 @@ // The state is set depending on the result of starting the capturer. // If the constraint can't be met or the capturer fails to start, the state // transition to kEnded, otherwise it transitions to kLive. - -namespace cricket { - -class ChannelManager; - -} // namespace cricket - namespace webrtc { class MediaConstraintsInterface; @@ -66,10 +59,9 @@ class VideoSource : public Notifier, void Stop() override; void Restart() override; - // |output| will be served video frames as long as the underlying capturer - // is running video frames. - virtual void AddSink(rtc::VideoSinkInterface* output); - virtual void RemoveSink(rtc::VideoSinkInterface* output); + void AddOrUpdateSink(rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants) override; + void RemoveSink(rtc::VideoSinkInterface* sink) override; protected: VideoSource(rtc::Thread* worker_thread, diff --git a/webrtc/api/videosource_unittest.cc b/webrtc/api/videosource_unittest.cc index e5f8b9f146..cfa1e721b8 100644 --- a/webrtc/api/videosource_unittest.cc +++ b/webrtc/api/videosource_unittest.cc @@ -137,7 +137,7 @@ class VideoSourceTest : public testing::Test { state_observer_.reset(new StateObserver(source_)); source_->RegisterObserver(state_observer_.get()); - source_->AddSink(&renderer_); + source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); } rtc::scoped_ptr capturer_cleanup_; @@ -200,7 +200,7 @@ TEST_F(VideoSourceTest, StartStopRemote) { state_observer_.reset(new StateObserver(source_)); source_->RegisterObserver(state_observer_.get()); - source_->AddSink(&renderer_); + source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), kMaxWaitMs); diff --git a/webrtc/api/videosourceinterface.h b/webrtc/api/videosourceinterface.h index 3e319fcc3c..d55f0aaa52 100644 --- a/webrtc/api/videosourceinterface.h +++ b/webrtc/api/videosourceinterface.h @@ -13,7 +13,7 @@ #include "webrtc/api/mediastreaminterface.h" #include "webrtc/media/base/mediachannel.h" -#include "webrtc/media/base/videorenderer.h" +#include "webrtc/media/base/videosourceinterface.h" namespace webrtc { @@ -21,31 +21,28 @@ namespace webrtc { // The same source can be used in multiple VideoTracks. // The methods are only supposed to be called by the PeerConnection // implementation. -class VideoSourceInterface : public MediaSourceInterface { +class VideoSourceInterface : + public MediaSourceInterface, + public rtc::VideoSourceInterface { public: // Get access to the source implementation of cricket::VideoCapturer. // This can be used for receiving frames and state notifications. // But it should not be used for starting or stopping capturing. virtual cricket::VideoCapturer* GetVideoCapturer() = 0; - // Stop the video capturer. virtual void Stop() = 0; virtual void Restart() = 0; - // Adds |output| to the source to receive frames. - virtual void AddSink( - rtc::VideoSinkInterface* output) = 0; - virtual void RemoveSink( - rtc::VideoSinkInterface* output) = 0; virtual const cricket::VideoOptions* options() const = 0; - // TODO(nisse): Dummy implementation. Delete as soon as chrome's - // MockVideoSource is updated. - virtual cricket::VideoRenderer* FrameInput() { return nullptr; } protected: virtual ~VideoSourceInterface() {} }; +// TODO(perkj): Rename webrtc::VideoSourceInterface to +// webrtc::VideoTrackSourceInterface +using VideoTrackSourceInterface = VideoSourceInterface; + } // namespace webrtc #endif // WEBRTC_API_VIDEOSOURCEINTERFACE_H_ diff --git a/webrtc/api/videosourceproxy.h b/webrtc/api/videosourceproxy.h index 9441bbd9b8..e0f94dc881 100644 --- a/webrtc/api/videosourceproxy.h +++ b/webrtc/api/videosourceproxy.h @@ -25,7 +25,9 @@ BEGIN_PROXY_MAP(VideoSource) PROXY_METHOD0(cricket::VideoCapturer*, GetVideoCapturer) PROXY_METHOD0(void, Stop) PROXY_METHOD0(void, Restart) - PROXY_METHOD1(void, AddSink, rtc::VideoSinkInterface*) + PROXY_METHOD2(void, AddOrUpdateSink, + rtc::VideoSinkInterface*, + const rtc::VideoSinkWants&) PROXY_METHOD1(void, RemoveSink, rtc::VideoSinkInterface*) PROXY_CONSTMETHOD0(const cricket::VideoOptions*, options) PROXY_METHOD1(void, RegisterObserver, ObserverInterface*) diff --git a/webrtc/api/videotrack.cc b/webrtc/api/videotrack.cc index 11a0177c77..b776509930 100644 --- a/webrtc/api/videotrack.cc +++ b/webrtc/api/videotrack.cc @@ -21,7 +21,7 @@ VideoTrack::VideoTrack(const std::string& label, : MediaStreamTrack(label), video_source_(video_source) { if (video_source_) - video_source_->AddSink(&renderers_); + video_source_->AddOrUpdateSink(&renderers_, rtc::VideoSinkWants()); } VideoTrack::~VideoTrack() { diff --git a/webrtc/media/base/videosourceinterface.h b/webrtc/media/base/videosourceinterface.h index 8895970df3..54f4c4c3d8 100644 --- a/webrtc/media/base/videosourceinterface.h +++ b/webrtc/media/base/videosourceinterface.h @@ -12,7 +12,6 @@ #define WEBRTC_MEDIA_BASE_VIDEOSOURCEINTERFACE_H_ #include "webrtc/media/base/videosinkinterface.h" -#include "webrtc/base/callback.h" #include "webrtc/base/optional.h" namespace rtc {