Bug 1022235: Make the webrtc LoadManager/LoadMonitor a singleton r=bsmedberg,pkerr a=abillings
authorRandell Jesup <rjesup@jesup.org>
Sat, 14 Jun 2014 17:21:18 -0400
changeset 207001 6c40063b2088a9acaa3694d6821555770279e00f
parent 207000 3f992b7341d0c9b856167c11fed8d883c41ab610
child 207002 514ecd42a161b314ae52591e0613689c2657df34
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, pkerr, abillings
bugs1022235
milestone32.0a2
Bug 1022235: Make the webrtc LoadManager/LoadMonitor a singleton r=bsmedberg,pkerr a=abillings
content/media/webrtc/LoadManager.cpp
content/media/webrtc/LoadManager.h
content/media/webrtc/LoadManagerFactory.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/CodecConfig.h
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.h
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
media/webrtc/signaling/test/mediaconduit_unittests.cpp
--- a/content/media/webrtc/LoadManager.cpp
+++ b/content/media/webrtc/LoadManager.cpp
@@ -10,66 +10,102 @@
 #include "prtime.h"
 #include "prinrval.h"
 #include "prsystem.h"
 
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsReadableUtils.h"
 #include "nsNetUtil.h"
+#include "nsIObserverService.h"
 
 // NSPR_LOG_MODULES=LoadManager:5
 PRLogModuleInfo *gLoadManagerLog = nullptr;
 #undef LOG
 #undef LOG_ENABLED
 #if defined(PR_LOGGING)
 #define LOG(args) PR_LOG(gLoadManagerLog, PR_LOG_DEBUG, args)
 #define LOG_ENABLED() PR_LOG_TEST(gLoadManagerLog, 5)
 #else
 #define LOG(args)
 #define LOG_ENABLED() (false)
 #endif
 
 namespace mozilla {
 
-LoadManager::LoadManager(int aLoadMeasurementInterval,
-                         int aAveragingMeasurements,
-                         float aHighLoadThreshold,
-                         float aLowLoadThreshold)
+/* static */ StaticRefPtr<LoadManagerSingleton> LoadManagerSingleton::sSingleton;
+
+NS_IMPL_ISUPPORTS(LoadManagerSingleton, nsIObserver)
+
+
+LoadManagerSingleton::LoadManagerSingleton(int aLoadMeasurementInterval,
+                                           int aAveragingMeasurements,
+                                           float aHighLoadThreshold,
+                                           float aLowLoadThreshold)
   : mLoadSum(0.0f),
     mLoadSumMeasurements(0),
     mOveruseActive(false),
     mLoadMeasurementInterval(aLoadMeasurementInterval),
     mAveragingMeasurements(aAveragingMeasurements),
     mHighLoadThreshold(aHighLoadThreshold),
     mLowLoadThreshold(aLowLoadThreshold),
-    mCurrentState(webrtc::kLoadNormal)
+    mCurrentState(webrtc::kLoadNormal),
+    mLock("LoadManager")
 {
 #if defined(PR_LOGGING)
   if (!gLoadManagerLog)
     gLoadManagerLog = PR_NewLogModule("LoadManager");
 #endif
   LOG(("LoadManager - Initializing (%dms x %d, %f, %f)",
        mLoadMeasurementInterval, mAveragingMeasurements,
        mHighLoadThreshold, mLowLoadThreshold));
   MOZ_ASSERT(mHighLoadThreshold > mLowLoadThreshold);
   mLoadMonitor = new LoadMonitor(mLoadMeasurementInterval);
   mLoadMonitor->Init(mLoadMonitor);
   mLoadMonitor->SetLoadChangeCallback(this);
 }
 
-LoadManager::~LoadManager()
+LoadManagerSingleton::~LoadManagerSingleton()
 {
   LOG(("LoadManager: shutting down LoadMonitor"));
-  mLoadMonitor->Shutdown();
+  MOZ_ASSERT(!mLoadMonitor, "why wasn't the LoadMonitor shut down in xpcom-shutdown?");
+  if (mLoadMonitor) {
+    mLoadMonitor->Shutdown();
+  }
+}
+
+nsresult
+LoadManagerSingleton::Observe(nsISupports* aSubject, const char* aTopic,
+                     const char16_t* aData)
+{
+  NS_ASSERTION(NS_IsMainThread(), "Observer invoked off the main thread");
+  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
+
+  if (!strcmp(aTopic, "xpcom-shutdown")) {
+    obs->RemoveObserver(this, "xpcom-shutdown");
+    {
+      MutexAutoLock lock(mLock);
+      mObservers.Clear();
+    }
+    if (mLoadMonitor) {
+      mLoadMonitor->Shutdown();
+      mLoadMonitor = nullptr;
+    }
+
+    LOG(("Releasing LoadManager singleton and thread"));
+    // Note: won't be released immediately as the Observer has a ref to us
+    sSingleton = nullptr;
+  }
+  return NS_OK;
 }
 
 void
-LoadManager::LoadChanged(float aSystemLoad, float aProcesLoad)
+LoadManagerSingleton::LoadChanged(float aSystemLoad, float aProcesLoad)
 {
+  MutexAutoLock lock(mLock);
   // Update total load, and total amount of measured seconds.
   mLoadSum += aSystemLoad;
   mLoadSumMeasurements++;
 
   if (mLoadSumMeasurements >= mAveragingMeasurements) {
     double averagedLoad = mLoadSum / (float)mLoadSumMeasurements;
 
     webrtc::CPULoadState oldState = mCurrentState;
@@ -89,52 +125,73 @@ LoadManager::LoadChanged(float aSystemLo
       LoadHasChanged();
 
     mLoadSum = 0;
     mLoadSumMeasurements = 0;
   }
 }
 
 void
-LoadManager::OveruseDetected()
+LoadManagerSingleton::OveruseDetected()
 {
   LOG(("LoadManager - Overuse Detected"));
+  MutexAutoLock lock(mLock);
   mOveruseActive = true;
   if (mCurrentState != webrtc::kLoadStressed) {
     mCurrentState = webrtc::kLoadStressed;
     LoadHasChanged();
   }
 }
 
 void
-LoadManager::NormalUsage()
+LoadManagerSingleton::NormalUsage()
 {
   LOG(("LoadManager - Overuse finished"));
+  MutexAutoLock lock(mLock);
   mOveruseActive = false;
 }
 
 void
-LoadManager::LoadHasChanged()
+LoadManagerSingleton::LoadHasChanged()
 {
+  mLock.AssertCurrentThreadOwns();
   LOG(("LoadManager - Signaling LoadHasChanged to %d listeners", mObservers.Length()));
   for (size_t i = 0; i < mObservers.Length(); i++) {
     mObservers.ElementAt(i)->onLoadStateChanged(mCurrentState);
   }
 }
 
 void
-LoadManager::AddObserver(webrtc::CPULoadStateObserver * aObserver)
+LoadManagerSingleton::AddObserver(webrtc::CPULoadStateObserver * aObserver)
 {
   LOG(("LoadManager - Adding Observer"));
+  MutexAutoLock lock(mLock);
   mObservers.AppendElement(aObserver);
+  if (mObservers.Length() == 1) {
+    if (!mLoadMonitor) {
+      mLoadMonitor = new LoadMonitor(mLoadMeasurementInterval);
+      mLoadMonitor->Init(mLoadMonitor);
+      mLoadMonitor->SetLoadChangeCallback(this);
+    }
+  }
 }
 
 void
-LoadManager::RemoveObserver(webrtc::CPULoadStateObserver * aObserver)
+LoadManagerSingleton::RemoveObserver(webrtc::CPULoadStateObserver * aObserver)
 {
   LOG(("LoadManager - Removing Observer"));
+  MutexAutoLock lock(mLock);
   if (!mObservers.RemoveElement(aObserver)) {
-    LOG(("LOadManager - Element to remove not found"));
+    LOG(("LoadManager - Element to remove not found"));
+  }
+  if (mObservers.Length() == 0) {
+    if (mLoadMonitor) {
+      // Dance to avoid deadlock on mLock!
+      nsRefPtr<LoadMonitor> loadMonitor = mLoadMonitor.forget();
+      MutexAutoUnlock unlock(mLock);
+
+      loadMonitor->Shutdown();
+    }
   }
 }
 
 
 }
--- a/content/media/webrtc/LoadManager.h
+++ b/content/media/webrtc/LoadManager.h
@@ -2,61 +2,106 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _LOADMANAGER_H_
 #define _LOADMANAGER_H_
 
 #include "LoadMonitor.h"
+#include "mozilla/StaticPtr.h"
+#include "mozilla/TimeStamp.h"
+#include "mozilla/Services.h"
+#include "nsTArray.h"
+#include "nsIObserver.h"
+
 #include "webrtc/common_types.h"
 #include "webrtc/video_engine/include/vie_base.h"
-#include "mozilla/TimeStamp.h"
-#include "nsTArray.h"
 
 extern PRLogModuleInfo *gLoadManagerLog;
 
 namespace mozilla {
 
-class LoadManager : public LoadNotificationCallback,
-                    public webrtc::CPULoadStateCallbackInvoker,
-                    public webrtc::CpuOveruseObserver
+class LoadManagerSingleton : public LoadNotificationCallback,
+                             public webrtc::CPULoadStateCallbackInvoker,
+                             public webrtc::CpuOveruseObserver,
+                             public nsIObserver
+
 {
 public:
-    LoadManager(int aLoadMeasurementInterval,
-                int aAveragingMeasurements,
-                float aHighLoadThreshold,
-                float aLowLoadThreshold);
-    ~LoadManager();
+    static LoadManagerSingleton* Get();
+
+    NS_DECL_THREADSAFE_ISUPPORTS
+    NS_DECL_NSIOBSERVER
 
     // LoadNotificationCallback interface
     virtual void LoadChanged(float aSystemLoad, float aProcessLoad) MOZ_OVERRIDE;
     // CpuOveruseObserver interface
     // Called as soon as an overuse is detected.
     virtual void OveruseDetected() MOZ_OVERRIDE;
     // Called periodically when the system is not overused any longer.
     virtual void NormalUsage() MOZ_OVERRIDE;
     // CPULoadStateCallbackInvoker interface
     virtual void AddObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE;
     virtual void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE;
 
 private:
+    LoadManagerSingleton(int aLoadMeasurementInterval,
+                         int aAveragingMeasurements,
+                         float aHighLoadThreshold,
+                         float aLowLoadThreshold);
+    ~LoadManagerSingleton();
+
     void LoadHasChanged();
 
     nsRefPtr<LoadMonitor> mLoadMonitor;
+
+    // This protexts access to the mObservers list, the current state, pretty much all
+    // the other members (below)
+    Mutex mLock;
+    nsTArray<webrtc::CPULoadStateObserver*> mObservers;
+    webrtc::CPULoadState mCurrentState;
+    // Set when overuse was signaled to us, and hasn't been un-signaled yet.
+    bool  mOveruseActive;
     float mLoadSum;
     int   mLoadSumMeasurements;
-    // Set when overuse was signaled to us, and hasn't been un-signaled yet.
-    bool  mOveruseActive;
     // Load measurement settings
     int mLoadMeasurementInterval;
     int mAveragingMeasurements;
     float mHighLoadThreshold;
     float mLowLoadThreshold;
 
-    webrtc::CPULoadState mCurrentState;
+    static StaticRefPtr<LoadManagerSingleton> sSingleton;
+};
+
+class LoadManager MOZ_FINAL : public webrtc::CPULoadStateCallbackInvoker,
+                              public webrtc::CpuOveruseObserver
+{
+public:
+    LoadManager(LoadManagerSingleton* aManager)
+        : mManager(aManager)
+    {}
+    ~LoadManager() {}
 
-    nsTArray<webrtc::CPULoadStateObserver*> mObservers;
+    void AddObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE
+    {
+        mManager->AddObserver(aObserver);
+    }
+    void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE
+    {
+        mManager->RemoveObserver(aObserver);
+    }
+    void OveruseDetected() MOZ_OVERRIDE
+    {
+        mManager->OveruseDetected();
+    }
+    void NormalUsage() MOZ_OVERRIDE
+    {
+        mManager->NormalUsage();
+    }
+
+private:
+    LoadManagerSingleton* mManager;
 };
 
 } //namespace
 
 #endif /* _LOADMANAGER_H_ */
--- a/content/media/webrtc/LoadManagerFactory.cpp
+++ b/content/media/webrtc/LoadManagerFactory.cpp
@@ -1,38 +1,49 @@
 /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "LoadManager.h"
 #include "LoadManagerFactory.h"
 #include "MainThreadUtils.h"
+#include "nsIObserverService.h"
 
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
 
-LoadManager* LoadManagerBuild(void)
+// Assume stored in an nsAutoPtr<>
+LoadManager *
+LoadManagerBuild(void)
 {
-  MOZ_ASSERT(NS_IsMainThread());
-
-  int loadMeasurementInterval =
-    mozilla::Preferences::GetInt("media.navigator.load_adapt.measure_interval", 1000);
-  int averagingSeconds =
-    mozilla::Preferences::GetInt("media.navigator.load_adapt.avg_seconds", 3);
-  float highLoadThreshold =
-    mozilla::Preferences::GetFloat("media.navigator.load_adapt.high_load", 0.90);
-  float lowLoadThreshold =
-    mozilla::Preferences::GetFloat("media.navigator.load_adapt.low_load", 0.40);
-
-  return new LoadManager(loadMeasurementInterval,
-                         averagingSeconds,
-                         highLoadThreshold,
-                         lowLoadThreshold);
+  return new LoadManager(LoadManagerSingleton::Get());
 }
 
-void LoadManagerDestroy(mozilla::LoadManager* aLoadManager)
-{
-  delete aLoadManager;
+/* static */  LoadManagerSingleton*
+LoadManagerSingleton::Get() {
+  if (!sSingleton) {
+    MOZ_ASSERT(NS_IsMainThread());
+
+    int loadMeasurementInterval =
+      mozilla::Preferences::GetInt("media.navigator.load_adapt.measure_interval", 1000);
+    int averagingSeconds =
+      mozilla::Preferences::GetInt("media.navigator.load_adapt.avg_seconds", 3);
+    float highLoadThreshold =
+      mozilla::Preferences::GetFloat("media.navigator.load_adapt.high_load", 0.90);
+    float lowLoadThreshold =
+      mozilla::Preferences::GetFloat("media.navigator.load_adapt.low_load", 0.40);
+
+    sSingleton = new LoadManagerSingleton(loadMeasurementInterval,
+                                          averagingSeconds,
+                                          highLoadThreshold,
+                                          lowLoadThreshold);
+
+    nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
+    if (obs) {
+      obs->AddObserver(sSingleton, "xpcom-shutdown", false);
+    }
+  }
+  return sSingleton;
 }
 
 }; // namespace
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -411,18 +411,17 @@ WebrtcAudioConduit::ConfigureSendMediaCo
   //Copy the applied config for future reference.
   delete mCurSendCodecConfig;
 
   mCurSendCodecConfig = new AudioCodecConfig(codecConfig->mType,
                                               codecConfig->mName,
                                               codecConfig->mFreq,
                                               codecConfig->mPacSize,
                                               codecConfig->mChannels,
-                                              codecConfig->mRate,
-                                              codecConfig->mLoadManager);
+                                              codecConfig->mRate);
 
   mEngineTransmitting = true;
   return kMediaConduitNoError;
 }
 
 MediaConduitErrorCode
 WebrtcAudioConduit::ConfigureRecvMediaCodecs(
                     const std::vector<AudioCodecConfig*>& codecConfigList)
@@ -905,18 +904,17 @@ bool
 WebrtcAudioConduit::CopyCodecToDB(const AudioCodecConfig* codecInfo)
 {
 
   AudioCodecConfig* cdcConfig = new AudioCodecConfig(codecInfo->mType,
                                                      codecInfo->mName,
                                                      codecInfo->mFreq,
                                                      codecInfo->mPacSize,
                                                      codecInfo->mChannels,
-                                                     codecInfo->mRate,
-                                                     codecInfo->mLoadManager);
+                                                     codecInfo->mRate);
   mRecvCodecList.push_back(cdcConfig);
   return true;
 }
 
 /**
  * Checks if 2 codec structs are same
  */
 bool
--- a/media/webrtc/signaling/src/media-conduit/CodecConfig.h
+++ b/media/webrtc/signaling/src/media-conduit/CodecConfig.h
@@ -6,49 +6,44 @@
 #ifndef CODEC_CONFIG_H_
 #define CODEC_CONFIG_H_
 
 #include <string>
 #include "ccsdp_rtcp_fb.h"
 
 namespace mozilla {
 
-class LoadManager;
-
 /**
  * Minimalistic Audio Codec Config Params
  */
 struct AudioCodecConfig
 {
   /*
    * The data-types for these properties mimic the
    * corresponding webrtc::CodecInst data-types.
    */
   int mType;
   std::string mName;
   int mFreq;
   int mPacSize;
   int mChannels;
   int mRate;
-  LoadManager* mLoadManager;
 
   /* Default constructor is not provided since as a consumer, we
    * can't decide the default configuration for the codec
    */
   explicit AudioCodecConfig(int type, std::string name,
                             int freq,int pacSize,
-                            int channels, int rate,
-                            LoadManager* load_manager = nullptr)
+                            int channels, int rate)
                                                    : mType(type),
                                                      mName(name),
                                                      mFreq(freq),
                                                      mPacSize(pacSize),
                                                      mChannels(channels),
-                                                     mRate(rate),
-                                                     mLoadManager(load_manager)
+                                                     mRate(rate)
 
   {
   }
 };
 
 /*
  * Minimalisitc video codec configuration
  * More to be added later depending on the use-case
@@ -60,54 +55,49 @@ struct VideoCodecConfig
    * The data-types for these properties mimic the
    * corresponding webrtc::VideoCodec data-types.
    */
   int mType; // payload type
   std::string mName;
   uint32_t mRtcpFbTypes;
   unsigned int mMaxFrameSize;
   unsigned int mMaxFrameRate;
-  LoadManager* mLoadManager;
   uint8_t mProfile;
   uint8_t mConstraints;
   uint8_t mLevel;
   uint8_t mPacketizationMode;
   // TODO: add external negotiated SPS/PPS
 
   VideoCodecConfig(int type,
                    std::string name,
                    int rtcpFbTypes,
-                   LoadManager* load_manager = nullptr,
                    uint8_t profile = 0x42,
                    uint8_t constraints = 0xC0,
                    uint8_t level = 30,
                    uint8_t packetization = 0) :
                                      mType(type),
                                      mName(name),
                                      mRtcpFbTypes(rtcpFbTypes),
                                      mMaxFrameSize(0),
                                      mMaxFrameRate(0),
-                                     mLoadManager(load_manager),
                                      mProfile(profile),
                                      mConstraints(constraints),
                                      mLevel(level),
                                      mPacketizationMode(packetization) {}
 
   VideoCodecConfig(int type,
                    std::string name,
                    int rtcpFbTypes,
                    unsigned int max_fs,
-                   unsigned int max_fr,
-                   LoadManager* load_manager = nullptr) :
+                   unsigned int max_fr) :
                                          mType(type),
                                          mName(name),
                                          mRtcpFbTypes(rtcpFbTypes),
                                          mMaxFrameSize(max_fs),
