Bug 1150322 - Fix duration parsing in MediaOmxReader. r=sotaro, a=jocheng
authorEdwin Flores <eflores@mozilla.com>
Mon, 04 May 2015 11:40:30 +1200
changeset 238355 ae7e61e290cbc76b4cc966a95a3dae27bd54e964
parent 238354 28b7fe8921516a355cbca82dbcd0691e5e8581cc
child 238356 70782f19acbfc2f1d7c74444b9d9cd027a7e56f6
push id586
push userryanvm@gmail.com
push dateMon, 11 May 2015 21:56:27 +0000
treeherdermozilla-b2g37_v2_2@70782f19acbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro, jocheng
bugs1150322
milestone37.0
Bug 1150322 - Fix duration parsing in MediaOmxReader. r=sotaro, a=jocheng
dom/media/omx/MediaOmxReader.cpp
dom/media/omx/MediaOmxReader.h
--- a/dom/media/omx/MediaOmxReader.cpp
+++ b/dom/media/omx/MediaOmxReader.cpp
@@ -139,17 +139,16 @@ MediaOmxReader::MediaOmxReader(AbstractM
   : MediaOmxCommonReader(aDecoder)
   , mMutex("MediaOmxReader.Data")
   , mHasVideo(false)
   , mHasAudio(false)
   , mVideoSeekTimeUs(-1)
   , mAudioSeekTimeUs(-1)
   , mLastParserDuration(-1)
   , mSkipCount(0)
-  , mUseParserDuration(false)
   , mIsShutdown(false)
   , mMP3FrameParser(-1)
   , mIsWaitingResources(false)
 {
 #ifdef PR_LOGGING
   if (!gMediaDecoderLog) {
     gMediaDecoderLog = PR_NewLogModule("MediaDecoder");
   }
@@ -283,26 +282,26 @@ nsresult MediaOmxReader::ReadMetadata(Me
     return NS_OK;
   }
   // After resources are available, set the metadata.
   if (!mOmxDecoder->EnsureMetadata()) {
     return NS_ERROR_FAILURE;
   }
 
   if (isMP3 && mMP3FrameParser.IsMP3()) {
-    int64_t duration = mMP3FrameParser.GetDuration();
-    // The MP3FrameParser may reported a duration;
-    // return -1 if no frame has been parsed.
-    if (duration >= 0) {
-      ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-      mUseParserDuration = true;
-      mLastParserDuration = duration;
-      mDecoder->SetMediaDuration(mLastParserDuration);
-    }
+    // Check if the MP3 frame parser found a duration.
+    mLastParserDuration = mMP3FrameParser.GetDuration();
+  }
+
+  if (mLastParserDuration >= 0) {
+    // Prefer the parser duration if we have it.
+    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
+    mDecoder->SetMediaDuration(mLastParserDuration);
   } else {
+    // MP3 parser failed to find a duration.
     // Set the total duration (the max of the audio and video track).
     int64_t durationUs;
     mOmxDecoder->GetDuration(&durationUs);
     if (durationUs) {
       ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
       mDecoder->SetMediaDuration(durationUs);
     }
   }
@@ -491,17 +490,17 @@ void MediaOmxReader::NotifyDataArrived(c
 
   if (!mMP3FrameParser.NeedsData()) {
     return;
   }
 
   mMP3FrameParser.Parse(aBuffer, aLength, aOffset);
   int64_t duration = mMP3FrameParser.GetDuration();
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-  if (duration != mLastParserDuration && mUseParserDuration) {
+  if (duration != mLastParserDuration) {
     mLastParserDuration = duration;
     mDecoder->UpdateEstimatedMediaDuration(mLastParserDuration);
   }
 }
 
 bool MediaOmxReader::DecodeAudioData()
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
--- a/dom/media/omx/MediaOmxReader.h
+++ b/dom/media/omx/MediaOmxReader.h
@@ -36,17 +36,16 @@ class MediaOmxReader : public MediaOmxCo
   bool mHasVideo;
   bool mHasAudio;
   nsIntRect mPicture;
   nsIntSize mInitialFrame;
   int64_t mVideoSeekTimeUs;
   int64_t mAudioSeekTimeUs;
   int64_t mLastParserDuration;
   int32_t mSkipCount;
-  bool mUseParserDuration;
   bool mIsShutdown;
 protected:
   android::sp<android::OmxDecoder> mOmxDecoder;
   android::sp<android::MediaExtractor> mExtractor;
   MP3FrameParser mMP3FrameParser;
 
   // A cache value updated by UpdateIsWaitingMediaResources(), makes the
   // "waiting resources state" is synchronous to StateMachine.