Bug 1300871 - Rollback to use original duration in video case. r?jesup draft
authorctai <ctai@mozilla.com>
Thu, 08 Sep 2016 13:46:48 +0800
changeset 411475 6b3aa9d42cd9ae09c601b954ec39b5111ca61623
parent 410870 91c2b9d5c1354ca79e5b174591dbb03b32b15bbf
child 530742 a557c1780ade9cfe9db6e93e121daa410892c4dd
push id28908
push userbmo:ctai@mozilla.com
push dateThu, 08 Sep 2016 05:55:39 +0000
reviewersjesup
bugs1300871
milestone51.0a1
Bug 1300871 - Rollback to use original duration in video case. r?jesup MozReview-Commit-ID: 2gK8vvBKtkC
dom/media/encoder/TrackEncoder.cpp
dom/media/encoder/TrackEncoder.h
--- a/dom/media/encoder/TrackEncoder.cpp
+++ b/dom/media/encoder/TrackEncoder.cpp
@@ -263,68 +263,52 @@ VideoTrackEncoder::NotifyQueuedTrackChan
   Init(video);
 
   AppendVideoSegment(video);
 
   // The stream has stopped and reached the end of track.
   if (aTrackEvents == TrackEventCommand::TRACK_EVENT_ENDED) {
     LOG("[VideoTrackEncoder]: Receive TRACK_EVENT_ENDED .");
     NotifyEndOfStream();
-    mFirstFrame = true;
   }
 
 }
 
 nsresult
 VideoTrackEncoder::AppendVideoSegment(const VideoSegment& aSegment)
 {
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
   // Append all video segments from MediaStreamGraph, including null an
   // non-null frames.
   VideoSegment::ChunkIterator iter(const_cast<VideoSegment&>(aSegment));
   while (!iter.IsEnded()) {
     VideoChunk chunk = *iter;
-    mTotalFrameDuration += chunk.GetDuration();
     mLastFrameDuration += chunk.GetDuration();
     // Send only the unique video frames for encoding.
     // Or if we got the same video chunks more than 1 seconds,
     // force to send into encoder.
     if ((mLastFrame != chunk.mFrame) ||
         (mLastFrameDuration >= mTrackRate)) {
       RefPtr<layers::Image> image = chunk.mFrame.GetImage();
 
-      // Fixme: see bug 1290777. We should remove the useage of duration here and
-      // in |GetEncodedTrack|.
-      StreamTime duration;
-      if (mFirstFrame)
-      {
-        duration = chunk.GetDuration();
-        mFirstFrame = false;
-      } else {
-        MOZ_ASSERT(chunk.mTimeStamp >= mLastFrameTimeStamp);
-        TimeDuration timeDuration = chunk.mTimeStamp - mLastFrameTimeStamp;
-        duration = SecondsToMediaTime(timeDuration.ToSeconds());
-      }
-
       // Because we may get chunks with a null image (due to input blocking),
       // accumulate duration and give it to the next frame that arrives.
       // Canonically incorrect - the duration should go to the previous frame
       // - but that would require delaying until the next frame arrives.
       // Best would be to do like OMXEncoder and pass an effective timestamp
       // in with each frame.
       if (image) {
         mRawSegment.AppendFrame(image.forget(),
-                                duration,
+                                mLastFrameDuration,
                                 chunk.mFrame.GetIntrinsicSize(),
                                 PRINCIPAL_HANDLE_NONE,
                                 chunk.mFrame.GetForceBlack());
         mLastFrameDuration = 0;
       }
-      mLastFrameTimeStamp = chunk.mTimeStamp;
     }
     mLastFrame.TakeFrom(&chunk.mFrame);
     iter.Next();
   }
 
   if (mRawSegment.GetDuration() > 0) {
     mReentrantMonitor.NotifyAll();
   }
--- a/dom/media/encoder/TrackEncoder.h
+++ b/dom/media/encoder/TrackEncoder.h
@@ -253,18 +253,16 @@ public:
     , mFrameWidth(0)
     , mFrameHeight(0)
     , mDisplayWidth(0)
     , mDisplayHeight(0)
     , mTrackRate(aTrackRate)
     , mTotalFrameDuration(0)
     , mLastFrameDuration(0)
     , mVideoBitrate(0)
-    , mLastFrameTimeStamp(TimeStamp::Now())
-    , mFirstFrame(true)
   {}
 
   /**
    * Notified by the same callback of MediaEncoder when it has received a track
    * change from MediaStreamGraph. Called on the MediaStreamGraph thread.
    */
   void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
                                 StreamTime aTrackOffset,
@@ -354,17 +352,13 @@ protected:
   StreamTime mLastFrameDuration;
 
   /**
    * A segment queue of audio track data, protected by mReentrantMonitor.
    */
   VideoSegment mRawSegment;
 
   uint32_t mVideoBitrate;
-
-private:
-  TimeStamp mLastFrameTimeStamp;
-  bool mFirstFrame;
 };
 
 } // namespace mozilla
 
 #endif