Bug 1374210: Reject/Cancel any pending operations. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 19 Jun 2017 10:38:22 +0200
changeset 596671 b62e37162ae63a1523507f3d14643992dfab8a4e
parent 596670 50dd0384437b4e1f7e96b2d4565314bb4b6edd8d
child 634028 7c5b0c8fbc3a1308077cf78a0339657638c6d0f0
push id64712
push userbmo:jyavenard@mozilla.com
push dateMon, 19 Jun 2017 15:55:57 +0000
reviewersgerald
bugs1374210
milestone56.0a1
Bug 1374210: Reject/Cancel any pending operations. r?gerald MozReview-Commit-ID: GVlzm2GWT1D
dom/media/platforms/wrappers/H264Converter.cpp
dom/media/platforms/wrappers/H264Converter.h
--- a/dom/media/platforms/wrappers/H264Converter.cpp
+++ b/dom/media/platforms/wrappers/H264Converter.cpp
@@ -187,26 +187,34 @@ H264Converter::Drain()
   return DecodePromise::CreateAndResolve(DecodedData(), __func__);
 }
 
 RefPtr<ShutdownPromise>
 H264Converter::Shutdown()
 {
   mInitPromiseRequest.DisconnectIfExists();
   mDecodePromiseRequest.DisconnectIfExists();
+  mDecodePromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
+  mDrainRequest.DisconnectIfExists();
   mFlushRequest.DisconnectIfExists();
+  mFlushPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
   mShutdownRequest.DisconnectIfExists();
-  mFlushPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
-  mNeedAVCC.reset();
 
   if (mShutdownPromise) {
     // We have a shutdown in progress, return that promise instead as we can't
     // shutdown a decoder twice.
     return mShutdownPromise.forget();
   }
+  return ShutdownDecoder();
+}
+
+RefPtr<ShutdownPromise>
+H264Converter::ShutdownDecoder()
+{
+  mNeedAVCC.reset();
   if (mDecoder) {
     RefPtr<MediaDataDecoder> decoder = mDecoder.forget();
     return decoder->Shutdown();
   }
   return ShutdownPromise::CreateAndResolve(true, __func__);
 }
 
 bool
@@ -474,17 +482,17 @@ void H264Converter::FlushThenShutdownDec
              mFlushRequest.Complete();
 
              if (!mFlushPromise.IsEmpty()) {
                // A Flush is pending, abort the current operation.
                mFlushPromise.Resolve(true, __func__);
                return;
              }
 
-             mShutdownPromise = Shutdown();
+             mShutdownPromise = ShutdownDecoder();
              mShutdownPromise
                ->Then(AbstractThread::GetCurrent()->AsTaskQueue(),
                       __func__,
                       [self, sample, this]() {
                         mShutdownRequest.Complete();
                         mShutdownPromise = nullptr;
 
                         if (!mFlushPromise.IsEmpty()) {
--- a/dom/media/platforms/wrappers/H264Converter.h
+++ b/dom/media/platforms/wrappers/H264Converter.h
@@ -71,16 +71,17 @@ private:
   nsresult CheckForSPSChange(MediaRawData* aSample);
   void UpdateConfigFromExtraData(MediaByteBuffer* aExtraData);
 
   bool CanRecycleDecoder() const;
 
   void DecodeFirstSample(MediaRawData* aSample);
   void DrainThenFlushDecoder(MediaRawData* aPendingSample);
   void FlushThenShutdownDecoder(MediaRawData* aPendingSample);
+  RefPtr<ShutdownPromise> ShutdownDecoder();
 
   RefPtr<PlatformDecoderModule> mPDM;
   const VideoInfo mOriginalConfig;
   VideoInfo mCurrentConfig;
   // Current out of band extra data (as found in metadata's VideoInfo).
   RefPtr<MediaByteBuffer> mOriginalExtraData;
   RefPtr<layers::KnowsCompositor> mKnowsCompositor;
   RefPtr<layers::ImageContainer> mImageContainer;