Bug 1383628. P1 - divide Clone() into 2 functions. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 03 Aug 2017 17:39:55 +0800
changeset 642339 b9594c03541876da7069390f69774912aae70c6d
parent 641464 7b8e5bedb22414747d1e331fc62eb21d3a2ee5c1
child 642340 0d9dfe70507aec20bf54a7bce9d75b28c389af95
push id72707
push userjwwang@mozilla.com
push dateTue, 08 Aug 2017 02:32:36 +0000
bugs1383628
milestone57.0a1
Bug 1383628. P1 - divide Clone() into 2 functions. Now we have a non-virtual Clone() and a virtual CloneImpl(). We will call Load() inside Clone(). MozReview-Commit-ID: Hd6p206Brhq
dom/media/ADTSDecoder.cpp
dom/media/ADTSDecoder.h
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
dom/media/flac/FlacDecoder.cpp
dom/media/flac/FlacDecoder.h
dom/media/fmp4/MP4Decoder.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/media/ADTSDecoder.cpp
+++ b/dom/media/ADTSDecoder.cpp
@@ -7,17 +7,17 @@
 #include "ADTSDecoder.h"
 #include "ADTSDemuxer.h"
 #include "MediaContainerType.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 ChannelMediaDecoder*
-ADTSDecoder::Clone(MediaDecoderInit& aInit)
+ADTSDecoder::CloneImpl(MediaDecoderInit& aInit)
 {
   if (!IsEnabled())
     return nullptr;
 
   return new ADTSDecoder(aInit);
 }
 
 /* static */ bool
--- a/dom/media/ADTSDecoder.h
+++ b/dom/media/ADTSDecoder.h
@@ -16,19 +16,21 @@ class MediaContainerType;
 class ADTSDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit ADTSDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) 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);
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override;
 };
 
 } // namespace mozilla
 
 #endif // !ADTS_DECODER_H_
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -150,16 +150,23 @@ ChannelMediaDecoder::ResourceCallback::N
 
 ChannelMediaDecoder::ChannelMediaDecoder(MediaDecoderInit& aInit)
   : MediaDecoder(aInit)
   , mResourceCallback(new ResourceCallback(aInit.mOwner->AbstractMainThread()))
 {
   mResourceCallback->Connect(this);
 }
 
+already_AddRefed<ChannelMediaDecoder>
+ChannelMediaDecoder::Clone(MediaDecoderInit& aInit)
+{
+  RefPtr<ChannelMediaDecoder> decoder = CloneImpl(aInit);
+  return decoder.forget();
+}
+
 MediaResource*
 ChannelMediaDecoder::GetResource() const
 {
   return mResource;
 }
 
 MediaDecoderStateMachine* ChannelMediaDecoder::CreateStateMachine()
 {
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -60,23 +60,23 @@ public:
 
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   MediaResource* GetResource() const override final;
 
   void Shutdown() override;
 
   // Create a new decoder of the same type as this one.
-  // Subclasses must implement this.
-  virtual ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) = 0;
+  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);
 };
 
 } // namespace mozilla
 
 #endif // ChannelMediaDecoder_h_
--- a/dom/media/flac/FlacDecoder.cpp
+++ b/dom/media/flac/FlacDecoder.cpp
@@ -7,17 +7,17 @@
 #include "FlacDecoder.h"
 #include "FlacDemuxer.h"
 #include "MediaContainerType.h"
 #include "MediaPrefs.h"
 
 namespace mozilla {
 
 ChannelMediaDecoder*
-FlacDecoder::Clone(MediaDecoderInit& aInit)
+FlacDecoder::CloneImpl(MediaDecoderInit& aInit)
 {
   if (!IsEnabled()) {
     return nullptr;
   }
 
   return new FlacDecoder(aInit);
 }
 
--- a/dom/media/flac/FlacDecoder.h
+++ b/dom/media/flac/FlacDecoder.h
@@ -16,19 +16,21 @@ class MediaContainerType;
 class FlacDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit FlacDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) 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);
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override;
 };
 
 } // namespace mozilla
 
 #endif // !FLAC_DECODER_H_
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -15,24 +15,16 @@ 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);
 
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
-  {
-    if (!IsEnabled()) {
-      return nullptr;
-    }
-    return new MP4Decoder(aInit);
-  }
-
   // Returns true if aContainerType is an MP4 type that we think we can render
   // with the a platform decoder backend.
   // If provided, codecs are checked for support.
   static bool IsSupportedType(const MediaContainerType& aContainerType,
                               DecoderDoctorDiagnostics* aDiagnostics);
 
   // Return true if aMimeType is a one of the strings used by our demuxers to
   // identify H264. Does not parse general content type strings, i.e. white
