Bug 1317239 - Part1 - Add an API to ask if the codec support adaptive playback. r=jolin
authorJames Cheng <jacheng@mozilla.com>
Wed, 23 Nov 2016 14:11:22 +0800
changeset 323996 4d45db027c096f1038f47c748fdbd21e7effa7a4
parent 323995 4e27de747d61e73f4f162012265f1e15c3f074af
child 323997 2e9dbc8426fbc59271da469b6697a0aa037b2053
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjolin
bugs1317239
milestone53.0a1
Bug 1317239 - Part1 - Add an API to ask if the codec support adaptive playback. r=jolin MozReview-Commit-ID: 7Pgj9hFE6pu
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/HardwareCodecCapabilityUtils.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/HardwareCodecCapabilityUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/HardwareCodecCapabilityUtils.java
@@ -4,16 +4,17 @@
  *    * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 package org.mozilla.gecko.util;
 
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.AppConstants.Versions;
 
+import android.media.MediaCodec;
 import android.media.MediaCodecInfo;
 import android.media.MediaCodecInfo.CodecCapabilities;
 import android.media.MediaCodecList;
 import android.util.Log;
 
 public final class HardwareCodecCapabilityUtils {
   private static final String LOGTAG = "GeckoHardwareCodecCapabilityUtils";
 
@@ -48,16 +49,35 @@ public final class HardwareCodecCapabili
         if (mimeType.equals(aMimeType)) {
           return true;
         }
       }
     }
     return false;
   }
 
+  @WrapForJNI
+  public static boolean checkSupportsAdaptivePlayback(MediaCodec aCodec, String aMimeType) {
+      // isFeatureSupported supported on API level >= 19.
+      if (!Versions.feature19Plus) {
+          return false;
+      }
+
+      try {
+          MediaCodecInfo info = aCodec.getCodecInfo();
+          MediaCodecInfo.CodecCapabilities capabilities = info.getCapabilitiesForType(aMimeType);
+          return capabilities != null &&
+                 capabilities.isFeatureSupported(
+                     MediaCodecInfo.CodecCapabilities.FEATURE_AdaptivePlayback);
+      } catch (IllegalArgumentException e) {
+            Log.e(LOGTAG, "Retrieve codec information failed", e);
+      }
+      return false;
+  }
+
   public static boolean getHWEncoderCapability() {
     if (Versions.feature20Plus) {
       for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
         MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
         if (!info.isEncoder()) {
           continue;
         }
         String name = null;
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1923,16 +1923,24 @@ const char HardwareCodecCapabilityUtils:
 constexpr char HardwareCodecCapabilityUtils::HasHWVP9_t::name[];
 constexpr char HardwareCodecCapabilityUtils::HasHWVP9_t::signature[];
 
 auto HardwareCodecCapabilityUtils::HasHWVP9() -> bool
 {
     return mozilla::jni::Method<HasHWVP9_t>::Call(HardwareCodecCapabilityUtils::Context(), nullptr);
 }
 
+constexpr char HardwareCodecCapabilityUtils::CheckSupportsAdaptivePlayback_t::name[];
+constexpr char HardwareCodecCapabilityUtils::CheckSupportsAdaptivePlayback_t::signature[];
+
+auto HardwareCodecCapabilityUtils::CheckSupportsAdaptivePlayback(mozilla::jni::Object::Param a0, mozilla::jni::String::Param a1) -> bool
+{
+    return mozilla::jni::Method<CheckSupportsAdaptivePlayback_t>::Call(HardwareCodecCapabilityUtils::Context(), nullptr, a0, a1);
+}
+
 constexpr char HardwareCodecCapabilityUtils::FindDecoderCodecInfoForMimeType_t::name[];
 constexpr char HardwareCodecCapabilityUtils::FindDecoderCodecInfoForMimeType_t::signature[];
 
 auto HardwareCodecCapabilityUtils::FindDecoderCodecInfoForMimeType(mozilla::jni::String::Param a0) -> bool
 {
     return mozilla::jni::Method<FindDecoderCodecInfoForMimeType_t>::Call(HardwareCodecCapabilityUtils::Context(), nullptr, a0);
 }
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -5390,16 +5390,37 @@ public:
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::ANY;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
     static auto HasHWVP9() -> bool;
 
+    struct CheckSupportsAdaptivePlayback_t {
+        typedef HardwareCodecCapabilityUtils Owner;
+        typedef bool ReturnType;
+        typedef bool SetterType;
+        typedef mozilla::jni::Args<
+                mozilla::jni::Object::Param,
+                mozilla::jni::String::Param> Args;
+        static constexpr char name[] = "checkSupportsAdaptivePlayback";
+        static constexpr char signature[] =
+                "(Landroid/media/MediaCodec;Ljava/lang/String;)Z";
+        static const bool isStatic = true;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+        static const mozilla::jni::CallingThread callingThread =
+                mozilla::jni::CallingThread::ANY;
+        static const mozilla::jni::DispatchTarget dispatchTarget =
+                mozilla::jni::DispatchTarget::CURRENT;
+    };
+
+    static auto CheckSupportsAdaptivePlayback(mozilla::jni::Object::Param, mozilla::jni::String::Param) -> bool;
+
     struct FindDecoderCodecInfoForMimeType_t {
         typedef HardwareCodecCapabilityUtils Owner;
         typedef bool ReturnType;
         typedef bool SetterType;
         typedef mozilla::jni::Args<
                 mozilla::jni::String::Param> Args;
         static constexpr char name[] = "findDecoderCodecInfoForMimeType";
         static constexpr char signature[] =