Bug 1050099 - Avoid calling deprecated FindStartTime and instead use buffer's decoded ranges in switching logic. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 11 Aug 2014 14:05:09 +1200
changeset 198820 c9c9e94945fe7bddadca0f20bcf79aab66cd57a5
parent 198819 1588a78a2feb61322a212cf55658ec6a4f3a6a7d
child 198821 8c4a1b3a2a8b12318ef39d255753caae59d01d7c
push id27286
push usernigelbabu@gmail.com
push dateMon, 11 Aug 2014 06:26:45 +0000
treeherdermozilla-central@8c4a1b3a2a8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1050099
milestone34.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 1050099 - Avoid calling deprecated FindStartTime and instead use buffer's decoded ranges in switching logic. r=cajbir
content/html/content/src/TimeRanges.cpp
content/html/content/src/TimeRanges.h
content/media/mediasource/MediaSourceDecoder.cpp
content/media/mediasource/SubBufferDecoder.h
--- a/content/html/content/src/TimeRanges.cpp
+++ b/content/html/content/src/TimeRanges.cpp
@@ -121,16 +121,27 @@ TimeRanges::Normalize()
     }
 
     normalized.AppendElement(current);
 
     mRanges = normalized;
   }
 }
 
+TimeRanges::index_type
+TimeRanges::Find(double aTime)
+{
+  for (index_type i = 0; i < mRanges.Length(); ++i) {
+    if (aTime >= mRanges[i].mStart && aTime < mRanges[i].mEnd) {
+      return i;
+    }
+  }
+  return NoIndex;
+}
+
 JSObject*
 TimeRanges::WrapObject(JSContext* aCx)
 {
   return TimeRangesBinding::Wrap(aCx, this);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/TimeRanges.h
+++ b/content/html/content/src/TimeRanges.h
@@ -75,14 +75,20 @@ private:
     }
 
     bool LessThan(const TimeRange& aTr1, const TimeRange& aTr2) const {
       return aTr1.mStart < aTr2.mStart;
     }
   };
 
   nsAutoTArray<TimeRange,4> mRanges;
