Add a 'remote' property to MediaSourceInterface. Also adding an implementation to the relevant sources we have (audio/video) and an extra check where we're casting a source into a local audio source :(

Additionally:
* Moving all implementation inside RemoteAudioTrack into AudioTrack and remove RemoteAudioTrack.
* AddSink/RemoveSink are now on all audio sources (like they are for video sources).

While doing this I found that some of our tests are broken :) and fixed them.  They were broken because AudioTrack didn't previously do much such as updating its state.

BUG=chromium:569526

Review URL: https://codereview.webrtc.org/1522903002

Cr-Commit-Position: refs/heads/master@{#11026}
diff --git a/talk/app/webrtc/audiotrack.cc b/talk/app/webrtc/audiotrack.cc
index 63bd87c..b3223cd 100644
--- a/talk/app/webrtc/audiotrack.cc
+++ b/talk/app/webrtc/audiotrack.cc
@@ -27,27 +27,82 @@
 
 #include "talk/app/webrtc/audiotrack.h"
 
-#include <string>
+#include "webrtc/base/checks.h"
+
+using rtc::scoped_refptr;
 
 namespace webrtc {
 
 const char MediaStreamTrackInterface::kAudioKind[] = "audio";
 
+// static
+scoped_refptr<AudioTrack> AudioTrack::Create(
+    const std::string& id,
+    const scoped_refptr<AudioSourceInterface>& source) {
+  return new rtc::RefCountedObject<AudioTrack>(id, source);
+}
+
 AudioTrack::AudioTrack(const std::string& label,
-                       AudioSourceInterface* audio_source)
-    : MediaStreamTrack<AudioTrackInterface>(label),
-      audio_source_(audio_source) {
+                       const scoped_refptr<AudioSourceInterface>& source)
+    : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) {
+  if (audio_source_) {
+    audio_source_->RegisterObserver(this);
+    OnChanged();
+  }
+}
+
+AudioTrack::~AudioTrack() {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  set_state(MediaStreamTrackInterface::kEnded);
+  if (audio_source_)
+    audio_source_->UnregisterObserver(this);
 }
 
 std::string AudioTrack::kind() const {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
   return kAudioKind;
 }
 
-rtc::scoped_refptr<AudioTrack> AudioTrack::Create(
-    const std::string& id, AudioSourceInterface* source) {
-  rtc::RefCountedObject<AudioTrack>* track =
-      new rtc::RefCountedObject<AudioTrack>(id, source);
-  return track;
+AudioSourceInterface* AudioTrack::GetSource() const {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  return audio_source_.get();
+}
+
+void AudioTrack::AddSink(AudioTrackSinkInterface* sink) {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  if (audio_source_)
+    audio_source_->AddSink(sink);
+}
+
+void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  if (audio_source_)
+    audio_source_->RemoveSink(sink);
+}
+
+void AudioTrack::OnChanged() {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  if (state() == kFailed)
+    return;  // We can't recover from this state (do we ever set it?).
+
+  TrackState new_state = kInitializing;
+
+  // |audio_source_| must be non-null if we ever get here.
+  switch (audio_source_->state()) {
+    case MediaSourceInterface::kLive:
+    case MediaSourceInterface::kMuted:
+      new_state = kLive;
+      break;
+    case MediaSourceInterface::kEnded:
+      new_state = kEnded;
+      break;
+    case MediaSourceInterface::kInitializing:
+    default:
+      // use kInitializing.
+      break;
+  }
+
+  set_state(new_state);
 }
 
 }  // namespace webrtc
diff --git a/talk/app/webrtc/audiotrack.h b/talk/app/webrtc/audiotrack.h
index 750f272..55f4837 100644
--- a/talk/app/webrtc/audiotrack.h
+++ b/talk/app/webrtc/audiotrack.h
@@ -28,40 +28,47 @@
 #ifndef TALK_APP_WEBRTC_AUDIOTRACK_H_
 #define TALK_APP_WEBRTC_AUDIOTRACK_H_
 
+#include <string>
+
 #include "talk/app/webrtc/mediastreaminterface.h"
 #include "talk/app/webrtc/mediastreamtrack.h"
 #include "talk/app/webrtc/notifier.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/base/scoped_ref_ptr.h"
