Bug 1510424 - fix AAC and FLAC EME support configuration. r=jya
authorJohn Lin <jolin@mozilla.com>
Fri, 07 Dec 2018 14:40:50 +0000
changeset 449602 a7f0acc59459f4a2be7d2b5edd8436081b5bbcf2
parent 449601 5ae509e2f3b638ca15e14cad8441a3cf75ad4647
child 449603 d341e1dcdfeff2ba187ada77af2e77f4b430604d
push id74367
push userjolin@mozilla.com
push dateFri, 07 Dec 2018 14:54:24 +0000
treeherderautoland@a7f0acc59459 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1510424
milestone65.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 1510424 - fix AAC and FLAC EME support configuration. r=jya Differential Revision: https://phabricator.services.mozilla.com/D13135
dom/media/eme/MediaKeySystemAccess.cpp
dom/media/eme/moz.build
dom/media/platforms/android/AndroidDecoderModule.cpp
dom/media/platforms/android/AndroidDecoderModule.h
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaDrmProxy.java
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -29,16 +29,17 @@
 #include "DecoderDoctorDiagnostics.h"
 #include "WebMDecoder.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/dom/MediaSource.h"
 #include "DecoderTraits.h"
 #ifdef MOZ_WIDGET_ANDROID
+#include "AndroidDecoderModule.h"
 #include "FennecJNIWrappers.h"
 #include "GeneratedJNIWrappers.h"
 #endif
 #include <functional>
 
 namespace mozilla {
 namespace dom {
 
@@ -304,19 +305,19 @@ static nsTArray<KeySystemConfig> GetSupp
       // decode AAC, and a codec wasn't specified, be conservative
       // and reject the MediaKeys request, since we assume Widevine
       // will be used with AAC.
       if (WMFDecoderModule::HasAAC()) {
         widevine.mMP4.SetCanDecrypt(EME_CODEC_AAC);
       }
 #elif !defined(MOZ_WIDGET_ANDROID)
       widevine.mMP4.SetCanDecrypt(EME_CODEC_AAC);
-#endif
       widevine.mMP4.SetCanDecrypt(EME_CODEC_FLAC);
       widevine.mMP4.SetCanDecrypt(EME_CODEC_OPUS);
+#endif
 
 #if defined(MOZ_WIDGET_ANDROID)
       using namespace mozilla::java;
       // MediaDrm.isCryptoSchemeSupported only allows passing
       // "video/mp4" or "video/webm" for mimetype string.
       // See
       // https://developer.android.com/reference/android/media/MediaDrm.html#isCryptoSchemeSupported(java.util.UUID,
       // java.lang.String) for more detail.
@@ -346,17 +347,17 @@ static nsTArray<KeySystemConfig> GetSupp
            &widevine.mWebM},
           {nsCString(AUDIO_WEBM), EME_CODEC_OPUS, MediaDrmProxy::OPUS,
            &widevine.mWebM},
       };
 
       for (const auto& data : validationList) {
         if (MediaDrmProxy::IsCryptoSchemeSupported(kEMEKeySystemWidevine,
                                                    data.mMimeType)) {
-          if (MediaDrmProxy::CanDecode(data.mCodecType)) {
+          if (AndroidDecoderModule::SupportsMimeType(data.mMimeType)) {
             data.mSupportType->SetCanDecryptAndDecode(data.mEMECodecType);
           } else {
             data.mSupportType->SetCanDecrypt(data.mEMECodecType);
           }
         }
       }
 #else
       widevine.mMP4.SetCanDecryptAndDecode(EME_CODEC_H264);
--- a/dom/media/eme/moz.build
+++ b/dom/media/eme/moz.build
@@ -35,12 +35,13 @@ UNIFIED_SOURCES += [
     'MediaKeySession.cpp',
     'MediaKeyStatusMap.cpp',
     'MediaKeySystemAccess.cpp',
     'MediaKeySystemAccessManager.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
   DIRS += ['mediadrm']
+  LOCAL_INCLUDES += ['/dom/media/platforms/android']
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
--- a/dom/media/platforms/android/AndroidDecoderModule.cpp
+++ b/dom/media/platforms/android/AndroidDecoderModule.cpp
@@ -16,16 +16,19 @@
 
 #include <jni.h>
 
 #undef LOG
 #define LOG(arg, ...)                                     \
   MOZ_LOG(                                                \
       sAndroidDecoderModuleLog, mozilla::LogLevel::Debug, \
       ("AndroidDecoderModule(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define SLOG(arg, ...)                                        \
+  MOZ_LOG(sAndroidDecoderModuleLog, mozilla::LogLevel::Debug, \
+          ("%s: " arg, __func__, ##__VA_ARGS__))
 
 using namespace mozilla;
 using namespace mozilla::gl;
 using namespace mozilla::java::sdk;
 using media::TimeUnit;
 
 namespace mozilla {
 
@@ -52,18 +55,17 @@ static bool GetFeatureStatus(int32_t aFe
   }
   return status == nsIGfxInfo::FEATURE_STATUS_OK;
 };
 
 AndroidDecoderModule::AndroidDecoderModule(CDMProxy* aProxy) {
   mProxy = static_cast<MediaDrmCDMProxy*>(aProxy);
 }
 
-bool AndroidDecoderModule::SupportsMimeType(
-    const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const {
+bool AndroidDecoderModule::SupportsMimeType(const nsACString& aMimeType) {
   if (jni::GetAPIVersion() < 16) {
     return false;
   }
 
   if (aMimeType.EqualsLiteral("video/mp4") ||
       aMimeType.EqualsLiteral("video/avc")) {
     return true;
   }
@@ -87,31 +89,36 @@ bool AndroidDecoderModule::SupportsMimeT
   }
 
   // Prefer the gecko decoder for opus and vorbis; stagefright crashes
   // on content demuxed from mp4.
   // Not all android devices support FLAC even when they say they do.
   if (OpusDataDecoder::IsOpus(aMimeType) ||
       VorbisDataDecoder::IsVorbis(aMimeType) ||
       aMimeType.EqualsLiteral("audio/flac")) {
-    LOG("Rejecting audio of type %s", aMimeType.Data());
+    SLOG("Rejecting audio of type %s", aMimeType.Data());
     return false;
   }
 
   // Prefer the gecko decoder for Theora.
   // Not all android devices support Theora even when they say they do.
   if (TheoraDecoder::IsTheora(aMimeType)) {
-    LOG("Rejecting video of type %s", aMimeType.Data());
+    SLOG("Rejecting video of type %s", aMimeType.Data());
     return false;
   }
 
   return java::HardwareCodecCapabilityUtils::FindDecoderCodecInfoForMimeType(
       TranslateMimeType(aMimeType));
 }
 
+bool AndroidDecoderModule::SupportsMimeType(
+    const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const {
+  return AndroidDecoderModule::SupportsMimeType(aMimeType);
+}
+
 already_AddRefed<MediaDataDecoder> AndroidDecoderModule::CreateVideoDecoder(
     const CreateDecoderParams& aParams) {
   // Temporary - forces use of VPXDecoder when alpha is present.
   // Bug 1263836 will handle alpha scenario once implemented. It will shift
   // the check for alpha to PDMFactory but not itself remove the need for a
   // check.
   if (aParams.VideoConfig().HasAlpha()) {
     return nullptr;
--- a/dom/media/platforms/android/AndroidDecoderModule.h
+++ b/dom/media/platforms/android/AndroidDecoderModule.h
@@ -18,16 +18,18 @@ class AndroidDecoderModule : public Plat
   already_AddRefed<MediaDataDecoder> CreateAudioDecoder(
       const CreateDecoderParams& aParams) override;
 
   explicit AndroidDecoderModule(CDMProxy* aProxy = nullptr);
 
   bool SupportsMimeType(const nsACString& aMimeType,
                         DecoderDoctorDiagnostics* aDiagnostics) const override;
 
+  static bool SupportsMimeType(const nsACString& aMimeType);
+
  private:
   virtual ~AndroidDecoderModule() {}
   RefPtr<MediaDrmCDMProxy> mProxy;
 };
 
 extern LazyLogModule sAndroidDecoderModuleLog;
 
 const nsCString TranslateMimeType(const nsACString& aMimeType);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaDrmProxy.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaDrmProxy.java
@@ -77,33 +77,16 @@ public final class MediaDrmProxy {
         }
         if (keySystem.equals(WIDEVINE_KEY_SYSTEM)) {
             return MediaDrm.isCryptoSchemeSupported(WIDEVINE_SCHEME_UUID, container);
         }
         if (DEBUG) Log.d(LOGTAG, "cannot decrypt key sytem = " + keySystem + ", container = " + container);
         return false;
     }
 
-    @WrapForJNI
-    public static boolean CanDecode(String mimeType) {
-        for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
-            MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
-            if (info.isEncoder()) {
-                continue;
-            }
-            for (String m : info.getSupportedTypes()) {
-                if (m.equals(mimeType)) {
-                  return true;
-                }
-            }
-        }
-        if (DEBUG) Log.d(LOGTAG, "cannot decode mimetype = " + mimeType);
-        return false;
-    }
-
      // Interface for callback to native.
     public interface Callbacks {
         void onSessionCreated(int createSessionToken,
                               int promiseId,
                               byte[] sessionId,
                               byte[] request);
 
         void onSessionUpdated(int promiseId, byte[] sessionId);