Bug 1197125: [webm]. Don't load the entire webm in RAM. r=kinetik a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 28 Aug 2015 11:19:14 +1000
changeset 289195 d9ca8b3490f14302796e64ab3d91cfe35c4e114d
parent 289194 0c0bfde2f006e612c873698c8e5cd4b879985aff
child 289196 216bc8e9f02bb1d0bd0fdc23b187ed6aaae4c233
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)
reviewerskinetik, ritu
bugs1197125
milestone42.0a2
Bug 1197125: [webm]. Don't load the entire webm in RAM. r=kinetik a=ritu Instead we parse it in chunks of 1MiB max.
dom/media/webm/WebMBufferedParser.cpp
--- a/dom/media/webm/WebMBufferedParser.cpp
+++ b/dom/media/webm/WebMBufferedParser.cpp
@@ -410,19 +410,26 @@ void WebMBufferedState::UpdateIndex(cons
         length -= uint32_t(adjust);
       } else {
         mRangeParsers.InsertElementAt(idx, WebMBufferedParser(offset));
         if (idx) {
           mRangeParsers[idx].SetTimecodeScale(mRangeParsers[0].GetTimecodeScale());
         }
       }
     }
-    nsRefPtr<MediaByteBuffer> bytes = aResource->MediaReadAt(offset, length);
-    if(bytes) {
+    while (length > 0) {
+      static const uint32_t BLOCK_SIZE = 1048576;
+      uint32_t block = std::min(length, BLOCK_SIZE);
+      nsRefPtr<MediaByteBuffer> bytes = aResource->MediaReadAt(offset, block);
+      if (!bytes) {
+        break;
+      }
       NotifyDataArrived(bytes->Elements(), bytes->Length(), offset);
+      length -= bytes->Length();
+      offset += bytes->Length();
     }
   }
 }
 
 int64_t WebMBufferedState::GetInitEndOffset()
 {
   if (mRangeParsers.IsEmpty()) {
     return -1;