Renamed VideoSourceInterface to VideoTrackSourceInterface.
Moved VideoSourceInterface to MediaStreamInterface.h
Renamed VideoSourceTest to VideoCapturerTrackSourceTest
Renamed VideoSource to VideoCaptureTrackSource and cl lint and cl format.
BUG=webrtc:5426
TBR=pthatcher@webrtc.org
Review URL: https://codereview.webrtc.org/1770003002 .
Cr-Commit-Position: refs/heads/master@{#11893}
diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp
index 7f571c0..1e32e36 100644
--- a/webrtc/api/api.gyp
+++ b/webrtc/api/api.gyp
@@ -307,8 +307,8 @@
'statstypes.cc',
'statstypes.h',
'streamcollection.h',
- 'videosource.cc',
- 'videosource.h',
+ 'videocapturertracksource.cc',
+ 'videocapturertracksource.h',
'videosourceinterface.h',
'videosourceproxy.h',
'videotrack.cc',
diff --git a/webrtc/api/api_tests.gyp b/webrtc/api/api_tests.gyp
index 814784f..53285f9 100644
--- a/webrtc/api/api_tests.gyp
+++ b/webrtc/api/api_tests.gyp
@@ -59,7 +59,7 @@
'test/peerconnectiontestwrapper.h',
'test/peerconnectiontestwrapper.cc',
'test/testsdpstrings.h',
- 'videosource_unittest.cc',
+ 'videocapturertracksource_unittest.cc',
'videotrack_unittest.cc',
'webrtcsdp_unittest.cc',
'webrtcsession_unittest.cc',
diff --git a/webrtc/api/java/jni/peerconnection_jni.cc b/webrtc/api/java/jni/peerconnection_jni.cc
index f7b9e90..7a95737 100644
--- a/webrtc/api/java/jni/peerconnection_jni.cc
+++ b/webrtc/api/java/jni/peerconnection_jni.cc
@@ -107,7 +107,7 @@
using webrtc::StatsReport;
using webrtc::StatsReports;
using webrtc::VideoRendererInterface;
-using webrtc::VideoSourceInterface;
+using webrtc::VideoTrackSourceInterface;
using webrtc::VideoTrackInterface;
using webrtc::VideoTrackVector;
using webrtc::kVideoCodecVP8;
@@ -1225,13 +1225,13 @@
jni, j_video_capturer, j_surface_texture_helper);
rtc::scoped_ptr<cricket::VideoCapturer> capturer(
new webrtc::AndroidVideoCapturer(delegate));
- // Create a webrtc::VideoSourceInterface from the cricket::VideoCapturer,
+ // Create a webrtc::VideoTrackSourceInterface from the cricket::VideoCapturer,
// native factory and constraints.
scoped_ptr<ConstraintsWrapper> constraints(
new ConstraintsWrapper(jni, j_constraints));
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
factoryFromJava(native_factory));
- rtc::scoped_refptr<VideoSourceInterface> source(
+ rtc::scoped_refptr<VideoTrackSourceInterface> source(
factory->CreateVideoSource(capturer.release(), constraints.get()));
return (jlong)source.release();
}
@@ -1241,10 +1241,9 @@
jlong native_source) {
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
factoryFromJava(native_factory));
- rtc::scoped_refptr<VideoTrackInterface> track(
- factory->CreateVideoTrack(
- JavaToStdString(jni, id),
- reinterpret_cast<VideoSourceInterface*>(native_source)));
+ rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack(
+ JavaToStdString(jni, id),
+ reinterpret_cast<VideoTrackSourceInterface*>(native_source)));
return (jlong)track.release();
}
@@ -1887,12 +1886,12 @@
}
JOW(void, VideoSource_stop)(JNIEnv* jni, jclass, jlong j_p) {
- reinterpret_cast<VideoSourceInterface*>(j_p)->Stop();
+ reinterpret_cast<VideoTrackSourceInterface*>(j_p)->Stop();
}
JOW(void, VideoSource_restart)(
JNIEnv* jni, jclass, jlong j_p_source, jlong j_p_format) {
- reinterpret_cast<VideoSourceInterface*>(j_p_source)->Restart();
+ reinterpret_cast<VideoTrackSourceInterface*>(j_p_source)->Restart();
}
JOW(jstring, MediaStreamTrack_nativeId)(JNIEnv* jni, jclass, jlong j_p) {
diff --git a/webrtc/api/mediastreaminterface.h b/webrtc/api/mediastreaminterface.h
index 100db08..c9ce4a5 100644
--- a/webrtc/api/mediastreaminterface.h
+++ b/webrtc/api/mediastreaminterface.h
@@ -23,6 +23,7 @@
#include "webrtc/base/basictypes.h"
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
+#include "webrtc/media/base/mediachannel.h"
#include "webrtc/media/base/videosinkinterface.h"
#include "webrtc/media/base/videosourceinterface.h"
@@ -120,17 +121,34 @@
virtual ~VideoRendererInterface() {}
};
-class VideoSourceInterface;
+// VideoTrackSourceInterface is a reference counted source used for VideoTracks.
+// The same source can be used in multiple VideoTracks.
+class VideoTrackSourceInterface
+ : public MediaSourceInterface,
+ public rtc::VideoSourceInterface<cricket::VideoFrame> {
+ 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.
+ // 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;
+
+ virtual const cricket::VideoOptions* options() const = 0;
+
+ protected:
+ virtual ~VideoTrackSourceInterface() {}
+};
class VideoTrackInterface
: public MediaStreamTrackInterface,
public rtc::VideoSourceInterface<cricket::VideoFrame> {
public:
- // Make an unqualified VideoSourceInterface resolve to
- // webrtc::VideoSourceInterface, not our base class
- // rtc::VideoSourceInterface<cricket::VideoFrame>.
- using VideoSourceInterface = webrtc::VideoSourceInterface;
-
// AddRenderer and RemoveRenderer are for backwards compatibility
// only. They are obsoleted by the methods of
// rtc::VideoSourceInterface.
@@ -147,7 +165,7 @@
void RemoveSink(
rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override{};
- virtual VideoSourceInterface* GetSource() const = 0;
+ virtual VideoTrackSourceInterface* GetSource() const = 0;
// Return the track input sink. I.e., frames sent to this sink are
// propagated to all renderers registered with the track. The
diff --git a/webrtc/api/mediastreamtrackproxy.h b/webrtc/api/mediastreamtrackproxy.h
index dca2d15..ada8291 100644
--- a/webrtc/api/mediastreamtrackproxy.h
+++ b/webrtc/api/mediastreamtrackproxy.h
@@ -53,7 +53,7 @@
rtc::VideoSinkInterface<cricket::VideoFrame>*,
const rtc::VideoSinkWants&)
PROXY_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<cricket::VideoFrame>*)
- PROXY_CONSTMETHOD0(VideoSourceInterface*, GetSource)
+ PROXY_CONSTMETHOD0(VideoTrackSourceInterface*, GetSource)
PROXY_METHOD0(rtc::VideoSinkInterface<cricket::VideoFrame>*, GetSink)
PROXY_METHOD1(void, RegisterObserver, ObserverInterface*)
diff --git a/webrtc/api/objc/RTCAVFoundationVideoSource.mm b/webrtc/api/objc/RTCAVFoundationVideoSource.mm
index 868f626..0cd0155 100644
--- a/webrtc/api/objc/RTCAVFoundationVideoSource.mm
+++ b/webrtc/api/objc/RTCAVFoundationVideoSource.mm
@@ -21,9 +21,9 @@
NSParameterAssert(factory);
rtc::scoped_ptr<webrtc::AVFoundationVideoCapturer> capturer;
capturer.reset(new webrtc::AVFoundationVideoCapturer());
- rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
- factory.nativeFactory->CreateVideoSource(capturer.release(),
- constraints.nativeConstraints.get());
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
+ factory.nativeFactory->CreateVideoSource(
+ capturer.release(), constraints.nativeConstraints.get());
return [super initWithNativeVideoSource:source];
}
diff --git a/webrtc/api/objc/RTCVideoSource+Private.h b/webrtc/api/objc/RTCVideoSource+Private.h
index c363d33..be064bd 100644
--- a/webrtc/api/objc/RTCVideoSource+Private.h
+++ b/webrtc/api/objc/RTCVideoSource+Private.h
@@ -17,15 +17,16 @@
@interface RTCVideoSource ()
/**
- * The VideoSourceInterface object passed to this RTCVideoSource during
+ * The VideoTrackSourceInterface object passed to this RTCVideoSource during
* construction.
*/
@property(nonatomic, readonly)
- rtc::scoped_refptr<webrtc::VideoSourceInterface> nativeVideoSource;
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>
+ nativeVideoSource;
-/** Initialize an RTCVideoSource from a native VideoSourceInterface. */
+/** Initialize an RTCVideoSource from a native VideoTrackSourceInterface. */
- (instancetype)initWithNativeVideoSource:
- (rtc::scoped_refptr<webrtc::VideoSourceInterface>)nativeVideoSource
+ (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource
NS_DESIGNATED_INITIALIZER;
+ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState:
diff --git a/webrtc/api/objc/RTCVideoSource.mm b/webrtc/api/objc/RTCVideoSource.mm
index 35f30e3..8e9c39d 100644
--- a/webrtc/api/objc/RTCVideoSource.mm
+++ b/webrtc/api/objc/RTCVideoSource.mm
@@ -13,7 +13,7 @@
#import "webrtc/api/objc/RTCVideoSource+Private.h"
@implementation RTCVideoSource {
- rtc::scoped_refptr<webrtc::VideoSourceInterface> _nativeVideoSource;
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
}
- (RTCSourceState)state {
@@ -27,12 +27,12 @@
#pragma mark - Private
-- (rtc::scoped_refptr<webrtc::VideoSourceInterface>)nativeVideoSource {
+- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
return _nativeVideoSource;
}
- (instancetype)initWithNativeVideoSource:
- (rtc::scoped_refptr<webrtc::VideoSourceInterface>)nativeVideoSource {
+ (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
NSParameterAssert(nativeVideoSource);
if (self = [super init]) {
_nativeVideoSource = nativeVideoSource;
diff --git a/webrtc/api/objc/RTCVideoTrack.mm b/webrtc/api/objc/RTCVideoTrack.mm
index 8a9e3d7..5834af7 100644
--- a/webrtc/api/objc/RTCVideoTrack.mm
+++ b/webrtc/api/objc/RTCVideoTrack.mm
@@ -58,7 +58,7 @@
- (RTCVideoSource *)source {
if (!_source) {
- rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
self.nativeVideoTrack->GetSource();
if (source) {
_source = [[RTCVideoSource alloc] initWithNativeVideoSource:source.get()];
diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc
index 6ea852d..c2039ae 100644
--- a/webrtc/api/peerconnection.cc
+++ b/webrtc/api/peerconnection.cc
@@ -29,7 +29,7 @@
#include "webrtc/api/rtpreceiver.h"
#include "webrtc/api/rtpsender.h"
#include "webrtc/api/streamcollection.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/arraysize.h"
#include "webrtc/base/logging.h"
@@ -404,8 +404,8 @@
const std::string& track_id) {
return AddTrack<VideoTrackInterface, VideoTrack, VideoTrackProxy>(
stream, track_id,
- VideoSource::Create(worker_thread_, new RemoteVideoCapturer(),
- nullptr, true)
+ VideoCapturerTrackSource::Create(
+ worker_thread_, new RemoteVideoCapturer(), nullptr, true)
.get());
}
diff --git a/webrtc/api/peerconnection_unittest.cc b/webrtc/api/peerconnection_unittest.cc
index 788a981..d0fb9ad 100644
--- a/webrtc/api/peerconnection_unittest.cc
+++ b/webrtc/api/peerconnection_unittest.cc
@@ -403,7 +403,7 @@
cricket::FakeVideoCapturer* fake_capturer =
new webrtc::FakePeriodicVideoCapturer();
video_capturers_.push_back(fake_capturer);
- rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
peer_connection_factory_->CreateVideoSource(fake_capturer,
&source_constraints);
std::string label = stream_label + kVideoTrackLabelBase;
diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc
index 40e845f..22e450c 100644
--- a/webrtc/api/peerconnectionfactory.cc
+++ b/webrtc/api/peerconnectionfactory.cc
@@ -21,7 +21,7 @@
#include "webrtc/api/peerconnection.h"
#include "webrtc/api/peerconnectionfactoryproxy.h"
#include "webrtc/api/peerconnectionproxy.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/api/videosourceproxy.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/bind.h"
@@ -208,22 +208,23 @@
return source;
}
-rtc::scoped_refptr<VideoSourceInterface>
+rtc::scoped_refptr<VideoTrackSourceInterface>
PeerConnectionFactory::CreateVideoSource(
cricket::VideoCapturer* capturer,
const MediaConstraintsInterface* constraints) {
RTC_DCHECK(signaling_thread_->IsCurrent());
- rtc::scoped_refptr<VideoSource> source(VideoSource::Create(
- worker_thread_, capturer, constraints, false));
- return VideoSourceProxy::Create(signaling_thread_, source);
+ rtc::scoped_refptr<VideoTrackSourceInterface> source(
+ VideoCapturerTrackSource::Create(worker_thread_, capturer, constraints,
+ false));
+ return VideoTrackSourceProxy::Create(signaling_thread_, source);
}
-rtc::scoped_refptr<VideoSourceInterface>
+rtc::scoped_refptr<VideoTrackSourceInterface>
PeerConnectionFactory::CreateVideoSource(cricket::VideoCapturer* capturer) {
RTC_DCHECK(signaling_thread_->IsCurrent());
- rtc::scoped_refptr<VideoSource> source(
- VideoSource::Create(worker_thread_, capturer, false));
- return VideoSourceProxy::Create(signaling_thread_, source);
+ rtc::scoped_refptr<VideoTrackSourceInterface> source(
+ VideoCapturerTrackSource::Create(worker_thread_, capturer, false));
+ return VideoTrackSourceProxy::Create(signaling_thread_, source);
}
bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file,
@@ -319,10 +320,9 @@
MediaStream::Create(label));
}
-rtc::scoped_refptr<VideoTrackInterface>
-PeerConnectionFactory::CreateVideoTrack(
+rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
const std::string& id,
- VideoSourceInterface* source) {
+ VideoTrackSourceInterface* source) {
RTC_DCHECK(signaling_thread_->IsCurrent());
rtc::scoped_refptr<VideoTrackInterface> track(
VideoTrack::Create(id, source));
diff --git a/webrtc/api/peerconnectionfactory.h b/webrtc/api/peerconnectionfactory.h
index 1bc40ed..b47f75a 100644
--- a/webrtc/api/peerconnectionfactory.h
+++ b/webrtc/api/peerconnectionfactory.h
@@ -63,19 +63,19 @@
rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
const MediaConstraintsInterface* constraints) override;
- virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
+ virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) override;
// This version supports filtering on width, height and frame rate.
// For the "constraints=null" case, use the version without constraints.
// TODO(hta): Design a version without MediaConstraintsInterface.
// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
- rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
+ rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer,
const MediaConstraintsInterface* constraints) override;
- rtc::scoped_refptr<VideoTrackInterface>
- CreateVideoTrack(const std::string& id,
- VideoSourceInterface* video_source) override;
+ rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
+ const std::string& id,
+ VideoTrackSourceInterface* video_source) override;
rtc::scoped_refptr<AudioTrackInterface>
CreateAudioTrack(const std::string& id,
diff --git a/webrtc/api/peerconnectionfactory_unittest.cc b/webrtc/api/peerconnectionfactory_unittest.cc
index b874f95..2165937 100644
--- a/webrtc/api/peerconnectionfactory_unittest.cc
+++ b/webrtc/api/peerconnectionfactory_unittest.cc
@@ -34,7 +34,7 @@
using webrtc::PeerConnectionFactoryInterface;
using webrtc::PeerConnectionInterface;
using webrtc::PeerConnectionObserver;
-using webrtc::VideoSourceInterface;
+using webrtc::VideoTrackSourceInterface;
using webrtc::VideoTrackInterface;
namespace {
@@ -332,7 +332,7 @@
TEST_F(PeerConnectionFactoryTest, LocalRendering) {
cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer();
// The source take ownership of |capturer|.
- rtc::scoped_refptr<VideoSourceInterface> source(
+ rtc::scoped_refptr<VideoTrackSourceInterface> source(
factory_->CreateVideoSource(capturer, NULL));
ASSERT_TRUE(source.get() != NULL);
rtc::scoped_refptr<VideoTrackInterface> track(
diff --git a/webrtc/api/peerconnectionfactoryproxy.h b/webrtc/api/peerconnectionfactoryproxy.h
index d83c300..829bf81 100644
--- a/webrtc/api/peerconnectionfactoryproxy.h
+++ b/webrtc/api/peerconnectionfactoryproxy.h
@@ -50,14 +50,17 @@
PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
CreateAudioSource,
const cricket::AudioOptions&)
- PROXY_METHOD2(rtc::scoped_refptr<VideoSourceInterface>,
- CreateVideoSource, cricket::VideoCapturer*,
+ PROXY_METHOD2(rtc::scoped_refptr<VideoTrackSourceInterface>,
+ CreateVideoSource,
+ cricket::VideoCapturer*,
const MediaConstraintsInterface*)
- PROXY_METHOD1(rtc::scoped_refptr<VideoSourceInterface>,
+ PROXY_METHOD1(rtc::scoped_refptr<VideoTrackSourceInterface>,
CreateVideoSource,
cricket::VideoCapturer*)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
- CreateVideoTrack, const std::string&, VideoSourceInterface*)
+ CreateVideoTrack,
+ const std::string&,
+ VideoTrackSourceInterface*)
PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
CreateAudioTrack, const std::string&, AudioSourceInterface*)
PROXY_METHOD2(bool, StartAecDump, rtc::PlatformFile, int64_t)
diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h
index 7a83343..f6c8cba 100644
--- a/webrtc/api/peerconnectioninterface.h
+++ b/webrtc/api/peerconnectioninterface.h
@@ -563,23 +563,23 @@
virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
const MediaConstraintsInterface* constraints) = 0;
- // Creates a VideoSourceInterface. The new source take ownership of
+ // Creates a VideoTrackSourceInterface. The new source take ownership of
// |capturer|.
- virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
+ virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) = 0;
// A video source creator that allows selection of resolution and frame rate.
// |constraints| decides video resolution and frame rate but can
// be NULL.
// In the NULL case, use the version above.
- virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
+ virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer,
const MediaConstraintsInterface* constraints) = 0;
// Creates a new local VideoTrack. The same |source| can be used in several
// tracks.
- virtual rtc::scoped_refptr<VideoTrackInterface>
- CreateVideoTrack(const std::string& label,
- VideoSourceInterface* source) = 0;
+ virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
+ const std::string& label,
+ VideoTrackSourceInterface* source) = 0;
// Creates an new AudioTrack. At the moment |source| can be NULL.
virtual rtc::scoped_refptr<AudioTrackInterface>
diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc
index 6d324c0..0448526 100644
--- a/webrtc/api/peerconnectioninterface_unittest.cc
+++ b/webrtc/api/peerconnectioninterface_unittest.cc
@@ -27,7 +27,7 @@
#include "webrtc/api/test/fakedtlsidentitystore.h"
#include "webrtc/api/test/mockpeerconnectionobservers.h"
#include "webrtc/api/test/testsdpstrings.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/scoped_ptr.h"
@@ -262,7 +262,7 @@
using webrtc::SessionDescriptionInterface;
using webrtc::StreamCollection;
using webrtc::StreamCollectionInterface;
-using webrtc::VideoSourceInterface;
+using webrtc::VideoTrackSourceInterface;
using webrtc::VideoTrack;
using webrtc::VideoTrackInterface;
@@ -597,7 +597,7 @@
// Create a local stream.
scoped_refptr<MediaStreamInterface> stream(
pc_factory_->CreateLocalMediaStream(label));
- scoped_refptr<VideoSourceInterface> video_source(
+ scoped_refptr<VideoTrackSourceInterface> video_source(
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
scoped_refptr<VideoTrackInterface> video_track(
pc_factory_->CreateVideoTrack(label + "v0", video_source));
diff --git a/webrtc/api/rtpsender.cc b/webrtc/api/rtpsender.cc
index 1ca8fc1..c5db929 100644
--- a/webrtc/api/rtpsender.cc
+++ b/webrtc/api/rtpsender.cc
@@ -268,7 +268,7 @@
// Update video provider.
if (can_send_track()) {
- VideoSourceInterface* source = track_->GetSource();
+ 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
@@ -296,7 +296,7 @@
}
ssrc_ = ssrc;
if (can_send_track()) {
- VideoSourceInterface* source = track_->GetSource();
+ VideoTrackSourceInterface* source = track_->GetSource();
provider_->SetCaptureDevice(ssrc_,
source ? source->GetVideoCapturer() : nullptr);
SetVideoSend();
@@ -321,7 +321,7 @@
void VideoRtpSender::SetVideoSend() {
RTC_DCHECK(!stopped_ && can_send_track());
const cricket::VideoOptions* options = nullptr;
- VideoSourceInterface* source = track_->GetSource();
+ VideoTrackSourceInterface* source = track_->GetSource();
if (track_->enabled() && source) {
options = source->options();
}
diff --git a/webrtc/api/rtpsenderreceiver_unittest.cc b/webrtc/api/rtpsenderreceiver_unittest.cc
index ca88a3b..5dc97c6 100644
--- a/webrtc/api/rtpsenderreceiver_unittest.cc
+++ b/webrtc/api/rtpsenderreceiver_unittest.cc
@@ -19,7 +19,7 @@
#include "webrtc/api/rtpreceiver.h"
#include "webrtc/api/rtpsender.h"
#include "webrtc/api/streamcollection.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/gunit.h"
#include "webrtc/media/base/fakevideocapturer.h"
@@ -78,7 +78,7 @@
const cricket::VideoOptions* options));
};
-class FakeVideoSource : public Notifier<VideoSourceInterface> {
+class FakeVideoSource : public Notifier<VideoTrackSourceInterface> {
public:
static rtc::scoped_refptr<FakeVideoSource> Create(bool remote) {
return new rtc::RefCountedObject<FakeVideoSource>(remote);
@@ -113,7 +113,7 @@
}
void AddVideoTrack(bool remote) {
- rtc::scoped_refptr<VideoSourceInterface> source(
+ rtc::scoped_refptr<VideoTrackSourceInterface> source(
FakeVideoSource::Create(remote));
video_track_ = VideoTrack::Create(kVideoTrackId, source);
EXPECT_TRUE(stream_->AddTrack(video_track_));
diff --git a/webrtc/api/test/peerconnectiontestwrapper.cc b/webrtc/api/test/peerconnectiontestwrapper.cc
index 4267156..353f0ee 100644
--- a/webrtc/api/test/peerconnectiontestwrapper.cc
+++ b/webrtc/api/test/peerconnectiontestwrapper.cc
@@ -267,7 +267,7 @@
FakeConstraints constraints = video_constraints;
constraints.SetMandatoryMaxFrameRate(10);
- rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
+ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
peer_connection_factory_->CreateVideoSource(
new webrtc::FakePeriodicVideoCapturer(), &constraints);
std::string videotrack_label = label + kVideoTrackLabelBase;
diff --git a/webrtc/api/videocapturertracksource.cc b/webrtc/api/videocapturertracksource.cc
index aeb2516..c505e86 100644
--- a/webrtc/api/videocapturertracksource.cc
+++ b/webrtc/api/videocapturertracksource.cc
@@ -1,5 +1,4 @@
/*
- /*
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
@@ -11,5 +10,436 @@
#include "webrtc/api/videocapturertracksource.h"
-// TODO(perkj): This file is added to prepare for changing name of VideoSource
-// to VideoCapturerTrackSource.
+#include <cstdlib>
+#include <string>
+#include <vector>
+
+#include "webrtc/api/mediaconstraintsinterface.h"
+#include "webrtc/base/arraysize.h"
+
+using cricket::CaptureState;
+using webrtc::MediaConstraintsInterface;
+using webrtc::MediaSourceInterface;
+
+namespace {
+
+const double kRoundingTruncation = 0.0005;
+
+// Default resolution. If no constraint is specified, this is the resolution we
+// will use.
+static const cricket::VideoFormatPod kDefaultFormat = {
+ 640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY};
+
+// List of formats used if the camera doesn't support capability enumeration.
+static const cricket::VideoFormatPod kVideoFormats[] = {
+ {1920, 1080, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {1280, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {960, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {320, 240, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
+ {320, 180, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY}};
+
+MediaSourceInterface::SourceState GetReadyState(cricket::CaptureState state) {
+ switch (state) {
+ case cricket::CS_STARTING:
+ return MediaSourceInterface::kInitializing;
+ case cricket::CS_RUNNING:
+ return MediaSourceInterface::kLive;
+ case cricket::CS_FAILED:
+ case cricket::CS_STOPPED:
+ return MediaSourceInterface::kEnded;
+ case cricket::CS_PAUSED:
+ return MediaSourceInterface::kMuted;
+ default:
+ ASSERT(false && "GetReadyState unknown state");
+ }
+ return MediaSourceInterface::kEnded;
+}
+
+void SetUpperLimit(int new_limit, int* original_limit) {
+ if (*original_limit < 0 || new_limit < *original_limit)
+ *original_limit = new_limit;
+}
+
+// Updates |format_upper_limit| from |constraint|.
+// If constraint.maxFoo is smaller than format_upper_limit.foo,
+// set format_upper_limit.foo to constraint.maxFoo.
+void SetUpperLimitFromConstraint(
+ const MediaConstraintsInterface::Constraint& constraint,
+ cricket::VideoFormat* format_upper_limit) {
+ if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
+ int value = rtc::FromString<int>(constraint.value);
+ SetUpperLimit(value, &(format_upper_limit->width));
+ } else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
+ int value = rtc::FromString<int>(constraint.value);
+ SetUpperLimit(value, &(format_upper_limit->height));
+ }
+}
+
+// Fills |format_out| with the max width and height allowed by |constraints|.
+void FromConstraintsForScreencast(
+ const MediaConstraintsInterface::Constraints& constraints,
+ cricket::VideoFormat* format_out) {
+ typedef MediaConstraintsInterface::Constraints::const_iterator
+ ConstraintsIterator;
+
+ cricket::VideoFormat upper_limit(-1, -1, 0, 0);
+ for (ConstraintsIterator constraints_it = constraints.begin();
+ constraints_it != constraints.end(); ++constraints_it)
+ SetUpperLimitFromConstraint(*constraints_it, &upper_limit);
+
+ if (upper_limit.width >= 0)
+ format_out->width = upper_limit.width;
+ if (upper_limit.height >= 0)
+ format_out->height = upper_limit.height;
+}
+
+// Returns true if |constraint| is fulfilled. |format_out| can differ from
+// |format_in| if the format is changed by the constraint. Ie - the frame rate
+// can be changed by setting maxFrameRate.
+bool NewFormatWithConstraints(
+ const MediaConstraintsInterface::Constraint& constraint,
+ const cricket::VideoFormat& format_in,
+ bool mandatory,
+ cricket::VideoFormat* format_out) {
+ ASSERT(format_out != NULL);
+ *format_out = format_in;
+
+ if (constraint.key == MediaConstraintsInterface::kMinWidth) {
+ int value = rtc::FromString<int>(constraint.value);
+ return (value <= format_in.width);
+ } else if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
+ int value = rtc::FromString<int>(constraint.value);
+ return (value >= format_in.width);
+ } else if (constraint.key == MediaConstraintsInterface::kMinHeight) {
+ int value = rtc::FromString<int>(constraint.value);
+ return (value <= format_in.height);
+ } else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
+ int value = rtc::FromString<int>(constraint.value);
+ return (value >= format_in.height);
+ } else if (constraint.key == MediaConstraintsInterface::kMinFrameRate) {
+ int value = rtc::FromString<int>(constraint.value);
+ return (value <= cricket::VideoFormat::IntervalToFps(format_in.interval));
+ } else if (constraint.key == MediaConstraintsInterface::kMaxFrameRate) {
+ int value = rtc::FromString<int>(constraint.value);
+ if (value == 0) {
+ if (mandatory) {
+ // TODO(ronghuawu): Convert the constraint value to float when sub-1fps
+ // is supported by the capturer.
+ return false;
+ } else {
+ value = 1;
+ }
+ }
+ if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval))
+ format_out->interval = cricket::VideoFormat::FpsToInterval(value);
+ return true;
+ } else if (constraint.key == MediaConstraintsInterface::kMinAspectRatio) {
+ double value = rtc::FromString<double>(constraint.value);
+ // The aspect ratio in |constraint.value| has been converted to a string and
+ // back to a double, so it may have a rounding error.
+ // E.g if the value 1/3 is converted to a string, the string will not have
+ // infinite length.
+ // We add a margin of 0.0005 which is high enough to detect the same aspect
+ // ratio but small enough to avoid matching wrong aspect ratios.
+ double ratio = static_cast<double>(format_in.width) / format_in.height;
+ return (value <= ratio + kRoundingTruncation);
+ } else if (constraint.key == MediaConstraintsInterface::kMaxAspectRatio) {
+ double value = rtc::FromString<double>(constraint.value);
+ double ratio = static_cast<double>(format_in.width) / format_in.height;
+ // Subtract 0.0005 to avoid rounding problems. Same as above.
+ const double kRoundingTruncation = 0.0005;
+ return (value >= ratio - kRoundingTruncation);
+ } else if (constraint.key == MediaConstraintsInterface::kNoiseReduction) {
+ // These are actually options, not constraints, so they can be satisfied
+ // regardless of the format.
+ return true;
+ }
+ LOG(LS_WARNING) << "Found unknown MediaStream constraint. Name:"
+ << constraint.key << " Value:" << constraint.value;
+ return false;
+}
+
+// Removes cricket::VideoFormats from |formats| that don't meet |constraint|.
+void FilterFormatsByConstraint(
+ const MediaConstraintsInterface::Constraint& constraint,
+ bool mandatory,
+ std::vector<cricket::VideoFormat>* formats) {
+ std::vector<cricket::VideoFormat>::iterator format_it = formats->begin();
+ while (format_it != formats->end()) {
+ // Modify the format_it to fulfill the constraint if possible.
+ // Delete it otherwise.
+ if (!NewFormatWithConstraints(constraint, (*format_it), mandatory,
+ &(*format_it))) {
+ format_it = formats->erase(format_it);
+ } else {
+ ++format_it;
+ }
+ }
+}
+
+// Returns a vector of cricket::VideoFormat that best match |constraints|.
+std::vector<cricket::VideoFormat> FilterFormats(
+ const MediaConstraintsInterface::Constraints& mandatory,
+ const MediaConstraintsInterface::Constraints& optional,
+ const std::vector<cricket::VideoFormat>& supported_formats) {
+ typedef MediaConstraintsInterface::Constraints::const_iterator
+ ConstraintsIterator;
+ std::vector<cricket::VideoFormat> candidates = supported_formats;
+
+ for (ConstraintsIterator constraints_it = mandatory.begin();
+ constraints_it != mandatory.end(); ++constraints_it)
+ FilterFormatsByConstraint(*constraints_it, true, &candidates);
+
+ if (candidates.size() == 0)
+ return candidates;
+
+ // Ok - all mandatory checked and we still have a candidate.
+ // Let's try filtering using the optional constraints.
+ for (ConstraintsIterator constraints_it = optional.begin();
+ constraints_it != optional.end(); ++constraints_it) {
+ std::vector<cricket::VideoFormat> current_candidates = candidates;
+ FilterFormatsByConstraint(*constraints_it, false, ¤t_candidates);
+ if (current_candidates.size() > 0) {
+ candidates = current_candidates;
+ }
+ }
+
+ // We have done as good as we can to filter the supported resolutions.
+ return candidates;
+}
+
+// Find the format that best matches the default video size.
+// Constraints are optional and since the performance of a video call
+// might be bad due to bitrate limitations, CPU, and camera performance,
+// it is better to select a resolution that is as close as possible to our
+// default and still meets the contraints.
+const cricket::VideoFormat& GetBestCaptureFormat(
+ const std::vector<cricket::VideoFormat>& formats) {
+ ASSERT(formats.size() > 0);
+
+ int default_area = kDefaultFormat.width * kDefaultFormat.height;
+
+ std::vector<cricket::VideoFormat>::const_iterator it = formats.begin();
+ std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin();
+ int best_diff_area = std::abs(default_area - it->width * it->height);
+ int64_t best_diff_interval = kDefaultFormat.interval;
+ for (; it != formats.end(); ++it) {
+ int diff_area = std::abs(default_area - it->width * it->height);
+ int64_t diff_interval = std::abs(kDefaultFormat.interval - it->interval);
+ if (diff_area < best_diff_area ||
+ (diff_area == best_diff_area && diff_interval < best_diff_interval)) {
+ best_diff_area = diff_area;
+ best_diff_interval = diff_interval;
+ best_it = it;
+ }
+ }
+ return *best_it;
+}
+
+// Set |option| to the highest-priority value of |key| in the constraints.
+// Return false if the key is mandatory, and the value is invalid.
+bool ExtractOption(const MediaConstraintsInterface* all_constraints,
+ const std::string& key,
+ rtc::Optional<bool>* option) {
+ size_t mandatory = 0;
+ bool value;
+ if (FindConstraint(all_constraints, key, &value, &mandatory)) {
+ *option = rtc::Optional<bool>(value);
+ return true;
+ }
+
+ return mandatory == 0;
+}
+
+// Search |all_constraints| for known video options. Apply all options that are
+// found with valid values, and return false if any mandatory video option was
+// found with an invalid value.
+bool ExtractVideoOptions(const MediaConstraintsInterface* all_constraints,
+ cricket::VideoOptions* options) {
+ bool all_valid = true;
+
+ all_valid &=
+ ExtractOption(all_constraints, MediaConstraintsInterface::kNoiseReduction,
+ &(options->video_noise_reduction));
+
+ return all_valid;
+}
+
+} // anonymous namespace
+
+namespace webrtc {
+
+rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
+ rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ const webrtc::MediaConstraintsInterface* constraints,
+ bool remote) {
+ RTC_DCHECK(worker_thread != NULL);
+ RTC_DCHECK(capturer != NULL);
+ rtc::scoped_refptr<VideoCapturerTrackSource> source(
+ new rtc::RefCountedObject<VideoCapturerTrackSource>(worker_thread,
+ capturer, remote));
+ source->Initialize(constraints);
+ return source;
+}
+
+rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
+ rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ bool remote) {
+ RTC_DCHECK(worker_thread != NULL);
+ RTC_DCHECK(capturer != NULL);
+ rtc::scoped_refptr<VideoCapturerTrackSource> source(
+ new rtc::RefCountedObject<VideoCapturerTrackSource>(worker_thread,
+ capturer, remote));
+ source->Initialize(nullptr);
+ return source;
+}
+
+VideoCapturerTrackSource::VideoCapturerTrackSource(
+ rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ bool remote)
+ : signaling_thread_(rtc::Thread::Current()),
+ worker_thread_(worker_thread),
+ video_capturer_(capturer),
+ started_(false),
+ state_(kInitializing),
+ remote_(remote) {
+ video_capturer_->SignalStateChange.connect(
+ this, &VideoCapturerTrackSource::OnStateChange);
+}
+
+VideoCapturerTrackSource::~VideoCapturerTrackSource() {
+ video_capturer_->SignalStateChange.disconnect(this);
+ Stop();
+}
+
+void VideoCapturerTrackSource::Initialize(
+ const webrtc::MediaConstraintsInterface* constraints) {
+ std::vector<cricket::VideoFormat> formats =
+ *video_capturer_->GetSupportedFormats();
+ if (formats.empty()) {
+ if (video_capturer_->IsScreencast()) {
+ // The screen capturer can accept any resolution and we will derive the
+ // format from the constraints if any.
+ // Note that this only affects tab capturing, not desktop capturing,
+ // since the desktop capturer does not respect the VideoFormat passed in.
+ formats.push_back(cricket::VideoFormat(kDefaultFormat));
+ } else {
+ // The VideoCapturer implementation doesn't support capability
+ // enumeration. We need to guess what the camera supports.
+ for (int i = 0; i < arraysize(kVideoFormats); ++i) {
+ formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
+ }
+ }
+ }
+
+ if (constraints) {
+ MediaConstraintsInterface::Constraints mandatory_constraints =
+ constraints->GetMandatory();
+ MediaConstraintsInterface::Constraints optional_constraints;
+ optional_constraints = constraints->GetOptional();
+
+ if (video_capturer_->IsScreencast()) {
+ // Use the maxWidth and maxHeight allowed by constraints for screencast.
+ FromConstraintsForScreencast(mandatory_constraints, &(formats[0]));
+ }
+
+ formats =
+ FilterFormats(mandatory_constraints, optional_constraints, formats);
+ }
+
+ if (formats.size() == 0) {
+ LOG(LS_WARNING) << "Failed to find a suitable video format.";
+ SetState(kEnded);
+ return;
+ }
+
+ cricket::VideoOptions options;
+ if (!ExtractVideoOptions(constraints, &options)) {
+ LOG(LS_WARNING) << "Could not satisfy mandatory options.";
+ SetState(kEnded);
+ return;
+ }
+ options_.SetAll(options);
+ options_.is_screencast = rtc::Optional<bool>(video_capturer_->IsScreencast());
+
+ format_ = GetBestCaptureFormat(formats);
+ // Start the camera with our best guess.
+ // TODO(perkj): Should we try again with another format it it turns out that
+ // the camera doesn't produce frames with the correct format? Or will
+ // cricket::VideCapturer be able to re-scale / crop to the requested
+ // resolution?
+ if (!worker_thread_->Invoke<bool>(
+ rtc::Bind(&cricket::VideoCapturer::StartCapturing,
+ video_capturer_.get(), format_))) {
+ SetState(kEnded);
+ return;
+ }
+ started_ = true;
+ // Initialize hasn't succeeded until a successful state change has occurred.
+}
+
+void VideoCapturerTrackSource::Stop() {
+ if (!started_) {
+ return;
+ }
+ started_ = false;
+ worker_thread_->Invoke<void>(
+ rtc::Bind(&cricket::VideoCapturer::Stop, video_capturer_.get()));
+}
+
+void VideoCapturerTrackSource::Restart() {
+ if (started_) {
+ return;
+ }
+ if (!worker_thread_->Invoke<bool>(
+ rtc::Bind(&cricket::VideoCapturer::StartCapturing,
+ video_capturer_.get(), format_))) {
+ SetState(kEnded);
+ return;
+ }
+ started_ = true;
+}
+
+void VideoCapturerTrackSource::AddOrUpdateSink(
+ rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
+ const rtc::VideoSinkWants& wants) {
+ worker_thread_->Invoke<void>(
+ rtc::Bind(&cricket::VideoCapturer::AddOrUpdateSink, video_capturer_.get(),
+ sink, wants));
+}
+
+void VideoCapturerTrackSource::RemoveSink(
+ rtc::VideoSinkInterface<cricket::VideoFrame>* output) {
+ worker_thread_->Invoke<void>(rtc::Bind(&cricket::VideoCapturer::RemoveSink,
+ video_capturer_.get(), output));
+}
+
+// OnStateChange listens to the cricket::VideoCapturer::SignalStateChange.
+void VideoCapturerTrackSource::OnStateChange(
+ cricket::VideoCapturer* capturer,
+ cricket::CaptureState capture_state) {
+ if (rtc::Thread::Current() != signaling_thread_) {
+ invoker_.AsyncInvoke<void>(
+ signaling_thread_, rtc::Bind(&VideoCapturerTrackSource::OnStateChange,
+ this, capturer, capture_state));
+ return;
+ }
+
+ if (capturer == video_capturer_.get()) {
+ SetState(GetReadyState(capture_state));
+ }
+}
+
+void VideoCapturerTrackSource::SetState(SourceState new_state) {
+ if (state_ != new_state) {
+ state_ = new_state;
+ FireOnChanged();
+ }
+}
+
+} // namespace webrtc
diff --git a/webrtc/api/videocapturertracksource.h b/webrtc/api/videocapturertracksource.h
index 15f8bf1..f086d79 100644
--- a/webrtc/api/videocapturertracksource.h
+++ b/webrtc/api/videocapturertracksource.h
@@ -11,7 +11,88 @@
#ifndef WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_
#define WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_
-// TODO(perkj): This file is added to prepare for changing name of VideoSource
-// to VideoCapturerTrackSource.
+#include <list>
-#endif // WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_
+#include "webrtc/api/mediastreaminterface.h"
+#include "webrtc/api/notifier.h"
+#include "webrtc/api/videosourceinterface.h"
+#include "webrtc/api/videotrackrenderers.h"
+#include "webrtc/base/asyncinvoker.h"
+#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/sigslot.h"
+#include "webrtc/media/base/videosinkinterface.h"
+#include "webrtc/media/base/videocapturer.h"
+#include "webrtc/media/base/videocommon.h"
+
+// VideoCapturerTrackSource implements VideoTrackSourceInterface. It owns a
+// cricket::VideoCapturer and make sure the camera is started at a resolution
+// that honors the constraints.
+// 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 webrtc {
+
+class MediaConstraintsInterface;
+
+class VideoCapturerTrackSource : public Notifier<VideoTrackSourceInterface>,
+ public sigslot::has_slots<> {
+ public:
+ // Creates an instance of VideoCapturerTrackSource.
+ // VideoCapturerTrackSource take ownership of |capturer|.
+ // |constraints| can be NULL and in that case the camera is opened using a
+ // default resolution.
+ static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
+ rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ const webrtc::MediaConstraintsInterface* constraints,
+ bool remote);
+
+ static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
+ rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ bool remote);
+
+ SourceState state() const override { return state_; }
+ bool remote() const override { return remote_; }
+
+ virtual const cricket::VideoOptions* options() const { return &options_; }
+
+ virtual cricket::VideoCapturer* GetVideoCapturer() {
+ return video_capturer_.get();
+ }
+
+ void Stop() override;
+ void Restart() override;
+
+ void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
+ const rtc::VideoSinkWants& wants) override;
+ void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
+
+ protected:
+ VideoCapturerTrackSource(rtc::Thread* worker_thread,
+ cricket::VideoCapturer* capturer,
+ bool remote);
+ virtual ~VideoCapturerTrackSource();
+ void Initialize(const webrtc::MediaConstraintsInterface* constraints);
+
+ private:
+ void OnStateChange(cricket::VideoCapturer* capturer,
+ cricket::CaptureState capture_state);
+ void SetState(SourceState new_state);
+
+ rtc::Thread* signaling_thread_;
+ rtc::Thread* worker_thread_;
+ rtc::AsyncInvoker invoker_;
+ rtc::scoped_ptr<cricket::VideoCapturer> video_capturer_;
+ bool started_;
+ rtc::scoped_ptr<cricket::VideoRenderer> frame_input_;
+
+ cricket::VideoFormat format_;
+ cricket::VideoOptions options_;
+ SourceState state_;
+ const bool remote_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_
diff --git a/webrtc/api/videosource_unittest.cc b/webrtc/api/videocapturertracksource_unittest.cc
similarity index 72%
rename from webrtc/api/videosource_unittest.cc
rename to webrtc/api/videocapturertracksource_unittest.cc
index cfa1e72..e059ef3 100644
--- a/webrtc/api/videosource_unittest.cc
+++ b/webrtc/api/videocapturertracksource_unittest.cc
@@ -13,7 +13,7 @@
#include "webrtc/api/remotevideocapturer.h"
#include "webrtc/api/test/fakeconstraints.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/base/gunit.h"
#include "webrtc/media/base/fakemediaengine.h"
#include "webrtc/media/base/fakevideocapturer.h"
@@ -21,11 +21,11 @@
#include "webrtc/media/engine/webrtcvideoframe.h"
using webrtc::FakeConstraints;
-using webrtc::VideoSource;
+using webrtc::VideoCapturerTrackSource;
using webrtc::MediaConstraintsInterface;
using webrtc::MediaSourceInterface;
using webrtc::ObserverInterface;
-using webrtc::VideoSourceInterface;
+using webrtc::VideoTrackSourceInterface;
namespace {
@@ -34,27 +34,30 @@
} // anonymous namespace
-
// TestVideoCapturer extends cricket::FakeVideoCapturer so it can be used for
// testing without known camera formats.
// It keeps its own lists of cricket::VideoFormats for the unit tests in this
// file.
class TestVideoCapturer : public cricket::FakeVideoCapturer {
public:
- TestVideoCapturer(bool is_screencast)
- : FakeVideoCapturer(is_screencast),
- test_without_formats_(false) {
+ explicit TestVideoCapturer(bool is_screencast)
+ : FakeVideoCapturer(is_screencast), test_without_formats_(false) {
std::vector<cricket::VideoFormat> formats;
- formats.push_back(cricket::VideoFormat(1280, 720,
- cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
- formats.push_back(cricket::VideoFormat(640, 480,
- cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
- formats.push_back(cricket::VideoFormat(640, 400,
- cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
- formats.push_back(cricket::VideoFormat(320, 240,
- cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
- formats.push_back(cricket::VideoFormat(352, 288,
- cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
+ formats.push_back(
+ cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30),
+ cricket::FOURCC_I420));
+ formats.push_back(
+ cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30),
+ cricket::FOURCC_I420));
+ formats.push_back(
+ cricket::VideoFormat(640, 400, cricket::VideoFormat::FpsToInterval(30),
+ cricket::FOURCC_I420));
+ formats.push_back(
+ cricket::VideoFormat(320, 240, cricket::VideoFormat::FpsToInterval(30),
+ cricket::FOURCC_I420));
+ formats.push_back(
+ cricket::VideoFormat(352, 288, cricket::VideoFormat::FpsToInterval(30),
+ cricket::FOURCC_I420));
ResetSupportedFormats(formats);
}
@@ -84,8 +87,7 @@
*best_format = desired;
return true;
}
- return FakeVideoCapturer::GetBestCaptureFormat(desired,
- best_format);
+ return FakeVideoCapturer::GetBestCaptureFormat(desired, best_format);
}
private:
@@ -94,25 +96,19 @@
class StateObserver : public ObserverInterface {
public:
- explicit StateObserver(VideoSourceInterface* source)
- : state_(source->state()),
- source_(source) {
- }
- virtual void OnChanged() {
- state_ = source_->state();
- }
+ explicit StateObserver(VideoTrackSourceInterface* source)
+ : state_(source->state()), source_(source) {}
+ virtual void OnChanged() { state_ = source_->state(); }
MediaSourceInterface::SourceState state() const { return state_; }
private:
MediaSourceInterface::SourceState state_;
- rtc::scoped_refptr<VideoSourceInterface> source_;
+ rtc::scoped_refptr<VideoTrackSourceInterface> source_;
};
-class VideoSourceTest : public testing::Test {
+class VideoCapturerTrackSourceTest : public testing::Test {
protected:
- VideoSourceTest() {
- InitCapturer(false);
- }
+ VideoCapturerTrackSourceTest() { InitCapturer(false); }
void InitCapturer(bool is_screencast) {
capturer_cleanup_ = rtc::scoped_ptr<TestVideoCapturer>(
new TestVideoCapturer(is_screencast));
@@ -121,16 +117,14 @@
void InitScreencast() { InitCapturer(true); }
- void CreateVideoSource() {
- CreateVideoSource(NULL);
- }
+ void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); }
- void CreateVideoSource(
+ void CreateVideoCapturerSource(
const webrtc::MediaConstraintsInterface* constraints) {
// VideoSource take ownership of |capturer_|
- source_ =
- VideoSource::Create(rtc::Thread::Current(), capturer_cleanup_.release(),
- constraints, false);
+ source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(),
+ capturer_cleanup_.release(),
+ constraints, false);
ASSERT_TRUE(source_.get() != NULL);
EXPECT_EQ(capturer_, source_->GetVideoCapturer());
@@ -144,16 +138,15 @@
TestVideoCapturer* capturer_;
cricket::FakeVideoRenderer renderer_;
rtc::scoped_ptr<StateObserver> state_observer_;
- rtc::scoped_refptr<VideoSource> source_;
+ rtc::scoped_refptr<VideoTrackSourceInterface> source_;
};
-
// Test that a VideoSource transition to kLive state when the capture
// device have started and kEnded if it is stopped.
// It also test that an output can receive video frames.
-TEST_F(VideoSourceTest, CapturerStartStop) {
+TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) {
// Initialize without constraints.
- CreateVideoSource();
+ CreateVideoCapturerSource();
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
@@ -166,9 +159,9 @@
}
// Test that a VideoSource can be stopped and restarted.
-TEST_F(VideoSourceTest, StopRestart) {
+TEST_F(VideoCapturerTrackSourceTest, StopRestart) {
// Initialize without constraints.
- CreateVideoSource();
+ CreateVideoCapturerSource();
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
@@ -191,9 +184,9 @@
// Test start stop with a remote VideoSource - the video source that has a
// RemoteVideoCapturer and takes video frames from FrameInput.
-TEST_F(VideoSourceTest, StartStopRemote) {
- source_ = VideoSource::Create(rtc::Thread::Current(),
- new webrtc::RemoteVideoCapturer(), NULL, true);
+TEST_F(VideoCapturerTrackSourceTest, StartStopRemote) {
+ source_ = VideoCapturerTrackSource::Create(
+ rtc::Thread::Current(), new webrtc::RemoteVideoCapturer(), NULL, true);
ASSERT_TRUE(source_.get() != NULL);
EXPECT_TRUE(NULL != source_->GetVideoCapturer());
@@ -212,8 +205,8 @@
// Test that a VideoSource transition to kEnded if the capture device
// fails.
-TEST_F(VideoSourceTest, CameraFailed) {
- CreateVideoSource();
+TEST_F(VideoCapturerTrackSourceTest, CameraFailed) {
+ CreateVideoCapturerSource();
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
@@ -224,13 +217,13 @@
// Test that the capture output is CIF if we set max constraints to CIF.
// and the capture device support CIF.
-TEST_F(VideoSourceTest, MandatoryConstraintCif5Fps) {
+TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -242,7 +235,7 @@
// Test that the capture output is 720P if the camera support it and the
// optional constraint is set to 720P.
-TEST_F(VideoSourceTest, MandatoryMinVgaOptional720P) {
+TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
@@ -250,7 +243,7 @@
constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio,
1280.0 / 720);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -263,7 +256,7 @@
// Test that the capture output have aspect ratio 4:3 if a mandatory constraint
// require it even if an optional constraint request a higher resolution
// that don't have this aspect ratio.
-TEST_F(VideoSourceTest, MandatoryAspectRatio4To3) {
+TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
@@ -271,7 +264,7 @@
640.0 / 480);
constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -281,23 +274,22 @@
EXPECT_EQ(30, format->framerate());
}
-
// Test that the source state transition to kEnded if the mandatory aspect ratio
// is set higher than supported.
-TEST_F(VideoSourceTest, MandatoryAspectRatioTooHigh) {
+TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
kMaxWaitMs);
}
// Test that the source ignores an optional aspect ratio that is higher than
// supported.
-TEST_F(VideoSourceTest, OptionalAspectRatioTooHigh) {
+TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) {
FakeConstraints constraints;
constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -308,10 +300,10 @@
// Test that the source starts video with the default resolution if the
// camera doesn't support capability enumeration and there are no constraints.
-TEST_F(VideoSourceTest, NoCameraCapability) {
+TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) {
capturer_->TestWithoutCameraFormats();
- CreateVideoSource();
+ CreateVideoCapturerSource();
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -324,7 +316,7 @@
// Test that the source can start the video and get the requested aspect ratio
// if the camera doesn't support capability enumeration and the aspect ratio is
// set.
-TEST_F(VideoSourceTest, NoCameraCapability16To9Ratio) {
+TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) {
capturer_->TestWithoutCameraFormats();
FakeConstraints constraints;
@@ -333,7 +325,7 @@
constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio,
requested_aspect_ratio);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -343,121 +335,113 @@
// Test that the source state transitions to kEnded if an unknown mandatory
// constraint is found.
-TEST_F(VideoSourceTest, InvalidMandatoryConstraint) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidMandatoryConstraint) {
FakeConstraints constraints;
constraints.AddMandatory("weird key", 640);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
kMaxWaitMs);
}
// Test that the source ignores an unknown optional constraint.
-TEST_F(VideoSourceTest, InvalidOptionalConstraint) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidOptionalConstraint) {
FakeConstraints constraints;
constraints.AddOptional("weird key", 640);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
}
-TEST_F(VideoSourceTest, SetValidOptionValues) {
+TEST_F(VideoCapturerTrackSourceTest, SetValidOptionValues) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "false");
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ(rtc::Optional<bool>(false),
source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, OptionNotSet) {
+TEST_F(VideoCapturerTrackSourceTest, OptionNotSet) {
FakeConstraints constraints;
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ(rtc::Optional<bool>(), source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) {
+TEST_F(VideoCapturerTrackSourceTest, MandatoryOptionOverridesOptional) {
FakeConstraints constraints;
- constraints.AddMandatory(
- MediaConstraintsInterface::kNoiseReduction, true);
- constraints.AddOptional(
- MediaConstraintsInterface::kNoiseReduction, false);
+ constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, true);
+ constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, false);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ(rtc::Optional<bool>(true),
source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, InvalidOptionKeyOptional) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidOptionKeyOptional) {
FakeConstraints constraints;
- constraints.AddOptional(
- MediaConstraintsInterface::kNoiseReduction, false);
+ constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, false);
constraints.AddOptional("invalidKey", false);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
- kMaxWaitMs);
+ kMaxWaitMs);
EXPECT_EQ(rtc::Optional<bool>(false),
source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, InvalidOptionKeyMandatory) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidOptionKeyMandatory) {
FakeConstraints constraints;
- constraints.AddMandatory(
- MediaConstraintsInterface::kNoiseReduction, false);
+ constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
constraints.AddMandatory("invalidKey", false);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
- kMaxWaitMs);
+ kMaxWaitMs);
EXPECT_EQ(rtc::Optional<bool>(), source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, InvalidOptionValueOptional) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidOptionValueOptional) {
FakeConstraints constraints;
- constraints.AddOptional(
- MediaConstraintsInterface::kNoiseReduction, "not a boolean");
+ constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction,
+ "not a boolean");
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
- kMaxWaitMs);
+ kMaxWaitMs);
EXPECT_EQ(rtc::Optional<bool>(), source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, InvalidOptionValueMandatory) {
+TEST_F(VideoCapturerTrackSourceTest, InvalidOptionValueMandatory) {
FakeConstraints constraints;
// Optional constraints should be ignored if the mandatory constraints fail.
- constraints.AddOptional(
- MediaConstraintsInterface::kNoiseReduction, "false");
+ constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, "false");
// Values are case-sensitive and must be all lower-case.
- constraints.AddMandatory(
- MediaConstraintsInterface::kNoiseReduction, "True");
+ constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "True");
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
- kMaxWaitMs);
+ kMaxWaitMs);
EXPECT_EQ(rtc::Optional<bool>(), source_->options()->video_noise_reduction);
}
-TEST_F(VideoSourceTest, MixedOptionsAndConstraints) {
+TEST_F(VideoCapturerTrackSourceTest, MixedOptionsAndConstraints) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5);
- constraints.AddMandatory(
- MediaConstraintsInterface::kNoiseReduction, false);
- constraints.AddOptional(
- MediaConstraintsInterface::kNoiseReduction, true);
+ constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
+ constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -472,11 +456,11 @@
// Tests that the source starts video with the default resolution for
// screencast if no constraint is set.
-TEST_F(VideoSourceTest, ScreencastResolutionNoConstraint) {
+TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) {
InitScreencast();
capturer_->TestWithoutCameraFormats();
- CreateVideoSource();
+ CreateVideoCapturerSource();
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -488,7 +472,7 @@
// Tests that the source starts video with the max width and height set by
// constraints for screencast.
-TEST_F(VideoSourceTest, ScreencastResolutionWithConstraint) {
+TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480);
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270);
@@ -496,7 +480,7 @@
InitScreencast();
capturer_->TestWithoutCameraFormats();
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
@@ -506,21 +490,21 @@
EXPECT_EQ(30, format->framerate());
}
-TEST_F(VideoSourceTest, MandatorySubOneFpsConstraints) {
+TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) {
FakeConstraints constraints;
constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0.5);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
kMaxWaitMs);
ASSERT_TRUE(capturer_->GetCaptureFormat() == NULL);
}
-TEST_F(VideoSourceTest, OptionalSubOneFpsConstraints) {
+TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) {
FakeConstraints constraints;
constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5);
- CreateVideoSource(&constraints);
+ CreateVideoCapturerSource(&constraints);
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
kMaxWaitMs);
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
diff --git a/webrtc/api/videosource.h b/webrtc/api/videosource.h
index eb46463..08e5422 100644
--- a/webrtc/api/videosource.h
+++ b/webrtc/api/videosource.h
@@ -8,93 +8,4 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_API_VIDEOSOURCE_H_
-#define WEBRTC_API_VIDEOSOURCE_H_
-
-#include <list>
-
-#include "webrtc/api/mediastreaminterface.h"
-#include "webrtc/api/notifier.h"
-#include "webrtc/api/videosourceinterface.h"
-#include "webrtc/api/videotrackrenderers.h"
-#include "webrtc/base/asyncinvoker.h"
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/base/sigslot.h"
-#include "webrtc/media/base/videosinkinterface.h"
-#include "webrtc/media/base/videocapturer.h"
-#include "webrtc/media/base/videocommon.h"
-
-// VideoSource implements VideoSourceInterface. It owns a
-// cricket::VideoCapturer and make sure the camera is started at a resolution
-// that honors the constraints.
-// 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 webrtc {
-
-class MediaConstraintsInterface;
-
-class VideoSource : public Notifier<VideoSourceInterface>,
- public sigslot::has_slots<> {
- public:
- // Creates an instance of VideoSource.
- // VideoSource take ownership of |capturer|.
- // |constraints| can be NULL and in that case the camera is opened using a
- // default resolution.
- static rtc::scoped_refptr<VideoSource> Create(
- rtc::Thread* worker_thread,
- cricket::VideoCapturer* capturer,
- const webrtc::MediaConstraintsInterface* constraints,
- bool remote);
-
- // Note that the non-constraints version does not have the ability to
- // select configuration based on width, height, aspect ratio or frame rate.
- static rtc::scoped_refptr<VideoSource> Create(
- rtc::Thread* worker_thread,
- cricket::VideoCapturer* capturer,
- bool remote);
-
- SourceState state() const override { return state_; }
- bool remote() const override { return remote_; }
-
- virtual const cricket::VideoOptions* options() const { return &options_; }
-
- virtual cricket::VideoCapturer* GetVideoCapturer() {
- return video_capturer_.get();
- }
-
- void Stop() override;
- void Restart() override;
-
- void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
- const rtc::VideoSinkWants& wants) override;
- void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
-
- protected:
- VideoSource(rtc::Thread* worker_thread,
- cricket::VideoCapturer* capturer,
- bool remote);
- virtual ~VideoSource();
- void Initialize(const webrtc::MediaConstraintsInterface* constraints);
-
- private:
- void OnStateChange(cricket::VideoCapturer* capturer,
- cricket::CaptureState capture_state);
- void SetState(SourceState new_state);
-
- rtc::Thread* signaling_thread_;
- rtc::Thread* worker_thread_;
- rtc::AsyncInvoker invoker_;
- rtc::scoped_ptr<cricket::VideoCapturer> video_capturer_;
- bool started_;
- rtc::scoped_ptr<cricket::VideoRenderer> frame_input_;
-
- cricket::VideoFormat format_;
- cricket::VideoOptions options_;
- SourceState state_;
- const bool remote_;
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_API_VIDEOSOURCE_H_
+// TODO(perkj): Remove this file once Chrome build files doesn't depend on it.
diff --git a/webrtc/api/videosourceinterface.h b/webrtc/api/videosourceinterface.h
index d55f0aa..10ded41 100644
--- a/webrtc/api/videosourceinterface.h
+++ b/webrtc/api/videosourceinterface.h
@@ -12,37 +12,7 @@
#define WEBRTC_API_VIDEOSOURCEINTERFACE_H_
#include "webrtc/api/mediastreaminterface.h"
-#include "webrtc/media/base/mediachannel.h"
-#include "webrtc/media/base/videosourceinterface.h"
-namespace webrtc {
-
-// VideoSourceInterface is a reference counted source used for VideoTracks.
-// 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,
- public rtc::VideoSourceInterface<cricket::VideoFrame> {
- 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;
-
- virtual void Stop() = 0;
- virtual void Restart() = 0;
-
- virtual const cricket::VideoOptions* options() const = 0;
-
- protected:
- virtual ~VideoSourceInterface() {}
-};
-
-// TODO(perkj): Rename webrtc::VideoSourceInterface to
-// webrtc::VideoTrackSourceInterface
-using VideoTrackSourceInterface = VideoSourceInterface;
-
-} // namespace webrtc
+// TODO(perkj): Remove this file once Chrome build files doesn't depend on it.
#endif // WEBRTC_API_VIDEOSOURCEINTERFACE_H_
diff --git a/webrtc/api/videosourceproxy.h b/webrtc/api/videosourceproxy.h
index e0f94dc..59adf89 100644
--- a/webrtc/api/videosourceproxy.h
+++ b/webrtc/api/videosourceproxy.h
@@ -16,22 +16,24 @@
namespace webrtc {
-// VideoSourceProxy makes sure the real VideoSourceInterface implementation is
+// VideoTrackSourceInterface makes sure the real VideoTrackSourceInterface
+// implementation is
// destroyed on the signaling thread and marshals all method calls to the
// signaling thread.
-BEGIN_PROXY_MAP(VideoSource)
- PROXY_CONSTMETHOD0(SourceState, state)
- PROXY_CONSTMETHOD0(bool, remote)
- PROXY_METHOD0(cricket::VideoCapturer*, GetVideoCapturer)
- PROXY_METHOD0(void, Stop)
- PROXY_METHOD0(void, Restart)
- PROXY_METHOD2(void, AddOrUpdateSink,
- rtc::VideoSinkInterface<cricket::VideoFrame>*,
- const rtc::VideoSinkWants&)
- PROXY_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<cricket::VideoFrame>*)
- PROXY_CONSTMETHOD0(const cricket::VideoOptions*, options)
- PROXY_METHOD1(void, RegisterObserver, ObserverInterface*)
- PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*)
+BEGIN_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_METHOD2(void,
+ AddOrUpdateSink,
+ rtc::VideoSinkInterface<cricket::VideoFrame>*,
+ const rtc::VideoSinkWants&)
+PROXY_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<cricket::VideoFrame>*)
+PROXY_CONSTMETHOD0(const cricket::VideoOptions*, options)
+PROXY_METHOD1(void, RegisterObserver, ObserverInterface*)
+PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*)
END_PROXY()
} // namespace webrtc
diff --git a/webrtc/api/videotrack.cc b/webrtc/api/videotrack.cc
index 0f933a0..36d256f 100644
--- a/webrtc/api/videotrack.cc
+++ b/webrtc/api/videotrack.cc
@@ -17,7 +17,7 @@
const char MediaStreamTrackInterface::kVideoKind[] = "video";
VideoTrack::VideoTrack(const std::string& label,
- VideoSourceInterface* video_source)
+ VideoTrackSourceInterface* video_source)
: MediaStreamTrack<VideoTrackInterface>(label),
video_source_(video_source) {
// TODO(perkj): Sinks should register directly to the source so that
@@ -61,7 +61,7 @@
rtc::scoped_refptr<VideoTrack> VideoTrack::Create(
const std::string& id,
- VideoSourceInterface* source) {
+ VideoTrackSourceInterface* source) {
rtc::RefCountedObject<VideoTrack>* track =
new rtc::RefCountedObject<VideoTrack>(id, source);
return track;
diff --git a/webrtc/api/videotrack.h b/webrtc/api/videotrack.h
index 1964cb4..066aa90 100644
--- a/webrtc/api/videotrack.h
+++ b/webrtc/api/videotrack.h
@@ -22,14 +22,15 @@
class VideoTrack : public MediaStreamTrack<VideoTrackInterface> {
public:
- static rtc::scoped_refptr<VideoTrack> Create(const std::string& label,
- VideoSourceInterface* source);
+ static rtc::scoped_refptr<VideoTrack> Create(
+ const std::string& label,
+ VideoTrackSourceInterface* source);
void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
const rtc::VideoSinkWants& wants) override;
void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
- virtual VideoSourceInterface* GetSource() const {
+ virtual VideoTrackSourceInterface* GetSource() const {
return video_source_.get();
}
rtc::VideoSinkInterface<cricket::VideoFrame>* GetSink() override;
@@ -37,12 +38,12 @@
virtual std::string kind() const;
protected:
- VideoTrack(const std::string& id, VideoSourceInterface* video_source);
+ VideoTrack(const std::string& id, VideoTrackSourceInterface* video_source);
~VideoTrack();
private:
VideoTrackRenderers renderers_;
- rtc::scoped_refptr<VideoSourceInterface> video_source_;
+ rtc::scoped_refptr<VideoTrackSourceInterface> video_source_;
};
} // namespace webrtc
diff --git a/webrtc/api/videotrack_unittest.cc b/webrtc/api/videotrack_unittest.cc
index 0c3e8b0..9f44b81 100644
--- a/webrtc/api/videotrack_unittest.cc
+++ b/webrtc/api/videotrack_unittest.cc
@@ -12,7 +12,7 @@
#include "webrtc/api/remotevideocapturer.h"
#include "webrtc/api/test/fakevideotrackrenderer.h"
-#include "webrtc/api/videosource.h"
+#include "webrtc/api/videocapturertracksource.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/scoped_ptr.h"
@@ -22,7 +22,7 @@
using webrtc::FakeVideoTrackRenderer;
using webrtc::FakeVideoTrackRendererOld;
-using webrtc::VideoSource;
+using webrtc::VideoCapturerTrackSource;
using webrtc::VideoTrack;
using webrtc::VideoTrackInterface;
@@ -40,9 +40,9 @@
VideoTrackTest() {
static const char kVideoTrackId[] = "track_id";
video_track_ = VideoTrack::Create(
- kVideoTrackId,
- VideoSource::Create(rtc::Thread::Current(),
- new webrtc::RemoteVideoCapturer(), NULL, true));
+ kVideoTrackId, VideoCapturerTrackSource::Create(
+ rtc::Thread::Current(),
+ new webrtc::RemoteVideoCapturer(), NULL, true));
}
protected: