2014-03-13 14:05:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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"
|
2016-01-05 05:16:32 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2014-06-13 23:50:51 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2014-03-13 14:05:27 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-06-13 23:50:51 +04:00
|
|
|
#include "mozilla/Services.h"
|
2014-03-13 14:05:27 +04:00
|
|
|
#include "nsTArray.h"
|
2014-06-13 23:50:51 +04:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
|
|
|
|
#include "webrtc/common_types.h"
|
|
|
|
#include "webrtc/video_engine/include/vie_base.h"
|
2014-03-13 14:05:27 +04:00
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern mozilla::LazyLogModule gLoadManagerLog;
|
2014-03-13 14:05:27 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-06-13 23:50:51 +04:00
|
|
|
class LoadManagerSingleton : public LoadNotificationCallback,
|
|
|
|
public webrtc::CPULoadStateCallbackInvoker,
|
|
|
|
public webrtc::CpuOveruseObserver,
|
2016-01-05 05:16:32 +03:00
|
|
|
public SupportsWeakPtr<LoadManagerSingleton>,
|
2014-06-13 23:50:51 +04:00
|
|
|
public nsIObserver
|
|
|
|
|
2014-03-13 14:05:27 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-06-13 23:50:51 +04:00
|
|
|
static LoadManagerSingleton* Get();
|
|
|
|
|
2016-01-05 05:16:32 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LoadManagerSingleton)
|
|
|
|
|
2014-06-13 23:50:51 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2014-03-13 14:05:27 +04:00
|
|
|
|
|
|
|
// LoadNotificationCallback interface
|
2016-01-18 06:50:29 +03:00
|
|
|
void LoadChanged(float aSystemLoad, float aProcessLoad) override;
|
2014-03-13 14:05:27 +04:00
|
|
|
// CpuOveruseObserver interface
|
|
|
|
// Called as soon as an overuse is detected.
|
2016-01-18 06:50:29 +03:00
|
|
|
void OveruseDetected() override;
|
2014-03-13 14:05:27 +04:00
|
|
|
// Called periodically when the system is not overused any longer.
|
2016-01-18 06:50:29 +03:00
|
|
|
void NormalUsage() override;
|
2014-03-13 14:05:27 +04:00
|
|
|
// CPULoadStateCallbackInvoker interface
|
2016-01-18 06:50:29 +03:00
|
|
|
void AddObserver(webrtc::CPULoadStateObserver * aObserver) override;
|
|
|
|
void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) override;
|
2014-03-13 14:05:27 +04:00
|
|
|
|
|
|
|
private:
|
2014-06-13 23:50:51 +04:00
|
|
|
LoadManagerSingleton(int aLoadMeasurementInterval,
|
|
|
|
int aAveragingMeasurements,
|
|
|
|
float aHighLoadThreshold,
|
|
|
|
float aLowLoadThreshold);
|
|
|
|
~LoadManagerSingleton();
|
|
|
|
|
2015-09-23 21:10:28 +03:00
|
|
|
void LoadHasChanged(webrtc::CPULoadState aNewState);
|
2014-03-13 14:05:27 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<LoadMonitor> mLoadMonitor;
|
2014-06-13 23:50:51 +04:00
|
|
|
|
2014-06-15 22:57:30 +04:00
|
|
|
// This protects access to the mObservers list, the current state, and
|
|
|
|
// pretty much all the other members (below).
|
2014-06-13 23:50:51 +04:00
|
|
|
Mutex mLock;
|
|
|
|
nsTArray<webrtc::CPULoadStateObserver*> mObservers;
|
|
|
|
webrtc::CPULoadState mCurrentState;
|
2015-09-23 21:10:28 +03:00
|
|
|
TimeStamp mLastStateChange;
|
|
|
|
float mTimeInState[static_cast<int>(webrtc::kLoadLast)];
|
|
|
|
|
2014-03-13 14:05:27 +04:00
|
|
|
// Set when overuse was signaled to us, and hasn't been un-signaled yet.
|
|
|
|
bool mOveruseActive;
|
2014-06-13 23:50:51 +04:00
|
|
|
float mLoadSum;
|
|
|
|
int mLoadSumMeasurements;
|
2014-03-13 14:05:27 +04:00
|
|
|
// Load measurement settings
|
|
|
|
int mLoadMeasurementInterval;
|
|
|
|
int mAveragingMeasurements;
|
|
|
|
float mHighLoadThreshold;
|
|
|
|
float mLowLoadThreshold;
|
|
|
|
|
2014-06-13 23:50:51 +04:00
|
|
|
static StaticRefPtr<LoadManagerSingleton> sSingleton;
|
|
|
|
};
|
2014-03-13 14:05:27 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class LoadManager final : public webrtc::CPULoadStateCallbackInvoker,
|
2015-03-27 21:52:19 +03:00
|
|
|
public webrtc::CpuOveruseObserver
|
2014-06-13 23:50:51 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:50:23 +04:00
|
|
|
explicit LoadManager(LoadManagerSingleton* aManager)
|
2014-06-13 23:50:51 +04:00
|
|
|
: mManager(aManager)
|
|
|
|
{}
|
|
|
|
~LoadManager() {}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void AddObserver(webrtc::CPULoadStateObserver * aObserver) override
|
2014-06-13 23:50:51 +04:00
|
|
|
{
|
2016-01-05 05:16:32 +03:00
|
|
|
if (mManager) {
|
|
|
|
mManager->AddObserver(aObserver);
|
|
|
|
}
|
2014-06-13 23:50:51 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) override
|
2014-06-13 23:50:51 +04:00
|
|
|
{
|
2016-01-05 05:16:32 +03:00
|
|
|
if (mManager) {
|
|
|
|
mManager->RemoveObserver(aObserver);
|
|
|
|
}
|
2014-06-13 23:50:51 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
void OveruseDetected() override
|
2014-06-13 23:50:51 +04:00
|
|
|
{
|
2016-01-05 05:16:32 +03:00
|
|
|
if (mManager) {
|
|
|
|
mManager->OveruseDetected();
|
|
|
|
}
|
2014-06-13 23:50:51 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
void NormalUsage() override
|
2014-06-13 23:50:51 +04:00
|
|
|
{
|
2016-01-05 05:16:32 +03:00
|
|
|
if (mManager) {
|
|
|
|
mManager->NormalUsage();
|
|
|
|
}
|
2014-06-13 23:50:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-01-05 05:16:32 +03:00
|
|
|
WeakPtr<LoadManagerSingleton> mManager;
|
2014-03-13 14:05:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} //namespace
|
|
|
|
|
|
|
|
#endif /* _LOADMANAGER_H_ */
|