Bug 1332584 - Use time conversion utils from VideoUtils. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 20 Jan 2017 18:59:46 +0100
changeset 377776 3be7e027a50bb9380e95b3726e8902ca08fcc3de
parent 377775 17f78bed73c29ee9d9a0792c1643f37932c60027
child 377777 76f2c83d048c379d19dbb2170db9f9f200df0804
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1332584
milestone53.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 1332584 - Use time conversion utils from VideoUtils. r=jesup MozReview-Commit-ID: 7AVeGp5akfx
dom/media/encoder/TrackEncoder.cpp
--- a/dom/media/encoder/TrackEncoder.cpp
+++ b/dom/media/encoder/TrackEncoder.cpp
@@ -302,19 +302,22 @@ VideoTrackEncoder::AppendVideoSegment(co
       const StreamTime nullDuration = mLastChunk.mDuration;
       mLastChunk = chunk;
 
       TRACK_LOG(LogLevel::Verbose,
                 ("[VideoTrackEncoder]: Got first video chunk after %lld ticks.",
                  nullDuration));
       // Adapt to the time before the first frame. This extends the first frame
       // from [start, end] to [0, end], but it'll do for now.
-      mLastChunk.mTimeStamp -=
-        TimeDuration::FromMicroseconds(
-          RateConvertTicksRoundUp(PR_USEC_PER_SEC, mTrackRate, nullDuration));
+      CheckedInt64 diff = FramesToUsecs(nullDuration, mTrackRate);
+      MOZ_ASSERT(diff.isValid());
+      if (diff.isValid()) {
+        mLastChunk.mTimeStamp -= TimeDuration::FromMicroseconds(diff.value());
+        mLastChunk.mDuration += nullDuration;
+      }
     }
 
     MOZ_ASSERT(!mLastChunk.IsNull());
     if (mLastChunk.CanCombineWithFollowing(chunk) || chunk.IsNull()) {
       TRACK_LOG(LogLevel::Verbose,
                 ("[VideoTrackEncoder]: Got dupe or null chunk."));
       // This is the same frame as before (or null). We extend the last chunk
       // with its duration.
@@ -389,17 +392,38 @@ VideoTrackEncoder::NotifyEndOfStream()
   // If source video track is muted till the end of encoding, initialize the
   // encoder with default frame width, frame height, and track rate.
   if (!mCanceled && !mInitialized) {
     Init(DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT,
          DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT);
   }
 
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+
+  if (mEndOfStream) {
+    // We have already been notified.
+    return;
+  }
+
   mEndOfStream = true;
+  TRACK_LOG(LogLevel::Info, ("[VideoTrackEncoder]: Reached end of stream"));
+
+  if (!mLastChunk.IsNull() && mLastChunk.mDuration > 0) {
+    RefPtr<layers::Image> lastImage = mLastChunk.mFrame.GetImage();
+    TRACK_LOG(LogLevel::Debug,
+              ("[VideoTrackEncoder]: Appending last video frame %p, "
+               "duration=%.5f", lastImage.get(),
+               FramesToTimeUnit(mLastChunk.mDuration, mTrackRate).ToSeconds()));
+    mRawSegment.AppendFrame(lastImage.forget(),
+                            mLastChunk.mDuration,
+                            mLastChunk.mFrame.GetIntrinsicSize(),
+                            PRINCIPAL_HANDLE_NONE,
+                            mLastChunk.mFrame.GetForceBlack(),
+                            mLastChunk.mTimeStamp);
+  }
   mReentrantMonitor.NotifyAll();
 }
 
 size_t
 VideoTrackEncoder::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   return mRawSegment.SizeOfExcludingThis(aMallocSizeOf);
 }