Bug 1211812 - Add pref to select GMP to use for unencrypted decoding. r=jwwang
authorChris Pearce <cpearce@mozilla.com>
Thu, 08 Oct 2015 20:40:09 +1300
changeset 300176 9b67cbe9ae7521f7032a182324401c49d1cba589
parent 300175 670449ecfd352674e568bceef34d98582c39b35f
child 300177 ad252d40df2c69e7f944edf03db19910e24468ef
push id5392
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:08:23 +0000
treeherdermozilla-beta@16ce8562a975 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1211812
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1211812 - Add pref to select GMP to use for unencrypted decoding. r=jwwang
browser/app/profile/firefox.js
dom/media/platforms/PDMFactory.cpp
dom/media/platforms/agnostic/eme/EMEAudioDecoder.cpp
dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
modules/libpref/init/all.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1820,16 +1820,21 @@ pref("identity.fxaccounts.migrateToDevEd
 #ifdef MOZ_WIDGET_GTK
 pref("ui.key.menuAccessKeyFocuses", true);
 #endif
 
 // Encrypted media extensions.
 pref("media.eme.enabled", true);
 pref("media.eme.apiVisible", true);
 
+// If decoding-via-gmp is turned on for <video>, default to using
+// Adobe's GMP for decoding.
+pref("media.fragmented-mp4.gmp.aac", 2);
+pref("media.fragmented-mp4.gmp.h264", 2);
+
 // Whether we should run a test-pattern through EME GMPs before assuming they'll
 // decode H.264.
 pref("media.gmp.trial-create.enabled", true);
 
 #ifdef MOZ_ADOBE_EME
 pref("browser.eme.ui.enabled", true);
 pref("media.gmp-eme-adobe.enabled", true);
 #endif
--- a/dom/media/platforms/PDMFactory.cpp
+++ b/dom/media/platforms/PDMFactory.cpp
@@ -91,16 +91,17 @@ PDMFactory::Init()
   WMFDecoderModule::Init();
 #endif
 #ifdef MOZ_APPLEMEDIA
   AppleDecoderModule::Init();
 #endif
 #ifdef MOZ_FFMPEG
   FFmpegRuntimeLinker::Link();
 #endif
+  GMPDecoderModule::Init();
 }
 
 PDMFactory::PDMFactory()
 {
   CreatePDMs();
 }
 
 PDMFactory::~PDMFactory()
--- a/dom/media/platforms/agnostic/eme/EMEAudioDecoder.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEAudioDecoder.cpp
@@ -19,17 +19,17 @@ EMEAudioCallbackAdapter::Error(GMPErr aE
     return;
   }
   AudioCallbackAdapter::Error(aErr);
 }
 
 void
 EMEAudioDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
-  GMPAudioDecoder::InitTags(aTags);
+  aTags.AppendElement(NS_LITERAL_CSTRING("aac"));
   aTags.AppendElement(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
 }
 
 nsCString
 EMEAudioDecoder::GetNodeId()
 {
   return mProxy->GetNodeId();
 }
--- a/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
@@ -21,17 +21,17 @@ EMEVideoCallbackAdapter::Error(GMPErr aE
     return;
   }
   VideoCallbackAdapter::Error(aErr);
 }
 
 void
 EMEVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
-  GMPVideoDecoder::InitTags(aTags);
+  aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
   aTags.AppendElement(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
 }
 
 nsCString
 EMEVideoDecoder::GetNodeId()
 {
   return mProxy->GetNodeId();
 }
--- a/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GMPAudioDecoder.h"
 #include "nsServiceManagerUtils.h"
 #include "MediaInfo.h"
+#include "GMPDecoderModule.h"
 
 namespace mozilla {
 
 #if defined(DEBUG)
 bool IsOnGMPThread()
 {
   nsCOMPtr<mozIGeckoMediaPluginService> mps = do_GetService("@mozilla.org/gecko-media-plugin-service;1");
   MOZ_ASSERT(mps);
@@ -120,16 +121,21 @@ AudioCallbackAdapter::Terminated()
   NS_WARNING("AAC GMP decoder terminated.");
   mCallback->Error();
 }
 
 void
 GMPAudioDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
   aTags.AppendElement(NS_LITERAL_CSTRING("aac"));
+  const Maybe<nsCString> gmp(
+    GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("audio/mp4a-latm")));
+  if (gmp.isSome()) {
+    aTags.AppendElement(gmp.value());
+  }
 }
 
 nsCString
 GMPAudioDecoder::GetNodeId()
 {
   return NS_LITERAL_CSTRING("");
 }
 
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GMPDecoderModule.h"
 #include "GMPAudioDecoder.h"
 #include "GMPVideoDecoder.h"
 #include "MediaDataDecoderProxy.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "nsServiceManagerUtils.h"
