Bug 1332584 - Use time conversion utils from VideoUtils. r?jesup
MozReview-Commit-ID: 7AVeGp5akfx
--- 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);
}