Bug 1212670 - Implement GMPDecoderModule::SupportsMimeType() and EMEDecoderModule::SupportsMimeType(). r=jwwang
authorChris Pearce <cpearce@mozilla.com>
Thu, 08 Oct 2015 20:40:54 +1300
changeset 266792 d117222e267ab8bdf877af787d7c3ee1e10a6a3b
parent 266791 ad252d40df2c69e7f944edf03db19910e24468ef
child 266793 8a05506e0a95b55aeab9a4fb8759925ed8e45117
push id29497
push usercbook@mozilla.com
push dateThu, 08 Oct 2015 13:27:17 +0000
treeherdermozilla-central@1f4cf75c8948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1212670
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 1212670 - Implement GMPDecoderModule::SupportsMimeType() and EMEDecoderModule::SupportsMimeType(). r=jwwang
dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
dom/media/platforms/agnostic/eme/EMEDecoderModule.h
dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
@@ -9,16 +9,17 @@
 #include "EMEVideoDecoder.h"
 #include "MediaDataDecoderProxy.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "mozilla/CDMProxy.h"
 #include "mozilla/unused.h"
 #include "nsServiceManagerUtils.h"
 #include "MediaInfo.h"
 #include "nsClassHashtable.h"
+#include "GMPDecoderModule.h"
 
 namespace mozilla {
 
 typedef MozPromiseRequestHolder<CDMProxy::DecryptPromise> DecryptPromiseRequestHolder;
 
 class EMEDecryptor : public MediaDataDecoder {
 
 public:
@@ -296,9 +297,17 @@ EMEDecoderModule::DecoderNeedsConversion
 {
   if (aConfig.IsVideo()) {
     return kNeedAVCC;
   } else {
     return kNeedNone;
   }
 }
 
+bool
+EMEDecoderModule::SupportsMimeType(const nsACString& aMimeType)
+{
+  Maybe<nsCString> gmp;
+  gmp.emplace(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
+  return GMPDecoderModule::SupportsMimeType(aMimeType, gmp);
+}
+
 } // namespace mozilla
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.h
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.h
@@ -40,23 +40,17 @@ protected:
   CreateAudioDecoder(const AudioInfo& aConfig,
                      FlushableTaskQueue* aAudioTaskQueue,
                      MediaDataDecoderCallback* aCallback) override;
 
   ConversionRequired
   DecoderNeedsConversion(const TrackInfo& aConfig) const override;
 
   bool
-  SupportsMimeType(const nsACString& aMimeType) override
-  {
-    // TODO Properly.
-    return aMimeType.EqualsLiteral("audio/mp4a-latm") ||
-      aMimeType.EqualsLiteral("video/mp4") ||
-      aMimeType.EqualsLiteral("video/avc");
-  }
+  SupportsMimeType(const nsACString& aMimeType) override;
 
 private:
   nsRefPtr<CDMProxy> mProxy;
   // Will be null if CDM has decoding capability.
   nsRefPtr<PDMFactory> mPDM;
   // We run the PDM on its own task queue.
   nsRefPtr<TaskQueue> mTaskQueue;
   bool mCDMDecodesAudio;
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -6,16 +6,18 @@
 
 #include "GMPDecoderModule.h"
 #include "GMPAudioDecoder.h"
 #include "GMPVideoDecoder.h"
 #include "MediaDataDecoderProxy.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/Preferences.h"
+#include "gmp-audio-decode.h"
+#include "gmp-video-decode.h"
 
 namespace mozilla {
 
 GMPDecoderModule::GMPDecoderModule()
 {
 }
 
 GMPDecoderModule::~GMPDecoderModule()
@@ -119,9 +121,46 @@ GMPDecoderModule::PreferredGMP(const nsA
       case 2: rv.emplace(NS_LITERAL_CSTRING("com.adobe.primetime")); break;
       default: break;
     }
   }
 
   return rv;
 }
 
+bool
+GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
+                                   const Maybe<nsCString>& aGMP)
+{
+  nsTArray<nsCString> tags;
+  nsCString api;
+  if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
+    tags.AppendElement(NS_LITERAL_CSTRING("aac"));
+    api = NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER);
+  } else if (aMimeType.EqualsLiteral("video/avc") ||
+             aMimeType.EqualsLiteral("video/mp4")) {
+    tags.AppendElement(NS_LITERAL_CSTRING("h264"));
+    api = NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER);
+  } else {
+    return false;
+  }
+  if (aGMP.isSome()) {
+    tags.AppendElement(aGMP.value());
+  }
+  nsCOMPtr<mozIGeckoMediaPluginService> mps =
+    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
+  if (NS_WARN_IF(!mps)) {
+    return false;
+  }
+  bool hasPlugin = false;
+  if (NS_FAILED(mps->HasPluginForAPI(api, &tags, &hasPlugin))) {
+    return false;
+  }
+  return hasPlugin;
+}
+
+bool
+GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType)
+{
+  return SupportsMimeType(aMimeType, PreferredGMP(aMimeType));
+}
+
 } // namespace mozilla
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.h
@@ -31,24 +31,22 @@ public:
   CreateAudioDecoder(const AudioInfo& aConfig,
                      FlushableTaskQueue* aAudioTaskQueue,
                      MediaDataDecoderCallback* aCallback) override;
 
   ConversionRequired
   DecoderNeedsConversion(const TrackInfo& aConfig) const override;
 
   bool
-  SupportsMimeType(const nsACString& aMimeType) override
-  {
-    // TODO properly.
-    return aMimeType.EqualsLiteral("audio/mp4a-latm") ||
-      aMimeType.EqualsLiteral("video/avc");
-  }
+  SupportsMimeType(const nsACString& aMimeType) override;
 
   static void Init();
 
   static const Maybe<nsCString> PreferredGMP(const nsACString& aMimeType);
 
+  static bool SupportsMimeType(const nsACString& aMimeType,
+                               const Maybe<nsCString>& aGMP);
+
 };
 
 } // namespace mozilla
 
 #endif // GMPDecoderModule_h_