Bug 1177147: Set mediasource duration to group end timestamp. r=karlt
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 24 Jun 2015 13:30:15 -0700
changeset 250846 78c1272f812f7ef77060706d40f1179911d5e829
parent 250845 1dd794cb1591eb46944af5a2bf23a070eef55393
child 250847 d376311b06e7e8fac5dff3b3e37aa98d1df2ce20
push id28972
push usercbook@mozilla.com
push dateWed, 01 Jul 2015 12:11:11 +0000
treeherdermozilla-central@2ec00565de09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1177147
milestone42.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 1177147: Set mediasource duration to group end timestamp. r=karlt
dom/media/mediasource/SourceBuffer.cpp
dom/media/mediasource/SourceBufferContentManager.h
dom/media/mediasource/TrackBuffer.h
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -422,17 +422,17 @@ SourceBuffer::AbortUpdating()
   QueueAsyncSimpleEvent("updateend");
 }
 
 void
 SourceBuffer::CheckEndTime()
 {
   MOZ_ASSERT(NS_IsMainThread());
   // Check if we need to update mMediaSource duration
-  double endTime = GetBufferedEnd();
+  double endTime = mContentManager->GroupEndTimestamp().ToSeconds();
   double duration = mMediaSource->Duration();
   if (endTime > duration) {
     mMediaSource->SetDuration(endTime, MSRangeRemovalAction::SKIP);
   }
 }
 
 void
 SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
--- a/dom/media/mediasource/SourceBufferContentManager.h
+++ b/dom/media/mediasource/SourceBufferContentManager.h
@@ -95,16 +95,17 @@ public:
 
   virtual AppendState GetAppendState()
   {
     return AppendState::WAITING_FOR_SEGMENT;
   }
 
   virtual void SetGroupStartTimestamp(const TimeUnit& aGroupStartTimestamp) {}
   virtual void RestartGroupStartTimestamp() {}
+  virtual TimeUnit GroupEndTimestamp() = 0;
 
 #if defined(DEBUG)
   virtual void Dump(const char* aPath) { }
 #endif
 
 protected:
   virtual ~SourceBufferContentManager() { }
 };
--- a/dom/media/mediasource/TrackBuffer.h
+++ b/dom/media/mediasource/TrackBuffer.h
@@ -63,16 +63,22 @@ public:
 
   void Ended() override
   {
     EndCurrentDecoder();
   }
 
   void Detach() override;
 
+  TimeUnit GroupEndTimestamp() override
+  {
+    return Buffered().GetEnd();
+  }
+
+
   // Mark the current decoder's resource as ended, clear mCurrentDecoder and
   // reset mLast{Start,End}Timestamp.  Main thread only.
   void DiscardCurrentDecoder();
   // Mark the current decoder's resource as ended.
   void EndCurrentDecoder();
 
   // Returns true if an init segment has been appended.
   bool HasInitSegment();
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1223,16 +1223,18 @@ TrackBuffersManager::CompleteCodedFrameP
     if (HasAudio()) {
       MSE_DEBUG("audio new buffered range = %s",
                 DumpTimeRanges(mAudioBufferedRanges).get());
     }
     if (HasVideo()) {
       MSE_DEBUG("video new buffered range = %s",
                 DumpTimeRanges(mVideoBufferedRanges).get());
     }
+
+    mOfficialGroupEndTimestamp = mGroupEndTimestamp;
   }
 
   // Update our reported total size.
   mSizeSourceBuffer = mVideoTracks.mSizeBuffer + mAudioTracks.mSizeBuffer;
 
   // Return to step 6.4 of Segment Parser Loop algorithm
   // 4. If this SourceBuffer is full and cannot accept more media data, then set the buffer full flag to true.
   if (mSizeSourceBuffer >= mEvictionThreshold) {
@@ -1668,16 +1670,23 @@ TrackBuffersManager::RestartGroupStartTi
       NS_NewRunnableMethod(this, &TrackBuffersManager::RestartGroupStartTimestamp);
     GetTaskQueue()->Dispatch(task.forget());
     return;
   }
   MOZ_ASSERT(OnTaskQueue());
   mGroupStartTimestamp = Some(mGroupEndTimestamp);
 }
 
+TimeUnit
+TrackBuffersManager::GroupEndTimestamp()
+{
+  MonitorAutoLock mon(mMonitor);
+  return mOfficialGroupEndTimestamp;
+}
+
 MediaInfo
 TrackBuffersManager::GetMetadata()
 {
   MonitorAutoLock mon(mMonitor);
   return mInfo;
 }
 
 const TimeIntervals&
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -66,16 +66,17 @@ public:
 
   AppendState GetAppendState() override
   {
     return mAppendState;
   }
 
   void SetGroupStartTimestamp(const TimeUnit& aGroupStartTimestamp) override;
   void RestartGroupStartTimestamp() override;
+  TimeUnit GroupEndTimestamp() override;
 
   // Interface for MediaSourceDemuxer
   MediaInfo GetMetadata();
   const TrackBuffer& GetTrackBuffer(TrackInfo::TrackType aTrack);
   const TimeIntervals& Buffered(TrackInfo::TrackType);
   bool IsEnded() const
   {
     return mEnded;
@@ -313,14 +314,15 @@ private:
   uint32_t mEvictionThreshold;
   Atomic<bool> mEvictionOccurred;
 
   // Monitor to protect following objects accessed across multipple threads.
   mutable Monitor mMonitor;
   // Stable audio and video track time ranges.
   TimeIntervals mVideoBufferedRanges;
   TimeIntervals mAudioBufferedRanges;
+  TimeUnit mOfficialGroupEndTimestamp;
   // MediaInfo of the first init segment read.
   MediaInfo mInfo;
 };
 
 } // namespace mozilla
 #endif /* MOZILLA_TRACKBUFFERSMANAGER_H_ */