From a58dd26b205d4e626028f1c7d27858d2ec927e41 Mon Sep 17 00:00:00 2001 From: Monroe Linden Date: Fri, 13 Nov 2009 18:15:35 -0800 Subject: Tweaks to media priority calculation. Enabled CPU limit setting by default (set to 100% of 1 CPU). Lowered default limits on plugin priorities: 2 normal+, 4 low, 8 total. Limit on total number of instances now only applies to inworld media -- media instances in the UI (such as the help browser and search) don't count toward the limit. UI media will still bump inworld media down from normal/low priority, though. Several improvements to plugin manager debug code in the nearby media list. Don't load unloaded instances that are at PRIORITY_SLIDESHOW or PRIORITY_HIDDEN (they don't get unloaded, they just won't be loaded unless they're at higher priority). Added LLViewerMediaImpl::isPlayable(), which indicates whether an instance would be loaded if it were high enough in the priority list (taking into account autoplay and current load state). Priority algorithm now takes this into account. Fixed a couple of issues with approximate texture interest calculation and its use in setting priorities. Adjusted sleep times on low and normal priorities to be more friendly. --- indra/newview/llviewermedia.cpp | 75 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 9 deletions(-) (limited to 'indra/newview/llviewermedia.cpp') diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 251d7d4a13..70490d3a6e 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -541,6 +541,16 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView // The item with user focus always comes to the front of the list, period. return false; } + else if(i1->isParcelMedia()) + { + // The parcel media impl sorts above all other inworld media, unless one has focus. + return true; + } + else if(i2->isParcelMedia()) + { + // The parcel media impl sorts above all other inworld media, unless one has focus. + return false; + } else if(i1->getUsedInUI() && !i2->getUsedInUI()) { // i1 is a UI element, i2 is not. This makes i1 "less than" i2, so it sorts earlier in our list. @@ -551,14 +561,14 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView // i2 is a UI element, i1 is not. This makes i2 "less than" i1, so it sorts earlier in our list. return false; } - else if(i1->isParcelMedia()) + else if(i1->isPlayable() && !i2->isPlayable()) { - // The parcel media impl sorts above all other inworld media, unless one has focus. + // Playable items sort above ones that wouldn't play even if they got high enough priority return true; } - else if(i2->isParcelMedia()) + else if(!i1->isPlayable() && i2->isPlayable()) { - // The parcel media impl sorts above all other inworld media, unless one has focus. + // Playable items sort above ones that wouldn't play even if they got high enough priority return false; } else @@ -629,10 +639,12 @@ void LLViewerMedia::updateMedia() else if(pimpl->hasFocus()) { new_priority = LLPluginClassMedia::PRIORITY_HIGH; + impl_count_interest_normal++; // count this against the count of "normal" instances for priority purposes } else if(pimpl->getUsedInUI()) { new_priority = LLPluginClassMedia::PRIORITY_NORMAL; + impl_count_interest_normal++; } else { @@ -640,7 +652,17 @@ void LLViewerMedia::updateMedia() // Heuristic -- if the media texture's approximate screen area is less than 1/4 of the native area of the texture, // turn it down to low instead of normal. This may downsample for plugins that support it. - bool media_is_small = pimpl->getInterest() < (pimpl->getApproximateTextureInterest() / 4); + bool media_is_small = false; + F64 approximate_interest = pimpl->getApproximateTextureInterest(); + if(approximate_interest == 0.0f) + { + // this media has no current size, which probably means it's not loaded. + media_is_small = true; + } + else if(pimpl->getInterest() < (approximate_interest / 4)) + { + media_is_small = true; + } if(pimpl->getInterest() == 0.0f) { @@ -678,7 +700,7 @@ void LLViewerMedia::updateMedia() } } - if(new_priority != LLPluginClassMedia::PRIORITY_UNLOADED) + if(!pimpl->getUsedInUI() && (new_priority != LLPluginClassMedia::PRIORITY_UNLOADED)) { impl_count_total++; } @@ -1588,6 +1610,10 @@ void LLViewerMediaImpl::update() { // This media source should not be loaded. } + else if(mPriority <= LLPluginClassMedia::PRIORITY_SLIDESHOW) + { + // Don't load new instances that are at PRIORITY_SLIDESHOW or below. They're just kept around to preserve state. + } else if(mMimeTypeProbe != NULL) { // this media source is doing a MIME type probe -- don't try loading it again. @@ -1816,7 +1842,7 @@ bool LLViewerMediaImpl::isMediaPaused() ////////////////////////////////////////////////////////////////////////////////////////// // -bool LLViewerMediaImpl::hasMedia() +bool LLViewerMediaImpl::hasMedia() const { return mMediaSource != NULL; } @@ -1850,6 +1876,31 @@ bool LLViewerMediaImpl::isForcedUnloaded() const return false; } +////////////////////////////////////////////////////////////////////////////////////////// +// +bool LLViewerMediaImpl::isPlayable() const +{ + if(isForcedUnloaded()) + { + // All of the forced-unloaded criteria also imply not playable. + return false; + } + + if(hasMedia()) + { + // Anything that's already playing is, by definition, playable. + return true; + } + + if(!mMediaURL.empty()) + { + // If something has navigated the instance, it's ready to be played. + return true; + } + + return false; +} + ////////////////////////////////////////////////////////////////////////////////////////// void LLViewerMediaImpl::handleMediaEvent(LLPluginClassMedia* plugin, LLPluginClassMediaOwner::EMediaEvent event) { @@ -2094,7 +2145,13 @@ F64 LLViewerMediaImpl::getApproximateTextureInterest() result = mMediaSource->getFullWidth(); result *= mMediaSource->getFullHeight(); } - + else + { + // No media source is loaded -- all we have to go on is the texture size that has been set on the impl, if any. + result = mMediaWidth; + result *= mMediaHeight; + } + return result; } @@ -2135,7 +2192,7 @@ void LLViewerMediaImpl::setPriority(LLPluginClassMedia::EPriority priority) { if(mPriority != priority) { - LL_INFOS("PluginPriority") + LL_DEBUGS("PluginPriority") << "changing priority of media id " << mTextureId << " from " << LLPluginClassMedia::priorityToString(mPriority) << " to " << LLPluginClassMedia::priorityToString(priority) -- cgit v1.3 From d504efe3018bd0ce616e67c30b0bb31f5637973a Mon Sep 17 00:00:00 2001 From: Monroe Linden Date: Mon, 16 Nov 2009 16:52:43 -0800 Subject: Made nearby media list sort on distance from avatar instead of priority. When the MediaPerformanceManagerDebug debug setting is enabled, the list will sort by priority the way it used to. --- indra/newview/llviewermedia.cpp | 62 ++++++++++++++++++++++++++++------------- indra/newview/llviewermedia.h | 2 ++ 2 files changed, 44 insertions(+), 20 deletions(-) (limited to 'indra/newview/llviewermedia.cpp') diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 70490d3a6e..4663e9c8e6 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -32,6 +32,7 @@ #include "llviewerprecompiledheaders.h" +#include "llagent.h" #include "llviewermedia.h" #include "llviewermediafocus.h" #include "llmimetypes.h" @@ -571,6 +572,11 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView // Playable items sort above ones that wouldn't play even if they got high enough priority return false; } + else if(i1->getInterest() == i2->getInterest()) + { + // Generally this will mean both objects have zero interest. In this case, sort on distance. + return (i1->getProximityDistance() < i2->getProximityDistance()); + } else { // The object with the larger interest value should be earlier in the list, so we reverse the sense of the comparison here. @@ -578,6 +584,11 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView } } +static bool proximity_comparitor(const LLViewerMediaImpl* i1, const LLViewerMediaImpl* i2) +{ + return (i1->getProximityDistance() < i2->getProximityDistance()); +} + ////////////////////////////////////////////////////////////////////////////////////////// // static void LLViewerMedia::updateMedia() @@ -603,12 +614,9 @@ void LLViewerMedia::updateMedia() int impl_count_total = 0; int impl_count_interest_low = 0; int impl_count_interest_normal = 0; - int i = 0; - -#if 0 - LL_DEBUGS("PluginPriority") << "Sorted impls:" << llendl; -#endif - + + std::vector proximity_order; + U32 max_instances = gSavedSettings.getU32("PluginInstancesTotal"); U32 max_normal = gSavedSettings.getU32("PluginInstancesNormal"); U32 max_low = gSavedSettings.getU32("PluginInstancesLow"); @@ -714,23 +722,27 @@ void LLViewerMedia::updateMedia() } else { - // Other impls just get the same ordering as the priority list (for now). - pimpl->mProximity = i; + proximity_order.push_back(pimpl); } -#if 0 - LL_DEBUGS("PluginPriority") << " " << pimpl - << ", setting priority to " << new_priority - << (pimpl->hasFocus()?", HAS FOCUS":"") - << (pimpl->getUsedInUI()?", is UI":"") - << ", cpu " << pimpl->getCPUUsage() - << ", interest " << pimpl->getInterest() - << ", media url " << pimpl->getMediaURL() << llendl; -#endif - total_cpu += pimpl->getCPUUsage(); - - i++; + } + + if(gSavedSettings.getBOOL("MediaPerformanceManagerDebug")) + { + // Give impls the same ordering as the priority list + // they're already in the right order for this. + } + else + { + // Use a distance-based sort for proximity values. + std::stable_sort(proximity_order.begin(), proximity_order.end(), proximity_comparitor); + } + + // Transfer the proximity order to the proximity fields in the objects. + for(int i = 0; i < proximity_order.size(); i++) + { + proximity_order[i]->mProximity = i; } LL_DEBUGS("PluginPriority") << "Total reported CPU usage is " << total_cpu << llendl; @@ -782,6 +794,7 @@ LLViewerMediaImpl::LLViewerMediaImpl( const LLUUID& texture_id, mIsDisabled(false), mIsParcelMedia(false), mProximity(-1), + mProximityDistance(0.0f), mMimeTypeProbe(NULL), mIsUpdated(false) { @@ -2109,6 +2122,15 @@ void LLViewerMediaImpl::calculateInterest() mInterest = 0.0f; } + // Calculate distance from the avatar, for use in the proximity calculation. + mProximityDistance = 0.0f; + if(!mObjectList.empty()) + { + // Just use the first object in the list. We could go through the list and find the closest object, but this should work well enough. + LLVector3d global_delta = gAgent.getPositionGlobal() - (*mObjectList.begin())->getPositionGlobal(); + mProximityDistance = global_delta.magVecSquared(); // use distance-squared because it's cheaper and sorts the same. + } + if(mNeedsMuteCheck) { // Check all objects this instance is associated with, and those objects' owners, against the mute list diff --git a/indra/newview/llviewermedia.h b/indra/newview/llviewermedia.h index a06079786e..f4afce6c4c 100644 --- a/indra/newview/llviewermedia.h +++ b/indra/newview/llviewermedia.h @@ -270,6 +270,7 @@ public: F64 getInterest() const { return mInterest; }; F64 getApproximateTextureInterest(); S32 getProximity() const { return mProximity; }; + F64 getProximityDistance() const { return mProximityDistance; }; // Mark this object as being used in a UI panel instead of on a prim // This will be used as part of the interest sorting algorithm. @@ -339,6 +340,7 @@ public: bool mIsDisabled; bool mIsParcelMedia; S32 mProximity; + F64 mProximityDistance; LLMimeDiscoveryResponder *mMimeTypeProbe; private: -- cgit v1.3 From 16fa3a40e30e453a0feadf7fe053ba6442057dc9 Mon Sep 17 00:00:00 2001 From: callum Date: Mon, 16 Nov 2009 18:41:53 -0800 Subject: Fix for usual signed/unsigned int error from Mac developed changes.. --- indra/newview/llviewermedia.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llviewermedia.cpp') diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 4663e9c8e6..3a7c54479b 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -740,7 +740,7 @@ void LLViewerMedia::updateMedia() } // Transfer the proximity order to the proximity fields in the objects. - for(int i = 0; i < proximity_order.size(); i++) + for(int i = 0; i < (int)proximity_order.size(); i++) { proximity_order[i]->mProximity = i; } -- cgit v1.3