Backout incorrectly pushed changes

This commit is contained in:
Robert O'Callahan 2009-04-06 14:19:27 +12:00
parent 2bb2ba8f08
commit d95f70cfbf
4 changed files with 25 additions and 45 deletions

View File

@ -40,6 +40,7 @@
#define nsMediaCache_h_
#include "nsTArray.h"
#include "prinrval.h"
#include "nsAutoLock.h"
/**

View File

@ -47,7 +47,6 @@
#include "nsMediaStream.h"
#include "nsMathUtils.h"
#include "prlog.h"
#include "nsTimeStamp.h"
#ifdef PR_LOGGING
PRLogModuleInfo* gMediaCacheLog;
@ -75,9 +74,6 @@ static const PRUint32 REPLAY_DELAY = 30;
// can.
static const PRUint32 FREE_BLOCK_SCAN_LIMIT = 16;
using mozilla::TimeStamp;
using mozilla::TimeDuration;
class nsMediaCache {
public:
friend class nsMediaCacheStream::BlockList;
@ -152,7 +148,7 @@ public:
// and thus hasn't yet been committed to the cache. The caller will
// call QueueUpdate().
void NoteBlockUsage(PRInt32 aBlockIndex, nsMediaCacheStream::ReadMode aMode,
TimeStamp aNow);
PRIntervalTime aNow);
// This queues a call to Update() on the main thread.
void QueueUpdate();
@ -179,7 +175,7 @@ protected:
// Find a free or reusable block and return its index. If there are no
// free blocks and no reusable blocks, add a new block to the cache
// and return it. Can return -1 on OOM.
PRInt32 FindBlockForIncomingData(TimeStamp aNow, nsMediaCacheStream* aStream);
PRInt32 FindBlockForIncomingData(PRIntervalTime aNow, nsMediaCacheStream* aStream);
// Find a reusable block --- a free block, if there is one, otherwise
// the reusable block with the latest predicted-next-use, or -1 if
// there aren't any freeable blocks. Only block indices less than
@ -187,7 +183,7 @@ protected:
// then aForStream and aForStreamBlock indicate what media data will
// be placed; FindReusableBlock will favour returning free blocks
// near other blocks for that point in the stream.
PRInt32 FindReusableBlock(TimeStamp aNow,
PRInt32 FindReusableBlock(PRIntervalTime aNow,
nsMediaCacheStream* aForStream,
PRInt32 aForStreamBlock,
PRInt32 aMaxSearchBlockIndex);
@ -226,7 +222,7 @@ protected:
PRUint32 mStreamBlock;
// Time at which this block was last used. Valid only if
// mClass is METADATA_BLOCK or PLAYED_BLOCK.
TimeStamp mLastUseTime;
PRIntervalTime mLastUseTime;
// The class is FREE_BLOCK if and only if mStream is null
BlockClass mClass;
// Next and previous blocks of this class (circular links, so
@ -249,9 +245,9 @@ protected:
void InsertReadaheadBlock(PRInt32 aBlockIndex);
// Guess the duration until block aBlock will be next used
TimeDuration PredictNextUse(TimeStamp aNow, PRInt32 aBlock);
PRIntervalTime PredictNextUse(PRIntervalTime aNow, PRInt32 aBlock);
// Guess the duration until the next incoming data on aStream will be used
TimeDuration PredictNextUseForIncomingData(nsMediaCacheStream* aStream);
PRIntervalTime PredictNextUseForIncomingData(nsMediaCacheStream* aStream);
// Truncate the file and index array if there are free blocks at the
// end
@ -541,7 +537,7 @@ static PRInt32 GetMaxBlocks()
}
PRInt32
nsMediaCache::FindBlockForIncomingData(TimeStamp aNow,
nsMediaCache::FindBlockForIncomingData(PRIntervalTime aNow,
nsMediaCacheStream* aStream)
{
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
@ -595,7 +591,7 @@ nsMediaCache::AppendMostReusableBlock(BlockList* aBlockList,
}
PRInt32
nsMediaCache::FindReusableBlock(TimeStamp aNow,
nsMediaCache::FindReusableBlock(PRIntervalTime aNow,
nsMediaCacheStream* aForStream,
PRInt32 aForStreamBlock,
PRInt32 aMaxSearchBlockIndex)
@ -655,10 +651,10 @@ nsMediaCache::FindReusableBlock(TimeStamp aNow,
}
}
TimeDuration latestUse = 0;
PRIntervalTime latestUse = 0;
PRInt32 latestUseBlock = -1;
for (PRUint32 i = 0; i < candidates.Length(); ++i) {
TimeDuration nextUse = PredictNextUse(aNow, candidates[i]);
PRIntervalTime nextUse = PredictNextUse(aNow, candidates[i]);
if (nextUse > latestUse) {
latestUse = nextUse;
latestUseBlock = candidates[i];
@ -771,8 +767,8 @@ nsMediaCache::FreeBlock(PRInt32 aBlock)
Verify();
}
TimeDuration
nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
PRIntervalTime
nsMediaCache::PredictNextUse(PRIntervalTime aNow, PRInt32 aBlock)
{
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
@ -789,8 +785,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
NS_ASSERTION(PRInt64(block->mStreamBlock)*BLOCK_SIZE <
block->mStream->mStreamOffset,
"Played block after the current stream position?");
return aNow - block->mLastUseTime +
TimeDuration::FromSeconds(REPLAY_DELAY);
return aNow - block->mLastUseTime + PR_SecondsToInterval(REPLAY_DELAY);
case READAHEAD_BLOCK: {
PRInt64 bytesAhead =
PRInt64(block->mStreamBlock)*BLOCK_SIZE - block->mStream->mStreamOffset;
@ -798,8 +793,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
"Readahead block before the current stream position?");
PRInt64 millisecondsAhead =
bytesAhead*1000/block->mStream->mPlaybackBytesPerSecond;
return TimeDuration::FromMilliseconds(
PR_MIN(millisecondsAhead, PR_INT32_MAX));
return PR_MillisecondsToInterval(PRUint32(PR_MIN(millisecondsAhead, PR_INT32_MAX)));
}
default:
NS_ERROR("Invalid class for predicting next use");
@ -807,7 +801,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
}
}
TimeDuration
PRIntervalTime
nsMediaCache::PredictNextUseForIncomingData(nsMediaCacheStream* aStream)
{
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
@ -818,10 +812,9 @@ nsMediaCache::PredictNextUseForIncomingData(nsMediaCacheStream* aStream)
return PR_SecondsToInterval(24*60*60);
}
if (bytesAhead <= 0)
return TimeDuration();
return PR_SecondsToInterval(0);
PRInt64 millisecondsAhead = bytesAhead*1000/aStream->mPlaybackBytesPerSecond;
return TimeDuration::FromMilliseconds(
PR_MIN(millisecondsAhead, PR_INT32_MAX));
return PR_MillisecondsToInterval(PRUint32(PR_MIN(millisecondsAhead, PR_INT32_MAX)));
}
void
@ -836,7 +829,7 @@ nsMediaCache::Update()
#endif
PRInt32 maxBlocks = GetMaxBlocks();
TimeStamp now = TimeStamp::Now();
PRIntervalTime now = PR_IntervalNow();
PRInt32 freeBlockCount = mFreeBlocks.GetCount();
// Try to trim back the cache to its desired maximum size. The cache may
@ -853,7 +846,7 @@ nsMediaCache::Update()
// to avoid that since it requires HTTP seeks.
// We also use this loop to eliminate overflowing blocks from
// freeBlockCount.
TimeDuration latestPredictedUseForOverflow = 0;
PRIntervalTime latestPredictedUseForOverflow = 0;
for (PRInt32 blockIndex = mIndex.Length() - 1; blockIndex >= maxBlocks;
--blockIndex) {
nsMediaCacheStream* stream = mIndex[blockIndex].mStream;
@ -862,7 +855,7 @@ nsMediaCache::Update()
--freeBlockCount;
continue;
}
TimeDuration predictedUse = PredictNextUse(now, blockIndex);
PRIntervalTime predictedUse = PredictNextUse(now, blockIndex);
latestPredictedUseForOverflow = PR_MAX(latestPredictedUseForOverflow, predictedUse);
}
@ -933,7 +926,7 @@ nsMediaCache::Update()
// If freeBlockCount is zero, then compute the latest of
// the predicted next-uses for all blocks
TimeDuration latestNextUse;
PRIntervalTime latestNextUse = 0;
if (freeBlockCount == 0) {
PRInt32 reusableBlock = FindReusableBlock(now, nsnull, 0, maxBlocks);
if (reusableBlock >= 0) {
@ -1013,7 +1006,7 @@ nsMediaCache::Update()
// Free blocks in the cache, so keep reading
LOG(PR_LOG_DEBUG, ("Stream %p reading since there are free blocks", stream));
enableReading = PR_TRUE;
} else if (latestNextUse <= TimeDuration()) {
} else if (latestNextUse <= 0) {
// No reusable blocks, so can't read anything
LOG(PR_LOG_DEBUG, ("Stream %p throttling due to no reusable blocks", stream));
enableReading = PR_FALSE;

View File

@ -72,21 +72,6 @@ public:
return TimeDuration(PRInt64(aMilliseconds)*PR_TicksPerSecond()/1000);
}
TimeDuration operator+(const TimeDuration& aOther) const {
return TimeDuration(mValue + aOther.mValue);
}
TimeDuration operator-(const TimeDuration& aOther) const {
return TimeDuration(mValue - aOther.mValue);
}
TimeDuration& operator+=(const TimeDuration& aOther) {
mValue += aOther.mValue;
return *this;
}
TimeDuration& operator-=(const TimeDuration& aOther) {
mValue -= aOther.mValue;
return *this;
}
PRBool operator<(const TimeDuration& aOther) const {
return mValue < aOther.mValue;
}
@ -102,6 +87,7 @@ public:
// We could define additional operators here:
// -- convert to/from other time units
// -- add/subtract durations
// -- scale duration by a float
// but let's do that on demand.
// Comparing durations for equality should be discouraged.

View File

@ -96,6 +96,7 @@ CPP_UNIT_TESTS = \
TestPipe.cpp \
TestServMgr.cpp \
TestTextFormatter.cpp \
TestTimeStamp.cpp \
$(NULL)
ifndef MOZ_ENABLE_LIBXUL
@ -114,7 +115,6 @@ CPP_UNIT_TESTS += \
TestStrings.cpp \
TestStorageStream.cpp \
TestTArray.cpp \
TestTimeStamp.cpp \
$(NULL)
endif