-                                         mMaxFrameRate(max_fr),
-                                         mLoadManager(load_manager) {}
+                                         mMaxFrameRate(max_fr) {}
 
   bool RtcpFbIsSet(sdp_rtcp_fb_nack_type_e type) const
   {
     return mRtcpFbTypes & sdp_rtcp_fb_nack_to_bitmap(type);
   }
 
   bool RtcpFbIsSet(sdp_rtcp_fb_ack_type_e type) const
   {
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -270,16 +270,21 @@ MediaConduitErrorCode WebrtcVideoConduit
       NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.start_bitrate", &temp)));
       if (temp >= 0) {
         mStartBitrate = temp;
       }
       NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.max_bitrate", &temp)));
       if (temp >= 0) {
         mMaxBitrate = temp;
       }
+      bool use_loadmanager = false;
+      NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.navigator.load_adapt", &use_loadmanager)));
+      if (use_loadmanager) {
+        mLoadManager = LoadManagerBuild();
+      }
     }
   }
 #endif
 
   if (other) {
     MOZ_ASSERT(!other->mOtherDirection);
     other->mOtherDirection = this;
     mOtherDirection = other;
@@ -547,19 +552,19 @@ WebrtcVideoConduit::ConfigureSendMediaCo
       CSFLogError(logTag, "%s StopSend() Failed %d ",__FUNCTION__,
                   mPtrViEBase->LastError());
       return kMediaConduitUnknownError;
     }
 
     mEngineTransmitting = false;
   }
 