+#include "webrtc/base/thread_checker.h"
 
 namespace webrtc {
 
-class AudioTrack : public MediaStreamTrack<AudioTrackInterface> {
+class AudioTrack : public MediaStreamTrack<AudioTrackInterface>,
+                   public ObserverInterface {
+ protected:
+  // Protected ctor to force use of factory method.
+  AudioTrack(const std::string& label,
+             const rtc::scoped_refptr<AudioSourceInterface>& source);
+  ~AudioTrack() override;
+
  public:
   static rtc::scoped_refptr<AudioTrack> Create(
-      const std::string& id, AudioSourceInterface* source);
+      const std::string& id,
+      const rtc::scoped_refptr<AudioSourceInterface>& source);
 
-  // AudioTrackInterface implementation.
-  AudioSourceInterface* GetSource() const override {
-    return audio_source_.get();
-  }
-  // TODO(xians): Implement these methods.
-  void AddSink(AudioTrackSinkInterface* sink) override {}
-  void RemoveSink(AudioTrackSinkInterface* sink) override {}
-  bool GetSignalLevel(int* level) override { return false; }
-  rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override {
-    return NULL;
-  }
-  cricket::AudioRenderer* GetRenderer() override { return NULL; }
-
+ private:
   // MediaStreamTrack implementation.
   std::string kind() const override;
 
- protected:
-  AudioTrack(const std::string& label, AudioSourceInterface* audio_source);
+  // AudioTrackInterface implementation.
+  AudioSourceInterface* GetSource() const override;
+
+  void AddSink(AudioTrackSinkInterface* sink) override;
+  void RemoveSink(AudioTrackSinkInterface* sink) override;
+
+  // ObserverInterface implementation.
+  void OnChanged() override;
 
  private:
-  rtc::scoped_refptr<AudioSourceInterface> audio_source_;
+  const rtc::scoped_refptr<AudioSourceInterface> audio_source_;
+  rtc::ThreadChecker thread_checker_;
+  RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTrack);
 };
 
 }  // namespace webrtc
diff --git a/talk/app/webrtc/localaudiosource.h b/talk/app/webrtc/localaudiosource.h
index 557745b..5158eb1 100644
--- a/talk/app/webrtc/localaudiosource.h
+++ b/talk/app/webrtc/localaudiosource.h
@@ -48,16 +48,17 @@
       const PeerConnectionFactoryInterface::Options& options,
       const MediaConstraintsInterface* constraints);
 
-  virtual SourceState state() const { return source_state_; }
+  SourceState state() const override { return source_state_; }
+  bool remote() const override { return false; }
+
   virtual const cricket::AudioOptions& options() const { return options_; }
 
- protected:
-  LocalAudioSource()
-      : source_state_(kInitializing) {
-  }
+  void AddSink(AudioTrackSinkInterface* sink) override {}
+  void RemoveSink(AudioTrackSinkInterface* sink) override {}
 
