Bug 1089480 - Assume a start time of 0 for MSE videos. r=cajbir
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 29 Oct 2014 09:30:36 +1300
changeset 212808 01eedb9f44d9
parent 212807 7a8948248cbd
child 212809 efef078ca75d
push id27730
push usercbook@mozilla.com
push dateWed, 29 Oct 2014 12:26:03 +0000
treeherdermozilla-central@fe5c1cb8075a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1089480
milestone36.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 1089480 - Assume a start time of 0 for MSE videos. r=cajbir
dom/media/MediaDecoderReader.cpp
dom/media/MediaDecoderReader.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/mediasource/MediaSourceReader.h
--- a/dom/media/MediaDecoderReader.cpp
+++ b/dom/media/MediaDecoderReader.cpp
@@ -15,25 +15,20 @@
 
 namespace mozilla {
 
 // Un-comment to enable logging of seek bisections.
 //#define SEEK_LOGGING
 
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gMediaDecoderLog;
-#define DECODER_LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg)
-#ifdef SEEK_LOGGING
-#define SEEK_LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg)
+#define DECODER_LOG(x, ...) \
+  PR_LOG(gMediaDecoderLog, PR_LOG_DEBUG, ("Decoder=%p " x, mDecoder, ##__VA_ARGS__))
 #else
-#define SEEK_LOG(type, msg)
-#endif
-#else
-#define DECODER_LOG(type, msg)
-#define SEEK_LOG(type, msg)
+#define DECODER_LOG(x, ...)
 #endif
 
 class VideoQueueMemoryFunctor : public nsDequeFunctor {
 public:
   VideoQueueMemoryFunctor() : mSize(0) {}
 
   MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf);
 
@@ -134,16 +129,30 @@ MediaDecoderReader::GetBuffered(mozilla:
   {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     durationUs = mDecoder->GetMediaDuration();
   }
   GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
   return NS_OK;
 }
 
+int64_t
+MediaDecoderReader::ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio)
+{
+  int64_t startTime = std::min<int64_t>(aAudio ? aAudio->mTime : INT64_MAX,
+                                        aVideo ? aVideo->mTime : INT64_MAX);
+  if (startTime == INT64_MAX) {
+    startTime = 0;
+  }
+  DECODER_LOG("ComputeStartTime first video frame start %lld", aVideo ? aVideo->mTime : -1);
+  DECODER_LOG("ComputeStartTime first audio frame start %lld", aAudio ? aAudio->mTime : -1);
+  MOZ_ASSERT(startTime >= 0);
+  return startTime;
+}
+
 class RequestVideoWithSkipTask : public nsRunnable {
 public:
   RequestVideoWithSkipTask(MediaDecoderReader* aReader,
                            int64_t aTimeThreshold)
     : mReader(aReader)
     , mTimeThreshold(aTimeThreshold)
   {
   }
--- a/dom/media/MediaDecoderReader.h
+++ b/dom/media/MediaDecoderReader.h
@@ -143,16 +143,18 @@ public:
   // is that it's a fast approximation, which does not perform any I/O.
   //
   // The OggReader relies on this base implementation not performing I/O,
   // since in FirefoxOS we can't do I/O on the main thread, where this is
   // called.
   virtual nsresult GetBuffered(dom::TimeRanges* aBuffered,
                                int64_t aStartTime);
 
+  virtual int64_t ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio);
+
   // Returns the number of bytes of memory allocated by structures/frames in
   // the video queue.
   size_t SizeOfVideoQueueInBytes() const;
 
   // Returns the number of bytes of memory allocated by structures/frames in
   // the audio queue.
   size_t SizeOfAudioQueueInBytes() const;
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2011,28 +2011,19 @@ MediaDecoderStateMachine::FinishDecodeMe
   NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
   DECODER_LOG("FinishDecodeMetadata");
 
   if (mState == DECODER_STATE_SHUTDOWN) {
     return NS_ERROR_FAILURE;
   }
 
   if (!mScheduler->IsRealTime() && !mDecodingFrozenAtStateMetadata) {
-
     const VideoData* v = VideoQueue().PeekFront();
     const AudioData* a = AudioQueue().PeekFront();
-
-    int64_t startTime = std::min<int64_t>(a ? a->mTime : INT64_MAX,
-                                          v ? v->mTime : INT64_MAX);
-    if (startTime == INT64_MAX) {
-      startTime = 0;
-    }
-    DECODER_LOG("DecodeMetadata first video frame start %lld", v ? v->mTime : -1);
-    DECODER_LOG("DecodeMetadata first audio frame start %lld", a ? a->mTime : -1);
-    SetStartTime(startTime);
+    SetStartTime(mReader->ComputeStartTime(v, a));
     if (VideoQueue().GetSize()) {
       ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
       RenderVideoFrame(VideoQueue().PeekFront(), TimeStamp::Now());
     }
   }
 
   NS_ASSERTION(mStartTime != -1, "Must have start time");
   MOZ_ASSERT((!HasVideo() && !HasAudio()) ||
--- a/dom/media/mediasource/MediaSourceReader.h
+++ b/dom/media/mediasource/MediaSourceReader.h
@@ -65,16 +65,21 @@ public:
     return mInfo.HasVideo();
   }
 
   bool HasAudio() MOZ_OVERRIDE
   {
     return mInfo.HasAudio();
   }
 
+  // We can't compute a proper start time since we won't necessarily
+  // have the first frame of the resource available. This does the same
+  // as chrome/blink and assumes that we always start at t=0.
+  virtual int64_t ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio) MOZ_OVERRIDE { return 0; }
+
   bool IsMediaSeekable() { return true; }
 
   nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) MOZ_OVERRIDE;
   nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
                 int64_t aCurrentTime) MOZ_OVERRIDE;
 
   already_AddRefed<SourceBufferDecoder> CreateSubDecoder(const nsACString& aType);