Bug 948326 - Actually address review comments in bug 918135. r=cpearce, a=1.3+
authorEdwin Flores <eflores@mozilla.com>
Mon, 16 Dec 2013 17:47:50 +1300
changeset 176178 dde493494cf6e079d4611f8cb118d8641291e919
parent 176177 6a87e8247640d77f4d8060f6ef3f78a80e114144
child 176179 bb8075885195e85b86be7d84cdd2887e5700f1a8
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, 1
bugs948326, 918135
milestone28.0a2
Bug 948326 - Actually address review comments in bug 918135. r=cpearce, a=1.3+
content/media/MP3FrameParser.cpp
--- a/content/media/MP3FrameParser.cpp
+++ b/content/media/MP3FrameParser.cpp
@@ -481,30 +481,39 @@ void MP3FrameParser::Parse(const char* a
   }
 
   MOZ_ASSERT(length <= (int)bytesRead, "All bytes should have been consumed");
 
   // Update next data offset
   mOffset = offset + bytesRead;
 
   // If we've parsed lots of data and we still have nothing, just give up.
-  // We don't count ID3 headers towards that count, as MP3 files can have
-  // massive ID3 sections.
+  // We don't count ID3 headers towards the skipped bytes count, as MP3 files
+  // can have massive ID3 sections.
   if (!mID3Parser.IsParsed() && mMP3Offset < 0 &&
       mOffset - mTotalID3Size > MAX_SKIPPED_BYTES) {
     mIsMP3 = NOT_MP3;
   }
 }
 
 int64_t MP3FrameParser::GetDuration()
 {
   MutexAutoLock mon(mLock);
 
-  if (mMP3Offset < 0) {
-    return -1; // Not a single frame decoded yet
+  if (!ParsedHeaders() || !mSamplesPerSecond) {
+    // Not a single frame decoded yet.
+    return -1;
+  }
+
+  MOZ_ASSERT(mFrameCount > 0 && mTotalFrameSize > 0,
+             "Frame parser should have seen at least one MP3 frame of positive length.");
+
+  if (!mFrameCount || !mTotalFrameSize) {
+    // This should never happen.
+    return -1;
   }
 
   double frames;
   if (mNumFrames < 0) {
     // Estimate the number of frames in the stream based on the average frame
     // size and the length of the MP3 file.
     double frameSize = (double)mTotalFrameSize / mFrameCount;
     frames = (double)(mLength - mMP3Offset) / frameSize;