-  ~LocalAudioSource() {
-  }
+ protected:
+  LocalAudioSource() : source_state_(kInitializing) {}
+  ~LocalAudioSource() override {}
 
  private:
   void Initialize(const PeerConnectionFactoryInterface::Options& options,
diff --git a/talk/app/webrtc/mediastream_unittest.cc b/talk/app/webrtc/mediastream_unittest.cc
index 2cf930c..f19b945 100644
--- a/talk/app/webrtc/mediastream_unittest.cc
+++ b/talk/app/webrtc/mediastream_unittest.cc
@@ -48,9 +48,23 @@
 // Helper class to test Observer.
 class MockObserver : public ObserverInterface {
  public:
-  MockObserver() {}
+  explicit MockObserver(NotifierInterface* notifier) : notifier_(notifier) {
+    notifier_->RegisterObserver(this);
+  }
+
+  ~MockObserver() { Unregister(); }
+
+  void Unregister() {
+    if (notifier_) {
+      notifier_->UnregisterObserver(this);
+      notifier_ = nullptr;
+    }
+  }
 
   MOCK_METHOD0(OnChanged, void());
+
+ private:
+  NotifierInterface* notifier_;
 };
 
 class MediaStreamTest: public testing::Test {
@@ -75,8 +89,7 @@
   }
 
   void ChangeTrack(MediaStreamTrackInterface* track) {
-    MockObserver observer;
-    track->RegisterObserver(&observer);
+    MockObserver observer(track);
 
     EXPECT_CALL(observer, OnChanged())
         .Times(Exactly(1));
@@ -127,8 +140,7 @@
 }
 
 TEST_F(MediaStreamTest, RemoveTrack) {
-  MockObserver observer;
-  stream_->RegisterObserver(&observer);
+  MockObserver observer(stream_);
 
   EXPECT_CALL(observer, OnChanged())
       .Times(Exactly(2));
diff --git a/talk/app/webrtc/mediastreaminterface.h b/talk/app/webrtc/mediastreaminterface.h
index 5327bd2..a1c0c80 100644
--- a/talk/app/webrtc/mediastreaminterface.h
+++ b/talk/app/webrtc/mediastreaminterface.h
@@ -71,8 +71,6 @@
 
 // Base class for sources. A MediaStreamTrack have an underlying source that
 // provide media. A source can be shared with multiple tracks.
-// TODO(perkj): Implement sources for local and remote audio tracks and
-// remote video tracks.
 class MediaSourceInterface : public rtc::RefCountInterface,
                              public NotifierInterface {
  public:
@@ -85,6 +83,8 @@
 
   virtual SourceState state() const = 0;
 
+  virtual bool remote() const = 0;
+
  protected:
   virtual ~MediaSourceInterface() {}
 };
@@ -152,6 +152,19 @@
   virtual ~VideoTrackInterface() {}
 };
 
+// Interface for receiving audio data from a AudioTrack.
+class AudioTrackSinkInterface {
+ public:
+  virtual void OnData(const void* audio_data,
+                      int bits_per_sample,
+                      int sample_rate,
+                      int number_of_channels,
+                      size_t number_of_frames) = 0;
+
+ protected:
+  virtual ~AudioTrackSinkInterface() {}
+};
+
 // AudioSourceInterface is a reference counted source used for AudioTracks.
 // The same source can be used in multiple AudioTracks.
 class AudioSourceInterface : public MediaSourceInterface {
@@ -174,18 +187,10 @@
   // Registers/unregisters observer to the audio source.
   virtual void RegisterAudioObserver(AudioObserver* observer) {}
   virtual void UnregisterAudioObserver(AudioObserver* observer) {}
-};
 
-// Interface for receiving audio data from a AudioTrack.
-class AudioTrackSinkInterface {
- public:
-  virtual void OnData(const void* audio_data,
-                      int bits_per_sample,
-                      int sample_rate,
-                      int number_of_channels,
-                      size_t number_of_frames) = 0;
- protected:
-  virtual ~AudioTrackSinkInterface() {}
+  // TODO(tommi): Make pure virtual.
+  virtual void AddSink(AudioTrackSinkInterface* sink) {}
+  virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
 };
 
 // Interface of the audio processor used by the audio track to collect
diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc
index 83380e1..6cca166 100644
--- a/talk/app/webrtc/peerconnection.cc
+++ b/talk/app/webrtc/peerconnection.cc
@@ -39,7 +39,6 @@
 #include "talk/app/webrtc/mediastreamproxy.h"
 #include "talk/app/webrtc/mediastreamtrackproxy.h"
 #include "talk/app/webrtc/remoteaudiosource.h"
-#include "talk/app/webrtc/remoteaudiotrack.h"
 #include "talk/app/webrtc/remotevideocapturer.h"
 #include "talk/app/webrtc/rtpreceiver.h"
 #include "talk/app/webrtc/rtpsender.h"
@@ -454,7 +453,7 @@
                                      AudioProviderInterface* provider,
                                      webrtc::MediaStreamInterface* stream,
                                      const std::string& track_id) {
-    return AddTrack<AudioTrackInterface, RemoteAudioTrack, AudioTrackProxy>(
+    return AddTrack<AudioTrackInterface, AudioTrack, AudioTrackProxy>(
         stream, track_id, RemoteAudioSource::Create(ssrc, provider));
   }
 
@@ -463,7 +462,7 @@
     return AddTrack<VideoTrackInterface, VideoTrack, VideoTrackProxy>(
         stream, track_id,
         VideoSource::Create(channel_manager_, new RemoteVideoCapturer(),
-                            nullptr)
+                            nullptr, true)
             .get());
   }
 