-  if (codecConfig->mLoadManager) {
-    mPtrViEBase->RegisterCpuOveruseObserver(mChannel, codecConfig->mLoadManager);
-    mPtrViEBase->SetLoadManager(codecConfig->mLoadManager);
+  if (mLoadManager) {
+    mPtrViEBase->RegisterCpuOveruseObserver(mChannel, mLoadManager);
+    mPtrViEBase->SetLoadManager(mLoadManager);
   }
 
   if (mExternalSendCodec &&
       codecConfig->mType == mExternalSendCodec->mType) {
     CSFLogError(logTag, "%s Configuring External H264 Send Codec", __FUNCTION__);
 
     // width/height will be overridden on the first frame
     video_codec.width = 320;
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h
@@ -6,16 +6,17 @@
 #define VIDEO_SESSION_H_
 
 #include "nsAutoPtr.h"
 #include "mozilla/Attributes.h"
 
 #include "MediaConduitInterface.h"
 #include "MediaEngineWrapper.h"
 #include "CodecStatistics.h"
+#include "LoadManagerFactory.h"
 
 // conflicts with #include of scoped_ptr.h
 #undef FF
 // Video Engine Includes
 #include "webrtc/common_types.h"
 #ifdef FF
 #undef FF // Avoid name collision between scoped_ptr.h and nsCRTGlue.h.
 #endif
@@ -353,13 +354,15 @@ private:
 
   mozilla::RefPtr<WebrtcAudioConduit> mSyncedTo;
 
   nsAutoPtr<VideoCodecConfig> mExternalSendCodec;
   nsAutoPtr<VideoCodecConfig> mExternalRecvCodec;
 
   // statistics object for video codec;
   nsAutoPtr<VideoCodecStatistics> mVideoCodecStat;
+
+  nsAutoPtr<LoadManager> mLoadManager;
 };
 
 } // end namespace
 
 #endif
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -1687,18 +1687,17 @@ static int vcmRxStartICE_m(cc_mcapid_t m
     for(int i=0; i <num_payloads ; i++)
     {
       config_raw = new mozilla::AudioCodecConfig(
         payloads[i].remote_rtp_pt,
         ccsdpCodecName(payloads[i].codec_type),
         payloads[i].audio.frequency,
         payloads[i].audio.packet_size,
         payloads[i].audio.channels,
-        payloads[i].audio.bitrate,
-        pc.impl()->load_manager());
+        payloads[i].audio.bitrate);
       configs.push_back(config_raw);
     }
 
     if (conduit->ConfigureRecvMediaCodecs(configs))
       return VCM_ERROR;
 
     // Now we have all the pieces, create the pipeline
     mozilla::RefPtr<mozilla::MediaPipelineReceiveAudio> pipeline =
