Bug 1332584 - Append last frame on EOS in VideoTrackEncoder. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 20 Jan 2017 18:29:26 +0100
changeset 377775 17f78bed73c29ee9d9a0792c1643f37932c60027
parent 377774 5f42a80cee038ae943ba4d3f6278208e0350fc3c
child 377776 3be7e027a50bb9380e95b3726e8902ca08fcc3de
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 - Append last frame on EOS in VideoTrackEncoder. r=jesup MozReview-Commit-ID: LARhY0LAEtG
dom/media/encoder/TrackEncoder.cpp
--- a/dom/media/encoder/TrackEncoder.cpp
+++ b/dom/media/encoder/TrackEncoder.cpp
@@ -272,16 +272,21 @@ VideoTrackEncoder::NotifyQueuedTrackChan
 
 }
 
 nsresult
 VideoTrackEncoder::AppendVideoSegment(const VideoSegment& aSegment)
 {
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
+  if (mEndOfStream) {
+    MOZ_ASSERT(false);
+    return NS_OK;
+  }
+
   // Append all video segments from MediaStreamGraph, including null an
   // non-null frames.
   VideoSegment::ConstChunkIterator iter(aSegment);
   for (; !iter.IsEnded(); iter.Next()) {
     VideoChunk chunk = *iter;
 
     if (mLastChunk.mTimeStamp.IsNull()) {
       if (chunk.IsNull()) {
@@ -325,16 +330,19 @@ VideoTrackEncoder::AppendVideoSegment(co
       TRACK_LOG(LogLevel::Verbose,
                 ("[VideoTrackEncoder]: Chunk >1 second. duration=%lld, "
                  "trackRate=%lld", mLastChunk.mDuration, mTrackRate));
 
       // If we have gotten dupes for over a second, we force send one
       // to the encoder to make sure there is some output.
       chunk.mTimeStamp = mLastChunk.mTimeStamp + TimeDuration::FromSeconds(1);
 
+      // chunk's duration has already been accounted for.
+      chunk.mDuration = 0;
+
       if (chunk.IsNull()) {
         // Ensure that we don't pass null to the encoder by making mLastChunk
         // null later on.
         chunk.mFrame = mLastChunk.mFrame;
       }
     }
 
     TimeDuration diff = chunk.mTimeStamp - mLastChunk.mTimeStamp;
@@ -348,24 +356,26 @@ VideoTrackEncoder::AppendVideoSegment(co
                 ("[VideoTrackEncoder]: Underrun detected. Diff=%.5fs",
                  diff.ToSeconds()));
       chunk.mTimeStamp = mLastChunk.mTimeStamp;
     } else {
       RefPtr<layers::Image> lastImage = mLastChunk.mFrame.GetImage();
       TRACK_LOG(LogLevel::Verbose,
                 ("[VideoTrackEncoder]: Appending video frame %p, duration=%.5f",
                  lastImage.get(), diff.ToSeconds()));
-      mRawSegment.AppendFrame(lastImage.forget(),
-                              RateConvertTicksRoundUp(
-                                  mTrackRate, PR_USEC_PER_SEC,
-                                  diff.ToMicroseconds()),
-                              mLastChunk.mFrame.GetIntrinsicSize(),
-                              PRINCIPAL_HANDLE_NONE,
-                              mLastChunk.mFrame.GetForceBlack(),
-                              mLastChunk.mTimeStamp);
+      CheckedInt64 duration = UsecsToFrames(diff.ToMicroseconds(), mTrackRate);
+      MOZ_ASSERT(duration.isValid());
+      if (duration.isValid()) {
+        mRawSegment.AppendFrame(lastImage.forget(),
+                                duration.value(),
+                                mLastChunk.mFrame.GetIntrinsicSize(),
+                                PRINCIPAL_HANDLE_NONE,
+                                mLastChunk.mFrame.GetForceBlack(),
+                                mLastChunk.mTimeStamp);
+      }
     }
 
     mLastChunk = chunk;
   }
 
   if (mRawSegment.GetDuration() > 0) {
     mReentrantMonitor.NotifyAll();
   }