From 7c3997d96a2571295a97457264832d54b05ee966 Mon Sep 17 00:00:00 2001 From: Zhijun He Date: Wed, 6 May 2015 10:08:37 -0700 Subject: ImageReader: Image getFormat should return the Image buffer format Also return buffer size correctly. Bug: 19527410 Change-Id: I9a912afc61d577571c1b2a7f6df21da40838e925 --- media/java/android/media/ImageReader.java | 17 +++++++++-------- media/jni/android_media_ImageReader.cpp | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/media/java/android/media/ImageReader.java b/media/java/android/media/ImageReader.java index 6d30208..26ac189 100644 --- a/media/java/android/media/ImageReader.java +++ b/media/java/android/media/ImageReader.java @@ -703,26 +703,26 @@ public class ImageReader implements AutoCloseable { @Override public int getFormat() { throwISEIfImageIsInvalid(); + int readerFormat = ImageReader.this.getImageFormat(); + // Assume opaque reader always produce opaque images. + mFormat = (readerFormat == ImageFormat.PRIVATE) ? readerFormat : + nativeGetFormat(readerFormat); return mFormat; } @Override public int getWidth() { throwISEIfImageIsInvalid(); - if (mWidth == -1) { - mWidth = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getWidth() : - nativeGetWidth(mFormat); - } + mWidth = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getWidth() : + nativeGetWidth(mFormat); return mWidth; } @Override public int getHeight() { throwISEIfImageIsInvalid(); - if (mHeight == -1) { - mHeight = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getHeight() : - nativeGetHeight(mFormat); - } + mHeight = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getHeight() : + nativeGetHeight(mFormat); return mHeight; } @@ -876,6 +876,7 @@ public class ImageReader implements AutoCloseable { private synchronized native SurfacePlane nativeCreatePlane(int idx, int readerFormat); private synchronized native int nativeGetWidth(int format); private synchronized native int nativeGetHeight(int format); + private synchronized native int nativeGetFormat(int readerFormat); } private synchronized native void nativeInit(Object weakSelf, int w, int h, diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp index 043e20b..49614bd 100644 --- a/media/jni/android_media_ImageReader.cpp +++ b/media/jni/android_media_ImageReader.cpp @@ -1222,6 +1222,19 @@ static jint Image_getHeight(JNIEnv* env, jobject thiz, jint format) } } +static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat) +{ + if (isFormatOpaque(readerFormat)) { + // Assuming opaque reader produce opaque images. + return static_cast(PublicFormat::PRIVATE); + } else { + CpuConsumer::LockedBuffer* buffer = Image_getLockedBuffer(env, thiz); + PublicFormat publicFmt = android_view_Surface_mapHalFormatDataspaceToPublicFormat( + buffer->flexFormat, buffer->dataSpace); + return static_cast(publicFmt); + } +} + } // extern "C" // ---------------------------------------------------------------------------- @@ -1240,8 +1253,9 @@ static JNINativeMethod gImageMethods[] = { {"nativeImageGetBuffer", "(II)Ljava/nio/ByteBuffer;", (void*)Image_getByteBuffer }, {"nativeCreatePlane", "(II)Landroid/media/ImageReader$SurfaceImage$SurfacePlane;", (void*)Image_createSurfacePlane }, - {"nativeGetWidth", "(I)I", (void*)Image_getWidth }, - {"nativeGetHeight", "(I)I", (void*)Image_getHeight }, + {"nativeGetWidth", "(I)I", (void*)Image_getWidth }, + {"nativeGetHeight", "(I)I", (void*)Image_getHeight }, + {"nativeGetFormat", "(I)I", (void*)Image_getFormat }, }; int register_android_media_ImageReader(JNIEnv *env) { -- cgit v1.1