diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 4c6ccb5da6d..a33d8f0ec66 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -6614,47 +6614,32 @@ nsContentUtils::FindInternalContentViewer(const char* aType, #ifdef MOZ_MEDIA #ifdef MOZ_OGG - if (nsHTMLMediaElement::IsOggEnabled()) { - for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gOggTypes); ++i) { - const char* type = nsHTMLMediaElement::gOggTypes[i]; - if (!strcmp(aType, type)) { - docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1"); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_CONTENT; - } - return docFactory.forget(); - } + if (nsHTMLMediaElement::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_WEBM - if (nsHTMLMediaElement::IsWebMEnabled()) { - for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gWebMTypes); ++i) { - const char* type = nsHTMLMediaElement::gWebMTypes[i]; - if (!strcmp(aType, type)) { - docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1"); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_CONTENT; - } - return docFactory.forget(); - } + if (nsHTMLMediaElement::IsWebMType(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 (nsHTMLMediaElement::IsH264Enabled()) { - for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gH264Types); ++i) { - const char* type = nsHTMLMediaElement::gH264Types[i]; - if (!strcmp(aType, type)) { - docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1"); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_CONTENT; - } - return docFactory.forget(); - } + if (nsHTMLMediaElement::IsGStreamerSupportedType(nsDependentCString(aType))) { + docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1"); + if (docFactory && aLoaderType) { + *aLoaderType = TYPE_CONTENT; } + return docFactory.forget(); } #endif @@ -6668,7 +6653,6 @@ nsContentUtils::FindInternalContentViewer(const char* aType, return docFactory.forget(); } #endif // MOZ_MEDIA_PLUGINS - #endif // MOZ_MEDIA return NULL; diff --git a/content/html/content/public/nsHTMLMediaElement.h b/content/html/content/public/nsHTMLMediaElement.h index d9024ab1c50..9681e973c91 100644 --- a/content/html/content/public/nsHTMLMediaElement.h +++ b/content/html/content/public/nsHTMLMediaElement.h @@ -308,7 +308,8 @@ public: #endif #ifdef MOZ_GSTREAMER - static bool IsH264Enabled(); + static bool IsGStreamerEnabled(); + static bool IsGStreamerSupportedType(const nsACString& aType); static bool IsH264Type(const nsACString& aType); static const char gH264Types[3][16]; static char const *const gH264Codecs[7]; diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 47932b7601d..46d9c11af91 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -2153,24 +2153,19 @@ const char nsHTMLMediaElement::gH264Types[3][16] = { }; bool -nsHTMLMediaElement::IsH264Enabled() +nsHTMLMediaElement::IsGStreamerEnabled() { - return Preferences::GetBool("media.h264.enabled"); + return Preferences::GetBool("media.gstreamer.enabled"); } bool nsHTMLMediaElement::IsH264Type(const nsACString& aType) { - if (!IsH264Enabled()) { - return false; - } - for (uint32_t i = 0; i < ArrayLength(gH264Types); ++i) { if (aType.EqualsASCII(gH264Types[i])) { return true; } } - return false; } #endif @@ -2265,7 +2260,7 @@ nsHTMLMediaElement::IsDASHMPDType(const nsACString& aType) #endif /* static */ -nsHTMLMediaElement::CanPlayStatus +nsHTMLMediaElement::CanPlayStatus nsHTMLMediaElement::CanHandleMediaType(const char* aMIMEType, char const *const ** aCodecList) { @@ -2429,9 +2424,43 @@ nsHTMLMediaElement::CanPlayType(const nsAString& aType, nsAString& aResult) return NS_OK; } +#ifdef MOZ_GSTREAMER +bool +nsHTMLMediaElement::IsGStreamerSupportedType(const nsACString& aMimeType) +{ + if (!IsGStreamerEnabled()) + return false; + if (IsH264Type(aMimeType)) + return true; + if (!Preferences::GetBool("media.prefer-gstreamer", false)) + return false; +#ifdef MOZ_WEBM + if (IsWebMType(aMimeType)) + return true; +#endif +#ifdef MOZ_OGG + if (IsOggType(aMimeType)) + return true; +#endif + return false; +} +#endif + already_AddRefed nsHTMLMediaElement::CreateDecoder(const nsACString& aType) { + +#ifdef MOZ_GSTREAMER + // When enabled, use GStreamer for H.264, but not for codecs handled by our + // bundled decoders, unless the "media.prefer-gstreamer" pref is set. + if (IsGStreamerSupportedType(aType)) { + nsRefPtr decoder = new nsGStreamerDecoder(); + if (decoder->Init(this)) { + return decoder.forget(); + } + } +#endif + #ifdef MOZ_RAW if (IsRawType(aType)) { nsRefPtr decoder = new nsRawDecoder(); @@ -2442,11 +2471,7 @@ nsHTMLMediaElement::CreateDecoder(const nsACString& aType) #endif #ifdef MOZ_OGG if (IsOggType(aType)) { -#ifdef MOZ_GSTREAMER - nsRefPtr decoder = new nsGStreamerDecoder(); -#else nsRefPtr decoder = new nsOggDecoder(); -#endif if (decoder->Init(this)) { return decoder.forget(); } @@ -2478,11 +2503,7 @@ nsHTMLMediaElement::CreateDecoder(const nsACString& aType) #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { -#ifdef MOZ_GSTREAMER - nsRefPtr decoder = new nsGStreamerDecoder(); -#else nsRefPtr decoder = new nsWebMDecoder(); -#endif if (decoder->Init(this)) { return decoder.forget(); } @@ -2498,14 +2519,6 @@ nsHTMLMediaElement::CreateDecoder(const nsACString& aType) } #endif -#ifdef MOZ_GSTREAMER - if (IsH264Type(aType)) { - nsRefPtr decoder = new nsGStreamerDecoder(); - if (decoder->Init(this)) { - return decoder.forget(); - } - } -#endif return nullptr; } diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index e2b23d7127d..47c17bdda30 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -169,7 +169,7 @@ pref("media.webm.enabled", true); pref("media.dash.enabled", true); #endif #ifdef MOZ_GSTREAMER -pref("media.h264.enabled", true); +pref("media.gstreamer.enabled", true); #endif #ifdef MOZ_WEBRTC pref("media.navigator.enabled", false);