Bug 1163223 - Move bailout case in GetBuffered into the readers. r=jww
authorBobby Holley <bobbyholley@gmail.com>
Wed, 10 Jun 2015 20:44:06 -0700
changeset 280020 84ab38ab2fac5fb65a0b45881af78499ffe19d90
parent 280019 8baf29b879aa3b042979c8e7baa30854394808ec
child 280021 2b13e8f82843c1b26b851fe446b985e677d45407
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjww
bugs1163223
milestone41.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 1163223 - Move bailout case in GetBuffered into the readers. r=jww The problem here is that, because we run mReader->SetStartTime() as a promise callback, MDSM::HasStartTime() may be true while the reader hasn't been notified yet. This is obviously broken, but no more broken than the fact that GetBuffered operates synchronously (and is basically the last piece of machinery left doing so). Fixing that is next on my list, but let's just hack around this for now to get this stack landed.
dom/media/MediaDecoderReader.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/MediaFormatReader.cpp
dom/media/fmp4/MP4Reader.cpp
dom/media/ogg/OggReader.cpp
dom/media/webm/WebMReader.cpp
--- a/dom/media/MediaDecoderReader.cpp
+++ b/dom/media/MediaDecoderReader.cpp
@@ -149,16 +149,17 @@ MediaDecoderReader::SetStartTime(int64_t
 {
   mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
   mStartTime = aStartTime;
 }
 
 media::TimeIntervals
 MediaDecoderReader::GetBuffered()
 {
+  NS_ENSURE_TRUE(mStartTime >= 0, media::TimeIntervals());
   AutoPinned<MediaResource> stream(mDecoder->GetResource());
   int64_t durationUs = 0;
   {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     durationUs = mDecoder->GetMediaDuration();
   }
   return GetEstimatedBufferedTimeRanges(stream, durationUs);
 }
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -261,24 +261,17 @@ public:
   // Must be called with the decode monitor held.
   bool IsSeeking() const {
     MOZ_ASSERT(OnTaskQueue());
     AssertCurrentThreadInMonitor();
     return mState == DECODER_STATE_SEEKING;
   }
 
   media::TimeIntervals GetBuffered() {
-    // It's possible for JS to query .buffered before we've determined the start
-    // time from metadata, in which case the reader isn't ready to be asked this
-    // question.
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-    if (mStartTime < 0) {
-      return media::TimeIntervals();
-    }
-
     return mReader->GetBuffered();
   }
 
   size_t SizeOfVideoQueue() {
     if (mReader) {
       return mReader->SizeOfVideoQueueInBytes();
     }
     return 0;
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1295,17 +1295,17 @@ MediaFormatReader::GetBuffered()
   media::TimeIntervals intervals;
 
   if (!mInitDone) {
     return intervals;
   }
   int64_t startTime;
   {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-    MOZ_ASSERT(mStartTime != -1, "Need to finish metadata decode first");
+    NS_ENSURE_TRUE(mStartTime >= 0, media::TimeIntervals());
     startTime = mStartTime;
   }
   if (NS_IsMainThread()) {
     if (mCachedTimeRangesStale) {
       MOZ_ASSERT(mMainThreadDemuxer);
       if (!mDataRange.IsEmpty()) {
         mMainThreadDemuxer->NotifyDataArrived(mDataRange.Length(), mDataRange.mStart);
       }
--- a/dom/media/fmp4/MP4Reader.cpp
+++ b/dom/media/fmp4/MP4Reader.cpp
@@ -1076,17 +1076,17 @@ media::TimeIntervals
 MP4Reader::GetBuffered()
 {
   MonitorAutoLock mon(mDemuxerMonitor);
   media::TimeIntervals buffered;
   if (!mIndexReady) {
     return buffered;
   }
   UpdateIndex();
-  MOZ_ASSERT(mStartTime != -1, "Need to finish metadata decode first");
+  NS_ENSURE_TRUE(mStartTime >= 0, media::TimeIntervals());
 
   AutoPinned<MediaResource> resource(mDecoder->GetResource());
   nsTArray<MediaByteRange> ranges;
   nsresult rv = resource->GetCachedRanges(ranges);
 
   if (NS_SUCCEEDED(rv)) {
     nsTArray<Interval<Microseconds>> timeRanges;
     mDemuxer->ConvertByteRangesToTime(ranges, &timeRanges);
--- a/dom/media/ogg/OggReader.cpp
+++ b/dom/media/ogg/OggReader.cpp
@@ -1847,17 +1847,17 @@ nsresult OggReader::SeekBisection(int64_
 
   SEEK_LOG(LogLevel::Debug, ("Seek complete in %d bisections.", hops));
 
   return NS_OK;
 }
 
 media::TimeIntervals OggReader::GetBuffered()
 {
-  MOZ_ASSERT(mStartTime != -1, "Need to finish metadata decode first");
+  NS_ENSURE_TRUE(mStartTime >= 0, media::TimeIntervals());
   {
     mozilla::ReentrantMonitorAutoEnter mon(mMonitor);
     if (mIsChained) {
       return media::TimeIntervals::Invalid();
     }
   }
 #ifdef OGG_ESTIMATE_BUFFERED
   return MediaDecoderReader::GetBuffered();
--- a/dom/media/webm/WebMReader.cpp
+++ b/dom/media/webm/WebMReader.cpp
@@ -1088,17 +1088,17 @@ nsresult WebMReader::SeekInternal(int64_
       return NS_ERROR_FAILURE;
     }
   }
   return NS_OK;
 }
 
 media::TimeIntervals WebMReader::GetBuffered()
 {
-  MOZ_ASSERT(mStartTime != -1, "Need to finish metadata decode first");
+  NS_ENSURE_TRUE(mStartTime >= 0, media::TimeIntervals());
   AutoPinned<MediaResource> resource(mDecoder->GetResource());
 
   media::TimeIntervals buffered;
   // Special case completely cached files.  This also handles local files.
   if (mContext && resource->IsDataCachedToEndOfResource(0)) {
     uint64_t duration = 0;
     if (nestegg_duration(mContext, &duration) == 0) {
       buffered +=