Bug 1370805: P1. Revert "Bug 1370164: Properly handle flushing during ongoing operations. r=jwwang"
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 07 Jun 2017 13:32:09 +0200
changeset 413458 a8b2d76d085c0f433fe1a21ffc34ac3882b9cc16
parent 413457 e92dd6dae230f9ebff1c30d7168d08c5eaac5920
child 413459 ce819cf67a70778cf715281df61afa96a918ccda
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1370805, 1370164
milestone55.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 1370805: P1. Revert "Bug 1370164: Properly handle flushing during ongoing operations. r=jwwang"
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
@@ -127,57 +127,24 @@ H264Converter::Decode(MediaRawData* aSam
 
   return mDecoder->Decode(aSample);
 }
 
 RefPtr<MediaDataDecoder::FlushPromise>
 H264Converter::Flush()
 {
   mDecodePromiseRequest.DisconnectIfExists();
+  mFlushRequest.DisconnectIfExists();
+  mShutdownRequest.DisconnectIfExists();
   mDecodePromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
   mNeedKeyframe = true;
-
-  /*
-      When we detect a change of content in the H264 stream, we first flush the
-    current decoder (1), then shut it down (2).
-    It is possible possible for H264Converter::Flush to be called during any of
-    those time.
-    If during (1):
-      - mFlushRequest and mFlushPromise will not be empty.
-      - The old decoder can still be used, with the current extradata as stored
-        in mCurrentConfig.mExtraData.
-
-    If during (2):
-      - mShutdownRequest and mShutdownPromise won't be empty.
-      - mDecoder is empty.
-      - The old decoder is no longer referenced by the H264Converter.
-  */
-  if (mFlushPromise) {
-    // Flush in progress, hijack that one.
-    mFlushRequest.Disconnect();
-    return mFlushPromise.forget();
-  }
   if (mDecoder) {
     return mDecoder->Flush();
   }
-  if (!mShutdownPromise) {
-    return FlushPromise::CreateAndResolve(true, __func__);
-  }
-
-  mShutdownRequest.Disconnect();
-  // Let's continue when the the current shutdown completes.
-  RefPtr<ShutdownPromise> shutdownPromise = mShutdownPromise.forget();
-  return shutdownPromise->Then(
-    AbstractThread::GetCurrent()->AsTaskQueue(),
-    __func__,
-    [](bool) { return FlushPromise::CreateAndResolve(true, __func__); },
-    [](bool) {
-      MOZ_ASSERT_UNREACHABLE("Shutdown promises are always resolved");
-      return FlushPromise::CreateAndResolve(true, __func__);
-    });
+  return FlushPromise::CreateAndResolve(true, __func__);
 }
 
 RefPtr<MediaDataDecoder::DecodePromise>
 H264Converter::Drain()
 {
   mNeedKeyframe = true;
   if (mDecoder) {
     return mDecoder->Drain();
@@ -186,21 +153,18 @@ H264Converter::Drain()
 }
 
 RefPtr<ShutdownPromise>
 H264Converter::Shutdown()
 {
   mInitPromiseRequest.DisconnectIfExists();
   mDecodePromiseRequest.DisconnectIfExists();
   mFlushRequest.DisconnectIfExists();
-  mFlushPromise = nullptr;
   mShutdownRequest.DisconnectIfExists();
   mPendingSample = nullptr;
-  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();
   }
   if (mDecoder) {
     RefPtr<MediaDataDecoder> decoder = mDecoder.forget();
     return decoder->Shutdown();
@@ -407,44 +371,43 @@ H264Converter::CheckForSPSChange(MediaRa
     }
     mNeedKeyframe = true;
     return NS_OK;
   }
 
   // The SPS has changed, signal to flush the current decoder and create a
   // new one.
   RefPtr<H264Converter> self = this;
-  mFlushPromise = mDecoder->Flush();
-  mFlushPromise
+  mDecoder->Flush()
     ->Then(AbstractThread::GetCurrent()->AsTaskQueue(),
            __func__,
            [self, sample, this]() {
              mFlushRequest.Complete();
              mShutdownPromise = Shutdown();
              mShutdownPromise
                ->Then(AbstractThread::GetCurrent()->AsTaskQueue(),
                       __func__,
                       [self, sample, this]() {
                         mShutdownRequest.Complete();
                         mShutdownPromise = nullptr;
+                        mNeedAVCC.reset();
                         nsresult rv = CreateDecoderAndInit(sample);
                         if (rv == NS_ERROR_DOM_MEDIA_INITIALIZING_DECODER) {
                           // All good so far, will continue later.
                           return;
                         }
                         MOZ_ASSERT(NS_FAILED(rv));
                         mDecodePromise.Reject(rv, __func__);
                         return;
                       },
                       [] { MOZ_CRASH("Can't reach here'"); })
                ->Track(mShutdownRequest);
            },
            [self, this](const MediaResult& aError) {
              mFlushRequest.Complete();
-             mFlushPromise = nullptr;
              mDecodePromise.Reject(aError, __func__);
            })
     ->Track(mFlushRequest);
   return NS_ERROR_DOM_MEDIA_INITIALIZING_DECODER;
 }
 
 void
 H264Converter::UpdateConfigFromExtraData(MediaByteBuffer* aExtraData)
--- a/dom/media/platforms/wrappers/H264Converter.h
+++ b/dom/media/platforms/wrappers/H264Converter.h
@@ -87,17 +87,16 @@ private:
   RefPtr<layers::ImageContainer> mImageContainer;
   const RefPtr<TaskQueue> mTaskQueue;
   RefPtr<MediaRawData> mPendingSample;
   RefPtr<MediaDataDecoder> mDecoder;
   MozPromiseRequestHolder<InitPromise> mInitPromiseRequest;
   MozPromiseRequestHolder<DecodePromise> mDecodePromiseRequest;
   MozPromiseHolder<DecodePromise> mDecodePromise;
   MozPromiseRequestHolder<FlushPromise> mFlushRequest;
-  RefPtr<FlushPromise> mFlushPromise;
   MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
   RefPtr<ShutdownPromise> mShutdownPromise;
 
   RefPtr<GMPCrashHelper> mGMPCrashHelper;
   Maybe<bool> mNeedAVCC;
   nsresult mLastError;
   bool mNeedKeyframe = true;
   const TrackInfo::TrackType mType;