Bug 1295073 - Remove the aRealTime parameter from the MediaDecoderStateMachine constructor. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 15 Aug 2016 14:54:10 +0800
changeset 405151 47c068d5afa556cfc1dec6f00f01644af387a868
parent 405150 cf9a2b23c16461787c16ac90a5e24ab36cffe100
child 405152 ecf26d49e4c537947dba1a502427d44f00824a7d
push id27416
push userjwwang@mozilla.com
push dateWed, 24 Aug 2016 23:06:18 +0000
bugs1295073
milestone51.0a1
Bug 1295073 - Remove the aRealTime parameter from the MediaDecoderStateMachine constructor. MozReview-Commit-ID: BXMVAV1R3gx
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderReaderWrapper.cpp
dom/media/MediaDecoderReaderWrapper.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/raw/RawDecoder.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1646,17 +1646,17 @@ MediaDecoder::UnpinForSeek()
   resource->Unpin();
 }
 
 bool
 MediaDecoder::CanPlayThrough()
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_TRUE(mDecoderStateMachine, false);
-  return mDecoderStateMachine->IsRealTime() || GetStatistics().CanPlayThrough();
+  return GetStatistics().CanPlayThrough();
 }
 
 #ifdef MOZ_EME
 RefPtr<MediaDecoder::CDMProxyPromise>
 MediaDecoder::RequestCDMProxy() const
 {
   return mCDMProxyPromise;
 }
--- a/dom/media/MediaDecoderReaderWrapper.cpp
+++ b/dom/media/MediaDecoderReaderWrapper.cpp
@@ -133,20 +133,19 @@ private:
   }
 
   MozPromiseHolder<HaveStartTimePromise> mHaveStartTimePromise;
   RefPtr<AbstractThread> mOwnerThread;
   Maybe<int64_t> mAudioStartTime;
   Maybe<int64_t> mVideoStartTime;
 };
 
-MediaDecoderReaderWrapper::MediaDecoderReaderWrapper(bool aIsRealTime,
-                                                     AbstractThread* aOwnerThread,
+MediaDecoderReaderWrapper::MediaDecoderReaderWrapper(AbstractThread* aOwnerThread,
                                                      MediaDecoderReader* aReader)
-  : mForceZeroStartTime(aIsRealTime || aReader->ForceZeroStartTime())
+  : mForceZeroStartTime(aReader->ForceZeroStartTime())
   , mOwnerThread(aOwnerThread)
   , mReader(aReader)
 {}
 
 MediaDecoderReaderWrapper::~MediaDecoderReaderWrapper()
 {}
 
 media::TimeUnit
--- a/dom/media/MediaDecoderReaderWrapper.h
+++ b/dom/media/MediaDecoderReaderWrapper.h
@@ -42,18 +42,17 @@ class MediaDecoderReaderWrapper {
 
 private:
   MediaCallbackExc<AudioCallbackData> mAudioCallback;
   MediaCallbackExc<VideoCallbackData> mVideoCallback;
   MediaCallbackExc<WaitCallbackData> mAudioWaitCallback;
   MediaCallbackExc<WaitCallbackData> mVideoWaitCallback;
 
 public:
-  MediaDecoderReaderWrapper(bool aIsRealTime,
-                            AbstractThread* aOwnerThread,
+  MediaDecoderReaderWrapper(AbstractThread* aOwnerThread,
                             MediaDecoderReader* aReader);
 
   media::TimeUnit StartTime() const;
   RefPtr<MetadataPromise> ReadMetadata();
   RefPtr<HaveStartTimePromise> AwaitStartTime();
 
   decltype(mAudioCallback)& AudioCallback() { return mAudioCallback; }
   decltype(mVideoCallback)& VideoCallback() { return mVideoCallback; }
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -207,33 +207,31 @@ SuspendBackgroundVideoDelay()
 #define INIT_WATCHABLE(name, val) \
   name(val, "MediaDecoderStateMachine::" #name)
 #define INIT_MIRROR(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Mirror)")
 #define INIT_CANONICAL(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Canonical)")
 
 MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
-                                                   MediaDecoderReader* aReader,
-                                                   bool aRealTime) :
+                                                   MediaDecoderReader* aReader) :
   mDecoderID(aDecoder),
   mFrameStats(&aDecoder->GetFrameStatistics()),
   mVideoFrameContainer(aDecoder->GetVideoFrameContainer()),
   mAudioChannel(aDecoder->GetAudioChannel()),
   mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
                            /* aSupportsTailDispatch = */ true)),
   mWatchManager(this, mTaskQueue),
-  mRealTime(aRealTime),
   mDispatchedStateMachine(false),
   mDelayedScheduler(mTaskQueue),
   INIT_WATCHABLE(mState, DECODER_STATE_DECODING_METADATA),
   mCurrentFrameID(0),
   INIT_WATCHABLE(mObservedDuration, TimeUnit()),
   mFragmentEndTime(-1),
