Bug 1432195 - Accept Mp3 streams with only 2 frames if both are valid. r?JanH draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 26 Feb 2018 19:07:46 -0500
changeset 761884 5659b9d2f0223f8b822aa2614abd9facedc88b86
parent 760935 ee326c976eebdca48128054022c443d3993e12b0
push id101028
push userbvandyk@mozilla.com
push dateThu, 01 Mar 2018 16:32:58 +0000
reviewersJanH
bugs1432195
milestone60.0a1
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();