Bug 1190258: [MSE] P3. Use actual allocated size rather than logical size when calculating eviction rate. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 05 Aug 2015 21:45:53 +1000
changeset 288169 01ae068187d8e3dad0015e43e1cd7f46c5398b2b
parent 288168 4562ee818a4c5cd03ab51c3a58c89ac88ea0817b
child 288170 3f861148c83c282f0ecbeb4e086cf84172f731e5
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1190258
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190258: [MSE] P3. Use actual allocated size rather than logical size when calculating eviction rate. r=gerald This makes eviction slightly more aggressive and ensure we are actually under the memory threshold.
dom/media/MediaData.h
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -389,16 +389,20 @@ class MediaRawData : public MediaData {
 public:
   MediaRawData();
   MediaRawData(const uint8_t* aData, size_t mSize);
 
   // Pointer to data or null if not-yet allocated
   const uint8_t* Data() const { return mData; }
   // Size of buffer.
   size_t Size() const { return mSize; }
+  size_t ComputedSizeOfIncludingThis() const
+  {
+    return sizeof(*this) + mCapacity;
+  }
 
   const CryptoSample& mCrypto;
   nsRefPtr<MediaByteBuffer> mExtraData;
 
   nsRefPtr<SharedTrackInfo> mTrackInfo;
 
   // Return a deep copy or nullptr if out of memory.
   virtual already_AddRefed<MediaRawData> Clone() const;
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -425,17 +425,17 @@ TrackBuffersManager::DoEvictData(const T
       if (toEvict < 0) {
         break;
       }
       partialEvict = 0;
     }
     if (frame->mTime >= lowerLimit.ToMicroseconds()) {
       break;
     }
-    partialEvict += sizeof(*frame) + frame->Size();
+    partialEvict += frame->ComputedSizeOfIncludingThis();
   }
 
   int64_t finalSize = mSizeSourceBuffer - aSizeToEvict;
 
   if (lastKeyFrameIndex > 0) {
     MSE_DEBUG("Step1. Evicting %u bytes prior currentTime",
               aSizeToEvict - toEvict);
     CodedFrameRemoval(
@@ -463,17 +463,17 @@ TrackBuffersManager::DoEvictData(const T
       if (toEvict < 0) {
         break;
       }
       partialEvict = 0;
     }
     if (frame->mTime <= upperLimit.ToMicroseconds()) {
       break;
     }
-    partialEvict += sizeof(*frame) + frame->Size();
+    partialEvict += frame->ComputedSizeOfIncludingThis();
   }
   if (lastKeyFrameIndex < buffer.Length()) {
     MSE_DEBUG("Step2. Evicting %u bytes from trailing data",
               mSizeSourceBuffer - finalSize);
     CodedFrameRemoval(
       TimeInterval(TimeUnit::FromMicroseconds(buffer[lastKeyFrameIndex]->GetEndTime() + 1),
                    TimeUnit::FromInfinity()));
   }
@@ -1395,17 +1395,17 @@ TrackBuffersManager::ProcessFrames(Track
         sizeNewSamples = 0;
       }
       trackBuffer.mNeedRandomAccessPoint = true;
       needDiscontinuityCheck = true;
       continue;
     }
 
     samplesRange += sampleInterval;
-    sizeNewSamples += sizeof(*sample) + sample->Size();
+    sizeNewSamples += sample->ComputedSizeOfIncludingThis();
     sample->mTime = sampleInterval.mStart.ToMicroseconds();
     sample->mTimecode = decodeTimestamp.ToMicroseconds();
     sample->mTrackInfo = trackBuffer.mLastInfo;
     samples.AppendElement(sample);
 
     // Steps 11,12,13,14, 15 and 16 will be done in one block in InsertFrames.
 
     // 17. Set last decode timestamp for track buffer to decode timestamp.
@@ -1601,17 +1601,17 @@ TrackBuffersManager::RemoveFrames(const 
     MediaRawData* sample = data[i].get();
     TimeInterval sampleInterval =
       TimeInterval(TimeUnit::FromMicroseconds(sample->mTime),
                    TimeUnit::FromMicroseconds(sample->GetEndTime()));
     removedIntervals += sampleInterval;
     if (sample->mDuration > maxSampleDuration) {
       maxSampleDuration = sample->mDuration;
     }
-    aTrackData.mSizeBuffer -= sizeof(*sample) + sample->Size();
+    aTrackData.mSizeBuffer -= sample->ComputedSizeOfIncludingThis();
   }
 
   removedIntervals.SetFuzz(TimeUnit::FromMicroseconds(maxSampleDuration));
 
   MSE_DEBUG("Removing frames from:%u (frames:%u) ([%f, %f))",
             firstRemovedIndex.ref(),
             lastRemovedIndex - firstRemovedIndex.ref() + 1,
             removedIntervals.GetStart().ToSeconds(),