Bug 1282658. Part 11 - merge OnAudioNotDecoded() and OnVideoNotDecoded(). r=kaku
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Jun 2016 16:54:38 +0800
changeset 303768 111114fbbe27deff5d3f038d6c63affc2ffc0577
parent 303767 a0325c3082b81c77fd8ba3537164d04031490def
child 303769 eb18fb6afd688f6155c3074e14639de6c45ac2e2
push id30401
push usercbook@mozilla.com
push dateWed, 06 Jul 2016 09:40:34 +0000
treeherdermozilla-central@a7d6bb9e7d12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1282658
milestone50.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 1282658. Part 11 - merge OnAudioNotDecoded() and OnVideoNotDecoded(). r=kaku MozReview-Commit-ID: GE0IZc6cqBY
dom/media/AccurateSeekTask.cpp
dom/media/AccurateSeekTask.h
--- a/dom/media/AccurateSeekTask.cpp
+++ b/dom/media/AccurateSeekTask.cpp
@@ -383,44 +383,59 @@ AccurateSeekTask::OnAudioDecoded(MediaDa
         return;
       }
     }
   }
   CheckIfSeekComplete();
 }
 
 void
-AccurateSeekTask::OnAudioNotDecoded(MediaDecoderReader::NotDecodedReason aReason)
+AccurateSeekTask::OnNotDecoded(MediaData::Type aType,
+                               MediaDecoderReader::NotDecodedReason aReason)
 {
   AssertOwnerThread();
   MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
 
-  SAMPLE_LOG("OnAduioNotDecoded (aReason=%u)", aReason);
+  SAMPLE_LOG("OnNotDecoded type=%d reason=%u", aType, aReason);
 
   if (aReason == MediaDecoderReader::DECODE_ERROR) {
     // If this is a decode error, delegate to the generic error path.
     RejectIfExist(__func__);
     return;
   }
 
   // If the decoder is waiting for data, we tell it to call us back when the
   // data arrives.
   if (aReason == MediaDecoderReader::WAITING_FOR_DATA) {
-    mReader->WaitForData(MediaData::AUDIO_DATA);
+    mReader->WaitForData(aType);
     return;
   }
 
   if (aReason == MediaDecoderReader::CANCELED) {
-    EnsureAudioDecodeTaskQueued();
+    if (aType == MediaData::AUDIO_DATA) {
+      EnsureAudioDecodeTaskQueued();
+    } else {
+      EnsureVideoDecodeTaskQueued();
+    }
     return;
   }
 
   if (aReason == MediaDecoderReader::END_OF_STREAM) {
-    mIsAudioQueueFinished = true;
-    mDoneAudioSeeking = true;
+    if (aType == MediaData::AUDIO_DATA) {
+      mIsAudioQueueFinished = true;
+      mDoneAudioSeeking = true;
+    } else {
+      mIsVideoQueueFinished = true;
+      mDoneVideoSeeking = true;
+      if (mFirstVideoFrameAfterSeek) {
+        // Hit the end of stream. Move mFirstVideoFrameAfterSeek into
+        // mSeekedVideoData so we have something to display after seeking.
+        mSeekedVideoData = mFirstVideoFrameAfterSeek.forget();
+      }
+    }
     CheckIfSeekComplete();
   }
 }
 
 void
 AccurateSeekTask::OnVideoDecoded(MediaData* aVideoSample)
 {
   AssertOwnerThread();
@@ -467,78 +482,38 @@ AccurateSeekTask::OnVideoDecoded(MediaDa
         return;
       }
     }
   }
   CheckIfSeekComplete();
 }
 
 void
-AccurateSeekTask::OnVideoNotDecoded(MediaDecoderReader::NotDecodedReason aReason)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  SAMPLE_LOG("OnVideoNotDecoded (aReason=%u)", aReason);
-
-  if (aReason == MediaDecoderReader::DECODE_ERROR) {
-    // If this is a decode error, delegate to the generic error path.
-    RejectIfExist(__func__);
-    return;
-  }
-
-  // If the decoder is waiting for data, we tell it to call us back when the
-  // data arrives.
-  if (aReason == MediaDecoderReader::WAITING_FOR_DATA) {
-    mReader->WaitForData(MediaData::VIDEO_DATA);
-    return;
-  }
-
-  if (aReason == MediaDecoderReader::CANCELED) {
-    EnsureVideoDecodeTaskQueued();
-    return;
-  }
-
-  if (aReason == MediaDecoderReader::END_OF_STREAM) {
-    if (mFirstVideoFrameAfterSeek) {
-      // Null sample. Hit end of stream. If we have decoded a frame,
-      // insert it into the queue so that we have something to display.
-      // We make sure to do this before invoking VideoQueue().Finish()
-      // below.
-      mSeekedVideoData = mFirstVideoFrameAfterSeek;
-      mFirstVideoFrameAfterSeek = nullptr;
-    }
-
-    mIsVideoQueueFinished = true;
-    mDoneVideoSeeking = true;
-    CheckIfSeekComplete();
-  }
-}
-
-void
 AccurateSeekTask::SetCallbacks()
 {
   AssertOwnerThread();
 
   mAudioCallback = mReader->AudioCallback().Connect(
     OwnerThread(), [this] (AudioCallbackData aData) {
     if (aData.is<MediaData*>()) {
       OnAudioDecoded(aData.as<MediaData*>());
     } else {
-      OnAudioNotDecoded(aData.as<MediaDecoderReader::NotDecodedReason>());
+      OnNotDecoded(MediaData::AUDIO_DATA,
+        aData.as<MediaDecoderReader::NotDecodedReason>());
     }
   });
 
   mVideoCallback = mReader->VideoCallback().Connect(
     OwnerThread(), [this] (VideoCallbackData aData) {
     typedef Tuple<MediaData*, TimeStamp> Type;
     if (aData.is<Type>()) {
       OnVideoDecoded(Get<0>(aData.as<Type>()));
     } else {
-      OnVideoNotDecoded(aData.as<MediaDecoderReader::NotDecodedReason>());
+      OnNotDecoded(MediaData::VIDEO_DATA,
+        aData.as<MediaDecoderReader::NotDecodedReason>());
     }
   });
 
   mAudioWaitCallback = mReader->AudioWaitCallback().Connect(
     OwnerThread(), [this] (WaitCallbackData aData) {
     if (aData.is<MediaData::Type>()) {
       EnsureAudioDecodeTaskQueued();
     }
--- a/dom/media/AccurateSeekTask.h
+++ b/dom/media/AccurateSeekTask.h
@@ -48,21 +48,19 @@ private:
   void CheckIfSeekComplete();
 
   void OnSeekResolved(media::TimeUnit);
 
   void OnSeekRejected(nsresult aResult);
 
   void OnAudioDecoded(MediaData* aAudioSample);
 
-  void OnAudioNotDecoded(MediaDecoderReader::NotDecodedReason aReason);
-
   void OnVideoDecoded(MediaData* aVideoSample);
 
-  void OnVideoNotDecoded(MediaDecoderReader::NotDecodedReason aReason);
+  void OnNotDecoded(MediaData::Type, MediaDecoderReader::NotDecodedReason);
 
   void SetCallbacks();
 
   void CancelCallbacks();
 
   /*
    * Internal state.
    */