Bug 1374296: Don't incorrectly reject promise. r=me draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 19 Jun 2017 17:01:20 +0200
changeset 596624 43c639564da50c9c39b9e156cdc60f3919f346a2
parent 596439 834836245c3e9e530c4ebe2652aa3e85a9cf4e6c
child 634017 3f95c8f29b4092e7839e24fea29729d8f7c075bd
push id64701
push userbmo:jyavenard@mozilla.com
push dateMon, 19 Jun 2017 15:08:22 +0000
reviewersme
bugs1374296
milestone56.0a1
Bug 1374296: Don't incorrectly reject promise. r=me MozReview-Commit-ID: 6VZLLlIA3fM
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
@@ -192,23 +192,29 @@ 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();
-  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
@@ -476,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;