Bug 1291946 - Append the latest video frames from updateTracks. r?pehrsons. draft
authorctai <ctai@mozilla.com>
Wed, 10 Aug 2016 10:31:14 +0800
changeset 409130 a6943b0eaeea8c8a5ae189175cda6b036b001c53
parent 409026 3e11b1a9cae799087d43189795e43cfb31200bac
child 530280 c7a2f9c0e4514f84f87b26d5105a939b3019cf21
push id28402
push userbmo:ctai@mozilla.com
push dateFri, 02 Sep 2016 08:54:28 +0000
reviewerspehrsons
bugs1291946
milestone51.0a1
Bug 1291946 - Append the latest video frames from updateTracks. r?pehrsons. In some cases, we need to resend missed VideoSegment to new added MediaStreamVideoSink. Append the latest video frames from updateTracks. MozReview-Commit-ID: 76RFs5fgKpY
dom/media/MediaStreamGraph.cpp
dom/media/VideoSegment.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -2865,17 +2865,26 @@ SourceMediaStream::AddDirectTrackListene
     // The track might be removed from mUpdateTrack but still exist in
     // mTracks.
     auto streamTrack = FindTrack(aTrackID);
     bool foundTrack = !!streamTrack;
     if (foundTrack) {
       MediaStreamVideoSink* videoSink = listener->AsMediaStreamVideoSink();
       // Re-send missed VideoSegment to new added MediaStreamVideoSink.
       if (streamTrack->GetType() == MediaSegment::VIDEO && videoSink) {
-        videoSink->SetCurrentFrames(*(static_cast<VideoSegment*>(streamTrack->GetSegment())));
+        VideoSegment videoSegment;
+        if (mTracks.GetForgottenDuration() < streamTrack->GetSegment()->GetDuration()) {
+          videoSegment.AppendSlice(*streamTrack->GetSegment(),
+                                   mTracks.GetForgottenDuration(),
+                                   streamTrack->GetSegment()->GetDuration());
+        }
+        if (found) {
+          videoSegment.AppendSlice(*data->mData, 0, data->mData->GetDuration());
+        }
+        videoSink->SetCurrentFrames(videoSegment);
       }
     }
 
     if (found && (isAudio || isVideo)) {
       for (auto entry : mDirectTrackListeners) {
         if (entry.mListener == listener &&
             (entry.mTrackID == TRACK_ANY || entry.mTrackID == aTrackID)) {
           listener->NotifyDirectListenerInstalled(
--- a/dom/media/VideoSegment.h
+++ b/dom/media/VideoSegment.h
@@ -87,19 +87,23 @@ struct VideoChunk {
   {
     // Future:
     // - mFrame
     return 0;
   }
 
   PrincipalHandle GetPrincipalHandle() const { return mFrame.GetPrincipalHandle(); }
 
+  TimeStamp GetTimeStamp() const {
+    return mTimeStamp;
+  }
+
   StreamTime mDuration;
   VideoFrame mFrame;
-  mozilla::TimeStamp mTimeStamp;
+  TimeStamp mTimeStamp;
 };
 
 class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
 public:
   typedef mozilla::layers::Image Image;
   typedef mozilla::gfx::IntSize IntSize;
 
   VideoSegment();