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
--- 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.