Delete MediaMonitor.

Bug: webrtc:8760
Change-Id: Ie9dd0d2836ad9c03d1cb2a64fabd664fb6045c80
Reviewed-on: https://webrtc-review.googlesource.com/39007
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Noah Richards <noahric@google.com>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21650}
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 7db227e..27679ac 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -45,8 +45,6 @@
     "externalhmac.h",
     "jseptransport.cc",
     "jseptransport.h",
-    "mediamonitor.cc",
-    "mediamonitor.h",
     "mediasession.cc",
     "mediasession.h",
     "rtcpmuxfilter.cc",
diff --git a/pc/channel.cc b/pc/channel.cc
index 3327d29..954cdce 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -1181,7 +1181,6 @@
 VoiceChannel::~VoiceChannel() {
   TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
   StopAudioMonitor();
-  StopMediaMonitor();
   // this can't be done in the base class, since it calls a virtual
   DisableMedia_w();
   Deinit();
@@ -1217,22 +1216,6 @@
                                                   media_channel(), stats));
 }
 
-void VoiceChannel::StartMediaMonitor(int cms) {
-  media_monitor_.reset(new VoiceMediaMonitor(media_channel(), worker_thread(),
-      rtc::Thread::Current()));
-  media_monitor_->SignalUpdate.connect(
-      this, &VoiceChannel::OnMediaMonitorUpdate);
-  media_monitor_->Start(cms);
-}
-
-void VoiceChannel::StopMediaMonitor() {
-  if (media_monitor_) {
-    media_monitor_->Stop();
-    media_monitor_->SignalUpdate.disconnect(this);
-    media_monitor_.reset();
-  }
-}
-
 void VoiceChannel::StartAudioMonitor(int cms) {
   audio_monitor_.reset(new AudioMonitor(this, rtc::Thread::Current()));
   audio_monitor_->Start(cms);
@@ -1419,12 +1402,6 @@
   SignalConnectionMonitor(this, infos);
 }
 
-void VoiceChannel::OnMediaMonitorUpdate(
-    VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) {
-  RTC_DCHECK(media_channel == this->media_channel());
-  SignalMediaMonitor(this, info);
-}
-
 VideoChannel::VideoChannel(rtc::Thread* worker_thread,
                            rtc::Thread* network_thread,
                            rtc::Thread* signaling_thread,
@@ -1442,7 +1419,6 @@
 
 VideoChannel::~VideoChannel() {
   TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
-  StopMediaMonitor();
   // this can't be done in the base class, since it calls a virtual
   DisableMedia_w();
 
@@ -1471,21 +1447,6 @@
                                                   media_channel(), stats));
 }
 
-void VideoChannel::StartMediaMonitor(int cms) {
-  media_monitor_.reset(new VideoMediaMonitor(media_channel(), worker_thread(),
-      rtc::Thread::Current()));
-  media_monitor_->SignalUpdate.connect(
-      this, &VideoChannel::OnMediaMonitorUpdate);
-  media_monitor_->Start(cms);
-}
-
-void VideoChannel::StopMediaMonitor() {
-  if (media_monitor_) {
-    media_monitor_->Stop();
-    media_monitor_.reset();
-  }
-}
-
 bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content,
                                      SdpType type,
                                      std::string* error_desc) {
@@ -1597,14 +1558,6 @@
   SignalConnectionMonitor(this, infos);
 }
 
-// TODO(pthatcher): Look into removing duplicate code between
-// audio, video, and data, perhaps by using templates.
-void VideoChannel::OnMediaMonitorUpdate(
-    VideoMediaChannel* media_channel, const VideoMediaInfo &info) {
-  RTC_DCHECK(media_channel == this->media_channel());
-  SignalMediaMonitor(this, info);
-}
-
 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread,
                                rtc::Thread* network_thread,
                                rtc::Thread* signaling_thread,
@@ -1622,7 +1575,6 @@
 
 RtpDataChannel::~RtpDataChannel() {
   TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel");
-  StopMediaMonitor();
   // this can't be done in the base class, since it calls a virtual
   DisableMedia_w();
 
@@ -1834,28 +1786,6 @@
   SignalConnectionMonitor(this, infos);
 }
 
