summaryrefslogtreecommitdiff
path: root/indra/newview/lltexturefetch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/lltexturefetch.cpp')
-rw-r--r--indra/newview/lltexturefetch.cpp166
1 files changed, 90 insertions, 76 deletions
diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index ceed90e210..4e9ebce4d1 100644
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -2,31 +2,25 @@
* @file lltexturefetch.cpp
* @brief Object which fetches textures from the cache and/or network
*
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2000&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 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.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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$
*/
@@ -54,6 +48,7 @@
#include "llviewertexturelist.h"
#include "llviewertexture.h"
#include "llviewerregion.h"
+#include "llviewerstats.h"
#include "llworld.h"
//////////////////////////////////////////////////////////////////////////////
@@ -150,7 +145,7 @@ public:
~LLTextureFetchWorker();
void relese() { --mActiveCount; }
- void callbackHttpGet(const LLChannelDescriptors& channels,
+ S32 callbackHttpGet(const LLChannelDescriptors& channels,
const LLIOPipe::buffer_ptr_t& buffer,
bool partial, bool success);
void callbackCacheRead(bool success, LLImageFormatted* image,
@@ -290,8 +285,8 @@ class HTTPGetResponder : public LLCurl::Responder
{
LOG_CLASS(HTTPGetResponder);
public:
- HTTPGetResponder(LLTextureFetch* fetcher, const LLUUID& id, U64 startTime, S32 requestedSize, U32 offset)
- : mFetcher(fetcher), mID(id), mStartTime(startTime), mRequestedSize(requestedSize), mOffset(offset)
+ HTTPGetResponder(LLTextureFetch* fetcher, const LLUUID& id, U64 startTime, S32 requestedSize, U32 offset, bool redir)
+ : mFetcher(fetcher), mID(id), mStartTime(startTime), mRequestedSize(requestedSize), mOffset(offset), mFollowRedir(redir)
{
}
~HTTPGetResponder()
@@ -335,8 +330,9 @@ public:
worker->setGetStatus(status, reason);
// llwarns << "CURL GET FAILED, status:" << status << " reason:" << reason << llendl;
}
- mFetcher->removeFromHTTPQueue(mID);
- worker->callbackHttpGet(channels, buffer, partial, success);
+
+ S32 data_size = worker->callbackHttpGet(channels, buffer, partial, success);
+ mFetcher->removeFromHTTPQueue(mID, data_size);
}
else
{
@@ -344,6 +340,11 @@ public:
llwarns << "Worker not found: " << mID << llendl;
}
}
+
+ virtual bool followRedir()
+ {
+ return mFollowRedir;
+ }
private:
LLTextureFetch* mFetcher;
@@ -351,6 +352,7 @@ private:
U64 mStartTime;
S32 mRequestedSize;
U32 mOffset;
+ bool mFollowRedir;
};
//////////////////////////////////////////////////////////////////////////////
@@ -589,7 +591,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
return true; // abort
}
}
- if(mImagePriority < 1.0f)
+ if(mImagePriority < F_ALMOST_ZERO)
{
if (mState == INIT || mState == LOAD_FROM_NETWORK || mState == LOAD_FROM_SIMULATOR)
{
@@ -844,20 +846,10 @@ bool LLTextureFetchWorker::doWork(S32 param)
{
if(mCanUseHTTP)
{
- const S32 HTTP_QUEUE_MAX_SIZE = 8;
- // *TODO: Integrate this with llviewerthrottle
- // Note: LLViewerThrottle uses dynamic throttling which makes sense for UDP,
- // but probably not for Textures.
- // Set the throttle to the entire bandwidth, assuming UDP packets will get priority
- // when they are needed
- F32 max_bandwidth = mFetcher->mMaxBandwidth;
- if ((mFetcher->getHTTPQueueSize() >= HTTP_QUEUE_MAX_SIZE) ||
- (mFetcher->getTextureBandwidth() > max_bandwidth))
- {
- // Make normal priority and return (i.e. wait until there is room in the queue)
- setPriority(LLWorkerThread::PRIORITY_NORMAL | mWorkPriority);
- return false;
- }
+ //NOTE:
+ //it seems ok to let sim control the UDP traffic
+ //so there is no throttle for http here.
+ //
mFetcher->removeFromNetworkQueue(this, false);
@@ -867,10 +859,17 @@ bool LLTextureFetchWorker::doWork(S32 param)
cur_size = mFormattedImage->getDataSize(); // amount of data we already have
if (mFormattedImage->getDiscardLevel() == 0)
{
- // We already have all the data, just decode it
- mLoadedDiscard = mFormattedImage->getDiscardLevel();
- mState = DECODE_IMAGE;
- return false;
+ if(cur_size > 0)
+ {
+ // We already have all the data, just decode it
+ mLoadedDiscard = mFormattedImage->getDiscardLevel();
+ mState = DECODE_IMAGE;
+ return false;
+ }
+ else
+ {
+ return true ; //abort.
+ }
}
}
mRequestedSize = mDesiredSize;
@@ -887,7 +886,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
mGetReason.clear();
LL_DEBUGS("Texture") << "HTTP GET: " << mID << " Offset: " << offset
<< " Bytes: " << mRequestedSize
- << " Bandwidth(kbps): " << mFetcher->getTextureBandwidth() << "/" << max_bandwidth
+ << " Bandwidth(kbps): " << mFetcher->getTextureBandwidth() << "/" << mFetcher->mMaxBandwidth
<< LL_ENDL;
setPriority(LLWorkerThread::PRIORITY_LOW | mWorkPriority);
mState = WAIT_HTTP_REQ;
@@ -897,7 +896,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
std::vector<std::string> headers;
headers.push_back("Accept: image/x-j2c");
res = mFetcher->mCurlGetRequest->getByteRange(mUrl, headers, offset, mRequestedSize,
- new HTTPGetResponder(mFetcher, mID, LLTimer::getTotalTime(), mRequestedSize, offset));
+ new HTTPGetResponder(mFetcher, mID, LLTimer::getTotalTime(), mRequestedSize, offset, true));
}
if (!res)
{
@@ -945,17 +944,6 @@ bool LLTextureFetchWorker::doWork(S32 param)
max_attempts = mHTTPFailCount+1; // Keep retrying
LL_INFOS_ONCE("Texture") << "Texture server busy (503): " << mUrl << LL_ENDL;
}
- else if(mGetStatus >= HTTP_MULTIPLE_CHOICES && mGetStatus < HTTP_BAD_REQUEST) //http re-direct
- {
- ++mHTTPFailCount;
- max_attempts = 5 ; //try at most 5 times to avoid infinite redirection loop.
-
- llwarns << "HTTP GET failed because of redirection: " << mUrl
- << " Status: " << mGetStatus << " Reason: '" << mGetReason << llendl ;
-
- //assign to the new url
- mUrl = mGetReason ;
- }
else
{
const S32 HTTP_MAX_RETRY_COUNT = 3;
@@ -978,6 +966,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
else
{
resetFormattedData();
+ mState = DONE;
return true; // failed
}
}
@@ -988,6 +977,17 @@ bool LLTextureFetchWorker::doWork(S32 param)
}
}
+ llassert_always(mBufferSize == cur_size + mRequestedSize);
+ if(!mBufferSize)//no data received.
+ {
+ delete[] mBuffer;
+ mBuffer = NULL;
+
+ //abort.
+ mState = DONE;
+ return true;
+ }
+
if (mFormattedImage.isNull())
{
// For now, create formatted image based on extension
@@ -998,8 +998,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
mFormattedImage = new LLImageJ2C; // default
}
}
-
- llassert_always(mBufferSize == cur_size + mRequestedSize);
+
if (mHaveAllData && mRequestedDiscard == 0) //the image file is fully loaded.
{
mFileSize = mBufferSize;
@@ -1058,7 +1057,12 @@ bool LLTextureFetchWorker::doWork(S32 param)
if (mFormattedImage->getDataSize() <= 0)
{
- llerrs << "Decode entered with invalid mFormattedImage. ID = " << mID << llendl;
+ //llerrs << "Decode entered with invalid mFormattedImage. ID = " << mID << llendl;
+
+ //abort, don't decode
+ mState = DONE;
+ setPriority(LLWorkerThread::PRIORITY_LOW | mWorkPriority);
+ return true;
}
if (mLoadedDiscard < 0)
{
@@ -1255,8 +1259,7 @@ bool LLTextureFetchWorker::deleteOK()
if ((haveWork() &&
// not ok to delete from these states
- ((mState >= SEND_HTTP_REQ && mState <= WAIT_HTTP_REQ) ||
- (mState >= WRITE_TO_CACHE && mState <= WAIT_ON_WRITE))))
+ ((mState >= WRITE_TO_CACHE && mState <= WAIT_ON_WRITE))))
{
delete_ok = false;
}
@@ -1335,29 +1338,29 @@ bool LLTextureFetchWorker::processSimulatorPackets()
//////////////////////////////////////////////////////////////////////////////
-void LLTextureFetchWorker::callbackHttpGet(const LLChannelDescriptors& channels,
+S32 LLTextureFetchWorker::callbackHttpGet(const LLChannelDescriptors& channels,
const LLIOPipe::buffer_ptr_t& buffer,
bool partial, bool success)
{
+ S32 data_size = 0 ;
+
LLMutexLock lock(&mWorkMutex);
if (mState != WAIT_HTTP_REQ)
{
llwarns << "callbackHttpGet for unrequested fetch worker: " << mID
<< " req=" << mSentRequest << " state= " << mState << llendl;
- return;
+ return data_size;
}
if (mLoaded)
{
llwarns << "Duplicate callback for " << mID.asString() << llendl;
- return; // ignore duplicate callback
+ return data_size ; // ignore duplicate callback
}
if (success)
{
// get length of stream:
- S32 data_size = buffer->countAfter(channels.in(), NULL);
-
- gTextureList.sTextureBits += data_size * 8; // Approximate - does not include header bits
+ data_size = buffer->countAfter(channels.in(), NULL);
LL_DEBUGS("Texture") << "HTTP RECEIVED: " << mID.asString() << " Bytes: " << data_size << LL_ENDL;
if (data_size > 0)
@@ -1394,6 +1397,8 @@ void LLTextureFetchWorker::callbackHttpGet(const LLChannelDescriptors& channels,
}
mLoaded = TRUE;
setPriority(LLWorkerThread::PRIORITY_HIGH | mWorkPriority);
+
+ return data_size ;
}
//////////////////////////////////////////////////////////////////////////////
@@ -1512,6 +1517,7 @@ LLTextureFetch::LLTextureFetch(LLTextureCache* cache, LLImageDecodeThread* image
mTextureCache(cache),
mImageDecodeThread(imagedecodethread),
mTextureBandwidth(0),
+ mHTTPTextureBits(0),
mCurlGetRequest(NULL)
{
mMaxBandwidth = gSavedSettings.getF32("ThrottleBandwidthKBPS");
@@ -1657,10 +1663,11 @@ void LLTextureFetch::addToHTTPQueue(const LLUUID& id)
mHTTPTextureQueue.insert(id);
}
-void LLTextureFetch::removeFromHTTPQueue(const LLUUID& id)
+void LLTextureFetch::removeFromHTTPQueue(const LLUUID& id, S32 received_size)
{
LLMutexLock lock(&mNetworkQueueMutex);
mHTTPTextureQueue.erase(id);
+ mHTTPTextureBits += received_size * 8; // Approximate - does not include header bits
}
void LLTextureFetch::deleteRequest(const LLUUID& id, bool cancel)
@@ -1808,12 +1815,19 @@ bool LLTextureFetch::updateRequestPriority(const LLUUID& id, F32 priority)
//virtual
S32 LLTextureFetch::update(U32 max_time_ms)
{
- S32 res;
-
static LLCachedControl<F32> band_width(gSavedSettings,"ThrottleBandwidthKBPS");
- mMaxBandwidth = band_width ;
-
- res = LLWorkerThread::update(max_time_ms);
+
+ {
+ mNetworkQueueMutex.lock() ;
+ mMaxBandwidth = band_width ;
+
+ gTextureList.sTextureBits += mHTTPTextureBits ;
+ mHTTPTextureBits = 0 ;
+
+ mNetworkQueueMutex.unlock() ;
+ }
+
+ S32 res = LLWorkerThread::update(max_time_ms);
if (!mDebugPause)
{
@@ -1829,7 +1843,7 @@ S32 LLTextureFetch::update(U32 max_time_ms)
lldebugs << "processed: " << processed << " messages." << llendl;
}
}
-
+
return res;
}