Bug 1243608: P5. Add type utility methods to SeekTarget class. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 28 Jan 2016 23:24:06 +1100
changeset 282626 89cd342eedb1d4afb8c32039629273393656ad16
parent 282625 85e1209e752659839fabe7af782110b4edbb2a0e
child 282627 950702b82f19c5327efab387bdbdbac80700c80d
push id71254
push userjyavenard@mozilla.com
push dateTue, 02 Feb 2016 08:01:20 +0000
treeherdermozilla-inbound@950702b82f19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1243608
milestone47.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 1243608: P5. Add type utility methods to SeekTarget class. r=cpearce
dom/media/MediaDecoderStateMachine.cpp
dom/media/SeekTarget.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -642,28 +642,28 @@ MediaDecoderStateMachine::OnAudioDecoded
         return;
       }
       if (audio->mDiscontinuity) {
         mDropAudioUntilNextDiscontinuity = false;
       }
       if (!mDropAudioUntilNextDiscontinuity) {
         // We must be after the discontinuity; we're receiving samples
         // at or after the seek target.
-        if (mCurrentSeek.mTarget.mType == SeekTarget::PrevSyncPoint &&
+        if (mCurrentSeek.mTarget.IsFast() &&
             mCurrentSeek.mTarget.GetTime().ToMicroseconds() > mCurrentTimeBeforeSeek &&
             audio->mTime < mCurrentTimeBeforeSeek) {
           // We are doing a fastSeek, but we ended up *before* the previous
           // playback position. This is surprising UX, so switch to an accurate
           // seek and decode to the seek target. This is not conformant to the
           // spec, fastSeek should always be fast, but until we get the time to
           // change all Readers to seek to the keyframe after the currentTime
           // in this case, we'll just decode forward. Bug 1026330.
-          mCurrentSeek.mTarget.mType = SeekTarget::Accurate;
+          mCurrentSeek.mTarget.SetType(SeekTarget::Accurate);
         }
-        if (mCurrentSeek.mTarget.mType == SeekTarget::PrevSyncPoint) {
+        if (mCurrentSeek.mTarget.IsFast()) {
           // Non-precise seek; we can stop the seek at the first sample.
           Push(audio, MediaData::AUDIO_DATA);
         } else {
           // We're doing an accurate seek. We must discard
           // MediaData up to the one containing exact seek target.
           if (NS_FAILED(DropAudioUpToSeekTarget(audio))) {
             DecodeError();
             return;
@@ -962,28 +962,28 @@ MediaDecoderStateMachine::OnVideoDecoded
       if (mDropVideoUntilNextDiscontinuity) {
         if (video->mDiscontinuity) {
           mDropVideoUntilNextDiscontinuity = false;
         }
       }
       if (!mDropVideoUntilNextDiscontinuity) {
         // We must be after the discontinuity; we're receiving samples
         // at or after the seek target.
-        if (mCurrentSeek.mTarget.mType == SeekTarget::PrevSyncPoint &&
+        if (mCurrentSeek.mTarget.IsFast() &&
             mCurrentSeek.mTarget.GetTime().ToMicroseconds() > mCurrentTimeBeforeSeek &&
             video->mTime < mCurrentTimeBeforeSeek) {
           // We are doing a fastSeek, but we ended up *before* the previous
           // playback position. This is surprising UX, so switch to an accurate
           // seek and decode to the seek target. This is not conformant to the
           // spec, fastSeek should always be fast, but until we get the time to
           // change all Readers to seek to the keyframe after the currentTime
           // in this case, we'll just decode forward. Bug 1026330.
-          mCurrentSeek.mTarget.mType = SeekTarget::Accurate;
+          mCurrentSeek.mTarget.SetType(SeekTarget::Accurate);
         }
-        if (mCurrentSeek.mTarget.mType == SeekTarget::PrevSyncPoint ||
+        if (mCurrentSeek.mTarget.IsFast() ||
             mPendingSeek.Exists()) {
           // Non-precise seek; or a pending seek exists ; we can stop the seek
           // at the first sample.
           Push(video, MediaData::VIDEO_DATA);
         } else {
           // We're doing an accurate seek. We still need to discard
           // MediaData up to the one containing exact seek target.
           if (NS_FAILED(DropVideoUpToSeekTarget(video))) {
@@ -2543,17 +2543,17 @@ MediaDecoderStateMachine::DropVideoUpToS
 
 nsresult
 MediaDecoderStateMachine::DropAudioUpToSeekTarget(MediaData* aSample)
 {
   MOZ_ASSERT(OnTaskQueue());
   RefPtr<AudioData> audio(aSample->As<AudioData>());
   MOZ_ASSERT(audio &&
              mCurrentSeek.Exists() &&
-             mCurrentSeek.mTarget.mType == SeekTarget::Accurate);
+             mCurrentSeek.mTarget.IsAccurate());
 
   CheckedInt64 sampleDuration =
     FramesToUsecs(audio->mFrames, mInfo.mAudio.mRate);
   if (!sampleDuration.isValid()) {
     return NS_ERROR_FAILURE;
   }
 
   if (audio->mTime + sampleDuration.value() <= mCurrentSeek.mTarget.GetTime().ToMicroseconds()) {
--- a/dom/media/SeekTarget.h
+++ b/dom/media/SeekTarget.h
@@ -20,43 +20,43 @@ enum class MediaDecoderEventVisibility :
 // or "Fast" (nearest keyframe) seek was requested.
 struct SeekTarget {
   enum Type {
     Invalid,
     PrevSyncPoint,
     Accurate
   };
   SeekTarget()
-    : mType(SeekTarget::Invalid)
-    , mEventVisibility(MediaDecoderEventVisibility::Observable)
+    : mEventVisibility(MediaDecoderEventVisibility::Observable)
     , mTime(media::TimeUnit::Invalid())
+    , mType(SeekTarget::Invalid)
   {
   }
   SeekTarget(int64_t aTimeUsecs,
              Type aType,
              MediaDecoderEventVisibility aEventVisibility =
                MediaDecoderEventVisibility::Observable)
-    : mType(aType)
-    , mEventVisibility(aEventVisibility)
+    : mEventVisibility(aEventVisibility)
     , mTime(media::TimeUnit::FromMicroseconds(aTimeUsecs))
+    , mType(aType)
   {
   }
   SeekTarget(const media::TimeUnit& aTime,
              Type aType,
              MediaDecoderEventVisibility aEventVisibility =
                MediaDecoderEventVisibility::Observable)
-    : mType(aType)
-    , mEventVisibility(aEventVisibility)
+    : mEventVisibility(aEventVisibility)
     , mTime(aTime)
+    , mType(aType)
   {
   }
   SeekTarget(const SeekTarget& aOther)
-    : mType(aOther.mType)
-    , mEventVisibility(aOther.mEventVisibility)
+    : mEventVisibility(aOther.mEventVisibility)
     , mTime(aOther.mTime)
+    , mType(aOther.mType)
   {
   }
   bool IsValid() const {
     return mType != SeekTarget::Invalid;
   }
   void Reset() {
     mTime = media::TimeUnit::Invalid();
     mType = SeekTarget::Invalid;
@@ -64,23 +64,32 @@ struct SeekTarget {
   media::TimeUnit GetTime() const {
     NS_ASSERTION(mTime.IsValid(), "Invalid SeekTarget");
     return mTime;
   }
   void SetTime(const media::TimeUnit& aTime) {
     NS_ASSERTION(aTime.IsValid(), "Invalid SeekTarget destination");
     mTime = aTime;
   }
+  void SetType(Type aType) {
+    mType = aType;
+  }
+  bool IsFast() const {
+    return mType == SeekTarget::Type::PrevSyncPoint;
+  }
+  bool IsAccurate() const {
+    return mType == SeekTarget::Type::Accurate;
+  }
 
-  // Whether we should seek "Fast", or "Accurate".
-  // "Fast" seeks to the seek point preceeding mTime, whereas
-  // "Accurate" seeks as close as possible to mTime.
-  Type mType;
   MediaDecoderEventVisibility mEventVisibility;
 
 private:
   // Seek target time.
   media::TimeUnit mTime;
+  // Whether we should seek "Fast", or "Accurate".
+  // "Fast" seeks to the seek point preceeding mTime, whereas
+  // "Accurate" seeks as close as possible to mTime.
+  Type mType;
 };
 
 } // namespace mozilla
 
 #endif /* SEEK_TARGET_H */