-void RtpDataChannel::StartMediaMonitor(int cms) {
-  media_monitor_.reset(new DataMediaMonitor(media_channel(), worker_thread(),
-      rtc::Thread::Current()));
-  media_monitor_->SignalUpdate.connect(this,
-                                       &RtpDataChannel::OnMediaMonitorUpdate);
-  media_monitor_->Start(cms);
-}
-
-void RtpDataChannel::StopMediaMonitor() {
-  if (media_monitor_) {
-    media_monitor_->Stop();
-    media_monitor_->SignalUpdate.disconnect(this);
-    media_monitor_.reset();
-  }
-}
-
-void RtpDataChannel::OnMediaMonitorUpdate(DataMediaChannel* media_channel,
-                                          const DataMediaInfo& info) {
-  RTC_DCHECK(media_channel == this->media_channel());
-  SignalMediaMonitor(this, info);
-}
-
 void RtpDataChannel::OnDataReceived(const ReceiveDataParams& params,
                                     const char* data,
                                     size_t len) {
diff --git a/pc/channel.h b/pc/channel.h
index 28f6a46..75299d5 100644
--- a/pc/channel.h
+++ b/pc/channel.h
@@ -31,7 +31,6 @@
 #include "p2p/client/socketmonitor.h"
 #include "pc/audiomonitor.h"
 #include "pc/dtlssrtptransport.h"
-#include "pc/mediamonitor.h"
 #include "pc/mediasession.h"
 #include "pc/rtcpmuxfilter.h"
 #include "pc/rtptransport.h"
@@ -489,10 +488,6 @@
   sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
       SignalConnectionMonitor;
 
-  void StartMediaMonitor(int cms);
-  void StopMediaMonitor();
-  sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
-
   void StartAudioMonitor(int cms);
   void StopAudioMonitor();
   bool IsAudioMonitorRunning() const;
@@ -522,13 +517,10 @@
   void OnConnectionMonitorUpdate(
       ConnectionMonitor* monitor,
       const std::vector<ConnectionInfo>& infos) override;
-  void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
-                            const VoiceMediaInfo& info);
 
   static const int kEarlyMediaTimeout = 1000;
   MediaEngineInterface* media_engine_;
   bool received_media_ = false;
-  std::unique_ptr<VoiceMediaMonitor> media_monitor_;
   std::unique_ptr<AudioMonitor> audio_monitor_;
 
   // Last AudioSendParameters sent down to the media_channel() via
@@ -563,10 +555,6 @@
   sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
       SignalConnectionMonitor;
 
-  void StartMediaMonitor(int cms);
-  void StopMediaMonitor();
-  sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
-
   cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
 
  private:
@@ -583,10 +571,6 @@
   void OnConnectionMonitorUpdate(
       ConnectionMonitor* monitor,
       const std::vector<ConnectionInfo>& infos) override;
-  void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
-                            const VideoMediaInfo& info);
-
-  std::unique_ptr<VideoMediaMonitor> media_monitor_;
 
   // Last VideoSendParameters sent down to the media_channel() via
   // SetSendParameters.
@@ -619,15 +603,11 @@
                         const rtc::CopyOnWriteBuffer& payload,
                         SendDataResult* result);
 
-  void StartMediaMonitor(int cms);
-  void StopMediaMonitor();
-
   // Should be called on the signaling thread only.
   bool ready_to_send_data() const {
     return ready_to_send_data_;
   }
 
-  sigslot::signal2<RtpDataChannel*, const DataMediaInfo&> SignalMediaMonitor;
   sigslot::signal2<RtpDataChannel*, const std::vector<ConnectionInfo>&>
       SignalConnectionMonitor;
 
@@ -693,13 +673,10 @@
   void OnConnectionMonitorUpdate(
       ConnectionMonitor* monitor,
       const std::vector<ConnectionInfo>& infos) override;
-  void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
-                            const DataMediaInfo& info);
   void OnDataReceived(
       const ReceiveDataParams& params, const char* data, size_t len);
   void OnDataChannelReadyToSend(bool writable);
 
-  std::unique_ptr<DataMediaMonitor> media_monitor_;
   bool ready_to_send_data_ = false;
 
   // Last DataSendParameters sent down to the media_channel() via
diff --git a/pc/channel_unittest.cc b/pc/channel_unittest.cc
index 7e3b459..e7a50dc 100644
--- a/pc/channel_unittest.cc
+++ b/pc/channel_unittest.cc
@@ -45,7 +45,7 @@
 const int kAudioPts[] = {0, 8};
 const int kVideoPts[] = {97, 99};
 enum class NetworkIsWorker { Yes, No };
-const int kDefaultTimeout = 10000;  // 10 seconds.
+
 }  // namespace
 
 template <class ChannelT,