@@ -46,13 +38,22 @@ public:
 
   // Returns true if the MP4 backend is preffed on.
   static bool IsEnabled();
 
   static already_AddRefed<dom::Promise>
   IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent);
 
   void GetMozDebugReaderData(nsACString& aString) override;
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override
+  {
+    if (!IsEnabled()) {
+      return nullptr;
+    }
+    return new MP4Decoder(aInit);
+  }
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/mp3/MP3Decoder.cpp
+++ b/dom/media/mp3/MP3Decoder.cpp
@@ -9,17 +9,17 @@
 
 #include "MediaContainerType.h"
 #include "MP3Demuxer.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 ChannelMediaDecoder*
-MP3Decoder::Clone(MediaDecoderInit& aInit)
+MP3Decoder::CloneImpl(MediaDecoderInit& aInit)
 {
   if (!IsEnabled()) {
     return nullptr;
   }
   return new MP3Decoder(aInit);
 }
 
 /* static */
--- a/dom/media/mp3/MP3Decoder.h
+++ b/dom/media/mp3/MP3Decoder.h
@@ -15,19 +15,21 @@ class MediaContainerType;
 class MP3Decoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit MP3Decoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) 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);
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/ogg/OggDecoder.h
+++ b/dom/media/ogg/OggDecoder.h
@@ -14,26 +14,28 @@ class MediaContainerType;
 
 class OggDecoder : public ChannelMediaDecoder
 {
 public:
   explicit OggDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {}
 
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
+  MediaDecoderStateMachine* CreateStateMachine() override;
+
+  // Returns true if aContainerType is an Ogg type that we think we can render
+  // with an enabled platform decoder backend.
+  // If provided, codecs are checked for support.
+  static bool IsSupportedType(const MediaContainerType& aContainerType);
+
+private:
+  ChannelMediaDecoder* CloneImpl(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
-  // with an enabled platform decoder backend.
-  // If provided, codecs are checked for support.
-  static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/wave/WaveDecoder.cpp
+++ b/dom/media/wave/WaveDecoder.cpp
@@ -7,17 +7,17 @@
 #include "WaveDemuxer.h"
 #include "MediaContainerType.h"
 #include "WaveDecoder.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 ChannelMediaDecoder*
-WaveDecoder::Clone(MediaDecoderInit& aInit)
+WaveDecoder::CloneImpl(MediaDecoderInit& aInit)
 {
   return new WaveDecoder(aInit);
 }
 
 /* static */ bool
 WaveDecoder::IsSupportedType(const MediaContainerType& aContainerType)
 {
   if (!IsWaveEnabled()) {
--- a/dom/media/wave/WaveDecoder.h
+++ b/dom/media/wave/WaveDecoder.h
@@ -15,18 +15,20 @@ class MediaContainerType;
 class WaveDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
   explicit WaveDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) 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);
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/webm/WebMDecoder.h
+++ b/dom/media/webm/WebMDecoder.h
@@ -14,27 +14,29 @@ class MediaContainerType;
 
 class WebMDecoder : public ChannelMediaDecoder
 {
 public:
   explicit WebMDecoder(MediaDecoderInit& aInit)
     : ChannelMediaDecoder(aInit)
   {
   }
-  ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override
-  {
-    if (!IsWebMEnabled()) {
-      return nullptr;
-    }
-    return new WebMDecoder(aInit);
-  }
 
   // Returns true if aContainerType is a WebM type that we think we can render
   // with an enabled platform decoder backend.
   // If provided, codecs are checked for support.
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 
   void GetMozDebugReaderData(nsACString& aString) override;
+
+private:
+  ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override
+  {
+    if (!IsWebMEnabled()) {
+      return nullptr;
+    }
+    return new WebMDecoder(aInit);
+  }
 };
 
 } // namespace mozilla
 
 #endif