From 5f704f19d4290d409b797e23cac6aed99898bd5e Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Thu, 1 Oct 2020 13:58:03 +0000 Subject: [PATCH] Bug 1566389 - Store the parsed encoder delay and padding when demuxing an mp3 file. r=jya,bryce Differential Revision: https://phabricator.services.mozilla.com/D91770 --- dom/media/mp3/MP3Demuxer.cpp | 11 ++++++++++- dom/media/mp3/MP3Demuxer.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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