diff options
| -rw-r--r-- | media/java/android/media/ImageReader.java | 8 | ||||
| -rw-r--r-- | media/jni/android_media_ImageReader.cpp | 11 |
2 files changed, 15 insertions, 4 deletions
diff --git a/media/java/android/media/ImageReader.java b/media/java/android/media/ImageReader.java index f9e48d4b1780..1bd32c4c976c 100644 --- a/media/java/android/media/ImageReader.java +++ b/media/java/android/media/ImageReader.java @@ -83,7 +83,8 @@ public class ImageReader implements AutoCloseable { * @param format * The format of the Image that this reader will produce. This * must be one of the {@link android.graphics.ImageFormat} or - * {@link android.graphics.PixelFormat} constants. + * {@link android.graphics.PixelFormat} constants. Note that + * not all formats is supported, like ImageFormat.NV21. * @param maxImages * The maximum number of images the user will want to * access simultaneously. This should be as small as possible to limit @@ -116,6 +117,11 @@ public class ImageReader implements AutoCloseable { "Maximum outstanding image count must be at least 1"); } + if (format == ImageFormat.NV21) { + throw new IllegalArgumentException( + "NV21 format is not supported"); + } + mNumPlanes = getNumPlanesFromFormat(); nativeInit(new WeakReference<ImageReader>(this), width, height, format, maxImages); diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp index a03dbf325e50..0030dbdafee2 100644 --- a/media/jni/android_media_ImageReader.cpp +++ b/media/jni/android_media_ImageReader.cpp @@ -721,13 +721,18 @@ static jint ImageReader_imageSetup(JNIEnv* env, jobject thiz, return ACQUIRE_NO_BUFFERS; } + if (buffer->format == HAL_PIXEL_FORMAT_YCrCb_420_SP) { + jniThrowException(env, "java/lang/UnsupportedOperationException", + "NV21 format is not supported by ImageReader"); + return -1; + } + // Check if the left-top corner of the crop rect is origin, we currently assume this point is // zero, will revist this once this assumption turns out problematic. Point lt = buffer->crop.leftTop(); if (lt.x != 0 || lt.y != 0) { - ALOGE("crop left: %d, top = %d", lt.x, lt.y); - jniThrowException(env, "java/lang/UnsupportedOperationException", - "crop left top corner need to at origin"); + jniThrowExceptionFmt(env, "java/lang/UnsupportedOperationException", + "crop left top corner [%d, %d] need to be at origin", lt.x, lt.y); return -1; } |