Bug 1121692 - Clean up semantics around m{Audio,Video}IsSeeking. r=mattwoodrow, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Fri, 16 Jan 2015 10:58:00 -0800
changeset 242940 35f5cf685186
parent 242939 871ab0d29bb8
child 242941 3e1dd9e96598
push id4343
push userryanvm@gmail.com
push date2015-01-20 16:38 +0000
treeherdermozilla-beta@c5dfa7d081f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, sledru
bugs1121692
milestone36.0
Bug 1121692 - Clean up semantics around m{Audio,Video}IsSeeking. r=mattwoodrow, a=sledru The comments indicate that they're supposed to be used for setting mDiscontinuity on the samples, but that never actually happens (and appears to happen in MP4Reader.cpp). Resetting them in Request{Audio,Video}Data doesn't make any sense at all. So we repurpose them to track our seek stage.
dom/media/mediasource/MediaSourceReader.cpp
dom/media/mediasource/MediaSourceReader.h
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -45,22 +45,22 @@ using mozilla::dom::TimeRanges;
 namespace mozilla {
 
 MediaSourceReader::MediaSourceReader(MediaSourceDecoder* aDecoder)
   : MediaDecoderReader(aDecoder)
   , mLastAudioTime(0)
   , mLastVideoTime(0)
   , mPendingSeekTime(-1)
   , mWaitingForSeekData(false)
+  , mAudioIsSeeking(false)
+  , mVideoIsSeeking(false)
   , mTimeThreshold(-1)
   , mDropAudioBeforeThreshold(false)
   , mDropVideoBeforeThreshold(false)
   , mEnded(false)
-  , mAudioIsSeeking(false)
-  , mVideoIsSeeking(false)
   , mHasEssentialTrackBuffers(false)
 #ifdef MOZ_FMP4
   , mSharedDecoderManager(new SharedDecoderManager())
 #endif
 {
 }
 
 void
@@ -113,17 +113,17 @@ MediaSourceReader::RequestAudioData()
 {
   nsRefPtr<AudioDataPromise> p = mAudioPromise.Ensure(__func__);
   MSE_DEBUGV("MediaSourceReader(%p)::RequestAudioData", this);
   if (!mAudioReader) {
     MSE_DEBUG("MediaSourceReader(%p)::RequestAudioData called with no audio reader", this);
     mAudioPromise.Reject(DECODE_ERROR, __func__);
     return p;
   }
-  mAudioIsSeeking = false;
+  MOZ_ASSERT(!mAudioIsSeeking);
   if (SwitchAudioReader(mLastAudioTime)) {
     mAudioReader->Seek(mLastAudioTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::RequestAudioDataComplete,
                        &MediaSourceReader::RequestAudioDataFailed);
   } else {
     RequestAudioDataComplete(0);
   }
@@ -247,17 +247,17 @@ MediaSourceReader::RequestVideoData(bool
     mVideoPromise.Reject(DECODE_ERROR, __func__);
     return p;
   }
   if (aSkipToNextKeyframe) {
     mTimeThreshold = aTimeThreshold;
     mDropAudioBeforeThreshold = true;
     mDropVideoBeforeThreshold = true;
   }
-  mVideoIsSeeking = false;
+  MOZ_ASSERT(!mVideoIsSeeking);
   if (SwitchVideoReader(mLastVideoTime)) {
     mVideoReader->Seek(mLastVideoTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::RequestVideoDataComplete,
                        &MediaSourceReader::RequestVideoDataFailed);
   } else {
     mVideoReader->RequestVideoData(aSkipToNextKeyframe, aTimeThreshold)
                 ->Then(GetTaskQueue(), __func__, this,
@@ -630,44 +630,62 @@ MediaSourceReader::Seek(int64_t aTime, i
   AttemptSeek();
   return p;
 }
 
 void
 MediaSourceReader::OnVideoSeekCompleted(int64_t aTime)
 {
   mPendingSeekTime = aTime;
+  MOZ_ASSERT(mVideoIsSeeking);
+  MOZ_ASSERT(!mAudioIsSeeking);
+  mVideoIsSeeking = false;
+
   if (mAudioTrack) {
     mAudioIsSeeking = true;
     SwitchAudioReader(mPendingSeekTime);
     mAudioReader->Seek(mPendingSeekTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::OnAudioSeekCompleted,
                        &MediaSourceReader::OnSeekFailed);
     MSE_DEBUG("MediaSourceReader(%p)::Seek audio reader=%p", this, mAudioReader.get());
     return;
   }
   mSeekPromise.Resolve(mPendingSeekTime, __func__);
 }
 
 void
 MediaSourceReader::OnAudioSeekCompleted(int64_t aTime)
 {
+  mPendingSeekTime = aTime;
+  MOZ_ASSERT(mAudioIsSeeking);
+  MOZ_ASSERT(!mVideoIsSeeking);
+  mAudioIsSeeking = false;
+
   mSeekPromise.Resolve(mPendingSeekTime, __func__);
+  mPendingSeekTime = -1;
 }
 
 void
 MediaSourceReader::OnSeekFailed(nsresult aResult)
 {
-  // Keep the most recent failed result (if any)
-  if (NS_FAILED(aResult)) {
-    mSeekPromise.Reject(aResult, __func__);
-    return;
+  MOZ_ASSERT(mVideoIsSeeking || mAudioIsSeeking);
+
+  if (mVideoIsSeeking) {
+    MOZ_ASSERT(!mAudioIsSeeking);
+    mVideoIsSeeking = false;
   }
-  mSeekPromise.Resolve(mPendingSeekTime, __func__);
+
+  if (mAudioIsSeeking) {
+    MOZ_ASSERT(!mVideoIsSeeking);
+    mAudioIsSeeking = false;
+  }
+
+  mPendingSeekTime = -1;
+  mSeekPromise.Reject(aResult, __func__);
 }
 
 void
 MediaSourceReader::AttemptSeek()
 {
   // Make sure we don't hold the monitor while calling into the reader
   // Seek methods since it can deadlock.
   {
--- a/dom/media/mediasource/MediaSourceReader.h
+++ b/dom/media/mediasource/MediaSourceReader.h
@@ -184,31 +184,25 @@ private:
   int64_t mLastAudioTime;
   int64_t mLastVideoTime;
 
   // Temporary seek information while we wait for the data
   // to be added to the track buffer.
   MediaPromiseHolder<SeekPromise> mSeekPromise;
   int64_t mPendingSeekTime;
   bool mWaitingForSeekData;
+  bool mAudioIsSeeking;
+  bool mVideoIsSeeking;
 
   int64_t mTimeThreshold;
   bool mDropAudioBeforeThreshold;
   bool mDropVideoBeforeThreshold;
 
   bool mEnded;
 
-  // For a seek to complete we need to send a sample with
-  // the mDiscontinuity field set to true once we have the
-  // first decoded sample. These flags are set during seeking
-  // so we can detect when we have the first decoded sample
-  // after a seek.
-  bool mAudioIsSeeking;
-  bool mVideoIsSeeking;
-
   bool mHasEssentialTrackBuffers;
 
   void ContinueShutdown();
   MediaPromiseHolder<ShutdownPromise> mMediaSourceShutdownPromise;
 #ifdef MOZ_FMP4
   nsRefPtr<SharedDecoderManager> mSharedDecoderManager;
 #endif
 };