summaryrefslogtreecommitdiff
path: root/indra/newview/llviewerthrottle.cpp
diff options
context:
space:
mode:
authorAnsariel <ansariel.hiller@phoenixviewer.com>2024-05-22 19:04:52 +0200
committerAnsariel <ansariel.hiller@phoenixviewer.com>2024-05-22 19:04:52 +0200
commit1b67dd855c41f5a0cda7ec2a68d98071986ca703 (patch)
treeab243607f74f78200787bba5b9b88f07ef1b966f /indra/newview/llviewerthrottle.cpp
parent6d6eabca44d08d5b97bfe3e941d2b9687c2246ea (diff)
parente1623bb276f83a43ce7a197e388720c05bdefe61 (diff)
Merge remote-tracking branch 'origin/main' into DRTVWR-600-maint-A
# Conflicts: # autobuild.xml # indra/cmake/CMakeLists.txt # indra/cmake/GoogleMock.cmake # indra/llaudio/llaudioengine_fmodstudio.cpp # indra/llaudio/llaudioengine_fmodstudio.h # indra/llaudio/lllistener_fmodstudio.cpp # indra/llaudio/lllistener_fmodstudio.h # indra/llaudio/llstreamingaudio_fmodstudio.cpp # indra/llaudio/llstreamingaudio_fmodstudio.h # indra/llcharacter/llmultigesture.cpp # indra/llcharacter/llmultigesture.h # indra/llimage/llimage.cpp # indra/llimage/llimagepng.cpp # indra/llimage/llimageworker.cpp # indra/llimage/tests/llimageworker_test.cpp # indra/llmessage/tests/llmockhttpclient.h # indra/llprimitive/llgltfmaterial.h # indra/llrender/llfontfreetype.cpp # indra/llui/llcombobox.cpp # indra/llui/llfolderview.cpp # indra/llui/llfolderviewmodel.h # indra/llui/lllineeditor.cpp # indra/llui/lllineeditor.h # indra/llui/lltextbase.cpp # indra/llui/lltextbase.h # indra/llui/lltexteditor.cpp # indra/llui/lltextvalidate.cpp # indra/llui/lltextvalidate.h # indra/llui/lluictrl.h # indra/llui/llview.cpp # indra/llwindow/llwindowmacosx.cpp # indra/newview/app_settings/settings.xml # indra/newview/llappearancemgr.cpp # indra/newview/llappearancemgr.h # indra/newview/llavatarpropertiesprocessor.cpp # indra/newview/llavatarpropertiesprocessor.h # indra/newview/llbreadcrumbview.cpp # indra/newview/llbreadcrumbview.h # indra/newview/llbreastmotion.cpp # indra/newview/llbreastmotion.h # indra/newview/llconversationmodel.h # indra/newview/lldensityctrl.cpp # indra/newview/lldensityctrl.h # indra/newview/llface.inl # indra/newview/llfloatereditsky.cpp # indra/newview/llfloatereditwater.cpp # indra/newview/llfloateremojipicker.h # indra/newview/llfloaterimsessiontab.cpp # indra/newview/llfloaterprofiletexture.cpp # indra/newview/llfloaterprofiletexture.h # indra/newview/llgesturemgr.cpp # indra/newview/llgesturemgr.h # indra/newview/llimpanel.cpp # indra/newview/llimpanel.h # indra/newview/llinventorybridge.cpp # indra/newview/llinventorybridge.h # indra/newview/llinventoryclipboard.cpp # indra/newview/llinventoryclipboard.h # indra/newview/llinventoryfunctions.cpp # indra/newview/llinventoryfunctions.h # indra/newview/llinventorygallery.cpp # indra/newview/lllistbrowser.cpp # indra/newview/lllistbrowser.h # indra/newview/llpanelobjectinventory.cpp # indra/newview/llpanelprofile.cpp # indra/newview/llpanelprofile.h # indra/newview/llpreviewgesture.cpp # indra/newview/llsavedsettingsglue.cpp # indra/newview/llsavedsettingsglue.h # indra/newview/lltooldraganddrop.cpp # indra/newview/llurllineeditorctrl.cpp # indra/newview/llvectorperfoptions.cpp # indra/newview/llvectorperfoptions.h # indra/newview/llviewerparceloverlay.cpp # indra/newview/llviewertexlayer.cpp # indra/newview/llviewertexturelist.cpp # indra/newview/macmain.h # indra/test/test.cpp
Diffstat (limited to 'indra/newview/llviewerthrottle.cpp')
-rw-r--r--indra/newview/llviewerthrottle.cpp668
1 files changed, 334 insertions, 334 deletions
diff --git a/indra/newview/llviewerthrottle.cpp b/indra/newview/llviewerthrottle.cpp
index 5de825e972..b6fff70234 100644
--- a/indra/newview/llviewerthrottle.cpp
+++ b/indra/newview/llviewerthrottle.cpp
@@ -1,334 +1,334 @@
-/**
- * @file llviewerthrottle.cpp
- * @brief LLViewerThrottle class implementation
- *
- * $LicenseInfo:firstyear=2002&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-#include "llviewerthrottle.h"
-
-#include "llviewercontrol.h"
-#include "message.h"
-#include "llagent.h"
-#include "llframetimer.h"
-#include "llviewerstats.h"
-#include "lldatapacker.h"
-
-using namespace LLOldEvents;
-
-// consts
-
-// The viewer is allowed to set the under-the-hood bandwidth to 50%
-// greater than the prefs UI shows, under the assumption that the
-// viewer won't receive all the different message types at once.
-// I didn't design this, don't know who did. JC
-const F32 MAX_FRACTIONAL = 1.5f;
-const F32 MIN_FRACTIONAL = 0.2f;
-
-const F32 MIN_BANDWIDTH = 50.f;
-const F32 MAX_BANDWIDTH = 6000.f;
-const F32 STEP_FRACTIONAL = 0.1f;
-const LLUnit<F32, LLUnits::Percent> TIGHTEN_THROTTLE_THRESHOLD(3.0f); // packet loss % per s
-const LLUnit<F32, LLUnits::Percent> EASE_THROTTLE_THRESHOLD(0.5f); // packet loss % per s
-const F32 DYNAMIC_UPDATE_DURATION = 5.0f; // seconds
-
-LLViewerThrottle gViewerThrottle;
-
-// static
-const std:: string LLViewerThrottle::sNames[TC_EOF] = {
- "Resend",
- "Land",
- "Wind",
- "Cloud",
- "Task",
- "Texture",
- "Asset"
- };
-
-
-// Bandwidth settings for different bit rates, they're interpolated/extrapolated.
-// Resend Land Wind Cloud Task Texture Asset
-const F32 BW_PRESET_50[TC_EOF] = { 5, 10, 3, 3, 10, 10, 9 };
-const F32 BW_PRESET_300[TC_EOF] = { 30, 40, 9, 9, 86, 86, 40 };
-const F32 BW_PRESET_500[TC_EOF] = { 50, 70, 14, 14, 136, 136, 80 };
-const F32 BW_PRESET_1000[TC_EOF] = { 100, 100, 20, 20, 310, 310, 140 };
-
-LLViewerThrottleGroup::LLViewerThrottleGroup()
-{
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- mThrottles[i] = 0.f;
- }
- mThrottleTotal = 0.f;
-}
-
-
-LLViewerThrottleGroup::LLViewerThrottleGroup(const F32 settings[TC_EOF])
-{
- mThrottleTotal = 0.f;
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- mThrottles[i] = settings[i];
- mThrottleTotal += settings[i];
- }
-}
-
-
-LLViewerThrottleGroup LLViewerThrottleGroup::operator*(const F32 frac) const
-{
- LLViewerThrottleGroup res;
- res.mThrottleTotal = 0.f;
-
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- res.mThrottles[i] = mThrottles[i] * frac;
- res.mThrottleTotal += res.mThrottles[i];
- }
-
- return res;
-}
-
-
-LLViewerThrottleGroup LLViewerThrottleGroup::operator+(const LLViewerThrottleGroup &b) const
-{
- LLViewerThrottleGroup res;
- res.mThrottleTotal = 0.f;
-
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- res.mThrottles[i] = mThrottles[i] + b.mThrottles[i];
- res.mThrottleTotal += res.mThrottles[i];
- }
-
- return res;
-}
-
-
-LLViewerThrottleGroup LLViewerThrottleGroup::operator-(const LLViewerThrottleGroup &b) const
-{
- LLViewerThrottleGroup res;
- res.mThrottleTotal = 0.f;
-
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- res.mThrottles[i] = mThrottles[i] - b.mThrottles[i];
- res.mThrottleTotal += res.mThrottles[i];
- }
-
- return res;
-}
-
-
-void LLViewerThrottleGroup::sendToSim() const
-{
- LL_INFOS() << "Sending throttle settings, total BW " << mThrottleTotal << LL_ENDL;
- LLMessageSystem* msg = gMessageSystem;
-
- msg->newMessageFast(_PREHASH_AgentThrottle);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
- msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
-
- msg->nextBlockFast(_PREHASH_Throttle);
- msg->addU32Fast(_PREHASH_GenCounter, 0);
-
- // Pack up the throttle data
- U8 tmp[64];
- LLDataPackerBinaryBuffer dp(tmp, MAX_THROTTLE_SIZE);
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- //sim wants BPS, not KBPS
- dp.packF32(mThrottles[i] * 1024.0f, "Throttle");
- }
- S32 len = dp.getCurrentSize();
- msg->addBinaryDataFast(_PREHASH_Throttles, tmp, len);
-
- gAgent.sendReliableMessage();
-}
-
-
-void LLViewerThrottleGroup::dump()
-{
- S32 i;
- for (i = 0; i < TC_EOF; i++)
- {
- LL_DEBUGS("Throttle") << LLViewerThrottle::sNames[i] << ": " << mThrottles[i] << LL_ENDL;
- }
- LL_DEBUGS("Throttle") << "Total: " << mThrottleTotal << LL_ENDL;
-}
-
-class LLBPSListener : public LLSimpleListener
-{
-public:
- virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
- {
- gViewerThrottle.setMaxBandwidth((F32) event->getValue().asReal()*1024);
- return true;
- }
-};
-
-LLViewerThrottle::LLViewerThrottle() :
- mMaxBandwidth(0.f),
- mCurrentBandwidth(0.f),
- mThrottleFrac(1.f)
-{
- // Need to be pushed on in bandwidth order
- mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_50));
- mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_300));
- mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_500));
- mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_1000));
-}
-
-
-void LLViewerThrottle::setMaxBandwidth(F32 kbits_per_second, bool from_event)
-{
- if (!from_event)
- {
- gSavedSettings.setF32("ThrottleBandwidthKBPS", kbits_per_second);
- }
- gViewerThrottle.load();
-
- if (gAgent.getRegion())
- {
- gViewerThrottle.sendToSim();
- }
-}
-
-void LLViewerThrottle::load()
-{
- mMaxBandwidth = gSavedSettings.getF32("ThrottleBandwidthKBPS")*1024;
- resetDynamicThrottle();
- mCurrent.dump();
-}
-
-
-void LLViewerThrottle::save() const
-{
- gSavedSettings.setF32("ThrottleBandwidthKBPS", mMaxBandwidth/1024);
-}
-
-
-void LLViewerThrottle::sendToSim() const
-{
- mCurrent.sendToSim();
-}
-
-
-LLViewerThrottleGroup LLViewerThrottle::getThrottleGroup(const F32 bandwidth_kbps)
-{
- //Clamp the bandwidth users can set.
- F32 set_bandwidth = llclamp(bandwidth_kbps, MIN_BANDWIDTH, MAX_BANDWIDTH);
-
- S32 count = mPresets.size();
-
- S32 i;
- for (i = 0; i < count; i++)
- {
- if (mPresets[i].getTotal() > set_bandwidth)
- {
- break;
- }
- }
-
- if (i == 0)
- {
- // We return the minimum if it's less than the minimum
- return mPresets[0];
- }
- else if (i == count)
- {
- // Higher than the highest preset, we extrapolate out based on the
- // last two presets. This allows us to keep certain throttle channels from
- // growing in bandwidth
- F32 delta_bw = set_bandwidth - mPresets[count-1].getTotal();
- LLViewerThrottleGroup delta_throttle = mPresets[count - 1] - mPresets[count - 2];
- F32 delta_total = delta_throttle.getTotal();
- F32 delta_frac = delta_bw / delta_total;
- delta_throttle = delta_throttle * delta_frac;
- return mPresets[count-1] + delta_throttle;
- }
- else
- {
- // In between two presets, just interpolate
- F32 delta_bw = set_bandwidth - mPresets[i - 1].getTotal();
- LLViewerThrottleGroup delta_throttle = mPresets[i] - mPresets[i - 1];
- F32 delta_total = delta_throttle.getTotal();
- F32 delta_frac = delta_bw / delta_total;
- delta_throttle = delta_throttle * delta_frac;
- return mPresets[i - 1] + delta_throttle;
- }
-}
-
-
-// static
-void LLViewerThrottle::resetDynamicThrottle()
-{
- mThrottleFrac = MAX_FRACTIONAL;
-
- mCurrentBandwidth = mMaxBandwidth*MAX_FRACTIONAL;
- mCurrent = getThrottleGroup(mCurrentBandwidth / 1024.0f);
-}
-
-void LLViewerThrottle::updateDynamicThrottle()
-{
- if (mUpdateTimer.getElapsedTimeF32() < DYNAMIC_UPDATE_DURATION)
- {
- return;
- }
- mUpdateTimer.reset();
-
- LLUnit<F32, LLUnits::Percent> mean_packets_lost = LLViewerStats::instance().getRecording().getMean(LLStatViewer::PACKETS_LOST_PERCENT);
- if (mean_packets_lost > TIGHTEN_THROTTLE_THRESHOLD)
- {
- if (mThrottleFrac <= MIN_FRACTIONAL || mCurrentBandwidth / 1024.0f <= MIN_BANDWIDTH)
- {
- return;
- }
- mThrottleFrac -= STEP_FRACTIONAL;
- mThrottleFrac = llmax(MIN_FRACTIONAL, mThrottleFrac);
- mCurrentBandwidth = mMaxBandwidth * mThrottleFrac;
- mCurrent = getThrottleGroup(mCurrentBandwidth / 1024.0f);
- mCurrent.sendToSim();
- LL_INFOS() << "Tightening network throttle to " << mCurrentBandwidth << LL_ENDL;
- }
- else if (mean_packets_lost <= EASE_THROTTLE_THRESHOLD)
- {
- if (mThrottleFrac >= MAX_FRACTIONAL || mCurrentBandwidth / 1024.0f >= MAX_BANDWIDTH)
- {
- return;
- }
- mThrottleFrac += STEP_FRACTIONAL;
- mThrottleFrac = llmin(MAX_FRACTIONAL, mThrottleFrac);
- mCurrentBandwidth = mMaxBandwidth * mThrottleFrac;
- mCurrent = getThrottleGroup(mCurrentBandwidth/1024.0f);
- mCurrent.sendToSim();
- LL_INFOS() << "Easing network throttle to " << mCurrentBandwidth << LL_ENDL;
- }
-}
+/**
+ * @file llviewerthrottle.cpp
+ * @brief LLViewerThrottle class implementation
+ *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+#include "llviewerthrottle.h"
+
+#include "llviewercontrol.h"
+#include "message.h"
+#include "llagent.h"
+#include "llframetimer.h"
+#include "llviewerstats.h"
+#include "lldatapacker.h"
+
+using namespace LLOldEvents;
+
+// consts
+
+// The viewer is allowed to set the under-the-hood bandwidth to 50%
+// greater than the prefs UI shows, under the assumption that the
+// viewer won't receive all the different message types at once.
+// I didn't design this, don't know who did. JC
+const F32 MAX_FRACTIONAL = 1.5f;
+const F32 MIN_FRACTIONAL = 0.2f;
+
+const F32 MIN_BANDWIDTH = 50.f;
+const F32 MAX_BANDWIDTH = 6000.f;
+const F32 STEP_FRACTIONAL = 0.1f;
+const LLUnit<F32, LLUnits::Percent> TIGHTEN_THROTTLE_THRESHOLD(3.0f); // packet loss % per s
+const LLUnit<F32, LLUnits::Percent> EASE_THROTTLE_THRESHOLD(0.5f); // packet loss % per s
+const F32 DYNAMIC_UPDATE_DURATION = 5.0f; // seconds
+
+LLViewerThrottle gViewerThrottle;
+
+// static
+const std:: string LLViewerThrottle::sNames[TC_EOF] = {
+ "Resend",
+ "Land",
+ "Wind",
+ "Cloud",
+ "Task",
+ "Texture",
+ "Asset"
+ };
+
+
+// Bandwidth settings for different bit rates, they're interpolated/extrapolated.
+// Resend Land Wind Cloud Task Texture Asset
+const F32 BW_PRESET_50[TC_EOF] = { 5, 10, 3, 3, 10, 10, 9 };
+const F32 BW_PRESET_300[TC_EOF] = { 30, 40, 9, 9, 86, 86, 40 };
+const F32 BW_PRESET_500[TC_EOF] = { 50, 70, 14, 14, 136, 136, 80 };
+const F32 BW_PRESET_1000[TC_EOF] = { 100, 100, 20, 20, 310, 310, 140 };
+
+LLViewerThrottleGroup::LLViewerThrottleGroup()
+{
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ mThrottles[i] = 0.f;
+ }
+ mThrottleTotal = 0.f;
+}
+
+
+LLViewerThrottleGroup::LLViewerThrottleGroup(const F32 settings[TC_EOF])
+{
+ mThrottleTotal = 0.f;
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ mThrottles[i] = settings[i];
+ mThrottleTotal += settings[i];
+ }
+}
+
+
+LLViewerThrottleGroup LLViewerThrottleGroup::operator*(const F32 frac) const
+{
+ LLViewerThrottleGroup res;
+ res.mThrottleTotal = 0.f;
+
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ res.mThrottles[i] = mThrottles[i] * frac;
+ res.mThrottleTotal += res.mThrottles[i];
+ }
+
+ return res;
+}
+
+
+LLViewerThrottleGroup LLViewerThrottleGroup::operator+(const LLViewerThrottleGroup &b) const
+{
+ LLViewerThrottleGroup res;
+ res.mThrottleTotal = 0.f;
+
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ res.mThrottles[i] = mThrottles[i] + b.mThrottles[i];
+ res.mThrottleTotal += res.mThrottles[i];
+ }
+
+ return res;
+}
+
+
+LLViewerThrottleGroup LLViewerThrottleGroup::operator-(const LLViewerThrottleGroup &b) const
+{
+ LLViewerThrottleGroup res;
+ res.mThrottleTotal = 0.f;
+
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ res.mThrottles[i] = mThrottles[i] - b.mThrottles[i];
+ res.mThrottleTotal += res.mThrottles[i];
+ }
+
+ return res;
+}
+
+
+void LLViewerThrottleGroup::sendToSim() const
+{
+ LL_INFOS() << "Sending throttle settings, total BW " << mThrottleTotal << LL_ENDL;
+ LLMessageSystem* msg = gMessageSystem;
+
+ msg->newMessageFast(_PREHASH_AgentThrottle);
+ msg->nextBlockFast(_PREHASH_AgentData);
+ msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+ msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+ msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
+
+ msg->nextBlockFast(_PREHASH_Throttle);
+ msg->addU32Fast(_PREHASH_GenCounter, 0);
+
+ // Pack up the throttle data
+ U8 tmp[64];
+ LLDataPackerBinaryBuffer dp(tmp, MAX_THROTTLE_SIZE);
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ //sim wants BPS, not KBPS
+ dp.packF32(mThrottles[i] * 1024.0f, "Throttle");
+ }
+ S32 len = dp.getCurrentSize();
+ msg->addBinaryDataFast(_PREHASH_Throttles, tmp, len);
+
+ gAgent.sendReliableMessage();
+}
+
+
+void LLViewerThrottleGroup::dump()
+{
+ S32 i;
+ for (i = 0; i < TC_EOF; i++)
+ {
+ LL_DEBUGS("Throttle") << LLViewerThrottle::sNames[i] << ": " << mThrottles[i] << LL_ENDL;
+ }
+ LL_DEBUGS("Throttle") << "Total: " << mThrottleTotal << LL_ENDL;
+}
+
+class LLBPSListener : public LLSimpleListener
+{
+public:
+ virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
+ {
+ gViewerThrottle.setMaxBandwidth((F32) event->getValue().asReal()*1024);
+ return true;
+ }
+};
+
+LLViewerThrottle::LLViewerThrottle() :
+ mMaxBandwidth(0.f),
+ mCurrentBandwidth(0.f),
+ mThrottleFrac(1.f)
+{
+ // Need to be pushed on in bandwidth order
+ mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_50));
+ mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_300));
+ mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_500));
+ mPresets.push_back(LLViewerThrottleGroup(BW_PRESET_1000));
+}
+
+
+void LLViewerThrottle::setMaxBandwidth(F32 kbits_per_second, bool from_event)
+{
+ if (!from_event)
+ {
+ gSavedSettings.setF32("ThrottleBandwidthKBPS", kbits_per_second);
+ }
+ gViewerThrottle.load();
+
+ if (gAgent.getRegion())
+ {
+ gViewerThrottle.sendToSim();
+ }
+}
+
+void LLViewerThrottle::load()
+{
+ mMaxBandwidth = gSavedSettings.getF32("ThrottleBandwidthKBPS")*1024;
+ resetDynamicThrottle();
+ mCurrent.dump();
+}
+
+
+void LLViewerThrottle::save() const
+{
+ gSavedSettings.setF32("ThrottleBandwidthKBPS", mMaxBandwidth/1024);
+}
+
+
+void LLViewerThrottle::sendToSim() const
+{
+ mCurrent.sendToSim();
+}
+
+
+LLViewerThrottleGroup LLViewerThrottle::getThrottleGroup(const F32 bandwidth_kbps)
+{
+ //Clamp the bandwidth users can set.
+ F32 set_bandwidth = llclamp(bandwidth_kbps, MIN_BANDWIDTH, MAX_BANDWIDTH);
+
+ S32 count = mPresets.size();
+
+ S32 i;
+ for (i = 0; i < count; i++)
+ {
+ if (mPresets[i].getTotal() > set_bandwidth)
+ {
+ break;
+ }
+ }
+
+ if (i == 0)
+ {
+ // We return the minimum if it's less than the minimum
+ return mPresets[0];
+ }
+ else if (i == count)
+ {
+ // Higher than the highest preset, we extrapolate out based on the
+ // last two presets. This allows us to keep certain throttle channels from
+ // growing in bandwidth
+ F32 delta_bw = set_bandwidth - mPresets[count-1].getTotal();
+ LLViewerThrottleGroup delta_throttle = mPresets[count - 1] - mPresets[count - 2];
+ F32 delta_total = delta_throttle.getTotal();
+ F32 delta_frac = delta_bw / delta_total;
+ delta_throttle = delta_throttle * delta_frac;
+ return mPresets[count-1] + delta_throttle;
+ }
+ else
+ {
+ // In between two presets, just interpolate
+ F32 delta_bw = set_bandwidth - mPresets[i - 1].getTotal();
+ LLViewerThrottleGroup delta_throttle = mPresets[i] - mPresets[i - 1];
+ F32 delta_total = delta_throttle.getTotal();
+ F32 delta_frac = delta_bw / delta_total;
+ delta_throttle = delta_throttle * delta_frac;
+ return mPresets[i - 1] + delta_throttle;
+ }
+}
+
+
+// static
+void LLViewerThrottle::resetDynamicThrottle()
+{
+ mThrottleFrac = MAX_FRACTIONAL;
+
+ mCurrentBandwidth = mMaxBandwidth*MAX_FRACTIONAL;
+ mCurrent = getThrottleGroup(mCurrentBandwidth / 1024.0f);
+}
+
+void LLViewerThrottle::updateDynamicThrottle()
+{
+ if (mUpdateTimer.getElapsedTimeF32() < DYNAMIC_UPDATE_DURATION)
+ {
+ return;
+ }
+ mUpdateTimer.reset();
+
+ LLUnit<F32, LLUnits::Percent> mean_packets_lost = LLViewerStats::instance().getRecording().getMean(LLStatViewer::PACKETS_LOST_PERCENT);
+ if (mean_packets_lost > TIGHTEN_THROTTLE_THRESHOLD)
+ {
+ if (mThrottleFrac <= MIN_FRACTIONAL || mCurrentBandwidth / 1024.0f <= MIN_BANDWIDTH)
+ {
+ return;
+ }
+ mThrottleFrac -= STEP_FRACTIONAL;
+ mThrottleFrac = llmax(MIN_FRACTIONAL, mThrottleFrac);
+ mCurrentBandwidth = mMaxBandwidth * mThrottleFrac;
+ mCurrent = getThrottleGroup(mCurrentBandwidth / 1024.0f);
+ mCurrent.sendToSim();
+ LL_INFOS() << "Tightening network throttle to " << mCurrentBandwidth << LL_ENDL;
+ }
+ else if (mean_packets_lost <= EASE_THROTTLE_THRESHOLD)
+ {
+ if (mThrottleFrac >= MAX_FRACTIONAL || mCurrentBandwidth / 1024.0f >= MAX_BANDWIDTH)
+ {
+ return;
+ }
+ mThrottleFrac += STEP_FRACTIONAL;
+ mThrottleFrac = llmin(MAX_FRACTIONAL, mThrottleFrac);
+ mCurrentBandwidth = mMaxBandwidth * mThrottleFrac;
+ mCurrent = getThrottleGroup(mCurrentBandwidth/1024.0f);
+ mCurrent.sendToSim();
+ LL_INFOS() << "Easing network throttle to " << mCurrentBandwidth << LL_ENDL;
+ }
+}