diff --git a/talk/app/webrtc/peerconnectionfactory.cc b/talk/app/webrtc/peerconnectionfactory.cc
index 6723550..d01f542 100644
--- a/talk/app/webrtc/peerconnectionfactory.cc
+++ b/talk/app/webrtc/peerconnectionfactory.cc
@@ -225,8 +225,8 @@
     cricket::VideoCapturer* capturer,
     const MediaConstraintsInterface* constraints) {
   RTC_DCHECK(signaling_thread_->IsCurrent());
-  rtc::scoped_refptr<VideoSource> source(
-      VideoSource::Create(channel_manager_.get(), capturer, constraints));
+  rtc::scoped_refptr<VideoSource> source(VideoSource::Create(
+      channel_manager_.get(), capturer, constraints, false));
   return VideoSourceProxy::Create(signaling_thread_, source);
 }
 
@@ -339,8 +339,7 @@
 PeerConnectionFactory::CreateAudioTrack(const std::string& id,
                                         AudioSourceInterface* source) {
   RTC_DCHECK(signaling_thread_->IsCurrent());
-  rtc::scoped_refptr<AudioTrackInterface> track(
-      AudioTrack::Create(id, source));
+  rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source));
   return AudioTrackProxy::Create(signaling_thread_, track);
 }
 
diff --git a/talk/app/webrtc/remoteaudiosource.cc b/talk/app/webrtc/remoteaudiosource.cc
index a35f0bb..e904dd9 100644
--- a/talk/app/webrtc/remoteaudiosource.cc
+++ b/talk/app/webrtc/remoteaudiosource.cc
@@ -106,6 +106,11 @@
   return state_;
 }
 
