Bug 1068996 - Make WMFMediaDataDecoder::Shutdown() actually shutdown. r=kentuckyfriedtakahe
authorChris Pearce <cpearce@mozilla.com>
Fri, 19 Sep 2014 15:44:27 +1200
changeset 206130 1674d241ce3d325eaf631fe44440d2da5886b125
parent 206129 9362521b7f7a5a938bb09d8f6f6ac96b02a609dc
child 206131 cafcd5e8dc591a55a29018c671cfeb73aede31e8
push id27513
push usercbook@mozilla.com
push dateFri, 19 Sep 2014 12:15:35 +0000
treeherdermozilla-central@dadafedc0760 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe
bugs1068996
milestone35.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 1068996 - Make WMFMediaDataDecoder::Shutdown() actually shutdown. r=kentuckyfriedtakahe
content/media/fmp4/wmf/WMFAudioMFTManager.cpp
content/media/fmp4/wmf/WMFAudioMFTManager.h
content/media/fmp4/wmf/WMFMediaDataDecoder.cpp
content/media/fmp4/wmf/WMFMediaDataDecoder.h
content/media/fmp4/wmf/WMFVideoMFTManager.cpp
content/media/fmp4/wmf/WMFVideoMFTManager.h
--- a/content/media/fmp4/wmf/WMFAudioMFTManager.cpp
+++ b/content/media/fmp4/wmf/WMFAudioMFTManager.cpp
@@ -303,9 +303,15 @@ WMFAudioMFTManager::Output(int64_t aStre
   #ifdef LOG_SAMPLE_DECODE
   LOG("Decoded audio sample! timestamp=%lld duration=%lld currentLength=%u",
       timestamp, duration, currentLength);
   #endif
 
   return S_OK;
 }
 
+void
+WMFAudioMFTManager::Shutdown()
+{
+  mDecoder = nullptr;
+}
+
 } // namespace mozilla
--- a/content/media/fmp4/wmf/WMFAudioMFTManager.h
+++ b/content/media/fmp4/wmf/WMFAudioMFTManager.h
@@ -24,16 +24,19 @@ public:
 
   virtual HRESULT Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE;
 
   // Note WMF's AAC decoder sometimes output negatively timestamped samples,
   // presumably they're the preroll samples, and we strip them. We may return
   // a null aOutput in this case.
   virtual HRESULT Output(int64_t aStreamOffset,
                          nsAutoPtr<MediaData>& aOutput) MOZ_OVERRIDE;
+
+  virtual void Shutdown() MOZ_OVERRIDE;
+
 private:
 
   HRESULT UpdateOutputType();
 
   // IMFTransform wrapper that performs the decoding.
   RefPtr<MFTDecoder> mDecoder;
 
   uint32_t mAudioChannels;
--- a/content/media/fmp4/wmf/WMFMediaDataDecoder.cpp
+++ b/content/media/fmp4/wmf/WMFMediaDataDecoder.cpp
@@ -43,18 +43,26 @@ WMFMediaDataDecoder::Init()
   NS_ENSURE_TRUE(mDecoder, NS_ERROR_FAILURE);
 
   return NS_OK;
 }
 
 nsresult
 WMFMediaDataDecoder::Shutdown()
 {
+  mTaskQueue->FlushAndDispatch(NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown));
+  return NS_OK;
+}
+
+void
+WMFMediaDataDecoder::ProcessShutdown()
+{
+  mMFTManager->Shutdown();
+  mMFTManager = nullptr;
   mDecoder = nullptr;
-  return NS_OK;
 }
 
 // Inserts data into the decoder's pipeline.
 nsresult
 WMFMediaDataDecoder::Input(mp4_demuxer::MP4Sample* aSample)
 {
   mTaskQueue->Dispatch(
     NS_NewRunnableMethodWithArg<nsAutoPtr<mp4_demuxer::MP4Sample>>(
--- a/content/media/fmp4/wmf/WMFMediaDataDecoder.h
+++ b/content/media/fmp4/wmf/WMFMediaDataDecoder.h
@@ -38,16 +38,19 @@ public:
   // Produces decoded output, if possible. Blocks until output can be produced,
   // or until no more is able to be produced.
   // Returns S_OK on success, or MF_E_TRANSFORM_NEED_MORE_INPUT if there's not
   // enough data to produce more output. If this returns a failure code other
   // than MF_E_TRANSFORM_NEED_MORE_INPUT, an error will be reported to the
   // MP4Reader.
   virtual HRESULT Output(int64_t aStreamOffset,
                          nsAutoPtr<MediaData>& aOutput) = 0;
+
+  // Destroys all resources.
+  virtual void Shutdown() = 0;
 };
 
 // Decodes audio and video using Windows Media Foundation. Samples are decoded
 // using the MFTDecoder created by the MFTManager. This class implements
 // the higher-level logic that drives mapping the MFT to the async
 // MediaDataDecoder interface. The specifics of decoding the exact stream
 // type are handled by MFTManager and the MFTDecoder it creates.
 class WMFMediaDataDecoder : public MediaDataDecoder {
@@ -76,16 +79,18 @@ private:
   // Called on the task queue. Extracts output if available, and delivers
   // it to the reader. Called after ProcessDecode() and ProcessDrain().
   void ProcessOutput();
 
   // Called on the task queue. Orders the MFT to drain, and then extracts
   // all available output.
   void ProcessDrain();
 
+  void ProcessShutdown();
+
   RefPtr<MediaTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
 
   RefPtr<MFTDecoder> mDecoder;
   nsAutoPtr<MFTManager> mMFTManager;
 
   // The last offset into the media resource that was passed into Input().
   // This is used to approximate the decoder's position in the media resource.
--- a/content/media/fmp4/wmf/WMFVideoMFTManager.cpp
+++ b/content/media/fmp4/wmf/WMFVideoMFTManager.cpp
@@ -394,9 +394,15 @@ WMFVideoMFTManager::Output(int64_t aStre
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
   NS_ENSURE_TRUE(frame, E_FAIL);
 
   aOutData = frame;
 
   return S_OK;
 }
 
+void
+WMFVideoMFTManager::Shutdown()
+{
+  mDecoder = nullptr;
+}
+
 } // namespace mozilla
--- a/content/media/fmp4/wmf/WMFVideoMFTManager.h
+++ b/content/media/fmp4/wmf/WMFVideoMFTManager.h
@@ -28,16 +28,18 @@ public:
 
   virtual TemporaryRef<MFTDecoder> Init() MOZ_OVERRIDE;
 
   virtual HRESULT Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE;
 
   virtual HRESULT Output(int64_t aStreamOffset,
                          nsAutoPtr<MediaData>& aOutput) MOZ_OVERRIDE;
 
+  virtual void Shutdown() MOZ_OVERRIDE;
+
 private:
 
   bool InitializeDXVA();
 
   HRESULT ConfigureVideoFrameGeometry();
 
   HRESULT CreateBasicVideoFrame(IMFSample* aSample,
                                 int64_t aStreamOffset,