-  mReader(new MediaDecoderReaderWrapper(aRealTime, mTaskQueue, aReader)),
+  mReader(new MediaDecoderReaderWrapper(mTaskQueue, aReader)),
   mDecodedAudioEndTime(0),
   mDecodedVideoEndTime(0),
   mPlaybackRate(1.0),
   mLowAudioThresholdUsecs(detail::LOW_AUDIO_USECS),
   mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_USECS),
   mQuickBufferingLowDataThresholdUsecs(detail::QUICK_BUFFERING_LOW_DATA_USECS),
   mIsAudioPrerolling(false),
   mIsVideoPrerolling(false),
@@ -277,18 +275,18 @@ MediaDecoderStateMachine::MediaDecoderSt
   INIT_CANONICAL(mPlaybackOffset, 0),
   INIT_CANONICAL(mIsAudioDataAudible, false)
 {
   MOZ_COUNT_CTOR(MediaDecoderStateMachine);
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
   InitVideoQueuePrefs();
 
-  mBufferingWait = IsRealTime() ? 0 : 15;
-  mLowDataThresholdUsecs = IsRealTime() ? 0 : detail::LOW_DATA_THRESHOLD_USECS;
+  mBufferingWait = 15;
+  mLowDataThresholdUsecs = detail::LOW_DATA_THRESHOLD_USECS;
 
 #ifdef XP_WIN
   // Ensure high precision timers are enabled on Windows, otherwise the state
   // machine isn't woken up at reliable intervals to set the next frame,
   // and we drop frames while painting. Note that multiple calls to this
   // function per-process is OK, provided each call is matched by a corresponding
   // timeEndPeriod() call.
   timeBeginPeriod(1);
@@ -1277,29 +1275,25 @@ MediaDecoderStateMachine::Shutdown()
 void MediaDecoderStateMachine::StartDecoding()
 {
   MOZ_ASSERT(OnTaskQueue());
   if (mState == DECODER_STATE_DECODING && !mDecodingFirstFrame) {
     return;
   }
   SetState(DECODER_STATE_DECODING);
 
-  if (mDecodingFirstFrame &&
-      (IsRealTime() || mSentFirstFrameLoadedEvent)) {
-    if (IsRealTime()) {
-      FinishDecodeFirstFrame();
-    } else {
-      // We're resuming from dormant state, so we don't need to request
-      // the first samples in order to determine the media start time,
-      // we have the start time from last time we loaded.
-      // FinishDecodeFirstFrame will be launched upon completion of the seek when
-      // we have data ready to play.
-      MOZ_ASSERT(mQueuedSeek.Exists() && mSentFirstFrameLoadedEvent,
-                 "Return from dormant must have queued seek");
-    }
+  if (mDecodingFirstFrame && mSentFirstFrameLoadedEvent) {
+    // We're resuming from dormant state, so we don't need to request
+    // the first samples in order to determine the media start time,
+    // we have the start time from last time we loaded.
+    // FinishDecodeFirstFrame will be launched upon completion of the seek when
+    // we have data ready to play.
+    MOZ_ASSERT(mQueuedSeek.Exists() && mSentFirstFrameLoadedEvent,
+               "Return from dormant must have queued seek");
+
     if (mQueuedSeek.Exists()) {
       InitiateSeek(Move(mQueuedSeek));
       return;
     }
   }
 
   mDecodeStartTime = TimeStamp::Now();
 
@@ -2112,17 +2106,17 @@ MediaDecoderStateMachine::IsDecodingFirs
 }
 
 void
 MediaDecoderStateMachine::FinishDecodeFirstFrame()
 {
   MOZ_ASSERT(OnTaskQueue());
   DECODER_LOG("FinishDecodeFirstFrame");
 
-  if (!IsRealTime() && !mSentFirstFrameLoadedEvent) {
+  if (!mSentFirstFrameLoadedEvent) {
     mMediaSink->Redraw(mInfo.mVideo);
   }
 
   // If we don't know the duration by this point, we assume infinity, per spec.
   if (mDuration.Ref().isNothing()) {
     mDuration = Some(TimeUnit::FromInfinity());
   }
 
@@ -2560,17 +2554,17 @@ bool MediaDecoderStateMachine::JustExite
     mQuickBuffering &&
     (TimeStamp::Now() - mDecodeStartTime) < TimeDuration::FromMicroseconds(QUICK_BUFFER_THRESHOLD_USECS);
 }
 
 bool
 MediaDecoderStateMachine::CanPlayThrough()
 {
   MOZ_ASSERT(OnTaskQueue());
-  return IsRealTime() || GetStatistics().CanPlayThrough();
+  return GetStatistics().CanPlayThrough();
 }
 
 MediaStatistics
 MediaDecoderStateMachine::GetStatistics()
 {
   MOZ_ASSERT(OnTaskQueue());
   MediaStatistics result;
   result.mDownloadRate = mResource->GetDownloadRate(&result.mDownloadRateReliable);
@@ -2636,21 +2630,16 @@ MediaDecoderStateMachine::ScheduleStateM
   MOZ_ASSERT(OnTaskQueue());          // mDelayedScheduler.Ensure() may Disconnect()
                                       // the promise, which must happen on the state
                                       // machine task queue.
   MOZ_ASSERT(aMicroseconds > 0);
   if (mDispatchedStateMachine) {
     return;
   }
 
-  // Real-time weirdness.
-  if (IsRealTime()) {
-    aMicroseconds = std::min(aMicroseconds, int64_t(40000));
-  }
-
   TimeStamp now = TimeStamp::Now();
   TimeStamp target = now + TimeDuration::FromMicroseconds(aMicroseconds);
 
   SAMPLE_LOG("Scheduling state machine for %lf ms from now", (target - now).ToMilliseconds());
 
   RefPtr<MediaDecoderStateMachine> self = this;
   mDelayedScheduler.Ensure(target, [self] () {
     self->OnDelayedSchedule();
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -141,18 +141,17 @@ class MediaDecoderStateMachine
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderStateMachine)
 
   using TrackSet = MediaDecoderReader::TrackSet;
 
 public:
   typedef MediaDecoderOwner::NextFrameStatus NextFrameStatus;
   typedef mozilla::layers::ImageContainer::FrameID FrameID;
   MediaDecoderStateMachine(MediaDecoder* aDecoder,
-                           MediaDecoderReader* aReader,
-                           bool aRealTime = false);
+                           MediaDecoderReader* aReader);
 
   nsresult Init(MediaDecoder* aDecoder);
 
   void SetMediaDecoderReaderWrapperCallback();
   void CancelMediaDecoderReaderWrapperCallback();
 
   // Enumeration for the valid decoding states
   enum State {
@@ -242,19 +241,16 @@ public:
 
   MediaEventSourceExc<nsAutoPtr<MediaInfo>,
                       MediaDecoderEventVisibility>&
   FirstFrameLoadedEvent() { return mFirstFrameLoadedEvent; }
 
   MediaEventSource<MediaEventType>&
   OnPlaybackEvent() { return mOnPlaybackEvent; }
 
-  // Immutable after construction - may be called on any thread.
-  bool IsRealTime() const { return mRealTime; }
-
   size_t SizeOfVideoQueue() const;
 
   size_t SizeOfAudioQueue() const;
 
 private:
   static const char* ToStateStr(State aState);
   const char* ToStateStr();
 
@@ -617,19 +613,16 @@ private:
   const dom::AudioChannel mAudioChannel;
 
   // Task queue for running the state machine.
   RefPtr<TaskQueue> mTaskQueue;
 
   // State-watching manager.
   WatchManager<MediaDecoderStateMachine> mWatchManager;
 
-  // True is we are decoding a realtime stream, like a camera stream.
-  const bool mRealTime;
-
   // True if we've dispatched a task to run the state machine but the task has
   // yet to run.
   bool mDispatchedStateMachine;
 
   // Used to dispatch another round schedule with specific target time.
   DelayedScheduler mDelayedScheduler;
 
   // Queue of audio frames. This queue is threadsafe, and is accessed from
@@ -755,23 +748,23 @@ private:
   // got a few frames decoded before we consider whether decode is falling
   // behind. Otherwise our "we're falling behind" logic will trigger
   // unnecessarily if we start playing as soon as the first sample is
   // decoded. These two fields store how many video frames and audio
   // samples we must consume before are considered to be finished prerolling.
   uint32_t AudioPrerollUsecs() const
   {
     MOZ_ASSERT(OnTaskQueue());
-    return IsRealTime() ? 0 : mAmpleAudioThresholdUsecs / 2;
+    return mAmpleAudioThresholdUsecs / 2;
   }
 
   uint32_t VideoPrerollFrames() const
   {
     MOZ_ASSERT(OnTaskQueue());
-    return IsRealTime() ? 0 : GetAmpleVideoFrames() / 2;
+    return GetAmpleVideoFrames() / 2;
   }
 
   bool DonePrerollingAudio()
   {
     MOZ_ASSERT(OnTaskQueue());
     return !IsAudioDecoding() ||
         GetDecodedAudioDuration() >= AudioPrerollUsecs() * mPlaybackRate;
   }
--- a/dom/media/raw/RawDecoder.cpp
+++ b/dom/media/raw/RawDecoder.cpp
@@ -5,13 +5,13 @@
 #include "MediaDecoderStateMachine.h"
 #include "RawReader.h"
 #include "RawDecoder.h"
 
 namespace mozilla {
 
 MediaDecoderStateMachine* RawDecoder::CreateStateMachine()
 {
-  return new MediaDecoderStateMachine(this, new RawReader(this), true);
+  return new MediaDecoderStateMachine(this, new RawReader(this));
 }
 
 } // namespace mozilla