+bool RemoteAudioSource::remote() const {
+  RTC_DCHECK(main_thread_->IsCurrent());
+  return true;
+}
+
 void RemoteAudioSource::SetVolume(double volume) {
   RTC_DCHECK(volume >= 0 && volume <= 10);
   for (auto* observer : audio_observers_)
diff --git a/talk/app/webrtc/remoteaudiosource.h b/talk/app/webrtc/remoteaudiosource.h
index f518d9b..d648ba4 100644
--- a/talk/app/webrtc/remoteaudiosource.h
+++ b/talk/app/webrtc/remoteaudiosource.h
@@ -56,9 +56,10 @@
 
   // MediaSourceInterface implementation.
   MediaSourceInterface::SourceState state() const override;
+  bool remote() const override;
 
-  void AddSink(AudioTrackSinkInterface* sink);
-  void RemoveSink(AudioTrackSinkInterface* sink);
+  void AddSink(AudioTrackSinkInterface* sink) override;
+  void RemoveSink(AudioTrackSinkInterface* sink) override;
 
  protected:
   RemoteAudioSource();
diff --git a/talk/app/webrtc/remoteaudiotrack.cc b/talk/app/webrtc/remoteaudiotrack.cc
index 2c4481c..5f0b23e 100644
--- a/talk/app/webrtc/remoteaudiotrack.cc
+++ b/talk/app/webrtc/remoteaudiotrack.cc
@@ -25,71 +25,4 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "talk/app/webrtc/remoteaudiotrack.h"
-
-#include "talk/app/webrtc/remoteaudiosource.h"
-
-using rtc::scoped_refptr;
-
-namespace webrtc {
-
-// static
-scoped_refptr<RemoteAudioTrack> RemoteAudioTrack::Create(
-    const std::string& id,
-    const scoped_refptr<RemoteAudioSource>& source) {
-  return new rtc::RefCountedObject<RemoteAudioTrack>(id, source);
-}
-
-RemoteAudioTrack::RemoteAudioTrack(
-    const std::string& label,
-    const scoped_refptr<RemoteAudioSource>& source)
-    : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) {
-  audio_source_->RegisterObserver(this);
-  TrackState new_state = kInitializing;
-  switch (audio_source_->state()) {
-    case MediaSourceInterface::kLive:
-    case MediaSourceInterface::kMuted:
-      new_state = kLive;
-      break;
-    case MediaSourceInterface::kEnded:
-      new_state = kEnded;
-      break;
-    case MediaSourceInterface::kInitializing:
-    default:
-      // kInitializing;
-      break;
-  }
-  set_state(new_state);
-}
-
-RemoteAudioTrack::~RemoteAudioTrack() {
-  set_state(MediaStreamTrackInterface::kEnded);
-  audio_source_->UnregisterObserver(this);
-}
-
-std::string RemoteAudioTrack::kind() const {
-  return MediaStreamTrackInterface::kAudioKind;
-}
-
-AudioSourceInterface* RemoteAudioTrack::GetSource() const {
-  return audio_source_.get();
-}
-
-void RemoteAudioTrack::AddSink(AudioTrackSinkInterface* sink) {
-  audio_source_->AddSink(sink);
-}
-
-void RemoteAudioTrack::RemoveSink(AudioTrackSinkInterface* sink) {
-  audio_source_->RemoveSink(sink);
-}
-
-bool RemoteAudioTrack::GetSignalLevel(int* level) {
-  return false;
-}
-
-void RemoteAudioTrack::OnChanged() {
-  if (audio_source_->state() == MediaSourceInterface::kEnded)
-    set_state(MediaStreamTrackInterface::kEnded);
-}
-
-}  // namespace webrtc
+// TODO(tommi): Delete this file when removed from build files in Chromium.
diff --git a/talk/app/webrtc/remoteaudiotrack.h b/talk/app/webrtc/remoteaudiotrack.h
index c9240eb..5f0b23e 100644
--- a/talk/app/webrtc/remoteaudiotrack.h
+++ b/talk/app/webrtc/remoteaudiotrack.h
@@ -25,53 +25,4 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef TALK_APP_WEBRTC_REMOTEAUDIOTRACK_H_
-#define TALK_APP_WEBRTC_REMOTEAUDIOTRACK_H_
-
-#include <string>
-
-#include "talk/app/webrtc/mediastreaminterface.h"
-#include "talk/app/webrtc/mediastreamtrack.h"
-#include "talk/app/webrtc/notifier.h"
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/base/scoped_ref_ptr.h"
-
-namespace webrtc {
-
-class RemoteAudioSource;
-
-class RemoteAudioTrack : public MediaStreamTrack<AudioTrackInterface>,
-                         public ObserverInterface {
- protected:
-  // Protected ctor to force use of factory method.
-  RemoteAudioTrack(const std::string& label,
-                   const rtc::scoped_refptr<RemoteAudioSource>& source);
-  ~RemoteAudioTrack() override;
-
- public:
-  static rtc::scoped_refptr<RemoteAudioTrack> Create(
-      const std::string& id,
-      const rtc::scoped_refptr<RemoteAudioSource>& source);
-
- private:
-  // MediaStreamTrack implementation.
-  std::string kind() const override;
-
-  // AudioTrackInterface implementation.
-  AudioSourceInterface* GetSource() const override;
-
-  void AddSink(AudioTrackSinkInterface* sink) override;
-  void RemoveSink(AudioTrackSinkInterface* sink) override;
-  bool GetSignalLevel(int* level) override;
-
-  // ObserverInterface implementation.
-  void OnChanged() override;
-
- private:
-  const rtc::scoped_refptr<RemoteAudioSource> audio_source_;
-  RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteAudioTrack);
-};
-
-}  // namespace webrtc
-
-#endif  // TALK_APP_WEBRTC_REMOTEAUDIOTRACK_H_
+// TODO(tommi): Delete this file when removed from build files in Chromium.
diff --git a/talk/app/webrtc/rtpreceiver.cc b/talk/app/webrtc/rtpreceiver.cc
index b88554f..9540f36 100644
--- a/talk/app/webrtc/rtpreceiver.cc
+++ b/talk/app/webrtc/rtpreceiver.cc
@@ -39,6 +39,7 @@
       ssrc_(ssrc),
       provider_(provider),
       cached_track_enabled_(track->enabled()) {
+  RTC_DCHECK(track_->GetSource()->remote());
   track_->RegisterObserver(this);
   track_->GetSource()->RegisterAudioObserver(this);
   Reconfigure();
@@ -85,6 +86,7 @@
                                    uint32_t ssrc,
                                    VideoProviderInterface* provider)
     : id_(track->id()), track_(track), ssrc_(ssrc), provider_(provider) {
+  RTC_DCHECK(track_->GetSource()->remote());
   provider_->SetVideoPlayout(ssrc_, true, track_->GetSource()->FrameInput());
 }
 
