Bug 1355756. P2 - let VideoData::UpdateDuration() take TimeUnit. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 12 Apr 2017 17:34:06 +0800
changeset 563450 cb58509ef76ee51e7f11f791e36911bbfa2d7b4e
parent 563449 cb5748026907f9ba01e603f993b1b86d0e89c2a1
child 563451 55b439daedc009ca082020e0865d24d2ba96f6fc
push id54305
push userjwwang@mozilla.com
push dateMon, 17 Apr 2017 02:37:16 +0000
bugs1355756
milestone55.0a1
Bug 1355756. P2 - let VideoData::UpdateDuration() take TimeUnit. MozReview-Commit-ID: BSydHhJwgup
dom/media/MediaData.cpp
dom/media/MediaData.h
dom/media/android/AndroidMediaReader.cpp
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -218,21 +218,20 @@ VideoData::SizeOfIncludingThis(MallocSiz
         static_cast<const mozilla::layers::PlanarYCbCrImage*>(mImage.get());
     size += img->SizeOfIncludingThis(aMallocSizeOf);
   }
 
   return size;
 }
 
 void
-VideoData::UpdateDuration(int64_t aDuration)
+VideoData::UpdateDuration(const TimeUnit& aDuration)
 {
-  MOZ_ASSERT(aDuration >= 0);
-
-  mDuration = TimeUnit::FromMicroseconds(aDuration);
+  MOZ_ASSERT(!aDuration.IsNegative());
+  mDuration = aDuration;
 }
 
 void
 VideoData::UpdateTimestamp(int64_t aTimestamp)
 {
   MOZ_ASSERT(aTimestamp >= 0);
 
   int64_t updatedDuration = GetEndTime() - aTimestamp;
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -553,17 +553,17 @@ public:
             int64_t aTimecode,
             IntSize aDisplay,
             uint32_t aFrameID);
 
   void SetListener(UniquePtr<Listener> aListener);
   void MarkSentToCompositor();
   bool IsSentToCompositor() { return mSentToCompositor; }
 
-  void UpdateDuration(int64_t aDuration);
+  void UpdateDuration(const media::TimeUnit& aDuration);
   void UpdateTimestamp(int64_t aTimestamp);
 
 protected:
   ~VideoData();
 
   bool mSentToCompositor;
   UniquePtr<Listener> mListener;
 };
--- a/dom/media/android/AndroidMediaReader.cpp
+++ b/dom/media/android/AndroidMediaReader.cpp
@@ -137,17 +137,17 @@ bool AndroidMediaReader::DecodeVideoFram
     if (!mPlugin->ReadVideo(mPlugin, &frame, mVideoSeekTimeUs, &bufferCallback)) {
       // We reached the end of the video stream. If we have a buffered
       // video frame, push it the video queue using the total duration
       // of the video as the end time.
       if (mLastVideoFrame) {
         int64_t durationUs;
         mPlugin->GetDuration(mPlugin, &durationUs);
         durationUs = std::max<int64_t>(durationUs - mLastVideoFrame->mTime, 0);
-        mLastVideoFrame->UpdateDuration(durationUs);
+        mLastVideoFrame->UpdateDuration(TimeUnit::FromMicroseconds(durationUs));
         mVideoQueue.Push(mLastVideoFrame);
         mLastVideoFrame = nullptr;
       }
       return false;
     }
     mVideoSeekTimeUs = -1;
 
     if (aKeyframeSkip) {
@@ -243,17 +243,17 @@ bool AndroidMediaReader::DecodeVideoFram
       mLastVideoFrame = v;
       continue;
     }
 
     // Calculate the duration as the timestamp of the current frame minus the
     // timestamp of the previous frame. We can then return the previously
     // decoded frame, and it will have a valid timestamp.
     int64_t duration = v->mTime - mLastVideoFrame->mTime;
-    mLastVideoFrame->UpdateDuration(duration);
+    mLastVideoFrame->UpdateDuration(TimeUnit::FromMicroseconds(duration));
 
     // We have the start time of the next frame, so we can push the previous
     // frame into the queue, except if the end time is below the threshold,
     // in which case it wouldn't be displayed anyway.
     if (mLastVideoFrame->GetEndTime() < aTimeThreshold.ToMicroseconds()) {
       mLastVideoFrame = nullptr;
       continue;
     }