Bug 1319295. Part 1 - add a field to identify audio or video seek failures. r?jya draft
authorJW Wang <jwwang@mozilla.com>
Fri, 16 Dec 2016 16:57:27 +0800
changeset 451481 6d8457fb70df15c29f9f7451bb8f41b1276d46af
parent 451480 867b2f18697a1b5a1b87b95ad6af8a4fc60e6162
child 451482 71b0535c35dbe3ea89744c0e84e598eee6d164de
push id39197
push userjwwang@mozilla.com
push dateTue, 20 Dec 2016 12:45:19 +0000
reviewersjya
bugs1319295
milestone53.0a1
Bug 1319295. Part 1 - add a field to identify audio or video seek failures. r?jya MozReview-Commit-ID: 3PXlISED4tm
dom/media/MediaDecoderReader.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaDecoderReader.h
+++ b/dom/media/MediaDecoderReader.h
@@ -35,16 +35,28 @@ struct WaitForDataRejectValue
   };
 
   WaitForDataRejectValue(MediaData::Type aType, Reason aReason)
     :mType(aType), mReason(aReason) {}
   MediaData::Type mType;
   Reason mReason;
 };
 
+struct SeekRejectValue
+{
+  MOZ_IMPLICIT SeekRejectValue(const MediaResult& aError)
+    : mType(MediaData::NULL_DATA), mError(aError) {}
+  MOZ_IMPLICIT SeekRejectValue(nsresult aResult)
+    : mType(MediaData::NULL_DATA), mError(aResult) {}
+  SeekRejectValue(MediaData::Type aType, const MediaResult& aError)
+    : mType(aType), mError(aError) {}
+  MediaData::Type mType;
+  MediaResult mError;
+};
+
 class MetadataHolder
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataHolder)
   MediaInfo mInfo;
   nsAutoPtr<MetadataTags> mTags;
 
 private:
@@ -65,17 +77,17 @@ class MediaDecoderReader {
 
 public:
   using TrackSet = EnumSet<TrackInfo::TrackType>;
 
   using MetadataPromise =
     MozPromise<RefPtr<MetadataHolder>, MediaResult, IsExclusive>;
   using MediaDataPromise =
     MozPromise<RefPtr<MediaData>, MediaResult, IsExclusive>;
-  using SeekPromise = MozPromise<media::TimeUnit, MediaResult, IsExclusive>;
+  using SeekPromise = MozPromise<media::TimeUnit, SeekRejectValue, IsExclusive>;
 
   // Note that, conceptually, WaitForData makes sense in a non-exclusive sense.
   // But in the current architecture it's only ever used exclusively (by MDSM),
   // so we mark it that way to verify our assumptions. If you have a use-case
   // for multiple WaitForData consumers, feel free to flip the exclusivity here.
   using WaitForDataPromise =
     MozPromise<MediaData::Type, WaitForDataRejectValue, IsExclusive>;
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -998,18 +998,18 @@ private:
     }
 
     // Request the demuxer to perform seek.
     mSeekRequest.Begin(Reader()->Seek(mSeekJob.mTarget.ref(), mMaster->Duration())
       ->Then(OwnerThread(), __func__,
              [this] (media::TimeUnit aUnit) {
                OnSeekResolved(aUnit);
              },
-             [this] (const MediaResult& aError) {
-               OnSeekRejected(aError);
+             [this] (const SeekRejectValue& aReject) {
+               OnSeekRejected(aReject);
              }));
   }
 
   int64_t CalculateNewCurrentTime() const override
   {
     const int64_t seekTime = mSeekJob.mTarget->GetTime().ToMicroseconds();
 
     // For the accurate seek, we always set the newCurrentTime = seekTime so that
@@ -1050,20 +1050,20 @@ private:
     if (!mDoneVideoSeeking) {
       RequestVideoData();
     }
     if (!mDoneAudioSeeking) {
       RequestAudioData();
     }
   }
 
-  void OnSeekRejected(const MediaResult& aError) {
+  void OnSeekRejected(const SeekRejectValue& aReject) {
     mSeekRequest.Complete();
-    MOZ_ASSERT(NS_FAILED(aError), "Cancels should also disconnect mSeekRequest");
-    mMaster->DecodeError(aError);
+    MOZ_ASSERT(NS_FAILED(aReject.mError), "Cancels should also disconnect mSeekRequest");
+    mMaster->DecodeError(aReject.mError);
   }
 
   void RequestAudioData()
   {
     MOZ_ASSERT(!mDoneAudioSeeking);
     MOZ_ASSERT(!mMaster->IsRequestingAudioData());
     MOZ_ASSERT(!mMaster->IsWaitingAudioData());
     mMaster->RequestAudioData();
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -2070,17 +2070,20 @@ MediaFormatReader::OnSeekFailed(TrackTyp
       return;
     }
     NotifyWaitingForData(aTrack);
     return;
   }
   MOZ_ASSERT(!mVideo.mSeekRequest.Exists() && !mAudio.mSeekRequest.Exists());
   mPendingSeekTime.reset();
   mOriginalSeekTarget.reset();
-  mSeekPromise.Reject(aError, __func__);
+
+  auto type = aTrack == TrackType::kAudioTrack
+    ? MediaData::AUDIO_DATA : MediaData::VIDEO_DATA;
+  mSeekPromise.Reject(SeekRejectValue(type, aError), __func__);
 }
 
 void
 MediaFormatReader::DoVideoSeek()
 {
   MOZ_ASSERT(mPendingSeekTime.isSome());
   LOGV("Seeking video to %lld", mPendingSeekTime.ref().ToMicroseconds());
   media::TimeUnit seekTime = mPendingSeekTime.ref();