summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2014-11-20 18:01:36 -0800
committerRuben Brunk <rubenbrunk@google.com>2014-12-09 11:56:22 -0800
commitf4a637d0be2e028d1e78c8bf90ad17ec3f84b5f3 (patch)
treea26159df0af836ad174358059d497ced16080354 /media
parent7fc9176c8a2102fb5be3668404bd15feb6878c89 (diff)
downloadframeworks_base-f4a637d0be2e028d1e78c8bf90ad17ec3f84b5f3.zip
frameworks_base-f4a637d0be2e028d1e78c8bf90ad17ec3f84b5f3.tar.gz
frameworks_base-f4a637d0be2e028d1e78c8bf90ad17ec3f84b5f3.tar.bz2
Camera2: Allow rendering to arbitrary surface sizes in LEGACY mode.
Bug: 16030677 Change-Id: Ida04e04f41983b9126609522dd12064a7bf9645f
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/ImageReader.java16
-rw-r--r--media/jni/android_media_ImageReader.cpp64
2 files changed, 54 insertions, 26 deletions
diff --git a/media/java/android/media/ImageReader.java b/media/java/android/media/ImageReader.java
index b541454..fed0f13 100644
--- a/media/java/android/media/ImageReader.java
+++ b/media/java/android/media/ImageReader.java
@@ -577,7 +577,11 @@ public class ImageReader implements AutoCloseable {
@Override
public int getWidth() {
if (mIsImageValid) {
- return ImageReader.this.mWidth;
+ if (mWidth == -1) {
+ mWidth = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getWidth() :
+ nativeGetWidth();
+ }
+ return mWidth;
} else {
throw new IllegalStateException("Image is already released");
}
@@ -586,7 +590,11 @@ public class ImageReader implements AutoCloseable {
@Override
public int getHeight() {
if (mIsImageValid) {
- return ImageReader.this.mHeight;
+ if (mHeight == -1) {
+ mHeight = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getHeight() :
+ nativeGetHeight();
+ }
+ return mHeight;
} else {
throw new IllegalStateException("Image is already released");
}
@@ -711,9 +719,13 @@ public class ImageReader implements AutoCloseable {
private SurfacePlane[] mPlanes;
private boolean mIsImageValid;
+ private int mHeight = -1;
+ private int mWidth = -1;
private synchronized native ByteBuffer nativeImageGetBuffer(int idx, int readerFormat);
private synchronized native SurfacePlane nativeCreatePlane(int idx, int readerFormat);
+ private synchronized native int nativeGetWidth();
+ private synchronized native int nativeGetHeight();
}
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 7830c80..3f4736d 100644
--- a/media/jni/android_media_ImageReader.cpp
+++ b/media/jni/android_media_ImageReader.cpp
@@ -615,6 +615,24 @@ static jint Image_imageGetRowStride(JNIEnv* env, CpuConsumer::LockedBuffer* buff
return rowStride;
}
+static int Image_getBufferWidth(CpuConsumer::LockedBuffer* buffer) {
+ if (buffer == NULL) return -1;
+
+ if (!buffer->crop.isEmpty()) {
+ return buffer->crop.getWidth();
+ }
+ return buffer->width;
+}
+
+static int Image_getBufferHeight(CpuConsumer::LockedBuffer* buffer) {
+ if (buffer == NULL) return -1;
+
+ if (!buffer->crop.isEmpty()) {
+ return buffer->crop.getHeight();
+ }
+ return buffer->height;
+}
+
// ----------------------------------------------------------------------------
static void ImageReader_classInit(JNIEnv* env, jclass clazz)
@@ -795,33 +813,16 @@ static jint ImageReader_imageSetup(JNIEnv* env, jobject thiz,
}
// Check if the producer buffer configurations match what ImageReader configured.
- // We want to fail for the very first image because this case is too bad.
- int outputWidth = buffer->width;
- int outputHeight = buffer->height;
-
- // Correct width/height when crop is set.
- if (!buffer->crop.isEmpty()) {
- outputWidth = buffer->crop.getWidth();
- outputHeight = buffer->crop.getHeight();
- }
+ int outputWidth = Image_getBufferWidth(buffer);
+ int outputHeight = Image_getBufferHeight(buffer);
int imgReaderFmt = ctx->getBufferFormat();
int imageReaderWidth = ctx->getBufferWidth();
int imageReaderHeight = ctx->getBufferHeight();
if ((buffer->format != HAL_PIXEL_FORMAT_BLOB) && (imgReaderFmt != HAL_PIXEL_FORMAT_BLOB) &&
- (imageReaderWidth != outputWidth || imageReaderHeight > outputHeight)) {
- /**
- * For video decoder, the buffer height is actually the vertical stride,
- * which is always >= actual image height. For future, decoder need provide
- * right crop rectangle to CpuConsumer to indicate the actual image height,
- * see bug 9563986. After this bug is fixed, we can enforce the height equal
- * check. Right now, only make sure buffer height is no less than ImageReader
- * height.
- */
- jniThrowExceptionFmt(env, "java/lang/IllegalStateException",
- "Producer buffer size: %dx%d, doesn't match ImageReader configured size: %dx%d",
- outputWidth, outputHeight, imageReaderWidth, imageReaderHeight);
- return -1;
+ (imageReaderWidth != outputWidth || imageReaderHeight != outputHeight)) {
+ ALOGV("%s: Producer buffer size: %dx%d, doesn't match ImageReader configured size: %dx%d",
+ __FUNCTION__, outputWidth, outputHeight, imageReaderWidth, imageReaderHeight);
}
int bufFmt = buffer->format;
@@ -934,6 +935,19 @@ static jobject Image_getByteBuffer(JNIEnv* env, jobject thiz, int idx, int reade
return byteBuffer;
}
+static jint Image_getWidth(JNIEnv* env, jobject thiz)
+{
+ CpuConsumer::LockedBuffer* buffer = Image_getLockedBuffer(env, thiz);
+ return Image_getBufferWidth(buffer);
+}
+
+static jint Image_getHeight(JNIEnv* env, jobject thiz)
+{
+ CpuConsumer::LockedBuffer* buffer = Image_getLockedBuffer(env, thiz);
+ return Image_getBufferHeight(buffer);
+}
+
+
} // extern "C"
// ----------------------------------------------------------------------------
@@ -943,14 +957,16 @@ static JNINativeMethod gImageReaderMethods[] = {
{"nativeInit", "(Ljava/lang/Object;IIII)V", (void*)ImageReader_init },
{"nativeClose", "()V", (void*)ImageReader_close },
{"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease },
- {"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup },
+ {"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup },
{"nativeGetSurface", "()Landroid/view/Surface;", (void*)ImageReader_getSurface },
};
static JNINativeMethod gImageMethods[] = {
{"nativeImageGetBuffer", "(II)Ljava/nio/ByteBuffer;", (void*)Image_getByteBuffer },
{"nativeCreatePlane", "(II)Landroid/media/ImageReader$SurfaceImage$SurfacePlane;",
- (void*)Image_createSurfacePlane },
+ (void*)Image_createSurfacePlane },
+ {"nativeGetWidth", "()I", (void*)Image_getWidth },
+ {"nativeGetHeight", "()I", (void*)Image_getHeight },
};
int register_android_media_ImageReader(JNIEnv *env) {