Bug 1190558 - Reset MP3 frame parser on track demuxer reset. r=kinetik
authorEugen Sawin <esawin@me73.com>
Fri, 31 Jul 2015 22:45:10 +0200
changeset 287870 69f15a2039fdac999ae3aa90a8c2181ad7bdba90
parent 287869 e90476303f406b58daa6d5eb35edf7e5b85ccb22
child 287871 d31e43ead2dcd242e6fba23cd970ae519c7ae6ef
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1190558
milestone42.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 1190558 - Reset MP3 frame parser on track demuxer reset. r=kinetik
dom/media/MP3Demuxer.cpp
dom/media/MP3Demuxer.h
--- a/dom/media/MP3Demuxer.cpp
+++ b/dom/media/MP3Demuxer.cpp
@@ -159,29 +159,30 @@ MP3TrackDemuxer::Seek(TimeUnit aTime) {
 }
 
 TimeUnit
 MP3TrackDemuxer::FastSeek(TimeUnit aTime) {
   if (!aTime.ToMicroseconds()) {
     // Quick seek to the beginning of the stream.
     mOffset = mFirstFrameOffset;
     mFrameIndex = 0;
-    mParser.FinishParsing();
+    mParser.EndFrameSession();
     return TimeUnit();
   }
 
   if (!mSamplesPerFrame || !mNumParsedFrames) {
     return TimeUnit::FromMicroseconds(-1);
   }
 
   const int64_t numFrames = aTime.ToSeconds() *
                             mSamplesPerSecond / mSamplesPerFrame;
   mOffset = mFirstFrameOffset + numFrames * AverageFrameLength();
   mFrameIndex = numFrames;
-  mParser.FinishParsing();
+
+  mParser.EndFrameSession();
 
   return Duration(mFrameIndex);
 }
 
 TimeUnit
 MP3TrackDemuxer::ScanUntil(TimeUnit aTime) {
   if (!aTime.ToMicroseconds()) {
     return FastSeek(aTime);
@@ -229,16 +230,18 @@ MP3TrackDemuxer::Reset() {
   mOffset = 0;
   mFirstFrameOffset = 0;
   mNumParsedFrames = 0;
   mFrameIndex = 0;
   mTotalFrameLen = 0;
   mSamplesPerFrame = 0;
   mSamplesPerSecond = 0;
   mChannels = 0;
+
+  mParser.Reset();
 }
 
 nsRefPtr<MP3TrackDemuxer::SkipAccessPointPromise>
 MP3TrackDemuxer::SkipToNextRandomAccessPoint(TimeUnit aTimeThreshold) {
   // Will not be called for audio-only resources.
   return SkipAccessPointPromise::CreateAndReject(
     SkipFailureHolder(DemuxerFailureReason::DEMUXER_ERROR, 0), __func__);
 }
@@ -387,17 +390,17 @@ MP3TrackDemuxer::UpdateState(const Media
   mSamplesPerFrame = mParser.CurrentFrame().Header().SamplesPerFrame();
   mSamplesPerSecond = mParser.CurrentFrame().Header().SampleRate();
   mChannels = mParser.CurrentFrame().Header().Channels();
   ++mNumParsedFrames;
   ++mFrameIndex;
   MOZ_ASSERT(mFrameIndex > 0);
 
   // Prepare the parser for the next frame parsing session.
-  mParser.FinishParsing();
+  mParser.EndFrameSession();
 }
 
 int32_t
 MP3TrackDemuxer::Read(uint8_t* aBuffer, int64_t aOffset, int32_t aSize) {
   const int64_t streamLen = StreamLength();
   if (mInfo && streamLen > 0) {
     // Prevent blocking reads after successful initialization.
     aSize = std::min<int64_t>(aSize, streamLen - aOffset);
@@ -435,17 +438,17 @@ FrameParser::FrameParser()
 void
 FrameParser::Reset() {
   mID3Parser.Reset();
   mFirstFrame.Reset();
   mFrame.Reset();
 }
 
 void
-FrameParser::FinishParsing() {
+FrameParser::EndFrameSession() {
   if (!mID3Parser.Header().IsValid()) {
     // Reset ID3 tags only if we have not parsed a valid ID3 header yet.
     mID3Parser.Reset();
   }
 #ifdef ENABLE_TESTS
   mPrevFrame = mFrame;
 #endif
   mFrame.Reset();
--- a/dom/media/MP3Demuxer.h
+++ b/dom/media/MP3Demuxer.h
@@ -251,17 +251,17 @@ public:
   private:
     // The currently parsed frame header.
     FrameHeader mHeader;
   };
 
   // Constructor.
   FrameParser();
 
-  // Returns the currently parsed frame. Reset via Reset or FinishParsing.
+  // Returns the currently parsed frame. Reset via Reset or EndFrameSession.
   const Frame& CurrentFrame() const;
 
 #ifdef ENABLE_TESTS
   // Returns the previously parsed frame. Reset via Reset.
   const Frame& PrevFrame() const;
 #endif
 
   // Returns the first parsed frame. Reset via Reset.
@@ -275,17 +275,17 @@ public:
 
   // Resets the parser. Don't use between frames as first frame data is reset.
   void Reset();
 
   // Clear the last parsed frame to allow for next frame parsing, i.e.:
   // - sets PrevFrame to CurrentFrame
   // - resets the CurrentFrame
   // - resets ID3Header if no valid header was parsed yet
-  void FinishParsing();
+  void EndFrameSession();
 
   // Parses given buffer [aBeg, aEnd) for a valid frame header.
   // Returns begin of frame header if a frame header was found or aEnd otherwise.
   const uint8_t* Parse(const uint8_t* aBeg, const uint8_t* aEnd);
 
   // Parses given buffer [aBeg, aEnd) for a valid VBR header.
   // Returns whether a valid VBR header was found.
   bool ParseVBRHeader(const uint8_t* aBeg, const uint8_t* aEnd);