Bug 1044498 - WebMBufferedReader used mBlockOffset in some places where it was intended to use mBlockTimecode. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 25 Aug 2014 16:09:44 +1200
changeset 201265 c40f86ae9b17c95cb2f81ba48e677cf3fb183307
parent 201264 8e1f729051790da142833502f4f12279d78b0be1
child 201266 f277da7fa9fac4046a97f20e4c21669d0eff684f
push id48139
push usermgregan@mozilla.com
push dateMon, 25 Aug 2014 04:10:24 +0000
treeherdermozilla-inbound@2c94c5407b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1044498
milestone34.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 1044498 - WebMBufferedReader used mBlockOffset in some places where it was intended to use mBlockTimecode. r=cajbir
content/media/webm/WebMBufferedParser.cpp
content/media/webm/WebMBufferedParser.h
content/media/webm/WebMReader.cpp
--- a/content/media/webm/WebMBufferedParser.cpp
+++ b/content/media/webm/WebMBufferedParser.cpp
@@ -142,17 +142,17 @@ void WebMBufferedParser::Append(const un
       } else {
         // It's possible we've parsed this data before, so avoid inserting
         // duplicate WebMTimeDataOffset entries.
         {
           ReentrantMonitorAutoEnter mon(aReentrantMonitor);
           uint32_t idx = aMapping.IndexOfFirstElementGt(mBlockOffset);
           if (idx == 0 || !(aMapping[idx - 1] == mBlockOffset)) {
             // Don't insert invalid negative timecodes.
-            if (mBlockOffset > 0 || mClusterTimecode > uint16_t(abs(mBlockOffset))) {
+            if (mBlockTimecode >= 0 || mClusterTimecode >= uint16_t(abs(mBlockTimecode))) {
               MOZ_ASSERT(mGotTimecodeScale);
               uint64_t absTimecode = mClusterTimecode + mBlockTimecode;
               absTimecode *= mTimecodeScale;
               WebMTimeDataOffset entry(mBlockOffset, absTimecode, mClusterOffset);
               aMapping.InsertElementAt(idx, entry);
             }
           }
         }
@@ -221,29 +221,29 @@ bool WebMBufferedState::CalculateBuffere
   // normalized in the range [0,duration].
 
   *aStartTime = mTimeMapping[start].mTimecode;
   *aEndTime = mTimeMapping[end].mTimecode;
   *aEndTime += mTimeMapping[end].mTimecode - mTimeMapping[end - 1].mTimecode;
   return true;
 }
 
-bool WebMBufferedState::GetOffsetForTime(uint64_t aTime, int64_t* aOffset, enum OffsetType aType)
+bool WebMBufferedState::GetOffsetForTime(uint64_t aTime, int64_t* aOffset)
 {
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
   WebMTimeDataOffset result(0, 0, 0);
 
   for (uint32_t i = 0; i < mTimeMapping.Length(); ++i) {
     WebMTimeDataOffset o = mTimeMapping[i];
     if (o.mTimecode < aTime && o.mTimecode > result.mTimecode) {
       result = o;
     }
   }
 
-  *aOffset = aType == CLUSTER_START ? result.mSyncOffset : result.mOffset;
+  *aOffset = result.mSyncOffset;
   return true;
 }
 
 void WebMBufferedState::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
   uint32_t idx = mRangeParsers.IndexOfFirstElementGt(aOffset - 1);
   if (idx == 0 || !(mRangeParsers[idx-1] == aOffset)) {
--- a/content/media/webm/WebMBufferedParser.h
+++ b/content/media/webm/WebMBufferedParser.h
@@ -204,21 +204,21 @@ class WebMBufferedState MOZ_FINAL
 public:
   WebMBufferedState() : mReentrantMonitor("WebMBufferedState") {
     MOZ_COUNT_CTOR(WebMBufferedState);
   }
 
   void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
   bool CalculateBufferedForRange(int64_t aStartOffset, int64_t aEndOffset,
                                  uint64_t* aStartTime, uint64_t* aEndTime);
-  enum OffsetType {
-    CLUSTER_START,
-    BLOCK_START
-  };
-  bool GetOffsetForTime(uint64_t aTime, int64_t* aOffset, enum OffsetType aType);
+
+  // Returns true if aTime is is present in mTimeMapping and sets aOffset to
+  // the latest offset for which decoding can resume without data
+  // dependencies to arrive at aTime.
+  bool GetOffsetForTime(uint64_t aTime, int64_t* aOffset);
 
 private:
   // Private destructor, to discourage deletion outside of Release():
   ~WebMBufferedState() {
     MOZ_COUNT_DTOR(WebMBufferedState);
   }
 
   // Synchronizes access to the mTimeMapping array.
--- a/content/media/webm/WebMReader.cpp
+++ b/content/media/webm/WebMReader.cpp
@@ -939,23 +939,23 @@ bool WebMReader::DecodeVideoFrame(bool &
       b.mPlanes[0].mWidth = img->d_w;
       b.mPlanes[0].mOffset = b.mPlanes[0].mSkip = 0;
 
       b.mPlanes[1].mData = img->planes[1];
       b.mPlanes[1].mStride = img->stride[1];
       b.mPlanes[1].mHeight = (img->d_h + 1) >> img->y_chroma_shift;
       b.mPlanes[1].mWidth = (img->d_w + 1) >> img->x_chroma_shift;
       b.mPlanes[1].mOffset = b.mPlanes[1].mSkip = 0;
- 
+
       b.mPlanes[2].mData = img->planes[2];
       b.mPlanes[2].mStride = img->stride[2];
       b.mPlanes[2].mHeight = (img->d_h + 1) >> img->y_chroma_shift;
       b.mPlanes[2].mWidth = (img->d_w + 1) >> img->x_chroma_shift;
       b.mPlanes[2].mOffset = b.mPlanes[2].mSkip = 0;
-  
+
       IntRect picture = ToIntRect(mPicture);
       if (img->d_w != static_cast<uint32_t>(mInitialFrame.width) ||
           img->d_h != static_cast<uint32_t>(mInitialFrame.height)) {
         // Frame size is different from what the container reports. This is legal
         // in WebM, and we will preserve the ratio of the crop rectangle as it
         // was reported relative to the picture size reported by the container.
         picture.x = (mPicture.x * img->d_w) / mInitialFrame.width;
         picture.y = (mPicture.y * img->d_h) / mInitialFrame.height;
@@ -1006,18 +1006,17 @@ nsresult WebMReader::Seek(int64_t aTarge
   uint64_t target = aTarget * NS_PER_USEC;
   if (mSeekPreroll) {
     target = std::max(static_cast<uint64_t>(aStartTime * NS_PER_USEC), target - mSeekPreroll);
   }
   int r = nestegg_track_seek(mContext, trackToSeek, target);
   if (r != 0) {
     // Try seeking directly based on cluster information in memory.
     int64_t offset = 0;
-    bool rv = mBufferedState->GetOffsetForTime((aTarget - aStartTime)/NS_PER_USEC, &offset,
-                                               WebMBufferedState::CLUSTER_START);
+    bool rv = mBufferedState->GetOffsetForTime((aTarget - aStartTime)/NS_PER_USEC, &offset);
     if (!rv) {
       return NS_ERROR_FAILURE;
     }
 
     r = nestegg_offset_seek(mContext, offset);
     if (r != 0) {
       return NS_ERROR_FAILURE;
     }
@@ -1082,17 +1081,16 @@ nsresult WebMReader::GetBuffered(dom::Ti
 void WebMReader::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
 {
   mBufferedState->NotifyDataArrived(aBuffer, aLength, aOffset);
 }
 
 int64_t WebMReader::GetEvictionOffset(double aTime)
 {
   int64_t offset;
-  if (!mBufferedState->GetOffsetForTime(aTime / NS_PER_USEC, &offset,
-                                        WebMBufferedState::CLUSTER_START)) {
+  if (!mBufferedState->GetOffsetForTime(aTime / NS_PER_USEC, &offset)) {
     return -1;
   }
 
   return offset;
 }
 
 } // namespace mozilla