Bug 1390748 - Create DecoderTraits::IsSupportedType(const MediaContainerType&). r=jwwang draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 15 Aug 2017 17:38:16 +1200
changeset 648062 88f259ea0245a4405897959d5c115b0b79dc45e2
parent 648061 505f9dce979aad0529b07d2c046dca5028af6de6
child 648063 eb7a6fedf7b118e951e5f701b2c9f54459b3f3f0
child 648395 5a87dfe0d77fc23d36a4f57452322c39d720698c
push id74604
push userbmo:cpearce@mozilla.com
push dateThu, 17 Aug 2017 06:10:02 +0000
reviewersjwwang
bugs1390748
milestone57.0a1
Bug 1390748 - Create DecoderTraits::IsSupportedType(const MediaContainerType&). r=jwwang Most ChannelMediaDecoder::CloneImpl() functions just check to see whether their "is enabled" pref is still true, and then clone their true type. If we had a function to check whether the decoder for an arbitrary type was still enabled, we'd not need the "is enabled" checks in the CloneImpl() implementations. We'd then have removed the last custom behaviour in the ChannelMediaDecoder subclasses. MozReview-Commit-ID: D7kW6kb6ztW
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -319,16 +319,40 @@ DecoderTraits::CreateReader(const MediaC
   if (WebMDecoder::IsSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aInit, new WebMDemuxer(resource));
   }
 
   return decoderReader;
 }
 
 /* static */
+bool
+DecoderTraits::IsSupportedType(const MediaContainerType& aType)
+{
+  typedef bool (*IsSupportedFunction)(const MediaContainerType& aType);
+  static const IsSupportedFunction funcs[] = {
+    &ADTSDecoder::IsSupportedType,
+    &FlacDecoder::IsSupportedType,
+    &MP3Decoder::IsSupportedType,
+#ifdef MOZ_FMP4
+    &MP4Decoder::IsSupportedTypeWithoutDiagnostics,
+#endif
+    &OggDecoder::IsSupportedType,
+    &WaveDecoder::IsSupportedType,
+    &WebMDecoder::IsSupportedType,
+  };
+  for (IsSupportedFunction func : funcs) {
+    if (func(aType)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+/* static */
 bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
 {
   // Forbid playing media in video documents if the user has opted
   // not to, using either the legacy WMF specific pref, or the newer
   // catch-all pref.
   if (!Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true) ||
       !Preferences::GetBool("media.play-stand-alone", true)) {
     return false;
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -60,14 +60,16 @@ public:
 
   // Convenience function that returns false if MOZ_FMP4 is not defined,
   // otherwise defers to MP4Decoder::IsSupportedType().
   static bool IsMP4SupportedType(const MediaContainerType& aType,
                                  DecoderDoctorDiagnostics* aDiagnostics);
 
   // Returns true if aType is MIME type of hls.
   static bool IsHttpLiveStreamingType(const MediaContainerType& aType);
+
+  static bool IsSupportedType(const MediaContainerType& aType);
 };
 
 } // namespace mozilla
 
 #endif
 
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -52,16 +52,24 @@ IsWhitelistedH264Codec(const nsAString& 
          (profile == H264_PROFILE_BASE ||
           profile == H264_PROFILE_MAIN ||
           profile == H264_PROFILE_EXTENDED ||
           profile == H264_PROFILE_HIGH);
 }
 
 /* static */
 bool
+MP4Decoder::IsSupportedTypeWithoutDiagnostics(
+  const MediaContainerType& aContainerType)
+{
+  return IsSupportedType(aContainerType, nullptr);
+}
+
+/* static */
+bool
 MP4Decoder::IsSupportedType(const MediaContainerType& aType,
                             DecoderDoctorDiagnostics* aDiagnostics)
 {
   if (!IsEnabled()) {
     return false;
   }
 
   // Whitelist MP4 types, so they explicitly match what we encounter on
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -21,16 +21,19 @@ public:
   explicit MP4Decoder(MediaDecoderInit& 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);
 
+  static bool IsSupportedTypeWithoutDiagnostics(
+    const MediaContainerType& aContainerType);
+
   // 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
   // space matters.
   static bool IsH264(const nsACString& aMimeType);
 
   // Return true if aMimeType is a one of the strings used by our demuxers to
   // identify AAC. Does not parse general content type strings, i.e. white
   // space matters.