Bug 1374930. P3 - move Clone() down to ChannelMediaDecoder for clone is possible only for those use channel-based resource. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 20 Jun 2017 18:10:27 +0800
changeset 598694 75402998582c0e79ecc7633b872f22b1adb07428
parent 597906 8a36827a5ac8c3689b676dda9855297918ca5181
child 598695 273d939798dc6bd47c3d90730a312608cecbcf70
push id65284
push userjwwang@mozilla.com
push dateThu, 22 Jun 2017 02:11:11 +0000
bugs1374930
milestone56.0a1
Bug 1374930. P3 - move Clone() down to ChannelMediaDecoder for clone is possible only for those use channel-based resource. MozReview-Commit-ID: Ci2kbts2pkQ
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
dom/media/ADTSDecoder.cpp
dom/media/ADTSDecoder.h
dom/media/ChannelMediaDecoder.h
dom/media/MediaDecoder.h
dom/media/android/AndroidMediaDecoder.h
dom/media/flac/FlacDecoder.cpp
dom/media/flac/FlacDecoder.h
dom/media/fmp4/MP4Decoder.h
dom/media/hls/HLSDecoder.cpp
dom/media/hls/HLSDecoder.h
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceDecoder.h
dom/media/mp3/MP3Decoder.cpp
dom/media/mp3/MP3Decoder.h
dom/media/ogg/OggDecoder.h
dom/media/wave/WaveDecoder.cpp
dom/media/wave/WaveDecoder.h
dom/media/webm/WebMDecoder.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -44,17 +44,16 @@
 
 #include "nsIScriptSecurityManager.h"
 #include "nsIXPConnect.h"
 #include "jsapi.h"
 
 #include "nsITimer.h"
 
 #include "MediaError.h"
-#include "MediaDecoder.h"
 #include "MediaPrefs.h"
 #include "MediaResource.h"
 
 #include "nsICategoryManager.h"
 #include "nsIContentPolicy.h"
 #include "nsContentPolicyUtils.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsICachingChannel.h"
@@ -65,16 +64,17 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsMediaFragmentURIParser.h"
 #include "nsURIHashKey.h"
 #include "nsJSUtils.h"
 #include "MediaStreamGraph.h"
 #include "nsIScriptError.h"
 #include "nsHostObjectProtocolHandler.h"
 #include "mozilla/dom/MediaSource.h"
+#include "ChannelMediaDecoder.h"
 #include "MediaMetadataManager.h"
 #include "MediaSourceDecoder.h"
 #include "MediaStreamListener.h"
 #include "DOMMediaStream.h"
 #include "AudioStreamTrack.h"
 #include "VideoStreamTrack.h"
 #include "MediaTrackList.h"
 #include "MediaStreamError.h"
@@ -2441,17 +2441,19 @@ nsresult HTMLMediaElement::LoadResource(
   }
 
   // Set the media element's CORS mode only when loading a resource
   mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
 
   HTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc);
   if (other && other->mDecoder) {
     // Clone it.
-    nsresult rv = InitializeDecoderAsClone(other->mDecoder);
+    // TODO: remove the cast by storing ChannelMediaDecoder in the URI table.
+    nsresult rv = InitializeDecoderAsClone(
+      static_cast<ChannelMediaDecoder*>(other->mDecoder.get()));
     if (NS_SUCCEEDED(rv))
       return rv;
   }
 
   if (IsMediaStreamURI(mLoadingSrc)) {
     RefPtr<DOMMediaStream> stream;
     nsresult rv = NS_GetStreamForMediaStreamURI(mLoadingSrc, getter_AddRefs(stream));
     if (NS_FAILED(rv)) {
@@ -4591,17 +4593,18 @@ HTMLMediaElement::CanPlayType(const nsAS
 
   LOG(LogLevel::Debug, ("%p CanPlayType(%s) = \"%s\"", this,
                      NS_ConvertUTF16toUTF8(aType).get(),
                      NS_ConvertUTF16toUTF8(aResult).get()));
 
   return NS_OK;
 }
 
-nsresult HTMLMediaElement::InitializeDecoderAsClone(MediaDecoder* aOriginal)
+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;
 
@@ -4610,17 +4613,17 @@ nsresult HTMLMediaElement::InitializeDec
     mAudioChannel,
     mMuted ? 0.0 : mVolume,
     mPreservesPitch,
     mPlaybackRate,
     mPreloadAction == HTMLMediaElement::PRELOAD_METADATA,
     mHasSuspendTaint,
     HasAttr(kNameSpaceID_None, nsGkAtoms::loop));
 
-  RefPtr<MediaDecoder> decoder = aOriginal->Clone(decoderInit);
+  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));
 
   RefPtr<MediaResource> resource =
     originalResource->CloneData(decoder->GetResourceCallback());
 
