Bug 1211328: [MSE] Fix timestampOffset attribute calculation in sequence mode. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 05 Oct 2015 15:17:33 +1100
changeset 265983 40ddc543dd16eb0c03634f9b5504622a0cbe3fb6
parent 265982 37fe4bcc5c314dae4c8b4b182a427191d27b486c
child 265984 45f01961ecd0ad9a45067f3e08bfb92539042eeb
child 266008 d977aeac761105ca8653ae6473f30672a6afbeb9
push id29476
push usercbook@mozilla.com
push dateMon, 05 Oct 2015 10:02:13 +0000
treeherdermozilla-central@45f01961ecd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1211328
milestone44.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 1211328: [MSE] Fix timestampOffset attribute calculation in sequence mode. r=gerald
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1349,37 +1349,44 @@ TrackBuffersManager::ResolveProcessing(b
     // mAppendPromise will be resolved immediately upon mProcessingPromise
     // completing.
     mAppendRunning = false;
   }
   mProcessingPromise.ResolveIfExists(aResolveValue, __func__);
 }
 
 void
-TrackBuffersManager::CheckSequenceDiscontinuity()
+TrackBuffersManager::CheckSequenceDiscontinuity(const TimeUnit& aPresentationTime)
 {
   if (mSourceBufferAttributes->GetAppendMode() == SourceBufferAppendMode::Sequence &&
       mGroupStartTimestamp.isSome()) {
-    mTimestampOffset = mGroupStartTimestamp.ref();
+    mTimestampOffset = mGroupStartTimestamp.ref() - aPresentationTime;
     mGroupEndTimestamp = mGroupStartTimestamp.ref();
     mVideoTracks.mNeedRandomAccessPoint = true;
     mAudioTracks.mNeedRandomAccessPoint = true;
     mGroupStartTimestamp.reset();
   }
 }
 
 void
 TrackBuffersManager::ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData)
 {
   if (!aSamples.Length()) {
     return;
   }
 
+  // 1. If generate timestamps flag equals true
+  // Let presentation timestamp equal 0.
+  // Otherwise
+  // Let presentation timestamp be a double precision floating point representation of the coded frame's presentation timestamp in seconds.
+  TimeUnit presentationTimestamp = mSourceBufferAttributes->mGenerateTimestamps
+    ? TimeUnit() : TimeUnit::FromMicroseconds(aSamples[0]->mTime);
+
   // 3. If mode equals "sequence" and group start timestamp is set, then run the following steps:
-  CheckSequenceDiscontinuity();
+  CheckSequenceDiscontinuity(presentationTimestamp);
 
   // 5. Let track buffer equal the track buffer that the coded frame will be added to.
   auto& trackBuffer = aTrackData;
 
   // We apply a fuzz search +- mLongestFrameDuration to get around videos where
   // the start time is negative but close to 0.
   TimeInterval targetWindow{
     TimeInterval(mAppendWindow.mStart, mAppendWindow.mEnd,
@@ -1477,17 +1484,19 @@ TrackBuffersManager::ProcessFrames(Track
         // 4. Unset the highest end timestamp on all track buffers.
         // 5. Set the need random access point flag on all track buffers to true.
         track->ResetAppendState();
       }
       // 6. Jump to the Loop Top step above to restart processing of the current coded frame.
       // Rather that restarting the process for the frame, we run the first
       // steps again instead.
       // 3. If mode equals "sequence" and group start timestamp is set, then run the following steps:
-      CheckSequenceDiscontinuity();
+      TimeUnit presentationTimestamp = mSourceBufferAttributes->mGenerateTimestamps
+        ? TimeUnit() : TimeUnit::FromMicroseconds(sample->mTime);
+      CheckSequenceDiscontinuity(presentationTimestamp);
 
       if (!sample->mKeyframe) {
         continue;
       }
       if (appendMode == SourceBufferAppendMode::Sequence) {
         // mTimestampOffset was modified during CheckSequenceDiscontinuity.
         // We need to update our variables.
         sampleInterval =
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -278,17 +278,17 @@ private:
       mHighestEndTimestamp.reset();
       mNeedRandomAccessPoint = true;
 
       mLongestFrameDuration.reset();
       mNextInsertionIndex.reset();
     }
   };
 
-  void CheckSequenceDiscontinuity();
+  void CheckSequenceDiscontinuity(const media::TimeUnit& aPresentationTime);
   void ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData);
   bool CheckNextInsertionIndex(TrackData& aTrackData,
                                const media::TimeUnit& aSampleTime);
   void InsertFrames(TrackBuffer& aSamples,
                     const media::TimeIntervals& aIntervals,
                     TrackData& aTrackData);
   void RemoveFrames(const media::TimeIntervals& aIntervals,
                     TrackData& aTrackData,