Replace SetCapturer and SetCaptureDevice by SetSource.
Drop return value.
BUG=webrtc:5426
Review URL: https://codereview.webrtc.org/1766653002
Cr-Commit-Position: refs/heads/master@{#12291}
diff --git a/webrtc/api/mediastreaminterface.h b/webrtc/api/mediastreaminterface.h
index 57c0776..7f56325 100644
--- a/webrtc/api/mediastreaminterface.h
+++ b/webrtc/api/mediastreaminterface.h
@@ -31,7 +31,6 @@
namespace cricket {
class AudioRenderer;
-class VideoCapturer;
class VideoRenderer;
class VideoFrame;
@@ -113,14 +112,6 @@
int input_width;
int input_height;
};
- // 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.
- // TODO(perkj): We are currently trying to replace all internal use of
- // cricket::VideoCapturer with rtc::VideoSourceInterface. Once that
- // refactoring is done,
- // remove this method.
- virtual cricket::VideoCapturer* GetVideoCapturer() = 0;
virtual void Stop() = 0;
virtual void Restart() = 0;
diff --git a/webrtc/api/mediastreamprovider.h b/webrtc/api/mediastreamprovider.h
index 6814c41..f3bb3f4 100644
--- a/webrtc/api/mediastreamprovider.h
+++ b/webrtc/api/mediastreamprovider.h
@@ -15,13 +15,12 @@
#include "webrtc/base/basictypes.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/media/base/videosinkinterface.h"
+#include "webrtc/media/base/videosourceinterface.h"
namespace cricket {
class AudioSource;
-class VideoCapturer;
class VideoFrame;
-class VideoRenderer;
struct AudioOptions;
struct VideoOptions;
@@ -75,8 +74,9 @@
// of a video track connected to a certain PeerConnection.
class VideoProviderInterface {
public:
- virtual bool SetCaptureDevice(uint32_t ssrc,
- cricket::VideoCapturer* camera) = 0;
+ virtual bool SetSource(
+ uint32_t ssrc,
+ rtc::VideoSourceInterface<cricket::VideoFrame>* source) = 0;
// Enable/disable the video playout of a remote video track with |ssrc|.
virtual void SetVideoPlayout(
uint32_t ssrc,
diff --git a/webrtc/api/objc/RTCAVFoundationVideoSource.mm b/webrtc/api/objc/RTCAVFoundationVideoSource.mm
index 1005c7d..94774f7 100644
--- a/webrtc/api/objc/RTCAVFoundationVideoSource.mm
+++ b/webrtc/api/objc/RTCAVFoundationVideoSource.mm
@@ -14,16 +14,21 @@
#import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h"
#import "webrtc/api/objc/RTCVideoSource+Private.h"
-@implementation RTCAVFoundationVideoSource
+@implementation RTCAVFoundationVideoSource {
+ webrtc::AVFoundationVideoCapturer *_capturer;
+}
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
constraints:(RTCMediaConstraints *)constraints {
NSParameterAssert(factory);
- rtc::scoped_ptr<webrtc::AVFoundationVideoCapturer> capturer;
- capturer.reset(new webrtc::AVFoundationVideoCapturer());
+ // We pass ownership of the capturer to the source, but since we own
+ // the source, it should be ok to keep a raw pointer to the
+ // capturer.
+ _capturer = new webrtc::AVFoundationVideoCapturer();
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
factory.nativeFactory->CreateVideoSource(
- capturer.release(), constraints.nativeConstraints.get());
+ _capturer, constraints.nativeConstraints.get());
+
return [super initWithNativeVideoSource:source];
}
@@ -44,12 +49,7 @@
}
- (webrtc::AVFoundationVideoCapturer *)capturer {
- cricket::VideoCapturer *capturer = self.nativeVideoSource->GetVideoCapturer();
- // This should be safe because no one should have changed the underlying video
- // source.
- webrtc::AVFoundationVideoCapturer *foundationCapturer =
- static_cast<webrtc::AVFoundationVideoCapturer *>(capturer);
- return foundationCapturer;
+ return _capturer;
}
@end
diff --git a/webrtc/api/rtpsender.cc b/webrtc/api/rtpsender.cc
index 94cea6c..214b4a3 100644
--- a/webrtc/api/rtpsender.cc
+++ b/webrtc/api/rtpsender.cc
@@ -276,18 +276,16 @@
// Update video provider.
if (can_send_track()) {
- VideoTrackSourceInterface* source = track_->GetSource();
// TODO(deadbeef): If SetTrack is called with a disabled track, and the
// previous track was enabled, this could cause a frame from the new track
- // to slip out. Really, what we need is for SetCaptureDevice and
- // SetVideoSend
+ // to slip out. Really, what we need is for SetSource and SetVideoSend
// to be combined into one atomic operation, all the way down to
// WebRtcVideoSendStream.
- provider_->SetCaptureDevice(ssrc_,
- source ? source->GetVideoCapturer() : nullptr);
+
+ provider_->SetSource(ssrc_, track_);
SetVideoSend();
} else if (prev_can_send_track) {
- provider_->SetCaptureDevice(ssrc_, nullptr);
+ provider_->SetSource(ssrc_, nullptr);
provider_->SetVideoSend(ssrc_, false, nullptr);
}
return true;
@@ -299,14 +297,12 @@
}
// If we are already sending with a particular SSRC, stop sending.
if (can_send_track()) {
- provider_->SetCaptureDevice(ssrc_, nullptr);
+ provider_->SetSource(ssrc_, nullptr);
provider_->SetVideoSend(ssrc_, false, nullptr);
}
ssrc_ = ssrc;
if (can_send_track()) {
- VideoTrackSourceInterface* source = track_->GetSource();
- provider_->SetCaptureDevice(ssrc_,
- source ? source->GetVideoCapturer() : nullptr);
+ provider_->SetSource(ssrc_, track_);
SetVideoSend();
}
}
@@ -320,7 +316,7 @@
track_->UnregisterObserver(this);
}
if (can_send_track()) {
- provider_->SetCaptureDevice(ssrc_, nullptr);
+ provider_->SetSource(ssrc_, nullptr);
provider_->SetVideoSend(ssrc_, false, nullptr);
}
stopped_ = true;
diff --git a/webrtc/api/rtpsenderreceiver_unittest.cc b/webrtc/api/rtpsenderreceiver_unittest.cc
index 7f32f29..188264e 100644
--- a/webrtc/api/rtpsenderreceiver_unittest.cc
+++ b/webrtc/api/rtpsenderreceiver_unittest.cc
@@ -70,8 +70,9 @@
class MockVideoProvider : public VideoProviderInterface {
public:
virtual ~MockVideoProvider() {}
- MOCK_METHOD2(SetCaptureDevice,
- bool(uint32_t ssrc, cricket::VideoCapturer* camera));
+ MOCK_METHOD2(SetSource,
+ bool(uint32_t ssrc,
+ rtc::VideoSourceInterface<cricket::VideoFrame>* source));
MOCK_METHOD3(SetVideoPlayout,
void(uint32_t ssrc,
bool enable,
@@ -111,9 +112,7 @@
void CreateVideoRtpSender() {
AddVideoTrack();
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(
- kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
stream_->label(), &video_provider_);
@@ -127,7 +126,7 @@
}
void DestroyVideoRtpSender() {
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, NULL)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
video_rtp_sender_ = nullptr;
}
@@ -345,14 +344,12 @@
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(&video_provider_);
sender->SetSsrc(kVideoSsrc);
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
sender->SetTrack(video_track_);
// Calls expected from destructor.
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
}
@@ -363,14 +360,12 @@
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(&video_provider_);
sender->SetTrack(video_track_);
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
sender->SetSsrc(kVideoSsrc);
// Calls expected from destructor.
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
}
@@ -396,21 +391,19 @@
// set to 0.
TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
AddVideoTrack();
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
sender->SetSsrc(0);
// Make sure it's SetSsrc that called methods on the provider, and not the
// destructor.
- EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
+ EXPECT_CALL(video_provider_, SetSource(_, _)).Times(0);
EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
}
@@ -432,21 +425,19 @@
TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
AddVideoTrack();
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
EXPECT_TRUE(sender->SetTrack(nullptr));
// Make sure it's SetTrack that called methods on the provider, and not the
// destructor.
- EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
+ EXPECT_CALL(video_provider_, SetSource(_, _)).Times(0);
EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
}
@@ -469,24 +460,20 @@
TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
AddVideoTrack();
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
- EXPECT_CALL(video_provider_,
- SetCaptureDevice(kVideoSsrc2,
- video_track_->GetSource()->GetVideoCapturer()));
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc2, video_track_.get()));
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, true, _));
sender->SetSsrc(kVideoSsrc2);
// Calls expected from destructor.
- EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc2, nullptr)).Times(1);
+ EXPECT_CALL(video_provider_, SetSource(kVideoSsrc2, nullptr)).Times(1);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, false, _)).Times(1);
}
diff --git a/webrtc/api/videocapturertracksource.h b/webrtc/api/videocapturertracksource.h
index 96f8bff..2eb7b50 100644
--- a/webrtc/api/videocapturertracksource.h
+++ b/webrtc/api/videocapturertracksource.h
@@ -47,10 +47,6 @@
cricket::VideoCapturer* capturer,
bool remote);
- cricket::VideoCapturer* GetVideoCapturer() override {
- return video_capturer_.get();
- }
-
bool is_screencast() const override {
return video_capturer_->IsScreencast();
}
diff --git a/webrtc/api/videocapturertracksource_unittest.cc b/webrtc/api/videocapturertracksource_unittest.cc
index 3925293..6b0d07b 100644
--- a/webrtc/api/videocapturertracksource_unittest.cc
+++ b/webrtc/api/videocapturertracksource_unittest.cc
@@ -126,7 +126,6 @@
constraints, false);
ASSERT_TRUE(source_.get() != NULL);
- EXPECT_EQ(capturer_, source_->GetVideoCapturer());
state_observer_.reset(new StateObserver(source_));
source_->RegisterObserver(state_observer_.get());
diff --git a/webrtc/api/videosourceproxy.h b/webrtc/api/videosourceproxy.h
index 4d687d4..0a34967 100644
--- a/webrtc/api/videosourceproxy.h
+++ b/webrtc/api/videosourceproxy.h
@@ -23,7 +23,6 @@
BEGIN_WORKER_PROXY_MAP(VideoTrackSource)
PROXY_CONSTMETHOD0(SourceState, state)
PROXY_CONSTMETHOD0(bool, remote)
- PROXY_METHOD0(cricket::VideoCapturer*, GetVideoCapturer)
PROXY_METHOD0(void, Stop)
PROXY_METHOD0(void, Restart)
PROXY_CONSTMETHOD0(bool, is_screencast)
diff --git a/webrtc/api/videotracksource.h b/webrtc/api/videotracksource.h
index 3d8d502..7100612 100644
--- a/webrtc/api/videotracksource.h
+++ b/webrtc/api/videotracksource.h
@@ -46,8 +46,6 @@
const rtc::VideoSinkWants& wants) override;
void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
- cricket::VideoCapturer* GetVideoCapturer() override { return nullptr; }
-
private:
rtc::ThreadChecker worker_thread_checker_;
rtc::VideoSourceInterface<cricket::VideoFrame>* source_;
diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc
index f546285..f51d4cd 100644
--- a/webrtc/api/webrtcsession.cc
+++ b/webrtc/api/webrtcsession.cc
@@ -1261,8 +1261,9 @@
return voice_channel_->SetRtpParameters(ssrc, parameters);
}
-bool WebRtcSession::SetCaptureDevice(uint32_t ssrc,
- cricket::VideoCapturer* camera) {
+bool WebRtcSession::SetSource(
+ uint32_t ssrc,
+ rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
ASSERT(signaling_thread()->IsCurrent());
if (!video_channel_) {
@@ -1271,13 +1272,7 @@
LOG(LS_WARNING) << "Video not used in this call.";
return false;
}
- if (!video_channel_->SetCapturer(ssrc, camera)) {
- // Allow that SetCapturer fail if |camera| is NULL but assert otherwise.
- // This in the normal case when the underlying media channel has already
- // been deleted.
- ASSERT(camera == NULL);
- return false;
- }
+ video_channel_->SetSource(ssrc, source);
return true;
}
diff --git a/webrtc/api/webrtcsession.h b/webrtc/api/webrtcsession.h
index 01ec526..752b20f 100644
--- a/webrtc/api/webrtcsession.h
+++ b/webrtc/api/webrtcsession.h
@@ -34,7 +34,6 @@
class ChannelManager;
class DataChannel;
class StatsReport;
-class VideoCapturer;
class VideoChannel;
class VoiceChannel;
@@ -250,7 +249,9 @@
const RtpParameters& parameters) override;
// Implements VideoMediaProviderInterface.
- bool SetCaptureDevice(uint32_t ssrc, cricket::VideoCapturer* camera) override;
+ bool SetSource(
+ uint32_t ssrc,
+ rtc::VideoSourceInterface<cricket::VideoFrame>* source) override;
void SetVideoPlayout(
uint32_t ssrc,
bool enable,
diff --git a/webrtc/api/webrtcsession_unittest.cc b/webrtc/api/webrtcsession_unittest.cc
index f4b41d3..28f93df 100644
--- a/webrtc/api/webrtcsession_unittest.cc
+++ b/webrtc/api/webrtcsession_unittest.cc
@@ -246,7 +246,7 @@
using webrtc::WebRtcSession::SetAudioPlayout;
using webrtc::WebRtcSession::SetAudioSend;
- using webrtc::WebRtcSession::SetCaptureDevice;
+ using webrtc::WebRtcSession::SetSource;
using webrtc::WebRtcSession::SetVideoPlayout;
using webrtc::WebRtcSession::SetVideoSend;