diff --git a/dom/media/mp3/MP3Demuxer.cpp b/dom/media/mp3/MP3Demuxer.cpp index 51524750f86a..a5b51c258f97 100644 --- a/dom/media/mp3/MP3Demuxer.cpp +++ b/dom/media/mp3/MP3Demuxer.cpp @@ -626,8 +626,17 @@ already_AddRefed MP3TrackDemuxer::GetNextFrame( if (mNumParsedFrames == 1) { // First frame parsed, let's read VBR info if available. BufferReader reader(frame->Data(), frame->Size()); - mParser.ParseVBRHeader(&reader); mFirstFrameOffset = frame->mOffset; + + if (mParser.ParseVBRHeader(&reader)) { + // Parsing was successful + if (mParser.VBRInfo().Type() == FrameParser::VBRHeader::XING) { + MP3LOGV("XING header present, skipping encoder delay (%u frames)", + mParser.VBRInfo().EncoderDelay()); + mEncoderDelay = mParser.VBRInfo().EncoderDelay(); + mEncoderPadding = mParser.VBRInfo().EncoderPadding(); + } + } } MP3LOGV("GetNext() End mOffset=%" PRIu64 " mNumParsedFrames=%" PRIu64 diff --git a/dom/media/mp3/MP3Demuxer.h b/dom/media/mp3/MP3Demuxer.h index ea91d9501d12..7ee4773d9d37 100644 --- a/dom/media/mp3/MP3Demuxer.h +++ b/dom/media/mp3/MP3Demuxer.h @@ -162,6 +162,11 @@ class MP3TrackDemuxer : public MediaTrackDemuxer, // Audio track config info. UniquePtr mInfo; + + // Number of frames to skip at the beginning + uint32_t mEncoderDelay = 0; + // Number of frames to skip at the end + uint32_t mEncoderPadding = 0; }; } // namespace mozilla