Bug 1409178 - Move DecoderTraits::CreateDecoder() to ChannelMediaDecoder::Create(). r?jwwang draft
authorChris Pearce <cpearce@mozilla.com>
Mon, 16 Oct 2017 22:55:26 +0200
changeset 681033 2479a84f108d4805fb61f2e1fd1d796c93e7f26e
parent 681028 12406089a325ea5818822b72b1d90382f07eb5a3
child 736066 c606bb4d22552046de71c2acf3f9b48f55b2ebf6
push id84735
push userbmo:cpearce@mozilla.com
push dateMon, 16 Oct 2017 21:27:56 +0000
reviewersjwwang
bugs1409178
milestone58.0a1
Bug 1409178 - Move DecoderTraits::CreateDecoder() to ChannelMediaDecoder::Create(). r?jwwang Now DecoderTraits doesn't need to depend on ChannelMediaDecoder. MozReview-Commit-ID: D4AUiV2eGWy
dom/html/HTMLMediaElement.cpp
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5006,17 +5006,17 @@ nsresult HTMLMediaElement::InitializeDec
   if (HLSDecoder::IsSupportedType(*containerType)) {
     RefPtr<HLSDecoder> decoder = new HLSDecoder(decoderInit);
     reportCanPlay(true);
     return SetupDecoder(decoder.get(), aChannel);
   }
 #endif
 
   RefPtr<ChannelMediaDecoder> decoder =
-    DecoderTraits::CreateDecoder(decoderInit, &diagnostics);
+    ChannelMediaDecoder::Create(decoderInit, &diagnostics);
   if (!decoder) {
     reportCanPlay(false);
     return NS_ERROR_FAILURE;
   }
 
   reportCanPlay(true);
   bool isPrivateBrowsing = NodePrincipal()->GetPrivateBrowsingId() > 0;
   return SetupDecoder(decoder.get(), aChannel, isPrivateBrowsing, aListener);
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -168,16 +168,38 @@ ChannelMediaDecoder::ChannelMediaDecoder
   , mWatchManager(this, aInit.mOwner->AbstractMainThread())
 {
   mResourceCallback->Connect(this);
 
   // mIgnoreProgressData
   mWatchManager.Watch(mLogicallySeeking, &ChannelMediaDecoder::SeekingChanged);
 }
 
+/* static */
+already_AddRefed<ChannelMediaDecoder>
+ChannelMediaDecoder::Create(MediaDecoderInit& aInit,
+                            DecoderDoctorDiagnostics* aDiagnostics)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  RefPtr<ChannelMediaDecoder> decoder;
+
+  const MediaContainerType& type = aInit.mContainerType;
+  if (DecoderTraits::IsSupportedType(type)) {
+    decoder = new ChannelMediaDecoder(aInit);
+    return decoder.forget();
+  }
+
+  if (DecoderTraits::IsHttpLiveStreamingType(type)) {
+    // We don't have an HLS decoder.
+    Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
+  }
+
+  return nullptr;
+}
+
 bool
 ChannelMediaDecoder::CanClone()
 {
   MOZ_ASSERT(NS_IsMainThread());
   return mResource && mResource->CanClone();
 }
 
 already_AddRefed<ChannelMediaDecoder>
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -61,18 +61,26 @@ protected:
   void DownloadProgressed() override;
   void MetadataLoaded(UniquePtr<MediaInfo> aInfo,
                       UniquePtr<MetadataTags> aTags,
                       MediaDecoderEventVisibility aEventVisibility) override;
 
   RefPtr<ResourceCallback> mResourceCallback;
   RefPtr<BaseMediaResource> mResource;
 
+  explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
+
 public:
-  explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
+
+  // Create a decoder for the given aType. Returns null if we were unable
+  // to create the decoder, for example because the requested MIME type in
+  // the init struct was unsupported.
+  static already_AddRefed<ChannelMediaDecoder> Create(
+    MediaDecoderInit& aInit,
+    DecoderDoctorDiagnostics* aDiagnostics);
 
   void Shutdown() override;
 
   bool CanClone();
 
   // Create a new decoder of the same type as this one.
   already_AddRefed<ChannelMediaDecoder> Clone(MediaDecoderInit& aInit);
 
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "ChannelMediaDecoder.h"
 #include "DecoderTraits.h"
 #include "MediaContainerType.h"
 #include "nsMimeTypes.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
 #include "OggDecoder.h"
 #include "OggDemuxer.h"
@@ -220,38 +219,16 @@ bool DecoderTraits::ShouldHandleMediaTyp
       return false;
     }
   }
 
   return CanHandleMediaType(*containerType, aDiagnostics) != CANPLAY_NO;
 }
 
 /* static */
-already_AddRefed<ChannelMediaDecoder>
-DecoderTraits::CreateDecoder(MediaDecoderInit& aInit,
-                             DecoderDoctorDiagnostics* aDiagnostics)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  RefPtr<ChannelMediaDecoder> decoder;
-
-  const MediaContainerType& type = aInit.mContainerType;
-  if (DecoderTraits::IsSupportedType(type)) {
-    decoder = new ChannelMediaDecoder(aInit);
-    return decoder.forget();
-  }
-
-  if (DecoderTraits::IsHttpLiveStreamingType(type)) {
-    // We don't have an HLS decoder.
-    Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
-  }
-
-  return nullptr;
-}
-
-/* static */
 MediaFormatReader*
 DecoderTraits::CreateReader(const MediaContainerType& aType,
                             MediaFormatReaderInit& aInit)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MediaFormatReader* decoderReader = nullptr;
   MediaResource* resource = aInit.mResource;
 
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -2,29 +2,24 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DecoderTraits_h_
 #define DecoderTraits_h_
 
-#include "nsCOMPtr.h"
 #include "nsStringFwd.h"
 
 namespace mozilla {
 
-class ChannelMediaDecoder;
 class DecoderDoctorDiagnostics;
 class MediaContainerType;
-struct MediaDecoderInit;
 struct MediaFormatReaderInit;
-class MediaDecoderOwner;
 class MediaFormatReader;
-class MediaResource;
 
 enum CanPlayStatus {
   CANPLAY_NO,
   CANPLAY_MAYBE,
   CANPLAY_YES
 };
 
 class DecoderTraits {
@@ -35,22 +30,16 @@ public:
 
   // Returns true if we should handle this MIME type when it appears
   // as an <object> or as a toplevel page. If, in practice, our support
   // for the type is more limited than appears in the wild, we should return
   // false here even if CanHandleMediaType would return true.
   static bool ShouldHandleMediaType(const char* aMIMEType,
                                     DecoderDoctorDiagnostics* aDiagnostics);
 
-  // Create a decoder for the given aType. Returns null if we
-  // were unable to create the decoder.
-  static already_AddRefed<ChannelMediaDecoder> CreateDecoder(
-    MediaDecoderInit& aInit,
-    DecoderDoctorDiagnostics* aDiagnostics);
-
   // Create a reader for thew given MIME type aType. Returns null
   // if we were unable to create the reader.
   static MediaFormatReader* CreateReader(const MediaContainerType& aType,
                                          MediaFormatReaderInit& aInit);
 
   // Returns true if MIME type aType is supported in video documents,
   // or false otherwise. Not all platforms support all MIME types, and
   // vice versa.