@@ -248,10 +248,6 @@
         CreateChannel(worker_thread, network_thread_, &media_engine_,
                       std::move(ch2), fake_rtp_dtls_transport2_.get(),
                       fake_rtcp_dtls_transport2_.get(), rtp2, rtcp2, flags2);
-    channel1_->SignalMediaMonitor.connect(this,
-                                          &ChannelTest<T>::OnMediaMonitor1);
-    channel2_->SignalMediaMonitor.connect(this,
-                                          &ChannelTest<T>::OnMediaMonitor2);
     channel1_->SignalRtcpMuxFullyActive.connect(
         this, &ChannelTest<T>::OnRtcpMuxFullyActive1);
     channel2_->SignalRtcpMuxFullyActive.connect(
@@ -541,16 +537,6 @@
     return false;  // overridden in specialized classes
   }
 
-  void OnMediaMonitor1(typename T::Channel* channel,
-                       const typename T::MediaInfo& info) {
-    RTC_DCHECK_EQ(channel, channel1_.get());
-    media_info_callbacks1_++;
-  }
-  void OnMediaMonitor2(typename T::Channel* channel,
-                       const typename T::MediaInfo& info) {
-    RTC_DCHECK_EQ(channel, channel2_.get());
-    media_info_callbacks2_++;
-  }
   void OnRtcpMuxFullyActive1(const std::string&) {
     rtcp_mux_activated_callbacks1_++;
   }
@@ -1658,26 +1644,6 @@
     EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
   }
 
-  // Test that the media monitor can be run and gives callbacks.
-  void TestMediaMonitor() {
-    CreateChannels(0, 0);
-    EXPECT_TRUE(SendInitiate());
-    EXPECT_TRUE(SendAccept());
-    channel1_->StartMediaMonitor(100);
-    channel2_->StartMediaMonitor(100);
-    // Ensure we get callbacks and stop.
-    EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
-    EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
-    channel1_->StopMediaMonitor();
-    channel2_->StopMediaMonitor();
-    // Ensure a restart of a stopped monitor works.
-    channel1_->StartMediaMonitor(100);
-    EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
-    channel1_->StopMediaMonitor();
-    // Ensure stopping a stopped monitor is OK.
-    channel1_->StopMediaMonitor();
-  }
-
   void TestSetContentFailure() {
     CreateChannels(0, 0);
 
@@ -1963,8 +1929,6 @@
   // The RTP and RTCP packets to send in the tests.
   rtc::Buffer rtp_packet_;
   rtc::Buffer rtcp_packet_;
-  int media_info_callbacks1_ = 0;
-  int media_info_callbacks2_ = 0;
   int rtcp_mux_activated_callbacks1_ = 0;
   int rtcp_mux_activated_callbacks2_ = 0;
   cricket::CandidatePairInterface* last_selected_candidate_pair_;
@@ -2324,10 +2288,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
   Base::TestSetContentFailure();
 }
@@ -2589,10 +2549,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
   Base::TestSetContentFailure();
 }
@@ -2788,10 +2744,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
   Base::TestSetContentFailure();
 }
@@ -2987,10 +2939,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
   Base::TestSetContentFailure();
 }
@@ -3225,10 +3173,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(RtpDataChannelSingleThreadTest, SocketOptionsMergedOnSetTransport) {
   Base::SocketOptionsMergedOnSetTransport();
 }
@@ -3349,10 +3293,6 @@
   Base::SendWithWritabilityLoss();
 }
 
-TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
-  Base::TestMediaMonitor();
-}
-
 TEST_F(RtpDataChannelDoubleThreadTest, SocketOptionsMergedOnSetTransport) {
   Base::SocketOptionsMergedOnSetTransport();
 }
