Bug 834172 - Implement IsSupportedTypeInVideo in DecoderTraits. r=cpearce
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 05 Mar 2013 09:56:35 -0500
changeset 123827 dd63d49eb5dce4abf7513a43a8fc6e27c91b74f7
parent 123826 dd75eab24983ba50e14c6cc4a67b1fda2264bd1e
child 123828 128510dd6c0344b9475b79f7842e7c396567c492
push id1401
push userpastithas@mozilla.com
push dateThu, 07 Mar 2013 07:26:45 +0000
treeherderfx-team@ee4879719f78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs834172
milestone22.0a1
Bug 834172 - Implement IsSupportedTypeInVideo in DecoderTraits. r=cpearce This change moves the policy of supported media types in the element nsHTMLMediaElement to the DecoderTraits class. The codec-specific code has been removed from the media element.
content/base/src/nsContentUtils.cpp
content/media/DecoderTraits.cpp
content/media/DecoderTraits.h
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -6330,87 +6330,23 @@ nsContentUtils::FindInternalContentViewe
         *aLoaderType = TYPE_PLUGIN;
       else
       *aLoaderType = TYPE_UNKNOWN;
     }
     return docFactory.forget();
   }
 
 #ifdef MOZ_MEDIA
-#ifdef MOZ_OGG
-  if (DecoderTraits::IsOggType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif
-
-#ifdef MOZ_WIDGET_GONK
-  if (DecoderTraits::IsOmxSupportedType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif
-
-#ifdef MOZ_WEBM
-  if (DecoderTraits::IsWebMType(nsDependentCString(aType))) {
+  if (DecoderTraits::IsSupportedInVideoDocument(nsDependentCString(aType))) {
     docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
     if (docFactory && aLoaderType) {
       *aLoaderType = TYPE_CONTENT;
     }
     return docFactory.forget();
   }
-#endif
-
-#ifdef MOZ_DASH
-  if (DecoderTraits::IsDASHMPDType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif
-
-#ifdef MOZ_GSTREAMER
-  if (DecoderTraits::IsGStreamerSupportedType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif
-
-#ifdef MOZ_MEDIA_PLUGINS
-  if (mozilla::MediaDecoder::IsMediaPluginsEnabled() &&
-      DecoderTraits::IsMediaPluginsType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif // MOZ_MEDIA_PLUGINS
-
-#ifdef MOZ_WMF
-  if (DecoderTraits::IsWMFSupportedType(nsDependentCString(aType))) {
-    docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
-    if (docFactory && aLoaderType) {
-      *aLoaderType = TYPE_CONTENT;
-    }
-    return docFactory.forget();
-  }
-#endif
-
 #endif // MOZ_MEDIA
 
   return NULL;
 }
 
 // static
 bool
 nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern,
--- a/content/media/DecoderTraits.cpp
+++ b/content/media/DecoderTraits.cpp
@@ -435,10 +435,37 @@ DecoderTraits::CreateDecoder(const nsACS
 #endif
 
   NS_ENSURE_TRUE(decoder != nullptr, nullptr);
   NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
 
   return decoder.forget();
 }
 
+/* static */
+bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
+{
+  return
+#ifdef MOZ_OGG
+    IsOggType(aType) ||
+#endif
+#ifdef MOZ_WIDGET_GONK
+    IsOmxSupportedType(aType) ||
+#endif
+#ifdef MOZ_WEBM
+    IsWebMType(aType) ||
+#endif
+#ifdef MOZ_DASH
+    IsDASHMPDType(aType) ||
+#endif
+#ifdef MOZ_GSTREAMER
+    IsGStreamerSupportedType(aType) ||
+#endif
+#ifdef MOZ_MEDIA_PLUGINS
+    (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
+#endif
+#ifdef MOZ_WMF
+    IsWMFSupportedType(aType) ||
+#endif
+    false;
 }
 
+}
--- a/content/media/DecoderTraits.h
+++ b/content/media/DecoderTraits.h
@@ -78,14 +78,19 @@ public:
 #ifdef MOZ_WMF
   static bool IsWMFSupportedType(const nsACString& aType);
 #endif
 
   // Create a decoder for the given aType. Returns null if we
   // were unable to create the decoder.
   static already_AddRefed<MediaDecoder> CreateDecoder(const nsACString& aType,
                                                       MediaDecoderOwner* aOwner);
+
+  // Returns true if MIME type aType is supported in video documents,
+  // or false otherwise. Not all platforms support all MIME types, and
+  // vice versa.
+  static bool IsSupportedInVideoDocument(const nsACString& aType);
 };
 
 }
 
 #endif