Bug 886196 - Add pref to enable creation of fmp4 reader in DecoderTraits. Preffed of by default. r=kinetik
authorChris Pearce <cpearce@mozilla.com>
Thu, 21 Nov 2013 10:04:33 +1300
changeset 156665 ca0986418ca02d93343096402e24e6fbf279a525
parent 156664 426dee2867bc71141d08c0fa5b9d237a39f1c320
child 156666 d8b8a8ac1d1e682890b315235ee32afd861b6c14
push idunknown
push userunknown
push dateunknown
reviewerskinetik
bugs886196
milestone28.0a1
Bug 886196 - Add pref to enable creation of fmp4 reader in DecoderTraits. Preffed of by default. r=kinetik
content/media/DecoderTraits.cpp
modules/libpref/src/init/all.js
--- a/content/media/DecoderTraits.cpp
+++ b/content/media/DecoderTraits.cpp
@@ -56,16 +56,20 @@
 #ifdef MOZ_DIRECTSHOW
 #include "DirectShowDecoder.h"
 #include "DirectShowReader.h"
 #endif
 #ifdef MOZ_APPLEMEDIA
 #include "AppleDecoder.h"
 #include "AppleMP3Reader.h"
 #endif
+#ifdef MOZ_FMP4
+#include "MP4Reader.h"
+#include "MP4Decoder.h"
+#endif
 
 namespace mozilla
 {
 
 template <class String>
 static bool
 CodecListContains(char const *const * aCodecs, const String& aCodec)
 {
@@ -293,16 +297,25 @@ IsWMFSupportedType(const nsACString& aTy
 #ifdef MOZ_DIRECTSHOW
 static bool
 IsDirectShowSupportedType(const nsACString& aType)
 {
   return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
 }
 #endif
 
+#ifdef MOZ_FMP4
+static bool
+IsMP4SupportedType(const nsACString& aType)
+{
+  return Preferences::GetBool("media.fragmented-mp4.exposed", false) &&
+         MP4Decoder::GetSupportedCodecs(aType, nullptr);
+}
+#endif
+
 #ifdef MOZ_APPLEMEDIA
 static const char * const gAppleMP3Types[] = {
   "audio/mp3",
   "audio/mpeg",
   nullptr,
 };
 
 static const char * const gAppleMP3Codecs[] = {
@@ -440,40 +453,45 @@ DecoderTraits::CanHandleMediaType(const 
   }
   if (expectMoreTokens) {
     // Last codec name was empty
     return CANPLAY_NO;
   }
   return CANPLAY_YES;
 }
 
-/* static */
+// Instantiates but does not initialize decoder.
+static
 already_AddRefed<MediaDecoder>
-DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
+InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
 {
   nsRefPtr<MediaDecoder> decoder;
 
 #ifdef MOZ_GSTREAMER
   if (IsGStreamerSupportedType(aType)) {
     decoder = new GStreamerDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_RAW
   if (IsRawType(aType)) {
     decoder = new RawDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_OGG
   if (IsOggType(aType)) {
     decoder = new OggDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_WAVE
   if (IsWaveType(aType)) {
     decoder = new WaveDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_OMX_DECODER
   if (IsOmxSupportedType(aType)) {
     // AMR audio is enabled for MMS, but we are discouraging Web and App
     // developers from using AMR, thus we only allow AMR to be played on WebApps.
     if (aType.EqualsASCII("audio/amr")) {
       dom::HTMLMediaElement* element = aOwner->GetMediaElement();
@@ -484,54 +502,77 @@ DecoderTraits::CreateDecoder(const nsACS
       if (!principal) {
         return nullptr;
       }
       if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
         return nullptr;
       }
     }
     decoder = new MediaOmxDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef NECKO_PROTOCOL_rtsp
   if (IsRtspSupportedType(aType)) {
     decoder = new RtspOmxDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_MEDIA_PLUGINS
   if (MediaDecoder::IsMediaPluginsEnabled() &&
       GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
     decoder = new MediaPluginDecoder(aType);
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_WEBM
   if (IsWebMType(aType)) {
     decoder = new WebMDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_DIRECTSHOW
   // Note: DirectShow decoder must come before WMFDecoder, else the pref
   // "media.directshow.preferred" won't be honored.
   if (IsDirectShowSupportedType(aType)) {
     decoder = new DirectShowDecoder();
+    return decoder.forget();
+  }
+#endif
+#ifdef MOZ_FMP4
+  if (IsMP4SupportedType(aType)) {
+    decoder = new MP4Decoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_WMF
   if (IsWMFSupportedType(aType)) {
     decoder = new WMFDecoder();
+    return decoder.forget();
   }
 #endif
 #ifdef MOZ_APPLEMEDIA
   if (IsAppleMediaSupportedType(aType)) {
     decoder = new AppleDecoder();
+    return decoder.forget();
   }
 #endif
 
   NS_ENSURE_TRUE(decoder != nullptr, nullptr);
   NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
+  return nullptr;
+}
+
+/* static */
+already_AddRefed<MediaDecoder>
+DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
+{
+  nsRefPtr<MediaDecoder> decoder(InstantiateDecoder(aType, aOwner));
+  NS_ENSURE_TRUE(decoder != nullptr, nullptr);
+  NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
 
   return decoder.forget();
 }
 
 /* static */
 MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
 {
   MediaDecoderReader* decoderReader = nullptr;
@@ -574,16 +615,21 @@ MediaDecoderReader* DecoderTraits::Creat
 #endif
 #ifdef MOZ_DIRECTSHOW
   // Note: DirectShowReader is preferred for MP3, but if it's disabled we
   // fallback to the WMFReader.
   if (IsDirectShowSupportedType(aType)) {
     decoderReader = new DirectShowReader(aDecoder);
   } else
 #endif
+#ifdef MOZ_FMP4
+  if (IsMP4SupportedType(aType)) {
+    decoderReader = new MP4Reader(aDecoder);
+  } else
+#endif
 #ifdef MOZ_WMF
   if (IsWMFSupportedType(aType)) {
     decoderReader = new WMFReader(aDecoder);
   } else
 #endif
 #ifdef MOZ_APPLEMEDIA
   if (IsAppleMediaSupportedType(aType)) {
     decoderReader = new AppleMP3Reader(aDecoder);
@@ -610,16 +656,19 @@ bool DecoderTraits::IsSupportedInVideoDo
     IsWebMType(aType) ||
 #endif
 #ifdef MOZ_GSTREAMER
     IsGStreamerSupportedType(aType) ||
 #endif
 #ifdef MOZ_MEDIA_PLUGINS
     (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
 #endif
+#ifdef MOZ_FMP4
+    IsMP4SupportedType(aType) ||
+#endif
 #ifdef MOZ_WMF
     (IsWMFSupportedType(aType) &&
      Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true)) ||
 #endif
 #ifdef MOZ_DIRECTSHOW
     IsDirectShowSupportedType(aType) ||
 #endif
 #ifdef MOZ_APPLEMEDIA
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -193,16 +193,20 @@ pref("media.windows-media-foundation.ena
 pref("media.windows-media-foundation.use-dxva", true);
 pref("media.windows-media-foundation.play-stand-alone", true);
 #endif
 #ifdef MOZ_DIRECTSHOW
 pref("media.directshow.enabled", true);
 #endif
 #ifdef MOZ_FMP4
 pref("media.fragmented-mp4.enabled", true);
+// Denotes that the fragmented MP4 parser can be created by <video> elements.
+// This is for testing, since the parser can't yet handle non-fragmented MP4,
+// so it will fail to play most MP4 files.
+pref("media.fragmented-mp4.exposed", false);
 #endif
 #ifdef MOZ_RAW
 pref("media.raw.enabled", true);
 #endif
 #ifdef MOZ_OGG
 pref("media.ogg.enabled", true);
 #endif
 #ifdef MOZ_OPUS