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 | |
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')
-rw-r--r-- | media/jni/android_media_MediaMetadataRetriever.cpp | 59 | ||||
-rw-r--r-- | media/libmediaplayerservice/MetadataRetrieverClient.cpp | 2 | ||||
-rw-r--r-- | media/libstagefright/StagefrightMetadataRetriever.cpp | 6 |
3 files changed, 66 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) diff --git a/media/libmediaplayerservice/MetadataRetrieverClient.cpp b/media/libmediaplayerservice/MetadataRetrieverClient.cpp index ca229fa..39fce81 100644 --- a/media/libmediaplayerservice/MetadataRetrieverClient.cpp +++ b/media/libmediaplayerservice/MetadataRetrieverClient.cpp @@ -253,6 +253,8 @@ sp<IMemory> MetadataRetrieverClient::captureFrame() frameCopy->mDisplayWidth = frame->mDisplayWidth; frameCopy->mDisplayHeight = frame->mDisplayHeight; frameCopy->mSize = frame->mSize; + frameCopy->mRotationAngle = frame->mRotationAngle; + LOGV("rotation: %d", frameCopy->mRotationAngle); frameCopy->mData = (uint8_t *)frameCopy + sizeof(VideoFrame); memcpy(frameCopy->mData, frame->mData, frame->mSize); delete frame; // Fix memory leakage diff --git a/media/libstagefright/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp index a800a93..9b2dec9 100644 --- a/media/libstagefright/StagefrightMetadataRetriever.cpp +++ b/media/libstagefright/StagefrightMetadataRetriever.cpp @@ -191,6 +191,11 @@ static VideoFrame *extractVideoFrameWithCodecFlags( CHECK(meta->findInt32(kKeyWidth, &width)); CHECK(meta->findInt32(kKeyHeight, &height)); + int32_t rotationAngle; + if (!trackMeta->findInt32(kKeyRotation, &rotationAngle)) { + rotationAngle = 0; // By default, no rotation + } + VideoFrame *frame = new VideoFrame; frame->mWidth = width; frame->mHeight = height; @@ -198,6 +203,7 @@ static VideoFrame *extractVideoFrameWithCodecFlags( frame->mDisplayHeight = height; frame->mSize = width * height * 2; frame->mData = new uint8_t[frame->mSize]; + frame->mRotationAngle = rotationAngle; int32_t srcFormat; CHECK(meta->findInt32(kKeyColorFormat, &srcFormat)); |