+
+public:
+  typedef nsTArray<TimeRange>::index_type index_type;
+  static const index_type NoIndex = index_type(-1);
+
+  index_type Find(double aTime);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_TimeRanges_h_
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -39,22 +39,16 @@ extern PRLogModuleInfo* GetMediaSourceAP
 #else
 #define MSE_DEBUG(...)
 #define MSE_DEBUGV(...)
 #define MSE_API(...)
 #endif
 
 namespace mozilla {
 
-namespace dom {
-
-class TimeRanges;
-
-} // namespace dom
-
 class MediaSourceReader : public MediaDecoderReader
 {
 public:
   MediaSourceReader(MediaSourceDecoder* aDecoder, dom::MediaSource* aSource)
     : MediaDecoderReader(aDecoder)
     , mTimeThreshold(-1)
     , mDropVideoBeforeThreshold(false)
     , mActiveVideoDecoder(-1)
@@ -201,27 +195,35 @@ private:
   bool SwitchVideoReaders(SwitchType aType) {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     MOZ_ASSERT(mActiveVideoDecoder != -1);
 
     InitializePendingDecoders();
 
     for (uint32_t i = mActiveVideoDecoder + 1; i < mDecoders.Length(); ++i) {
       SubBufferDecoder* decoder = mDecoders[i];
+
+      nsRefPtr<dom::TimeRanges> ranges = new dom::TimeRanges();
+      decoder->GetBuffered(ranges);
+
       MSE_DEBUGV("MediaDecoderReader(%p)::SwitchVideoReaders(%d) decoder=%u (%p) discarded=%d"
-                 " hasVideo=%d timeThreshold=%lld startTime=%lld",
+                 " hasVideo=%d timeThreshold=%f startTime=%f endTime=%f length=%u",
                  this, aType, i, decoder, decoder->IsDiscarded(),
                  decoder->GetReader()->GetMediaInfo().HasVideo(),
-                 mTimeThreshold, decoder->GetMediaStartTime());
+                 double(mTimeThreshold) / USECS_PER_S,
+                 ranges->GetStartTime(), ranges->GetEndTime(), ranges->Length());
 
-      if (decoder->IsDiscarded() || !decoder->GetReader()->GetMediaInfo().HasVideo()) {
+      if (decoder->IsDiscarded() ||
+          !decoder->GetReader()->GetMediaInfo().HasVideo() ||
+          ranges->Length() == 0) {
         continue;
       }
 
-      if (aType == SWITCH_FORCED || mTimeThreshold >= decoder->GetMediaStartTime()) {
+      if (aType == SWITCH_FORCED ||
+          ranges->Find(double(mTimeThreshold) / USECS_PER_S) != dom::TimeRanges::NoIndex) {
         GetVideoReader()->SetIdle();
 
         mActiveVideoDecoder = i;
         mDropVideoBeforeThreshold = true;
         MSE_DEBUG("MediaDecoderReader(%p)::SwitchVideoReaders(%d) switching to %d (%p)",
                   this, aType, mActiveVideoDecoder, mDecoders[mActiveVideoDecoder].get());
         return true;
       }
@@ -418,37 +420,32 @@ MediaSourceReader::InitializePendingDeco
     nsRefPtr<SubBufferDecoder> decoder = mPendingDecoders[i];
     MediaDecoderReader* reader = decoder->GetReader();
     MSE_DEBUG("MediaSourceReader(%p): Initializing subdecoder %p reader %p",
               this, decoder.get(), reader);
 
     MediaInfo mi;
     nsAutoPtr<MetadataTags> tags; // TODO: Handle metadata.
     nsresult rv;
-    int64_t startTime = INT64_MIN;
     {
       ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
       rv = reader->ReadMetadata(&mi, getter_Transfers(tags));
-      if (NS_SUCCEEDED(rv)) {
-        reader->FindStartTime(startTime);
-      }
     }
     reader->SetIdle();
-    if (NS_FAILED(rv) || startTime == INT64_MIN) {
+    if (NS_FAILED(rv)) {
       // XXX: Need to signal error back to owning SourceBuffer.
-      MSE_DEBUG("MediaSourceReader(%p): Reader %p failed to initialize rv=%x startTime=%lld",
-                this, reader, rv, startTime);
+      MSE_DEBUG("MediaSourceReader(%p): Reader %p failed to initialize rv=%x",
+                this, reader, rv);
       continue;
     }
-    decoder->SetMediaStartTime(startTime);
 
     bool active = false;
     if (mi.HasVideo() || mi.HasAudio()) {
-      MSE_DEBUG("MediaSourceReader(%p): Reader %p has video=%d audio=%d startTime=%lld",
-                this, reader, mi.HasVideo(), mi.HasAudio(), startTime);
+      MSE_DEBUG("MediaSourceReader(%p): Reader %p has video=%d audio=%d",
+                this, reader, mi.HasVideo(), mi.HasAudio());
       if (mi.HasVideo()) {
         MSE_DEBUG("MediaSourceReader(%p): Reader %p video resolution=%dx%d",
                   this, reader, mi.mVideo.mDisplay.width, mi.mVideo.mDisplay.height);
       }
       if (mi.HasAudio()) {
         MSE_DEBUG("MediaSourceReader(%p): Reader %p audio sampleRate=%d channels=%d",
                   this, reader, mi.mAudio.mRate, mi.mAudio.mChannels);
       }
--- a/content/media/mediasource/SubBufferDecoder.h
+++ b/content/media/mediasource/SubBufferDecoder.h
@@ -24,17 +24,17 @@ class TimeRanges;
 
 class SubBufferDecoder : public BufferDecoder
 {
 public:
   // This class holds a weak pointer to MediaResource.  It's the responsibility
   // of the caller to manage the memory of the MediaResource object.
   SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder)
     : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr)
-    , mMediaDuration(-1), mMediaStartTime(0), mDiscarded(false)
+    , mMediaDuration(-1), mDiscarded(false)
   {
   }
 
   void SetReader(MediaDecoderReader* aReader)
   {
     MOZ_ASSERT(!mReader);
     mReader = aReader;
   }
@@ -64,40 +64,29 @@ public:
   // cached data. Returns -1 if no such value is computable.
   int64_t ConvertToByteOffset(double aTime);
 
   int64_t GetMediaDuration() MOZ_OVERRIDE
   {
     return mMediaDuration;
   }
 
-  int64_t GetMediaStartTime()
-  {
-    return mMediaStartTime;
-  }
-
-  void SetMediaStartTime(int64_t aMediaStartTime)
-  {
-    mMediaStartTime = aMediaStartTime;
-  }
-
   bool IsDiscarded()
   {
     return mDiscarded;
   }
 
   void SetDiscarded()
   {
     GetResource()->Ended();
     mDiscarded = true;
   }
 
 private:
   MediaSourceDecoder* mParentDecoder;
   nsRefPtr<MediaDecoderReader> mReader;
   int64_t mMediaDuration;
-  int64_t mMediaStartTime;
   bool mDiscarded;
 };
 
 } // namespace mozilla
 
 #endif /* MOZILLA_SUBBUFFERDECODER_H_ */