Bug 1432195 - Accept Mp3 streams with only 2 frames if both are valid. r=JanH
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 26 Feb 2018 19:07:46 -0500
changeset 461042 8d90e4a0e8817ba896493ffbbda8873197606c82
parent 461041 91f0a95a1fab930728e0712a7006a06c847eaa70
child 461043 b5c420d486dbd2095cdda93ae7a2acaa8fefe699
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH
bugs1432195
milestone60.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 1432195 - Accept Mp3 streams with only 2 frames if both are valid. r=JanH MozReview-Commit-ID: Gl5mgNuzZTt
dom/media/mp3/MP3Demuxer.cpp
--- a/dom/media/mp3/MP3Demuxer.cpp
+++ b/dom/media/mp3/MP3Demuxer.cpp
@@ -442,17 +442,17 @@ MP3TrackDemuxer::FindFirstFrame()
 
   MediaByteRange candidateFrame = FindNextFrame();
   int numSuccFrames = candidateFrame.Length() > 0;
   MediaByteRange currentFrame = candidateFrame;
   MP3LOGV("FindFirst() first candidate frame: mOffset=%" PRIu64
           " Length()=%" PRIu64,
           candidateFrame.mStart, candidateFrame.Length());
 
-  while (candidateFrame.Length() && numSuccFrames < MIN_SUCCESSIVE_FRAMES) {
+  while (candidateFrame.Length()) {
     mParser.EndFrameSession();
     mOffset = currentFrame.mEnd;
     const MediaByteRange prevFrame = currentFrame;
 
     // FindNextFrame() here will only return frames consistent with our candidate frame.
     currentFrame = FindNextFrame();
     numSuccFrames += currentFrame.Length() > 0;
     // Multiple successive false positives, which wouldn't be caught by the consistency
@@ -468,26 +468,36 @@ MP3TrackDemuxer::FindFirstFrame()
       mParser.ResetFrameData();
       mOffset = candidateFrame.mStart + 1;
       candidateFrame = FindNextFrame();
       numSuccFrames = candidateFrame.Length() > 0;
       currentFrame = candidateFrame;
       MP3LOGV("FindFirst() new candidate frame: mOffset=%" PRIu64
               " Length()=%" PRIu64,
               candidateFrame.mStart, candidateFrame.Length());
+    } else if (numSuccFrames >= MIN_SUCCESSIVE_FRAMES) {
+      MP3LOG("FindFirst() accepting candidate frame: "
+             "successiveFrames=%d", numSuccFrames);
+      mFrameLock = true;
+      return candidateFrame;
+    } else if (prevFrame.mStart == mParser.ID3Header().TotalTagSize() &&
+               currentFrame.mEnd == StreamLength()) {
+      // We accept streams with only two frames if both frames are valid. This
+      // is to handle very short files and provide parity with Chrome. See
+      // bug 1432195 for more information. This will not handle short files
+      // with a trailing tag, but as of writing we lack infrastructure to
+      // handle such tags.
+      MP3LOG("FindFirst() accepting candidate frame for short stream: "
+             "successiveFrames=%d", numSuccFrames);
+      mFrameLock = true;
+      return candidateFrame;
     }
   }
 
-  if (numSuccFrames >= MIN_SUCCESSIVE_FRAMES) {
-    MP3LOG("FindFirst() accepting candidate frame: "
-           "successiveFrames=%d", numSuccFrames);
-    mFrameLock = true;
-  } else {
-    MP3LOG("FindFirst() no suitable first frame found");
-  }
+  MP3LOG("FindFirst() no suitable first frame found");
   return candidateFrame;
 }
 
 static bool
 VerifyFrameConsistency(const FrameParser::Frame& aFrame1,
                        const FrameParser::Frame& aFrame2)
 {
   const auto& h1 = aFrame1.Header();