am c4ad3cb0: Merge "Add support for common encryption" into jb-mr2-dev
* commit 'c4ad3cb07ed76c5697c60285456d9c49675174d9': Add support for common encryption
This commit is contained in:
@@ -22,6 +22,7 @@ import android.media.MediaCrypto;
|
||||
import android.media.MediaFormat;
|
||||
import android.view.Surface;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -395,6 +396,27 @@ final public class MediaCodec {
|
||||
* see {@link #CRYPTO_MODE_UNENCRYPTED} and {@link #CRYPTO_MODE_AES_CTR}.
|
||||
*/
|
||||
public int mode;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(numSubSamples + " subsamples, key [");
|
||||
String hexdigits = "0123456789abcdef";
|
||||
for (int i = 0; i < key.length; i++) {
|
||||
builder.append(hexdigits.charAt((key[i] & 0xf0) >> 4));
|
||||
builder.append(hexdigits.charAt(key[i] & 0x0f));
|
||||
}
|
||||
builder.append("], iv [");
|
||||
for (int i = 0; i < key.length; i++) {
|
||||
builder.append(hexdigits.charAt((iv[i] & 0xf0) >> 4));
|
||||
builder.append(hexdigits.charAt(iv[i] & 0x0f));
|
||||
}
|
||||
builder.append("], clear ");
|
||||
builder.append(Arrays.toString(numBytesOfClearData));
|
||||
builder.append(", encrypted ");
|
||||
builder.append(Arrays.toString(numBytesOfEncryptedData));
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,10 @@ import android.net.Uri;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* MediaExtractor facilitates extraction of demuxed, typically encoded, media data
|
||||
@@ -194,6 +197,38 @@ final public class MediaExtractor {
|
||||
*/
|
||||
public native final int getTrackCount();
|
||||
|
||||
/**
|
||||
* Get the PSSH info if present. This returns a map of uuid-to-bytes, with the uuid specifying
|
||||
* the crypto scheme, and the bytes being the data specific to that scheme.
|
||||
* {@hide}
|
||||
*/
|
||||
public Map<UUID, byte[]> getPsshInfo() {
|
||||
Map<UUID, byte[]> psshMap = null;
|
||||
Map<String, Object> formatMap = getFileFormatNative();
|
||||
if (formatMap != null && formatMap.containsKey("pssh")) {
|
||||
ByteBuffer rawpssh = (ByteBuffer) formatMap.get("pssh");
|
||||
rawpssh.order(ByteOrder.nativeOrder());
|
||||
rawpssh.rewind();
|
||||
formatMap.remove("pssh");
|
||||
// parse the flat pssh bytebuffer into something more manageable
|
||||
psshMap = new HashMap<UUID, byte[]>();
|
||||
while (rawpssh.remaining() > 0) {
|
||||
rawpssh.order(ByteOrder.BIG_ENDIAN);
|
||||
long msb = rawpssh.getLong();
|
||||
long lsb = rawpssh.getLong();
|
||||
UUID uuid = new UUID(msb, lsb);
|
||||
rawpssh.order(ByteOrder.nativeOrder());
|
||||
int datalen = rawpssh.getInt();
|
||||
byte [] psshdata = new byte[datalen];
|
||||
rawpssh.get(psshdata);
|
||||
psshMap.put(uuid, psshdata);
|
||||
}
|
||||
}
|
||||
return psshMap;
|
||||
}
|
||||
|
||||
private native Map<String, Object> getFileFormatNative();
|
||||
|
||||
/**
|
||||
* Get the track format at the specified index.
|
||||
* More detail on the representation can be found at {@link android.media.MediaCodec}
|
||||
|
||||
@@ -372,7 +372,7 @@ static jint throwExceptionAsNecessary(
|
||||
|
||||
default:
|
||||
{
|
||||
jniThrowException(env, "java/lang/IllegalStateException", NULL);
|
||||
jniThrowException(env, "java/lang/IllegalStateException", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -455,13 +455,13 @@ static void android_media_MediaCodec_start(JNIEnv *env, jobject thiz) {
|
||||
sp<JMediaCodec> codec = getMediaCodec(env, thiz);
|
||||
|
||||
if (codec == NULL) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException", NULL);
|
||||
jniThrowException(env, "java/lang/IllegalStateException", "no codec found");
|
||||
return;
|
||||
}
|
||||
|
||||
status_t err = codec->start();
|
||||
|
||||
throwExceptionAsNecessary(env, err);
|
||||
throwExceptionAsNecessary(env, err, "start failed");
|
||||
}
|
||||
|
||||
static void android_media_MediaCodec_stop(JNIEnv *env, jobject thiz) {
|
||||
|
||||
@@ -162,6 +162,18 @@ status_t JMediaExtractor::getTrackFormat(size_t index, jobject *format) const {
|
||||
return ConvertMessageToMap(env, msg, format);
|
||||
}
|
||||
|
||||
status_t JMediaExtractor::getFileFormat(jobject *format) const {
|
||||
sp<AMessage> msg;
|
||||
status_t err;
|
||||
if ((err = mImpl->getFileFormat(&msg)) != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||
|
||||
return ConvertMessageToMap(env, msg, format);
|
||||
}
|
||||
|
||||
status_t JMediaExtractor::selectTrack(size_t index) {
|
||||
return mImpl->selectTrack(index);
|
||||
}
|
||||
@@ -339,6 +351,26 @@ static jobject android_media_MediaExtractor_getTrackFormatNative(
|
||||
return format;
|
||||
}
|
||||
|
||||
static jobject android_media_MediaExtractor_getFileFormatNative(
|
||||
JNIEnv *env, jobject thiz) {
|
||||
sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
|
||||
|
||||
if (extractor == NULL) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException", NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobject format;
|
||||
status_t err = extractor->getFileFormat(&format);
|
||||
|
||||
if (err != OK) {
|
||||
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
static void android_media_MediaExtractor_selectTrack(
|
||||
JNIEnv *env, jobject thiz, jint index) {
|
||||
sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
|
||||
@@ -768,6 +800,9 @@ static JNINativeMethod gMethods[] = {
|
||||
|
||||
{ "getTrackCount", "()I", (void *)android_media_MediaExtractor_getTrackCount },
|
||||
|
||||
{ "getFileFormatNative", "()Ljava/util/Map;",
|
||||
(void *)android_media_MediaExtractor_getFileFormatNative },
|
||||
|
||||
{ "getTrackFormatNative", "(I)Ljava/util/Map;",
|
||||
(void *)android_media_MediaExtractor_getTrackFormatNative },
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ struct JMediaExtractor : public RefBase {
|
||||
size_t countTracks() const;
|
||||
status_t getTrackFormat(size_t index, jobject *format) const;
|
||||
|
||||
status_t getFileFormat(jobject *format) const;
|
||||
|
||||
status_t selectTrack(size_t index);
|
||||
status_t unselectTrack(size_t index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user