diff options
| -rw-r--r-- | media/java/android/media/MediaCodec.java | 22 | ||||
| -rw-r--r-- | media/java/android/media/MediaExtractor.java | 35 | ||||
| -rw-r--r-- | media/jni/android_media_MediaCodec.cpp | 6 | ||||
| -rw-r--r-- | media/jni/android_media_MediaExtractor.cpp | 35 | ||||
| -rw-r--r-- | media/jni/android_media_MediaExtractor.h | 2 |
5 files changed, 97 insertions, 3 deletions
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index b6b49a2..45a8b99 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -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(); + } }; /** diff --git a/media/java/android/media/MediaExtractor.java b/media/java/android/media/MediaExtractor.java index 749ef12..286e203 100644 --- a/media/java/android/media/MediaExtractor.java +++ b/media/java/android/media/MediaExtractor.java @@ -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 @@ -195,6 +198,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} */ diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index 3a42db2..cd1d9ce 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -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) { diff --git a/media/jni/android_media_MediaExtractor.cpp b/media/jni/android_media_MediaExtractor.cpp index 23949fa..1704d5c 100644 --- a/media/jni/android_media_MediaExtractor.cpp +++ b/media/jni/android_media_MediaExtractor.cpp @@ -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 }, diff --git a/media/jni/android_media_MediaExtractor.h b/media/jni/android_media_MediaExtractor.h index 03900db..ccbad8c 100644 --- a/media/jni/android_media_MediaExtractor.h +++ b/media/jni/android_media_MediaExtractor.h @@ -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); |
