Index: media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
index 5bda3df60c9b0e6abe2797e20d21738b4b17f1a5..93295f87c1e59cb450f20f24c930467bb24fd7bd 100644 |
--- a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
@@ -15,6 +15,9 @@ import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
import org.chromium.base.annotations.MainDex; |
+import java.lang.reflect.Constructor; |
+import java.lang.reflect.InvocationTargetException; |
+import java.lang.reflect.Method; |
import java.util.Locale; |
/** |
@@ -322,4 +325,73 @@ class MediaCodecUtil { |
} |
return false; |
} |
+ |
+ static boolean trySetCryptoInfoPattern( |
+ MediaCodec.CryptoInfo cryptoInfo, int encrypt, int skip) { |
+ if (sMediaCodecCryptoInfoPatternCtor == null |
+ || sMediaCodecCryptoInfoSetPatternMethod == null) { |
+ return false; |
+ } |
+ Object pattern; |
+ try { |
+ pattern = sMediaCodecCryptoInfoPatternCtor.newInstance(encrypt, skip); |
+ } catch (IllegalAccessException e) { |
+ Log.e(TAG, "Cannot construct Pattern instance.", e); |
+ return false; |
+ } catch (InstantiationException e) { |
+ Log.e(TAG, "Cannot construct Pattern instance.", e); |
+ return false; |
+ } catch (InvocationTargetException e) { |
+ Log.e(TAG, "Cannot construct Pattern instance.", e); |
+ return false; |
+ } |
+ try { |
+ sMediaCodecCryptoInfoSetPatternMethod.invoke(cryptoInfo, pattern); |
+ return true; |
+ } catch (NullPointerException e) { |
+ Log.e(TAG, "Cannot call setPattern method.", e); |
+ } catch (IllegalAccessException e) { |
+ Log.e(TAG, "Cannot call setPattern method.", e); |
+ } catch (IllegalArgumentException e) { |
+ Log.e(TAG, "Cannot call setPattern method.", e); |
+ } catch (InvocationTargetException e) { |
+ Log.e(TAG, "Cannot call setPattern method.", e); |
+ } |
+ return false; |
+ } |
+ |
+ static { |
+ initMediaCodecCryptoInfoPatternMethods(); |
+ } |
+ |
+ private static void initMediaCodecCryptoInfoPatternMethods() { |
+ Class<?> cryptoInfoClazz = MediaCodec.CryptoInfo.class; |
+ Class<?> cryptoInfoPatternClazz = null; |
+ for (Class<?> clazz : cryptoInfoClazz.getClasses()) { |
+ if (clazz.getSimpleName().equals(PATTERN_CLASS_SIMPLE_NAME)) { |
+ cryptoInfoPatternClazz = clazz; |
+ break; |
+ } |
+ } |
+ if (cryptoInfoPatternClazz == null) return; |
+ try { |
+ sMediaCodecCryptoInfoPatternCtor = |
+ cryptoInfoPatternClazz.getConstructor(int.class, int.class); |
xhwang
2016/06/15 05:29:05
Can you just check the API level instead of using
dougsteed
2016/06/15 17:57:38
As I am accessing a new method only added in N, I
dougsteed
2016/10/20 17:07:35
Android N SDK has now been added to chromium, so I
|
+ } catch (NoSuchMethodException e) { |
+ Log.e(TAG, "Cannot find MediaCodec.CryptInfo.Pattern constructor", e); |
xhwang
2016/06/15 05:29:05
s/CryptInfo/CryptoInfo
|
+ return; |
+ } |
+ try { |
+ sMediaCodecCryptoInfoSetPatternMethod = |
+ cryptoInfoClazz.getMethod(SET_PATTERN_METHOD_NAME, cryptoInfoPatternClazz); |
+ } catch (NoSuchMethodException e) { |
+ Log.e(TAG, "Cannot access MediaCodec.CryptInfo.setPattern method", e); |
xhwang
2016/06/15 05:29:05
ditto
|
+ return; |
+ } |
+ } |
+ |
+ static final String PATTERN_CLASS_SIMPLE_NAME = "Pattern"; |
+ static final String SET_PATTERN_METHOD_NAME = "setPattern"; |
+ static Method sMediaCodecCryptoInfoSetPatternMethod; |
+ static Constructor<?> sMediaCodecCryptoInfoPatternCtor; |
} |