Bug 1432195 - Accept Mp3 streams with only 2 frames if both are valid. r?JanH
MozReview-Commit-ID: Gl5mgNuzZTt
--- 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();