Bug 1332584 - Use time conversion utils from VideoUtils. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 20 Jan 2017 18:59:46 +0100
changeset 464232 ea6b4f40dcbeaec6f81f26ec95483f844a37b2ca
parent 464231 72bcbe049bcbca33e613508f5a63e691c0110ee4
child 464233 41debe52a3e32820eb33a18ad86e794a3efdc6c6
push id42308
push userbmo:pehrson@telenordigital.com
push dateFri, 20 Jan 2017 18:10:47 +0000
reviewersjesup
bugs1332584
milestone53.0a1
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);
 }