Skip to content

Commit 8240d92

Browse files
committed
New Crypto JAVA class to facilitate decryption via MediaCodec.
Change-Id: Ic4e395faa84f003793c2804f2badabab9e7f1034 related-to-bug: 6275919
1 parent cf15200 commit 8240d92

File tree

9 files changed

+430
-10
lines changed

9 files changed

+430
-10
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.media;
18+
19+
/**
20+
* Crypto class can be used in conjunction with MediaCodec to decode
21+
* encrypted media data.
22+
* @hide
23+
*/
24+
public final class Crypto {
25+
public static final native boolean isCryptoSchemeSupported(byte[] uuid);
26+
27+
public Crypto(byte[] uuid, byte[] initData) {
28+
native_setup(uuid, initData);
29+
}
30+
31+
public final native boolean requiresSecureDecoderComponent(String mime);
32+
33+
@Override
34+
protected void finalize() {
35+
native_finalize();
36+
}
37+
38+
public native final void release();
39+
private static native final void native_init();
40+
private native final void native_setup(byte[] uuid, byte[] initData);
41+
private native final void native_finalize();
42+
43+
static {
44+
System.loadLibrary("media_jni");
45+
native_init();
46+
}
47+
48+
private int mNativeContext;
49+
}

media/java/android/media/MediaCodec.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.media;
1818

19+
import android.media.Crypto;
1920
import android.view.Surface;
2021
import java.nio.ByteBuffer;
2122
import java.util.Map;
@@ -25,8 +26,7 @@
2526
* encoder/decoder components.
2627
* @hide
2728
*/
28-
public class MediaCodec
29-
{
29+
final public class MediaCodec {
3030
/** Per buffer metadata includes an offset and size specifying
3131
the range of valid data in the associated codec buffer.
3232
*/
@@ -113,11 +113,14 @@ protected void finalize() {
113113
*
114114
* @param surface Specify a surface on which to render the output of this
115115
* decoder.
116+
* @param crypto Specify a crypto object to facilitate secure decryption
117+
* of the media data.
116118
* @param flags Specify {@link #CONFIGURE_FLAG_ENCODE} to configure the
117119
* component as an encoder.
118120
*/
119121
public void configure(
120-
Map<String, Object> format, Surface surface, int flags) {
122+
Map<String, Object> format,
123+
Surface surface, Crypto crypto, int flags) {
121124
String[] keys = null;
122125
Object[] values = null;
123126

@@ -133,11 +136,12 @@ public void configure(
133136
}
134137
}
135138

136-
native_configure(keys, values, surface, flags);
139+
native_configure(keys, values, surface, crypto, flags);
137140
}
138141

139142
private native final void native_configure(
140-
String[] keys, Object[] values, Surface surface, int flags);
143+
String[] keys, Object[] values,
144+
Surface surface, Crypto crypto, int flags);
141145

142146
/** After successfully configuring the component, call start. On return
143147
* you can query the component for its input/output buffers.

media/java/android/media/MediaExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* MediaExtractor
2424
* @hide
2525
*/
26-
public class MediaExtractor
27-
{
26+
final public class MediaExtractor {
2827
public MediaExtractor(String path) {
2928
native_setup(path);
3029
}

media/jni/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LOCAL_PATH:= $(call my-dir)
22
include $(CLEAR_VARS)
33

44
LOCAL_SRC_FILES:= \
5+
android_media_Crypto.cpp \
56
android_media_MediaCodec.cpp \
67
android_media_MediaCodecList.cpp \
78
android_media_MediaExtractor.cpp \

0 commit comments

Comments
 (0)