diff options
author | James Dong <jdong@google.com> | 2010-11-08 16:04:27 -0800 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-11-08 16:52:59 -0800 |
commit | 53ebc72fd83f83bb5536d5917390aae03b7f5cad (patch) | |
tree | 1fe4af89aa72abfd2c969789cd0b98fe0b4737fd /media/jni/android_media_MediaMetadataRetriever.cpp | |
parent | 17ae359721ba74399e785369346509b776999d1f (diff) | |
download | frameworks_base-53ebc72fd83f83bb5536d5917390aae03b7f5cad.zip frameworks_base-53ebc72fd83f83bb5536d5917390aae03b7f5cad.tar.gz frameworks_base-53ebc72fd83f83bb5536d5917390aae03b7f5cad.tar.bz2 |
Support extracting thumbnail from rotated video tracks
Change-Id: Ife0a2536aaac5ff1efdf1035b9d2c892773ee16c
Diffstat (limited to 'media/jni/android_media_MediaMetadataRetriever.cpp')
-rw-r--r-- | media/jni/android_media_MediaMetadataRetriever.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp index efea802..63e9dc8 100644 --- a/media/jni/android_media_MediaMetadataRetriever.cpp +++ b/media/jni/android_media_MediaMetadataRetriever.cpp @@ -36,6 +36,7 @@ struct fields_t { jfieldID context; jclass bitmapClazz; jmethodID bitmapConstructor; + jmethodID createBitmapMethod; }; static fields_t fields; @@ -174,6 +175,41 @@ static jobject android_media_MediaMetadataRetriever_captureFrame(JNIEnv *env, jo return NULL; } + jobject matrix = NULL; + if (videoFrame->mRotationAngle != 0) { + LOGD("Create a rotation matrix: %d degrees", videoFrame->mRotationAngle); + jclass matrixClazz = env->FindClass("android/graphics/Matrix"); + if (matrixClazz == NULL) { + jniThrowException(env, "java/lang/RuntimeException", + "Can't find android/graphics/Matrix"); + return NULL; + } + jmethodID matrixConstructor = + env->GetMethodID(matrixClazz, "<init>", "()V"); + if (matrixConstructor == NULL) { + jniThrowException(env, "java/lang/RuntimeException", + "Can't find Matrix constructor"); + return NULL; + } + matrix = + env->NewObject(matrixClazz, matrixConstructor); + if (matrix == NULL) { + LOGE("Could not create a Matrix object"); + return NULL; + } + + LOGV("Rotate the matrix: %d degrees", videoFrame->mRotationAngle); + jmethodID setRotateMethod = + env->GetMethodID(matrixClazz, "setRotate", "(F)V"); + if (setRotateMethod == NULL) { + jniThrowException(env, "java/lang/RuntimeException", + "Can't find Matrix setRotate method"); + return NULL; + } + env->CallVoidMethod(matrix, setRotateMethod, 1.0 * videoFrame->mRotationAngle); + env->DeleteLocalRef(matrixClazz); + } + // Create a SkBitmap to hold the pixels SkBitmap *bitmap = new SkBitmap(); if (bitmap == NULL) { @@ -191,7 +227,19 @@ static jobject android_media_MediaMetadataRetriever_captureFrame(JNIEnv *env, jo // Since internally SkBitmap uses reference count to manage the reference to // its pixels, it is important that the pixels (along with SkBitmap) be // available after creating the Bitmap is returned to Java app. - return env->NewObject(fields.bitmapClazz, fields.bitmapConstructor, (int) bitmap, true, NULL, -1); + jobject jSrcBitmap = env->NewObject(fields.bitmapClazz, + fields.bitmapConstructor, (int) bitmap, true, NULL, -1); + + LOGV("Return a new bitmap constructed with the rotation matrix"); + return env->CallStaticObjectMethod( + fields.bitmapClazz, fields.createBitmapMethod, + jSrcBitmap, // source Bitmap + 0, // x + 0, // y + videoFrame->mDisplayWidth, // width + videoFrame->mDisplayHeight, // height + matrix, // transform matrix + false); // filter } static jbyteArray android_media_MediaMetadataRetriever_extractAlbumArt(JNIEnv *env, jobject thiz) @@ -291,6 +339,15 @@ static void android_media_MediaMetadataRetriever_native_init(JNIEnv *env) jniThrowException(env, "java/lang/RuntimeException", "Can't find Bitmap constructor"); return; } + fields.createBitmapMethod = + env->GetStaticMethodID(fields.bitmapClazz, "createBitmap", + "(Landroid/graphics/Bitmap;IIIILandroid/graphics/Matrix;Z)" + "Landroid/graphics/Bitmap;"); + if (fields.createBitmapMethod == NULL) { + jniThrowException(env, "java/lang/RuntimeException", + "Can't find Bitmap.createBitmap method"); + return; + } } static void android_media_MediaMetadataRetriever_native_setup(JNIEnv *env, jobject thiz) |