Bug 1216850. Part 3 - backout bug 1214073. r=me.
authorJW Wang <jwwang@mozilla.com>
Wed, 21 Oct 2015 14:04:20 +0800
changeset 268736 a2e952efafc09ee625ef5bc3d736cd5be1471788
parent 268735 0a956a76fcfc2daf13cbfd669eb602575665b73a
child 268737 859f04d0f77e7db9c442b33de327194a8f639882
push id29562
push userkwierso@gmail.com
push dateWed, 21 Oct 2015 23:29:46 +0000
treeherdermozilla-central@4879f22ef96a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1216850, 1214073
milestone44.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 1216850. Part 3 - backout bug 1214073. r=me.
dom/media/MediaDecoderReader.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
dom/media/omx/MediaCodecReader.cpp
dom/media/omx/MediaCodecReader.h
dom/media/omx/MediaOmxReader.cpp
dom/media/omx/MediaOmxReader.h
--- a/dom/media/MediaDecoderReader.h
+++ b/dom/media/MediaDecoderReader.h
@@ -91,26 +91,17 @@ public:
   void InitializationTask();
 
   // Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
   // on failure.
   virtual nsresult Init() { return NS_OK; }
 
   // Release media resources they should be released in dormant state
   // The reader can be made usable again by calling ReadMetadata().
-  void ReleaseMediaResources()
-  {
-    if (OnTaskQueue()) {
-      ReleaseMediaResourcesInternal();
-      return;
-    }
-    nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
-      this, &MediaDecoderReader::ReleaseMediaResourcesInternal);
-    OwnerThread()->Dispatch(r.forget());
-  }
+  virtual void ReleaseMediaResources() {};
   // Breaks reference-counted cycles. Called during shutdown.
   // WARNING: If you override this, you must call the base implementation
   // in your override.
   virtual void BreakCycles();
 
   // Destroys the decoding state. The reader cannot be made usable again.
   // This is different from ReleaseMediaResources() as it is irreversable,
   // whereas ReleaseMediaResources() is.  Must be called on the decode
@@ -247,19 +238,16 @@ public:
 
   // Returns the number of bytes of memory allocated by structures/frames in
   // the audio queue.
   size_t SizeOfAudioQueueInBytes() const;
 
   virtual size_t SizeOfVideoQueueInFrames();
   virtual size_t SizeOfAudioQueueInFrames();
 
-private:
-  virtual void ReleaseMediaResourcesInternal() {}
-
 protected:
   friend class TrackBuffer;
   virtual void NotifyDataArrivedInternal(uint32_t aLength, int64_t aOffset) { }
 
   void NotifyDataArrived(const media::Interval<int64_t>& aInfo)
   {
     MOZ_ASSERT(OnTaskQueue());
     NS_ENSURE_TRUE_VOID(!mShutdown);
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1282,17 +1282,18 @@ MediaDecoderStateMachine::SetDormant(boo
     Reset();
 
     // Note that we do not wait for the decode task queue to go idle before
     // queuing the ReleaseMediaResources task - instead, we disconnect promises,
     // reset state, and put a ResetDecode in the decode task queue. Any tasks
     // that run after ResetDecode are supposed to run with a clean slate. We rely
     // on that in other places (i.e. seeking), so it seems reasonable to rely on
     // it here as well.
-    mReader->ReleaseMediaResources();
+    nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(mReader, &MediaDecoderReader::ReleaseMediaResources);
+    DecodeTaskQueue()->Dispatch(r.forget());
   } else if ((aDormant != true) && (mState == DECODER_STATE_DORMANT)) {
     ScheduleStateMachine();
     mDecodingFirstFrame = true;
     SetState(DECODER_STATE_DECODING_NONE);
   }
 }
 
 void MediaDecoderStateMachine::Shutdown()
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1577,19 +1577,18 @@ MediaFormatReader::GetBuffered()
     intervals = Move(audioti);
   } else if (HasVideo()) {
     intervals = Move(videoti);
   }
 
   return intervals.Shift(media::TimeUnit::FromMicroseconds(-startTime));
 }
 