@@ -1745,18 +1744,17 @@ static int vcmRxStartICE_m(cc_mcapid_t m
 
     mozilla::VideoCodecConfig *config_raw;
 
     for(int i=0; i <num_payloads; i++)
     {
       config_raw = new mozilla::VideoCodecConfig(
         payloads[i].remote_rtp_pt,
         ccsdpCodecName(payloads[i].codec_type),
-        payloads[i].video.rtcp_fb_types,
-        pc.impl()->load_manager());
+        payloads[i].video.rtcp_fb_types);
       if (vcmEnsureExternalCodec(conduit, config_raw, false)) {
         continue;
       }
       configs.push_back(config_raw);
     }
 
     if (conduit->ConfigureRecvMediaCodecs(configs))
       return VCM_ERROR;
@@ -2345,18 +2343,17 @@ static int vcmTxCreateAudioConduit(int l
 {
   mozilla::AudioCodecConfig *config_raw =
     new mozilla::AudioCodecConfig(
       payload->remote_rtp_pt,
       ccsdpCodecName(payload->codec_type),
       payload->audio.frequency,
       payload->audio.packet_size,
       payload->audio.channels,
-      payload->audio.bitrate,
-      pc.impl()->load_manager());
+      payload->audio.bitrate);
 
   // Take possession of this pointer
   mozilla::ScopedDeletePtr<mozilla::AudioCodecConfig> config(config_raw);
 
   // Instantiate an appropriate conduit
   mozilla::RefPtr<mozilla::MediaSessionConduit> rx_conduit =
     pc.impl()->media()->GetConduit(level, true);
   MOZ_ASSERT_IF(rx_conduit, rx_conduit->type() == MediaSessionConduit::AUDIO);
@@ -2393,18 +2390,17 @@ static int vcmTxCreateVideoConduit(int l
                                    mozilla::RefPtr<mozilla::MediaSessionConduit> &conduit)
 {
   mozilla::VideoCodecConfig *config_raw;
   config_raw = new mozilla::VideoCodecConfig(
     payload->remote_rtp_pt,
     ccsdpCodecName(payload->codec_type),
     payload->video.rtcp_fb_types,
     payload->video.max_fs,
-    payload->video.max_fr,
-    pc.impl()->load_manager());
+    payload->video.max_fr);
 
   // Take possession of this pointer
   mozilla::ScopedDeletePtr<mozilla::VideoCodecConfig> config(config_raw);
 
   // Instantiate an appropriate conduit
   mozilla::RefPtr<mozilla::MediaSessionConduit> rx_conduit =
     pc.impl()->media()->GetConduit(level, true);
   MOZ_ASSERT_IF(rx_conduit, rx_conduit->type() == MediaSessionConduit::VIDEO);
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -484,17 +484,16 @@ PeerConnectionImpl::PeerConnectionImpl(c
   , mInternal(new Internal())
   , mSignalingState(PCImplSignalingState::SignalingStable)
   , mIceConnectionState(PCImplIceConnectionState::New)
   , mIceGatheringState(PCImplIceGatheringState::New)
   , mDtlsConnected(false)
   , mWindow(nullptr)
   , mIdentity(nullptr)
   , mSTSThread(nullptr)
-  , mLoadManager(nullptr)
   , mMedia(nullptr)
   , mNumAudioStreams(0)
   , mNumVideoStreams(0)
   , mHaveDataStream(false)
   , mAddCandidateErrorCount(0)
   , mTrickle(true) // TODO(ekr@rtfm.com): Use pref
 {
 #ifdef MOZILLA_INTERNAL_API
@@ -533,20 +532,16 @@ PeerConnectionImpl::~PeerConnectionImpl(
   {
     // Deregister as an NSS Shutdown Object
     nsNSSShutDownPreventionLock locker;
     if (!isAlreadyShutDown()) {
       destructorSafeDestroyNSSReference();
       shutdown(calledFromObject);
     }
   }
-  if (mLoadManager) {
-      mozilla::LoadManagerDestroy(mLoadManager);
-      mLoadManager = nullptr;
-  }
 #endif
 
   // Since this and Initialize() occur on MainThread, they can't both be
   // running at once
 
   // Right now, we delete PeerConnectionCtx at XPCOM shutdown only, but we
   // probably want to shut it down more aggressively to save memory.  We
   // could shut down here when there are no uses.  It might be more optimal
@@ -872,22 +867,16 @@ PeerConnectionImpl::Initialize(PeerConne
   }
 
   mFingerprint = mIdentity->GetFormattedFingerprint();
   if (mFingerprint.empty()) {
     CSFLogError(logTag, "%s: unable to get fingerprint", __FUNCTION__);
     return res;
   }
 
-#ifdef MOZILLA_INTERNAL_API
-  if (mozilla::Preferences::GetBool("media.navigator.load_adapt", false)) {
-    mLoadManager = mozilla::LoadManagerBuild();
-  }
-#endif
-
   return NS_OK;
 }
 
 RefPtr<DtlsIdentity> const
 PeerConnectionImpl::GetIdentity() const
 {
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
   return mIdentity;
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -22,17 +22,16 @@
 #include "nricemediastream.h"
 #include "nsComponentManagerUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsIThread.h"
 
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/PeerConnectionImplEnumsBinding.h"
 #include "StreamBuffer.h"
-#include "LoadManagerFactory.h"
 
 #ifdef MOZILLA_INTERNAL_API
 #include "mozilla/TimeStamp.h"
 #include "mozilla/net/DataChannel.h"
 #include "VideoUtils.h"
 #include "VideoSegment.h"
 #include "nsNSSShutDown.h"
 #include "mozilla/dom/RTCStatsReportBinding.h"
@@ -249,20 +248,16 @@ public:
   void NotifyDataChannel(already_AddRefed<mozilla::DataChannel> aChannel);
 
   // Get the media object
   const nsRefPtr<PeerConnectionMedia>& media() const {
     PC_AUTO_ENTER_API_CALL_NO_CHECK();
     return mMedia;
   }
 
-  mozilla::LoadManager* load_manager()  {
-    return mLoadManager;
-  }
-
   // Handle system to allow weak references to be passed through C code
   virtual const std::string& GetHandle();
 
   // Name suitable for exposing to content
   virtual const std::string& GetName();
 
   // ICE events
   void IceConnectionStateChange(NrIceCtx* ctx,
@@ -689,19 +684,16 @@ private:
   std::string mHandle;
 
   // A name for this PC that we are willing to expose to content.
   std::string mName;
 
   // The target to run stuff on
   nsCOMPtr<nsIEventTarget> mSTSThread;
 
-  // CPU Load adaptation stuff
-  mozilla::LoadManager* mLoadManager;
-
 #ifdef MOZILLA_INTERNAL_API
   // DataConnection that's used to get all the DataChannels
   nsRefPtr<mozilla::DataChannelConnection> mDataConnection;
 #endif
 
   nsRefPtr<PeerConnectionMedia> mMedia;
 
 #ifdef MOZILLA_INTERNAL_API
--- a/media/webrtc/signaling/test/mediaconduit_unittests.cpp
+++ b/media/webrtc/signaling/test/mediaconduit_unittests.cpp
@@ -807,17 +807,17 @@ class TransportConduitTest : public ::te
                                             WrapRunnableNMRet(
                                                 &mozilla::VideoSessionConduit::Create,
                                                 nullptr,
                                                 &mVideoSession));
     if( !mVideoSession )
       ASSERT_NE(mVideoSession, (void*)nullptr);
 
     // Configure send codecs on the conduit.
-    mozilla::VideoCodecConfig cinst1(120, "VP8", 0, max_fs, 0);
+    mozilla::VideoCodecConfig cinst1(120, "VP8", 0, max_fs);
 
     err = mVideoSession->ConfigureSendMediaCodec(&cinst1);
     ASSERT_EQ(mozilla::kMediaConduitNoError, err);
 
     // Send one frame.
     MOZ_ASSERT(!(orig_width & 1));
     MOZ_ASSERT(!(orig_height & 1));
     int len = ((orig_width * orig_height) * 3 / 2);