@@ -4649,17 +4652,17 @@ nsresult HTMLMediaElement::InitializeDec
     mAudioChannel,
     mMuted ? 0.0 : mVolume,
     mPreservesPitch,
     mPlaybackRate,
     mPreloadAction == HTMLMediaElement::PRELOAD_METADATA,
     mHasSuspendTaint,
     HasAttr(kNameSpaceID_None, nsGkAtoms::loop));
 
-  RefPtr<MediaDecoder> decoder =
+  RefPtr<ChannelMediaDecoder> decoder =
     DecoderTraits::CreateDecoder(mimeType, decoderInit, &diagnostics);
   diagnostics.StoreFormatDiagnostics(OwnerDoc(),
                                      NS_ConvertASCIItoUTF16(mimeType),
                                      decoder != nullptr,
                                      __func__);
   if (!decoder) {
     nsAutoString src;
     GetCurrentSrc(src);
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -37,16 +37,17 @@
 typedef uint16_t nsMediaNetworkState;
 typedef uint16_t nsMediaReadyState;
 typedef uint32_t SuspendTypes;
 typedef uint32_t AudibleChangedReasons;
 typedef uint8_t AudibleState;
 
 namespace mozilla {
 class AbstractThread;
+class ChannelMediaDecoder;
 class DecoderDoctorDiagnostics;
 class DOMMediaStream;
 class ErrorResult;
 class MediaResource;
 class MediaDecoder;
 class VideoFrameContainer;
 namespace dom {
 class MediaKeys;
@@ -934,17 +935,17 @@ protected:
                                                          bool aCaptureAudio,
                                                          MediaStreamGraph* aGraph);
 
   /**
    * Initialize a decoder as a clone of an existing decoder in another
    * element.
    * mLoadingSrc must already be set.
    */
-  nsresult InitializeDecoderAsClone(MediaDecoder* aOriginal);
+  nsresult InitializeDecoderAsClone(ChannelMediaDecoder* aOriginal);
 
   /**
    * Initialize a decoder to load the given channel. The decoder's stream
    * listener is returned via aListener.
    * mLoadingSrc must already be set.
    */
   nsresult InitializeDecoderForChannel(nsIChannel *aChannel,
                                        nsIStreamListener **aListener);
--- a/dom/media/ADTSDecoder.cpp
+++ b/dom/media/ADTSDecoder.cpp
@@ -8,17 +8,17 @@
 #include "ADTSDemuxer.h"
 #include "MediaContainerType.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
-MediaDecoder*
+ChannelMediaDecoder*
 ADTSDecoder::Clone(MediaDecoderInit& aInit)
 {
   if (!IsEnabled())
     return nullptr;
 
   return new ADTSDecoder(aInit);
 }
 
--- a/dom/media/ADTSDecoder.h
+++ b/dom/media/ADTSDecoder.h
@@ -16,17 +16,17 @@ class MediaContainerType;
 class ADTSDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit ADTSDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the ADTS backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -10,13 +10,17 @@
 #include "MediaDecoder.h"
 
 namespace mozilla {
 
 class ChannelMediaDecoder : public MediaDecoder
 {
 public:
   explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
+
+  // Create a new decoder of the same type as this one.
+  // Subclasses must implement this.
+  virtual ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) = 0;
 };
 
 } // namespace mozilla
 
 #endif // ChannelMediaDecoder_h_
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -146,20 +146,16 @@ public:
   // Must be called exactly once, on the main thread, during startup.
   static void InitStatics();
 
   explicit MediaDecoder(MediaDecoderInit& aInit);
 
   // Return a callback object used to register with MediaResource to receive
   // notifications.
   MediaResourceCallback* GetResourceCallback() const;
-
-  // Create a new decoder of the same type as this one.
-  // Subclasses must implement this.
-  virtual MediaDecoder* Clone(MediaDecoderInit& aInit) = 0;
   // Create a new state machine to run this decoder.
   // Subclasses must implement this.
   virtual MediaDecoderStateMachine* CreateStateMachine() = 0;
 
   // Cleanup internal data structures. Must be called on the main
   // thread by the owning object before that object disposes of this object.
   virtual void Shutdown();
 
--- a/dom/media/android/AndroidMediaDecoder.h
+++ b/dom/media/android/AndroidMediaDecoder.h
@@ -13,17 +13,18 @@
 namespace mozilla {
 
 class AndroidMediaDecoder : public ChannelMediaDecoder
 {
   MediaContainerType mType;
 public:
   AndroidMediaDecoder(MediaDecoderInit& aInit, const MediaContainerType& aType);
 
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override {
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
+  {
     return new AndroidMediaDecoder(aInit, mType);
   }
   MediaDecoderStateMachine* CreateStateMachine() override;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/flac/FlacDecoder.cpp
+++ b/dom/media/flac/FlacDecoder.cpp
@@ -8,17 +8,17 @@
 #include "FlacDemuxer.h"
 #include "MediaContainerType.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "MediaPrefs.h"
 
 namespace mozilla {
 
-MediaDecoder*
+ChannelMediaDecoder*
 FlacDecoder::Clone(MediaDecoderInit& aInit)
 {
   if (!IsEnabled()) {
     return nullptr;
   }
 
   return new FlacDecoder(aInit);
 }
--- a/dom/media/flac/FlacDecoder.h
+++ b/dom/media/flac/FlacDecoder.h
@@ -16,17 +16,17 @@ class MediaContainerType;
 class FlacDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit FlacDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the Flac backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -16,17 +16,18 @@ namespace mozilla {
 class MediaContainerType;
 
 // Decoder that uses a bundled MP4 demuxer and platform decoders to play MP4.
 class MP4Decoder : public ChannelMediaDecoder
 {
 public:
   explicit MP4Decoder(MediaDecoderInit& aInit);
 
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override {
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
+  {
     if (!IsEnabled()) {
       return nullptr;
     }
     return new MP4Decoder(aInit);
   }
 
   MediaDecoderStateMachine* CreateStateMachine() override;
 
--- a/dom/media/hls/HLSDecoder.cpp
+++ b/dom/media/hls/HLSDecoder.cpp
@@ -29,17 +29,17 @@ HLSDecoder::CreateStateMachine()
   mReader =
     new MediaFormatReader(this,
                           new HLSDemuxer(resourceWrapper->GetPlayerId()),
                           GetVideoFrameContainer());
 
   return new MediaDecoderStateMachine(this, mReader);
 }
 
-MediaDecoder*
+ChannelMediaDecoder*
 HLSDecoder::Clone(MediaDecoderInit& aInit)
 {
   if (!IsEnabled()) {
     return nullptr;
   }
   return new HLSDecoder(aInit);
 }
 
--- a/dom/media/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -16,17 +16,17 @@ class HLSDecoder final : public ChannelM
 {
 public:
   // MediaDecoder interface.
   explicit HLSDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
 
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
 
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the HLS backend is pref'ed on.
   static bool IsEnabled();
 
   // Returns true if aContainerType is an HLS type that we think we can render
   // with the a platform decoder backend.
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -29,23 +29,16 @@ namespace mozilla {
 MediaSourceDecoder::MediaSourceDecoder(MediaDecoderInit& aInit)
   : MediaDecoder(aInit)
   , mMediaSource(nullptr)
   , mEnded(false)
 {
   mExplicitDuration.Set(Some(UnspecifiedNaN<double>()));
 }
 
-MediaDecoder*
-MediaSourceDecoder::Clone(MediaDecoderInit& aInit)
-{
-  // TODO: Sort out cloning.
-  return nullptr;
-}
-
 MediaDecoderStateMachine*
 MediaSourceDecoder::CreateStateMachine()
 {
   MOZ_ASSERT(NS_IsMainThread());
   mDemuxer = new MediaSourceDemuxer(AbstractMainThread());
   mReader = new MediaFormatReader(this, mDemuxer, GetVideoFrameContainer());
   return new MediaDecoderStateMachine(this, mReader);
 }
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -32,17 +32,16 @@ class MediaSource;
 
 } // namespace dom
 
 class MediaSourceDecoder : public MediaDecoder
 {
 public:
   explicit MediaSourceDecoder(MediaDecoderInit& aInit);
 
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
   nsresult Load(nsIStreamListener**) override;
   media::TimeIntervals GetSeekable() override;
   media::TimeIntervals GetBuffered() override;
 
   void Shutdown() override;
 
   static already_AddRefed<MediaResource> CreateResource(nsIPrincipal* aPrincipal = nullptr);
--- a/dom/media/mp3/MP3Decoder.cpp
+++ b/dom/media/mp3/MP3Decoder.cpp
@@ -10,18 +10,19 @@
 #include "MediaContainerType.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "MP3Demuxer.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
-MediaDecoder*
-MP3Decoder::Clone(MediaDecoderInit& aInit) {
+ChannelMediaDecoder*
+MP3Decoder::Clone(MediaDecoderInit& aInit)
+{
   if (!IsEnabled()) {
     return nullptr;
   }
   return new MP3Decoder(aInit);
 }
 
 MediaDecoderStateMachine*
 MP3Decoder::CreateStateMachine() {
--- a/dom/media/mp3/MP3Decoder.h
+++ b/dom/media/mp3/MP3Decoder.h
@@ -15,17 +15,17 @@ class MediaContainerType;
 class MP3Decoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit MP3Decoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the MP3 backend is preffed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
--- a/dom/media/ogg/OggDecoder.h
+++ b/dom/media/ogg/OggDecoder.h
@@ -14,17 +14,18 @@ class MediaContainerType;
 
 class OggDecoder : public ChannelMediaDecoder
 {
 public:
   explicit OggDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {}
 
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override {
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
+  {
     if (!IsOggEnabled()) {
       return nullptr;
     }
     return new OggDecoder(aInit);
   }
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if aContainerType is an Ogg type that we think we can render
--- a/dom/media/wave/WaveDecoder.cpp
+++ b/dom/media/wave/WaveDecoder.cpp
@@ -8,17 +8,17 @@
 #include "MediaContainerType.h"
 #include "MediaDecoderStateMachine.h"
 #include "WaveDecoder.h"
 #include "MediaFormatReader.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
-MediaDecoder*
+ChannelMediaDecoder*
 WaveDecoder::Clone(MediaDecoderInit& aInit)
 {
   return new WaveDecoder(aInit);
 }
 
 MediaDecoderStateMachine*
 WaveDecoder::CreateStateMachine()
 {
--- a/dom/media/wave/WaveDecoder.h
+++ b/dom/media/wave/WaveDecoder.h
@@ -15,17 +15,17 @@ class MediaContainerType;
 class WaveDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit WaveDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the Wave backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
 } // namespace mozilla
--- a/dom/media/webm/WebMDecoder.h
+++ b/dom/media/webm/WebMDecoder.h
@@ -15,17 +15,18 @@ class MediaContainerType;
 
 class WebMDecoder : public ChannelMediaDecoder
 {
 public:
   explicit WebMDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  MediaDecoder* Clone(MediaDecoderInit& aInit) override {
+  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
+  {
     if (!IsWebMEnabled()) {
       return nullptr;
     }
     return new WebMDecoder(aInit);
   }
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if aContainerType is a WebM type that we think we can render