-void MediaFormatReader::ReleaseMediaResourcesInternal()
+void MediaFormatReader::ReleaseMediaResources()
 {
-  MOZ_ASSERT(OnTaskQueue());
   // Before freeing a video codec, all video buffers needed to be released
   // even from graphics pipeline.
   if (mVideoFrameContainer) {
     mVideoFrameContainer->ClearCurrentFrame();
   }
   if (mVideo.mDecoder) {
     mVideo.mDecoder->Shutdown();
     mVideo.mDecoder = nullptr;
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -68,16 +68,19 @@ protected:
   void NotifyDataArrivedInternal(uint32_t aLength, int64_t aOffset) override;
 public:
   void NotifyDataRemoved() override;
 
   media::TimeIntervals GetBuffered() override;
 
   virtual bool ForceZeroStartTime() const override;
 
+  // For Media Resource Management
+  void ReleaseMediaResources() override;
+
   nsresult ResetDecode() override;
 
   RefPtr<ShutdownPromise> Shutdown() override;
 
   bool IsAsync() const override { return true; }
 
   bool VideoIsHardwareAccelerated() const override;
 
@@ -434,17 +437,13 @@ private:
 
 #ifdef MOZ_EME
   RefPtr<CDMProxy> mCDMProxy;
 #endif
 
 #if defined(READER_DORMANT_HEURISTIC)
   const bool mDormantEnabled;
 #endif
-
-private:
-  // For Media Resource Management
-  void ReleaseMediaResourcesInternal() override;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/omx/MediaCodecReader.cpp
+++ b/dom/media/omx/MediaCodecReader.cpp
@@ -279,20 +279,18 @@ MediaCodecReader::MediaCodecReader(Abstr
   mVideoListener = new VideoResourceListener(this);
 }
 
 MediaCodecReader::~MediaCodecReader()
 {
 }
 
 void
-MediaCodecReader::ReleaseMediaResourcesInternal()
+MediaCodecReader::ReleaseMediaResources()
 {
-  MOZ_ASSERT(OnTaskQueue());
-
   // Stop the mSource because we are in the dormant state and the stop function
   // will rewind the mSource to the beginning of the stream.
   if (mVideoTrack.mSource != nullptr && !mVideoTrack.mSourceIsStopped) {
     mVideoTrack.mSource->stop();
     mVideoTrack.mSourceIsStopped = true;
   }
   if (mAudioTrack.mSource != nullptr && !mAudioTrack.mSourceIsStopped) {
     mAudioTrack.mSource->stop();
--- a/dom/media/omx/MediaCodecReader.h
+++ b/dom/media/omx/MediaCodecReader.h
@@ -55,16 +55,19 @@ class MediaCodecReader : public MediaOmx
   typedef mozilla::layers::TextureClient TextureClient;
   typedef mozilla::layers::FenceHandle FenceHandle;
   typedef MediaOmxCommonReader::MediaResourcePromise MediaResourcePromise;
 
 public:
   MediaCodecReader(AbstractMediaDecoder* aDecoder);
   virtual ~MediaCodecReader();
 
+  // Release media resources they should be released in dormant state
+  virtual void ReleaseMediaResources();
+
   // Destroys the decoding state. The reader cannot be made usable again.
   // This is different from ReleaseMediaResources() as Shutdown() is
   // irreversible, whereas ReleaseMediaResources() is reversible.
   virtual RefPtr<ShutdownPromise> Shutdown();
 
 protected:
   // Used to retrieve some special information that can only be retrieved after
   // all contents have been continuously parsed. (ex. total duration of some
@@ -428,17 +431,13 @@ private:
     : mReleaseIndex(aIndex)
     , mReleaseFence(aFence) {}
     size_t mReleaseIndex;
     FenceHandle mReleaseFence;
   };
   nsTArray<ReleaseItem> mPendingReleaseItems;
 
   NotifyDataArrivedFilter mFilter;
-
-private:
-  // Release media resources they should be released in dormant state
-  virtual void ReleaseMediaResourcesInternal() override;
 };
 
 } // namespace mozilla
 
 #endif // MEDIA_CODEC_READER_H
--- a/dom/media/omx/MediaOmxReader.cpp
+++ b/dom/media/omx/MediaOmxReader.cpp
@@ -165,20 +165,18 @@ MediaOmxReader::Shutdown()
 
   // Wait for the superclass to finish tearing things down before releasing
   // the decoder on the main thread.
   p->Then(AbstractThread::MainThread(), __func__, this, &MediaOmxReader::ReleaseDecoder, &MediaOmxReader::ReleaseDecoder);
 
   return p;
 }
 
-void MediaOmxReader::ReleaseMediaResourcesInternal()
+void MediaOmxReader::ReleaseMediaResources()
 {
-  MOZ_ASSERT(OnTaskQueue());
-
   mMediaResourceRequest.DisconnectIfExists();
   mMetadataPromise.RejectIfExists(ReadMetadataFailureReason::METADATA_ERROR, __func__);
 
   ResetDecode();
   // Before freeing a video codec, all video buffers needed to be released
   // even from graphics pipeline.
   VideoFrameContainer* container = mDecoder->GetVideoFrameContainer();
   if (container) {
--- a/dom/media/omx/MediaOmxReader.h
+++ b/dom/media/omx/MediaOmxReader.h
@@ -90,16 +90,18 @@ public:
     return mHasAudio;
   }
 
   virtual bool HasVideo()
   {
     return mHasVideo;
   }
 
+  virtual void ReleaseMediaResources() override;
+
   virtual RefPtr<MediaDecoderReader::MetadataPromise> AsyncReadMetadata() override;
 
   virtual RefPtr<SeekPromise>
   Seek(int64_t aTime, int64_t aEndTime) override;
 
   virtual bool IsMediaSeekable() override;
 
   virtual void SetIdle() override;
@@ -111,18 +113,16 @@ public:
   // This method is intended only for private use but public only for
   // MozPromise::InvokeCallbackMethod().
   void ReleaseDecoder();
 
 private:
   class ProcessCachedDataTask;
   class NotifyDataArrivedRunnable;
 
-  virtual void ReleaseMediaResourcesInternal() override;
-
   bool IsShutdown() {
     MutexAutoLock lock(mShutdownMutex);
     return mIsShutdown;
   }
 
   int64_t ProcessCachedData(int64_t aOffset);
 
   already_AddRefed<AbstractMediaDecoder> SafeGetDecoder();