+#include "mozilla/Preferences.h"
 
 namespace mozilla {
 
 GMPDecoderModule::GMPDecoderModule()
 {
 }
 
 GMPDecoderModule::~GMPDecoderModule()
@@ -81,9 +82,46 @@ GMPDecoderModule::DecoderNeedsConversion
   // GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
   if (aConfig.IsVideo()) {
     return kNeedAVCC;
   } else {
     return kNeedNone;
   }
 }
 
+static uint32_t sPreferredAacGmp = 0;
+static uint32_t sPreferredH264Gmp = 0;
+
+/* static */
+void
+GMPDecoderModule::Init()
+{
+  Preferences::AddUintVarCache(&sPreferredAacGmp,
+                               "media.fragmented-mp4.gmp.aac", 0);
+  Preferences::AddUintVarCache(&sPreferredH264Gmp,
+                               "media.fragmented-mp4.gmp.h264", 0);
+}
+
+/* static */
+const Maybe<nsCString>
+GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
+{
+  Maybe<nsCString> rv;
+  if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
+    switch (sPreferredAacGmp) {
+      case 1: rv.emplace(NS_LITERAL_CSTRING("org.w3.clearkey")); break;
+      case 2: rv.emplace(NS_LITERAL_CSTRING("com.adobe.primetime")); break;
+      default: break;
+    }
+  }
+
+  if (aMimeType.EqualsLiteral("video/avc")) {
+    switch (sPreferredH264Gmp) {
+      case 1: rv.emplace(NS_LITERAL_CSTRING("org.w3.clearkey")); break;
+      case 2: rv.emplace(NS_LITERAL_CSTRING("com.adobe.primetime")); break;
+      default: break;
+    }
+  }
+
+  return rv;
+}
+
 } // namespace mozilla
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(GMPDecoderModule_h_)
 #define GMPDecoderModule_h_
 
 #include "PlatformDecoderModule.h"
+#include "mozilla/Maybe.h"
 
 namespace mozilla {
 
 class GMPDecoderModule : public PlatformDecoderModule {
 public:
   GMPDecoderModule();
 
   virtual ~GMPDecoderModule();
@@ -36,13 +37,18 @@ public:
 
   bool
   SupportsMimeType(const nsACString& aMimeType) override
   {
     // TODO properly.
     return aMimeType.EqualsLiteral("audio/mp4a-latm") ||
       aMimeType.EqualsLiteral("video/avc");
   }
+
+  static void Init();
+
+  static const Maybe<nsCString> PreferredGMP(const nsACString& aMimeType);
+
 };
 
 } // namespace mozilla
 
 #endif // GMPDecoderModule_h_
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GMPVideoDecoder.h"
 #include "GMPVideoHost.h"
 #include "mozilla/Endian.h"
 #include "prsystem.h"
 #include "MediaData.h"
+#include "GMPDecoderModule.h"
 
 namespace mozilla {
 
 #if defined(DEBUG)
 extern bool IsOnGMPThread();
 #endif
 
 void
@@ -102,16 +103,21 @@ VideoCallbackAdapter::Terminated()
   NS_WARNING("H.264 GMP decoder terminated.");
   mCallback->Error();
 }
 
 void
 GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
   aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
+  const Maybe<nsCString> gmp(
+    GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
+  if (gmp.isSome()) {
+    aTags.AppendElement(gmp.value());
+  }
 }
 
 nsCString
 GMPVideoDecoder::GetNodeId()
 {
   return NS_LITERAL_CSTRING("");
 }
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -317,16 +317,18 @@ pref("media.wmf.decoder.thread-count", -
 #endif
 #ifdef MOZ_DIRECTSHOW
 pref("media.directshow.enabled", true);
 #endif
 #ifdef MOZ_FMP4
 pref("media.fragmented-mp4.enabled", true);
 pref("media.fragmented-mp4.ffmpeg.enabled", false);
 pref("media.fragmented-mp4.gmp.enabled", false);
+pref("media.fragmented-mp4.gmp.aac", 0);
+pref("media.fragmented-mp4.gmp.h264", 0);
 // Specifies whether the fragmented MP4 parser uses a test decoder that
 // just outputs blank frames/audio instead of actually decoding. The blank
 // decoder works on all platforms.
 pref("media.fragmented-mp4.use-blank-decoder", false);
 #endif
 #ifdef MOZ_RAW
 pref("media.raw.enabled", true);
 #endif