diff --git a/talk/app/webrtc/rtpsender.cc b/talk/app/webrtc/rtpsender.cc
index ea10b7b..c0d23a0 100644
--- a/talk/app/webrtc/rtpsender.cc
+++ b/talk/app/webrtc/rtpsender.cc
@@ -184,7 +184,8 @@
 void AudioRtpSender::SetAudioSend() {
   RTC_DCHECK(!stopped_ && can_send_track());
   cricket::AudioOptions options;
-  if (track_->enabled() && track_->GetSource()) {
+  if (track_->enabled() && track_->GetSource() &&
+      !track_->GetSource()->remote()) {
     // TODO(xians): Remove this static_cast since we should be able to connect
     // a remote audio track to a peer connection.
     options = static_cast<LocalAudioSource*>(track_->GetSource())->options();
diff --git a/talk/app/webrtc/rtpsenderreceiver_unittest.cc b/talk/app/webrtc/rtpsenderreceiver_unittest.cc
index 3f61504..a590e1d 100644
--- a/talk/app/webrtc/rtpsenderreceiver_unittest.cc
+++ b/talk/app/webrtc/rtpsenderreceiver_unittest.cc
@@ -31,7 +31,6 @@
 #include "talk/app/webrtc/audiotrack.h"
 #include "talk/app/webrtc/mediastream.h"
 #include "talk/app/webrtc/remoteaudiosource.h"
-#include "talk/app/webrtc/remoteaudiotrack.h"
 #include "talk/app/webrtc/rtpreceiver.h"
 #include "talk/app/webrtc/rtpsender.h"
 #include "talk/app/webrtc/streamcollection.h"
@@ -98,8 +97,8 @@
 
 class FakeVideoSource : public Notifier<VideoSourceInterface> {
  public:
-  static rtc::scoped_refptr<FakeVideoSource> Create() {
-    return new rtc::RefCountedObject<FakeVideoSource>();
+  static rtc::scoped_refptr<FakeVideoSource> Create(bool remote) {
+    return new rtc::RefCountedObject<FakeVideoSource>(remote);
   }
   virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; }
   virtual void Stop() {}
@@ -107,16 +106,18 @@
   virtual void AddSink(cricket::VideoRenderer* output) {}
   virtual void RemoveSink(cricket::VideoRenderer* 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; }
 
  protected:
-  FakeVideoSource() : state_(kLive) {}
+  explicit FakeVideoSource(bool remote) : state_(kLive), remote_(remote) {}
   ~FakeVideoSource() {}
 
  private:
   cricket::FakeVideoCapturer fake_capturer_;
   SourceState state_;
+  bool remote_;
   cricket::VideoOptions options_;
 };
 
@@ -124,7 +125,11 @@
  public:
   virtual void SetUp() {
     stream_ = MediaStream::Create(kStreamLabel1);
-    rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create());
+  }
+
+  void AddVideoTrack(bool remote) {
+    rtc::scoped_refptr<VideoSourceInterface> source(
+        FakeVideoSource::Create(remote));
     video_track_ = VideoTrack::Create(kVideoTrackId, source);
     EXPECT_TRUE(stream_->AddTrack(video_track_));
   }
@@ -140,6 +145,7 @@
   }
 
   void CreateVideoRtpSender() {
+    AddVideoTrack(false);
     EXPECT_CALL(video_provider_,
                 SetCaptureDevice(
                     kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
@@ -162,7 +168,7 @@
   }
 
   void CreateAudioRtpReceiver() {
-    audio_track_ = RemoteAudioTrack::Create(
+    audio_track_ = AudioTrack::Create(
         kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
     EXPECT_TRUE(stream_->AddTrack(audio_track_));
     EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
@@ -171,6 +177,7 @@
   }
 
   void CreateVideoRtpReceiver() {
+    AddVideoTrack(true);
     EXPECT_CALL(video_provider_,
                 SetVideoPlayout(kVideoSsrc, true,
                                 video_track_->GetSource()->FrameInput()));
@@ -355,6 +362,7 @@
 // Test that a video sender calls the expected methods on the provider once
 // it has a track and SSRC, when the SSRC is set first.
 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
+  AddVideoTrack(false);
   rtc::scoped_refptr<VideoRtpSender> sender =
       new VideoRtpSender(&video_provider_);
   sender->SetSsrc(kVideoSsrc);
@@ -372,6 +380,7 @@
 // Test that a video sender calls the expected methods on the provider once
 // it has a track and SSRC, when the SSRC is set last.
 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
+  AddVideoTrack(false);
   rtc::scoped_refptr<VideoRtpSender> sender =
       new VideoRtpSender(&video_provider_);
   sender->SetTrack(video_track_);
@@ -407,6 +416,7 @@
 // Test that the sender is disconnected from the provider when its SSRC is
 // set to 0.
 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
+  AddVideoTrack(false);
   EXPECT_CALL(video_provider_,
               SetCaptureDevice(kVideoSsrc,
                                video_track_->GetSource()->GetVideoCapturer()));
@@ -442,6 +452,7 @@
 }
 
 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
+  AddVideoTrack(false);
   EXPECT_CALL(video_provider_,
               SetCaptureDevice(kVideoSsrc,
                                video_track_->GetSource()->GetVideoCapturer()));
@@ -461,6 +472,7 @@
 }
 
 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
+  AddVideoTrack(false);
   rtc::scoped_refptr<AudioTrackInterface> track =
       AudioTrack::Create(kAudioTrackId, nullptr);
   EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
@@ -477,6 +489,7 @@
 }
 
 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
+  AddVideoTrack(false);
   EXPECT_CALL(video_provider_,
               SetCaptureDevice(kVideoSsrc,
                                video_track_->GetSource()->GetVideoCapturer()));
diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc
index 5cef7be..5bd735a 100644
--- a/talk/app/webrtc/videosource.cc
+++ b/talk/app/webrtc/videosource.cc
@@ -331,21 +331,23 @@
 rtc::scoped_refptr<VideoSource> VideoSource::Create(
     cricket::ChannelManager* channel_manager,
     cricket::VideoCapturer* capturer,
-    const webrtc::MediaConstraintsInterface* constraints) {
+    const webrtc::MediaConstraintsInterface* constraints,
+    bool remote) {
   ASSERT(channel_manager != NULL);
   ASSERT(capturer != NULL);
-  rtc::scoped_refptr<VideoSource> source(
-      new rtc::RefCountedObject<VideoSource>(channel_manager,
-                                                   capturer));
+  rtc::scoped_refptr<VideoSource> source(new rtc::RefCountedObject<VideoSource>(
+      channel_manager, capturer, remote));
   source->Initialize(constraints);
   return source;
 }
 
 VideoSource::VideoSource(cricket::ChannelManager* channel_manager,
-                         cricket::VideoCapturer* capturer)
+                         cricket::VideoCapturer* capturer,
+                         bool remote)
     : channel_manager_(channel_manager),
       video_capturer_(capturer),
-      state_(kInitializing) {
+      state_(kInitializing),
+      remote_(remote) {
   channel_manager_->SignalVideoCaptureStateChange.connect(
       this, &VideoSource::OnStateChange);
 }
diff --git a/talk/app/webrtc/videosource.h b/talk/app/webrtc/videosource.h
index 8253cba..98c1e08 100644
--- a/talk/app/webrtc/videosource.h
+++ b/talk/app/webrtc/videosource.h
@@ -66,9 +66,12 @@
   static rtc::scoped_refptr<VideoSource> Create(
       cricket::ChannelManager* channel_manager,
       cricket::VideoCapturer* capturer,
-      const webrtc::MediaConstraintsInterface* constraints);
+      const webrtc::MediaConstraintsInterface* constraints,
+      bool remote);
 
-  virtual SourceState state() const { return state_; }
+  SourceState state() const override { return state_; }
+  bool remote() const override { return remote_; }
+
   virtual const cricket::VideoOptions* options() const { return &options_; }
   virtual cricket::VideoRenderer* FrameInput();
 
@@ -86,7 +89,8 @@
 
  protected:
   VideoSource(cricket::ChannelManager* channel_manager,
-              cricket::VideoCapturer* capturer);
+              cricket::VideoCapturer* capturer,
+              bool remote);
   virtual ~VideoSource();
   void Initialize(const webrtc::MediaConstraintsInterface* constraints);
 
@@ -104,6 +108,7 @@
   cricket::VideoFormat format_;
   cricket::VideoOptions options_;
   SourceState state_;
+  const bool remote_;
 };
 
 }  // namespace webrtc
