Bug 1383628. P2 - move the call to Load() into Clone(). draft
authorJW Wang <jwwang@mozilla.com>
Thu, 03 Aug 2017 17:47:23 +0800
changeset 642340 0d9dfe70507aec20bf54a7bce9d75b28c389af95
parent 642339 b9594c03541876da7069390f69774912aae70c6d
child 642341 3265d73695a18ad24d63b82042936856ad1a8d5c
push id72707
push userjwwang@mozilla.com
push dateTue, 08 Aug 2017 02:32:36 +0000
bugs1383628
milestone57.0a1
Bug 1383628. P2 - move the call to Load() into Clone(). MozReview-Commit-ID: 9k8BXLwAepI
dom/html/HTMLMediaElement.cpp
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4716,20 +4716,16 @@ HTMLMediaElement::CanPlayType(const nsAS
 }
 
 nsresult
 HTMLMediaElement::InitializeDecoderAsClone(ChannelMediaDecoder* aOriginal)
 {
   NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
   NS_ASSERTION(mDecoder == nullptr, "Shouldn't have a decoder");
 
-  MediaResource* originalResource = aOriginal->GetResource();
-  if (!originalResource)
-    return NS_ERROR_FAILURE;
-
   MediaDecoderInit decoderInit(this,
                                mAudioChannel,
                                mMuted ? 0.0 : mVolume,
                                mPreservesPitch,
                                mPlaybackRate,
                                mPreloadAction ==
                                  HTMLMediaElement::PRELOAD_METADATA,
                                mHasSuspendTaint,
@@ -4737,24 +4733,16 @@ HTMLMediaElement::InitializeDecoderAsClo
                                aOriginal->ContainerType());
 
   RefPtr<ChannelMediaDecoder> decoder = aOriginal->Clone(decoderInit);
   if (!decoder)
     return NS_ERROR_FAILURE;
 
   LOG(LogLevel::Debug, ("%p Cloned decoder %p from %p", this, decoder.get(), aOriginal));
 
-  nsresult rv = decoder->Load(originalResource);
-  if (NS_FAILED(rv)) {
-    decoder->Shutdown();
-    LOG(LogLevel::Debug,
-        ("%p Failed to load for decoder %p", this, decoder.get()));
-    return rv;
-  }
-
   return FinishDecoderSetup(decoder);
 }
 
 template<typename DecoderType, typename... LoadArgs>
 nsresult
 HTMLMediaElement::SetupDecoder(DecoderType* aDecoder, LoadArgs&&... aArgs)
 {
   LOG(LogLevel::Debug,
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -153,17 +153,28 @@ ChannelMediaDecoder::ChannelMediaDecoder
   , mResourceCallback(new ResourceCallback(aInit.mOwner->AbstractMainThread()))
 {
   mResourceCallback->Connect(this);
 }
 
 already_AddRefed<ChannelMediaDecoder>
 ChannelMediaDecoder::Clone(MediaDecoderInit& aInit)
 {
+  if (!mResource) {
+    return nullptr;
+  }
   RefPtr<ChannelMediaDecoder> decoder = CloneImpl(aInit);
+  if (!decoder) {
+    return nullptr;
+  }
+  nsresult rv = decoder->Load(mResource);
+  if (NS_FAILED(rv)) {
+    decoder->Shutdown();
+    return nullptr;
+  }
   return decoder.forget();
 }
 
 MediaResource*
 ChannelMediaDecoder::GetResource() const
 {
   return mResource;
 }
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -65,18 +65,18 @@ public:
   void Shutdown() override;
 
   // Create a new decoder of the same type as this one.
   already_AddRefed<ChannelMediaDecoder> Clone(MediaDecoderInit& aInit);
 
   virtual nsresult Load(nsIChannel* aChannel,
                         bool aIsPrivateBrowsing,
                         nsIStreamListener** aStreamListener);
-  virtual nsresult Load(MediaResource* aOriginal);
 
 private:
   virtual ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) = 0;
   nsresult OpenResource(nsIStreamListener** aStreamListener);
+  virtual nsresult Load(MediaResource* aOriginal);
 };
 
 } // namespace mozilla
 
 #endif // ChannelMediaDecoder_h_