Bug 799344 - Remove nsBuiltinDecoder::GetDecodeState(), so that nsBuiltinDecoder doesn't need to know about nsDecoderStateMachine::State. r=roc
authorChris Pearce <cpearce@mozilla.com>
Wed, 07 Nov 2012 11:33:01 +1300
changeset 112461 dd7663e686574e9277704bdac7d747983e07ae43
parent 112460 6156bdfbde2eff19397e18c7731cd19bdf8d7661
child 112462 24870ebc966555225345bffd16af4239be8900c9
push id17602
push usercpearce@mozilla.com
push dateTue, 06 Nov 2012 22:33:17 +0000
treeherdermozilla-inbound@3f0e69962962 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs799344
milestone19.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 799344 - Remove nsBuiltinDecoder::GetDecodeState(), so that nsBuiltinDecoder doesn't need to know about nsDecoderStateMachine::State. r=roc
content/media/dash/nsDASHRepDecoder.cpp
content/media/dash/nsDASHRepDecoder.h
content/media/nsBuiltinDecoder.h
content/media/nsBuiltinDecoderReader.cpp
content/media/nsBuiltinDecoderReader.h
content/media/nsBuiltinDecoderStateMachine.cpp
content/media/nsBuiltinDecoderStateMachine.h
content/media/ogg/nsOggReader.cpp
content/media/raw/nsRawReader.cpp
--- a/content/media/dash/nsDASHRepDecoder.cpp
+++ b/content/media/dash/nsDASHRepDecoder.cpp
@@ -341,24 +341,16 @@ nsDASHRepDecoder::OnDecodeThread() const
 }
 
 ReentrantMonitor&
 nsDASHRepDecoder::GetReentrantMonitor()
 {
   return mMainDecoder->GetReentrantMonitor();
 }
 
-nsDecoderStateMachine::State
-nsDASHRepDecoder::GetDecodeState()
-{
-  // XXX SHUTDOWN might not be an appropriate error.
-  return (mMainDecoder ? mMainDecoder->GetDecodeState()
-                       : nsDecoderStateMachine::DECODER_STATE_SHUTDOWN);
-}
-
 mozilla::layers::ImageContainer*
 nsDASHRepDecoder::GetImageContainer()
 {
   NS_ASSERTION(mMainDecoder && mMainDecoder->OnDecodeThread(),
                "Should be on decode thread.");
   return (mMainDecoder ? mMainDecoder->GetImageContainer() : nullptr);
 }
 
--- a/content/media/dash/nsDASHRepDecoder.h
+++ b/content/media/dash/nsDASHRepDecoder.h
@@ -130,20 +130,16 @@ public:
   bool OnStateMachineThread() const;
 
   // Returns true if the current thread is the decode thread.
   bool OnDecodeThread() const;
 
   // Returns main decoder's monitor for synchronised access.
   ReentrantMonitor& GetReentrantMonitor();
 
-  // Return the current decode state, according to the main decoder. The
-  // decoder monitor must be obtained before calling this.
-  nsDecoderStateMachine::State GetDecodeState();
-
   // Called on the decode thread from nsWebMReader.
   ImageContainer* GetImageContainer();
 
   // Called when Metadata has been read; notifies that index data is read.
   // Called on the decode thread only.
   void OnReadMetadataCompleted();
 
   // Overridden to cleanup ref to |nsDASHDecoder|. Called on main thread only.
--- a/content/media/nsBuiltinDecoder.h
+++ b/content/media/nsBuiltinDecoder.h
@@ -235,16 +235,20 @@ public:
 
   // Set the audio volume. The decoder monitor must be obtained before
   // calling this.
   virtual void SetVolume(double aVolume) = 0;
   virtual void SetAudioCaptured(bool aCapture) = 0;
 
   virtual void Shutdown() = 0;
 
+  // True if the state machine has shutdown, or is in the process of
+  // shutting down. The decoder monitor must be obtained before calling this.
+  virtual bool IsShutdown() = 0;
+
   // Called from the main thread to get the duration. The decoder monitor
   // must be obtained before calling this. It is in units of microseconds.
   virtual int64_t GetDuration() = 0;
 
   // Called from the main thread to set the duration of the media resource
   // if it is able to be obtained via HTTP headers. Called from the 
   // state machine thread to set the duration if it is obtained from the
   // media metadata. The decoder monitor must be obtained before calling this.