diff --git a/talk/app/webrtc/videosource_unittest.cc b/talk/app/webrtc/videosource_unittest.cc
index 8d6d6ac..6f1df34 100644
--- a/talk/app/webrtc/videosource_unittest.cc
+++ b/talk/app/webrtc/videosource_unittest.cc
@@ -144,9 +144,9 @@
   void CreateVideoSource(
       const webrtc::MediaConstraintsInterface* constraints) {
     // VideoSource take ownership of |capturer_|
-    source_ = VideoSource::Create(channel_manager_.get(),
-                                  capturer_cleanup_.release(),
-                                  constraints);
+    source_ =
+        VideoSource::Create(channel_manager_.get(), capturer_cleanup_.release(),
+                            constraints, false);
 
     ASSERT_TRUE(source_.get() != NULL);
     EXPECT_EQ(capturer_, source_->GetVideoCapturer());
@@ -210,8 +210,7 @@
 // RemoteVideoCapturer and takes video frames from FrameInput.
 TEST_F(VideoSourceTest, StartStopRemote) {
   source_ = VideoSource::Create(channel_manager_.get(),
-                                new webrtc::RemoteVideoCapturer(),
-                                NULL);
+                                new webrtc::RemoteVideoCapturer(), NULL, true);
 
   ASSERT_TRUE(source_.get() != NULL);
   EXPECT_TRUE(NULL != source_->GetVideoCapturer());
diff --git a/talk/app/webrtc/videosourceproxy.h b/talk/app/webrtc/videosourceproxy.h
index 677fa9c..ce96e8e 100644
--- a/talk/app/webrtc/videosourceproxy.h
+++ b/talk/app/webrtc/videosourceproxy.h
@@ -38,6 +38,7 @@
 // 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)
diff --git a/talk/app/webrtc/videotrack_unittest.cc b/talk/app/webrtc/videotrack_unittest.cc
index 609ee80..013d925 100644
--- a/talk/app/webrtc/videotrack_unittest.cc
+++ b/talk/app/webrtc/videotrack_unittest.cc
@@ -62,7 +62,7 @@
     video_track_ = VideoTrack::Create(
         kVideoTrackId,
         VideoSource::Create(channel_manager_.get(),
-                            new webrtc::RemoteVideoCapturer(), NULL));
+                            new webrtc::RemoteVideoCapturer(), NULL, true));
   }
 
  protected:
diff --git a/talk/libjingle.gyp b/talk/libjingle.gyp
index 4ad1e39..e8035fe 100755
--- a/talk/libjingle.gyp
+++ b/talk/libjingle.gyp
@@ -763,8 +763,6 @@
         'app/webrtc/proxy.h',
         'app/webrtc/remoteaudiosource.cc',
         'app/webrtc/remoteaudiosource.h',
-        'app/webrtc/remoteaudiotrack.cc',
-        'app/webrtc/remoteaudiotrack.h',
         'app/webrtc/remotevideocapturer.cc',
         'app/webrtc/remotevideocapturer.h',
         'app/webrtc/rtpreceiver.cc',