Bug 1065235 - Apply eviction to all decoders owned by TrackBuffer and make EvictData threshold apply per-TrackBuffer rather than per-decoder. r=cajbir

--HG--
extra : rebase_source : f4ea425c9adeece7b37a4966131a1b566377add7
This commit is contained in:
Matthew Gregan 2014-09-09 21:12:00 +12:00
parent d94484630e
commit c56b93ea7b
5 changed files with 39 additions and 15 deletions

View File

@ -103,20 +103,19 @@ public:
}
// Evict data in queue if the total queue size is greater than
// aThreshold past the offset. Returns true if some data was
// actually evicted.
bool Evict(uint64_t aOffset, uint32_t aThreshold) {
bool evicted = false;
// aThreshold past the offset. Returns amount evicted.
uint32_t Evict(uint64_t aOffset, uint32_t aThreshold) {
uint32_t evicted = 0;
while (GetLength() - mOffset > aThreshold) {
ResourceItem* item = ResourceAt(0);
if (item->mData.Length() + mOffset > aOffset) {
break;
}
mOffset += item->mData.Length();
evicted += item->mData.Length();
SBR_DEBUGV("ResourceQueue(%p)::Evict(%llu, %u) removed chunk length=%u",
this, aOffset, aThreshold, item->mData.Length());
delete PopFront();
evicted = true;
}
return evicted;
}

View File

@ -659,6 +659,7 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
// about.
// TODO: Make the eviction threshold smaller for audio-only streams.
// TODO: Drive evictions off memory pressure notifications.
// TODO: Consider a global eviction threshold rather than per TrackBuffer.
const uint32_t evict_threshold = 75 * (1 << 20);
bool evicted = mTrackBuffer->EvictData(evict_threshold);
if (evicted) {

View File

@ -147,7 +147,7 @@ SourceBufferResource::ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCo
return rv;
}
bool
uint32_t
SourceBufferResource::EvictData(uint32_t aThreshold)
{
SBR_DEBUG("SourceBufferResource(%p)::EvictData(aThreshold=%u)", this, aThreshold);

View File

@ -65,6 +65,7 @@ public:
virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { UNIMPLEMENTED(); *aIsReliable = false; return 0; }
virtual int64_t GetLength() MOZ_OVERRIDE { return mInputBuffer.GetLength(); }
virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE {
ReentrantMonitorAutoEnter mon(mMonitor);
MOZ_ASSERT(aOffset >= 0);
if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
return mInputBuffer.GetOffset();
@ -83,6 +84,7 @@ public:
virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) MOZ_OVERRIDE
{
ReentrantMonitorAutoEnter mon(mMonitor);
if (mInputBuffer.GetLength()) {
aRanges.AppendElement(MediaByteRange(mInputBuffer.GetOffset(),
mInputBuffer.GetLength()));
@ -114,12 +116,18 @@ public:
void AppendData(const uint8_t* aData, uint32_t aLength);
void Ended();
// Remove data from resource if it holds more than the threshold
// number of bytes. Returns true if some data was evicted.
bool EvictData(uint32_t aThreshold);
// number of bytes. Returns amount evicted.
uint32_t EvictData(uint32_t aThreshold);
// Remove data from resource before the given offset.
void EvictBefore(uint64_t aOffset);
// Returns the amount of data currently retained by this resource.
int64_t GetSize() {
ReentrantMonitorAutoEnter mon(mMonitor);
return mInputBuffer.GetLength() - mInputBuffer.GetOffset();
}
#if defined(DEBUG)
void Dump(const char* aPath) {
mInputBuffer.Dump(aPath);

View File

@ -124,20 +124,36 @@ bool
TrackBuffer::EvictData(uint32_t aThreshold)
{
MOZ_ASSERT(NS_IsMainThread());
// XXX Call EvictData on mDecoders?
return mCurrentDecoder->GetResource()->EvictData(aThreshold);
int64_t totalSize = 0;
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
totalSize += mDecoders[i]->GetResource()->GetSize();
}
int64_t toEvict = totalSize - aThreshold;
if (toEvict <= 0) {
return false;
}
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
MSE_DEBUG("TrackBuffer(%p)::EvictData decoder=%u threshold=%u toEvict=%lld",
this, i, aThreshold, toEvict);
toEvict -= mDecoders[i]->GetResource()->EvictData(toEvict);
}
return toEvict < (totalSize - aThreshold);
}
void
TrackBuffer::EvictBefore(double aTime)
{
MOZ_ASSERT(NS_IsMainThread());
// XXX Call EvictBefore on mDecoders?
int64_t endOffset = mCurrentDecoder->ConvertToByteOffset(aTime);
if (endOffset > 0) {
mCurrentDecoder->GetResource()->EvictBefore(endOffset);
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
int64_t endOffset = mDecoders[i]->ConvertToByteOffset(aTime);
if (endOffset > 0) {
MSE_DEBUG("TrackBuffer(%p)::EvictBefore decoder=%u offset=%lld", this, i, endOffset);
mDecoders[i]->GetResource()->EvictBefore(endOffset);
}
}
MSE_DEBUG("TrackBuffer(%p)::EvictBefore offset=%lld", this, endOffset);
}
double