@@ -694,20 +698,16 @@ public:
 
   // Updates the approximate byte offset which playback has reached. This is
   // used to calculate the readyState transitions.
   void UpdatePlaybackOffset(int64_t aOffset);
 
   // Provide access to the state machine object
   nsDecoderStateMachine* GetStateMachine() { return mDecoderStateMachine; }
 
-  // Return the current decode state. The decoder monitor must be
-  // obtained before calling this.
-  nsDecoderStateMachine::State GetDecodeState() { return mDecoderStateMachine->GetState(); }
-
   // Drop reference to state machine.  Only called during shutdown dance.
   virtual void ReleaseStateMachine() { mDecoderStateMachine = nullptr; }
 
    // Called when a "MozAudioAvailable" event listener is added to the media
    // element. Called on the main thread.
    virtual void NotifyAudioAvailableListener();
 
   // Notifies the element that decoding has failed.
--- a/content/media/nsBuiltinDecoderReader.cpp
+++ b/content/media/nsBuiltinDecoderReader.cpp
@@ -384,17 +384,17 @@ nsresult nsBuiltinDecoderReader::DecodeT
     int64_t startTime = -1;
     nsAutoPtr<VideoData> video;
     while (HasVideo() && !eof) {
       while (mVideoQueue.GetSize() == 0 && !eof) {
         bool skip = false;
         eof = !DecodeVideoFrame(skip, 0);
         {
           ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
-          if (mDecoder->GetDecodeState() == nsBuiltinDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+          if (mDecoder->GetStateMachine()->IsShutdown()) {
             return NS_ERROR_FAILURE;
           }
         }
       }
       if (mVideoQueue.GetSize() == 0) {
         // Hit end of file, we want to display the last frame of the video.
         if (video) {
           mVideoQueue.PushFront(video.forget());
@@ -411,32 +411,32 @@ nsresult nsBuiltinDecoderReader::DecodeT
         mVideoQueue.PopFront();
       } else {
         video.forget();
         break;
       }
     }
     {
       ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
-      if (mDecoder->GetDecodeState() == nsBuiltinDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+      if (mDecoder->GetStateMachine()->IsShutdown()) {
         return NS_ERROR_FAILURE;
       }
     }
     LOG(PR_LOG_DEBUG, ("First video frame after decode is %lld", startTime));
   }
 
   if (HasAudio()) {
     // Decode audio forward to the seek target.
     bool eof = false;
     while (HasAudio() && !eof) {
       while (!eof && mAudioQueue.GetSize() == 0) {
         eof = !DecodeAudioData();
         {
           ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
-          if (mDecoder->GetDecodeState() == nsBuiltinDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+          if (mDecoder->GetStateMachine()->IsShutdown()) {
             return NS_ERROR_FAILURE;
           }
         }
       }
       const AudioData* audio = mAudioQueue.PeekFront();
       if (!audio)
         break;
       CheckedInt64 startFrame = UsecsToFrames(audio->mTime, mInfo.mAudioRate);
--- a/content/media/nsBuiltinDecoderReader.h
+++ b/content/media/nsBuiltinDecoderReader.h
@@ -481,18 +481,17 @@ public:
   template<class Data>
   Data* DecodeToFirstData(DecodeFn aDecodeFn,
                           MediaQueue<Data>& aQueue)
   {
     bool eof = false;
     while (!eof && aQueue.GetSize() == 0) {
       {
         ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
-        if (mDecoder->GetDecodeState()
-            == nsDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+        if (mDecoder->GetStateMachine()->IsShutdown()) {
           return nullptr;
         }
       }
       eof = !(this->*aDecodeFn)();
     }
     Data* d = nullptr;
     return (d = aQueue.PeekFront()) ? d : nullptr;
   }
--- a/content/media/nsBuiltinDecoderStateMachine.cpp
+++ b/content/media/nsBuiltinDecoderStateMachine.cpp
@@ -2608,8 +2608,15 @@ nsIThread* nsBuiltinDecoderStateMachine:
   return StateMachineTracker::Instance().GetGlobalStateMachineThread();
 }
 
 void nsBuiltinDecoderStateMachine::NotifyAudioAvailableListener()
 {
   mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
   mEventManager.NotifyAudioAvailableListener();
 }
+
+bool nsBuiltinDecoderStateMachine::IsShutdown()
+{
+  mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
+  return GetState() == DECODER_STATE_SHUTDOWN;
+}
+
--- a/content/media/nsBuiltinDecoderStateMachine.h
+++ b/content/media/nsBuiltinDecoderStateMachine.h
@@ -111,19 +111,19 @@ public:
   typedef mozilla::VideoSegment VideoSegment;
 
   nsBuiltinDecoderStateMachine(nsBuiltinDecoder* aDecoder, nsBuiltinDecoderReader* aReader, bool aRealTime = false);
   ~nsBuiltinDecoderStateMachine();
 
   // nsDecoderStateMachine interface
   virtual nsresult Init(nsDecoderStateMachine* aCloneDonor);
   State GetState()
-  { 
+  {
     mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
-    return mState; 
+    return mState;
   }
   virtual void SetVolume(double aVolume);
   virtual void SetAudioCaptured(bool aCapture);
   virtual void Shutdown();
   virtual int64_t GetDuration();
   virtual void SetDuration(int64_t aDuration);
   void SetEndTime(int64_t aEndTime);
   virtual bool OnDecodeThread() const {
@@ -259,16 +259,20 @@ public:
 
   // Copy queued audio/video data in the reader to any output MediaStreams that
   // need it.
   void SendStreamData();
   void FinishStreamData();
   bool HaveEnoughDecodedAudio(int64_t aAmpleAudioUSecs);
   bool HaveEnoughDecodedVideo();
 
+  // Returns true if the state machine has shutdown or is in the process of
+  // shutting down. The decoder monitor must be held while calling this.
+  bool IsShutdown() MOZ_OVERRIDE;
+
 protected:
   class WakeDecoderRunnable : public nsRunnable {
   public:
     WakeDecoderRunnable(nsBuiltinDecoderStateMachine* aSM)
       : mMutex("WakeDecoderRunnable"), mStateMachine(aSM) {}
     NS_IMETHOD Run()
     {
       nsRefPtr<nsBuiltinDecoderStateMachine> stateMachine;
--- a/content/media/ogg/nsOggReader.cpp
+++ b/content/media/ogg/nsOggReader.cpp
@@ -1101,17 +1101,17 @@ nsOggReader::IndexedSeekResult nsOggRead
   mCodecStates.Get(serial, &codecState);
   if (codecState &&
       codecState->mActive &&
       ogg_stream_pagein(&codecState->mState, &page) != 0)
   {
     // Couldn't insert page into the ogg resource, or somehow the resource
     // is no longer active.
     return RollbackIndexedSeek(tell);
-  }      
+  }
   mPageOffset = keyframe.mKeyPoint.mOffset + page.header_len + page.body_len;
   return SEEK_OK;
 }
 
 nsresult nsOggReader::SeekInBufferedRange(int64_t aTarget,
                                           int64_t aAdjustedTarget,
                                           int64_t aStartTime,
                                           int64_t aEndTime,
@@ -1131,17 +1131,17 @@ nsresult nsOggReader::SeekInBufferedRang
     // We have an active Theora bitstream. Decode the next Theora frame, and
     // extract its keyframe's time.
     bool eof;
     do {
       bool skip = false;
       eof = !DecodeVideoFrame(skip, 0);
       {
         ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-        if (mDecoder->GetDecodeState() == nsBuiltinDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+        if (mDecoder->GetStateMachine()->IsShutdown()) {
           return NS_ERROR_FAILURE;
         }
       }
     } while (!eof &&
              mVideoQueue.GetSize() == 0);
 
     VideoData* video = mVideoQueue.PeekFront();
     if (video && !video->mKeyframe) {
--- a/content/media/raw/nsRawReader.cpp
+++ b/content/media/raw/nsRawReader.cpp
@@ -253,18 +253,17 @@ nsresult nsRawReader::Seek(int64_t aTime
     bool keyframeSkip = false;
     if (!DecodeVideoFrame(keyframeSkip, 0)) {
       mCurrentFrame = frame;
       return NS_ERROR_FAILURE;
     }
 
     {
       mozilla::ReentrantMonitorAutoEnter autoMonitor(mDecoder->GetReentrantMonitor());
-      if (mDecoder->GetDecodeState() ==
-          nsBuiltinDecoderStateMachine::DECODER_STATE_SHUTDOWN) {
+      if (mDecoder->GetStateMachine()->IsShutdown()) {
         mCurrentFrame = frame;
         return NS_ERROR_FAILURE;
       }
     }
 
     nsAutoPtr<VideoData> video(mVideoQueue.PeekFront());
     if (video && video->mEndTime < aTime) {
       mVideoQueue.PopFront();