diff --git a/pc/mediamonitor.cc b/pc/mediamonitor.cc
deleted file mode 100644
index e2e3da8..0000000
--- a/pc/mediamonitor.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- *  Copyright 2005 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "pc/mediamonitor.h"
-#include "pc/channelmanager.h"
-#include "rtc_base/checks.h"
-
-namespace cricket {
-
-enum {
-  MSG_MONITOR_POLL = 1,
-  MSG_MONITOR_START = 2,
-  MSG_MONITOR_STOP = 3,
-  MSG_MONITOR_SIGNAL = 4
-};
-
-MediaMonitor::MediaMonitor(rtc::Thread* worker_thread,
-                           rtc::Thread* monitor_thread)
-    : worker_thread_(worker_thread),
-      monitor_thread_(monitor_thread), monitoring_(false), rate_(0) {
-}
-
-MediaMonitor::~MediaMonitor() {
-  monitoring_ = false;
-  monitor_thread_->Clear(this);
-  worker_thread_->Clear(this);
-}
-
-void MediaMonitor::Start(uint32_t milliseconds) {
-  rate_ = milliseconds;
-  if (rate_ < 100)
-    rate_ = 100;
-  worker_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_START);
-}
-
-void MediaMonitor::Stop() {
-  worker_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_STOP);
-  rate_ = 0;
-}
-
-void MediaMonitor::OnMessage(rtc::Message* message) {
-  rtc::CritScope cs(&crit_);
-
-  switch (message->message_id) {
-  case MSG_MONITOR_START:
-    RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
-    if (!monitoring_) {
-      monitoring_ = true;
-      PollMediaChannel();
-    }
-    break;
-
-  case MSG_MONITOR_STOP:
-    RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
-    if (monitoring_) {
-      monitoring_ = false;
-      worker_thread_->Clear(this);
-    }
-    break;
-
-  case MSG_MONITOR_POLL:
-    RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
-    PollMediaChannel();
-    break;
-
-  case MSG_MONITOR_SIGNAL:
-    RTC_DCHECK(rtc::Thread::Current() == monitor_thread_);
-    Update();
-    break;
-  }
-}
-
-void MediaMonitor::PollMediaChannel() {
-  rtc::CritScope cs(&crit_);
-  RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
-
-  GetStats();
-
-  // Signal the monitoring thread, start another poll timer
-  monitor_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_SIGNAL);
-  worker_thread_->PostDelayed(RTC_FROM_HERE, rate_, this, MSG_MONITOR_POLL);
-}
-
-}  // namespace cricket
diff --git a/pc/mediamonitor.h b/pc/mediamonitor.h
deleted file mode 100644
index fcd2410..0000000
--- a/pc/mediamonitor.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- *  Copyright 2005 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-// Class to collect statistics from a media channel
-
-#ifndef PC_MEDIAMONITOR_H_
-#define PC_MEDIAMONITOR_H_
-
-#include "media/base/mediachannel.h"
-#include "rtc_base/criticalsection.h"
-#include "rtc_base/sigslot.h"
-#include "rtc_base/thread.h"
-#include "rtc_base/thread_annotations.h"
-
-namespace cricket {
-
-// The base MediaMonitor class, independent of voice and video.
-class MediaMonitor : public rtc::MessageHandler,
-    public sigslot::has_slots<> {
- public:
-  MediaMonitor(rtc::Thread* worker_thread,
-               rtc::Thread* monitor_thread);
-  ~MediaMonitor();
-
-  void Start(uint32_t milliseconds);
-  void Stop();
-
- protected:
-  void OnMessage(rtc::Message *message);
-  void PollMediaChannel();
-  virtual void GetStats() = 0;
-  virtual void Update() = 0;
-
-  rtc::CriticalSection crit_;
-  rtc::Thread* worker_thread_;
-  rtc::Thread* monitor_thread_;
-  bool monitoring_;
-  uint32_t rate_;
-};
-
-// Templatized MediaMonitor that can deal with different kinds of media.
-template<class MC, class MI>
-class MediaMonitorT : public MediaMonitor {
- public:
-  MediaMonitorT(MC* media_channel, rtc::Thread* worker_thread,
-                rtc::Thread* monitor_thread)
-      : MediaMonitor(worker_thread, monitor_thread),
-        media_channel_(media_channel) {}
-  sigslot::signal2<MC*, const MI&> SignalUpdate;
-
- protected:
-  // These routines assume the crit_ lock is held by the calling thread.
-  virtual void GetStats() {
-    media_info_.Clear();
-    media_channel_->GetStats(&media_info_);
-  }
-  virtual void Update() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
-    MI stats(media_info_);
-    crit_.Leave();
-    SignalUpdate(media_channel_, stats);
-    crit_.Enter();
-  }
-
- private:
-  MC* media_channel_;
-  MI media_info_;
-};
-
-typedef MediaMonitorT<VoiceMediaChannel, VoiceMediaInfo> VoiceMediaMonitor;
-typedef MediaMonitorT<VideoMediaChannel, VideoMediaInfo> VideoMediaMonitor;
-typedef MediaMonitorT<DataMediaChannel, DataMediaInfo> DataMediaMonitor;
-
-}  // namespace cricket
-
-#endif  // PC_MEDIAMONITOR_H_