diff options
author | Ruben Brunk <rubenbrunk@google.com> | 2014-09-27 02:16:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-27 02:16:30 +0000 |
commit | 7b28c66a6cc10b48231f8a5d8d45f5e22322e798 (patch) | |
tree | b98606f0868552c660b5e301a601b4371b720165 /media | |
parent | c8a3e0dc9d4c1e59ad250f45c2ee416beee8dd89 (diff) | |
parent | 31798f33184fd59dd3d3cc55e6373d9f91d220b6 (diff) | |
download | frameworks_base-7b28c66a6cc10b48231f8a5d8d45f5e22322e798.zip frameworks_base-7b28c66a6cc10b48231f8a5d8d45f5e22322e798.tar.gz frameworks_base-7b28c66a6cc10b48231f8a5d8d45f5e22322e798.tar.bz2 |
Merge "camera2: Fix native ImageReader test segfaults." into lmp-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/jni/android_media_ImageReader.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp index a734774..f4eb459 100644 --- a/media/jni/android_media_ImageReader.cpp +++ b/media/jni/android_media_ImageReader.cpp @@ -286,13 +286,17 @@ static int Image_getPixelFormat(JNIEnv* env, int format) return format; } -static uint32_t Image_getJpegSize(CpuConsumer::LockedBuffer* buffer) +static uint32_t Image_getJpegSize(CpuConsumer::LockedBuffer* buffer, bool usingRGBAOverride) { ALOG_ASSERT(buffer != NULL, "Input buffer is NULL!!!"); uint32_t size = 0; uint32_t width = buffer->width; uint8_t* jpegBuffer = buffer->data; + if (usingRGBAOverride) { + width *= 4; + } + // First check for JPEG transport header at the end of the buffer uint8_t* header = jpegBuffer + (width - sizeof(struct camera3_jpeg_blob)); struct camera3_jpeg_blob *blob = (struct camera3_jpeg_blob*)(header); @@ -317,11 +321,15 @@ static uint32_t Image_getJpegSize(CpuConsumer::LockedBuffer* buffer) return size; } +static bool usingRGBAToJpegOverride(int32_t bufferFormat, int32_t readerCtxFormat) { + return readerCtxFormat == HAL_PIXEL_FORMAT_BLOB && bufferFormat == HAL_PIXEL_FORMAT_RGBA_8888; +} + static int32_t applyFormatOverrides(int32_t bufferFormat, int32_t readerCtxFormat) { // Using HAL_PIXEL_FORMAT_RGBA_8888 gralloc buffers containing JPEGs to get around SW // write limitations for some platforms (b/17379185). - if (readerCtxFormat == HAL_PIXEL_FORMAT_BLOB && bufferFormat == HAL_PIXEL_FORMAT_RGBA_8888) { + if (usingRGBAToJpegOverride(bufferFormat, readerCtxFormat)) { return HAL_PIXEL_FORMAT_BLOB; } return bufferFormat; @@ -345,6 +353,7 @@ static void Image_getLockedBufferInfo(JNIEnv* env, CpuConsumer::LockedBuffer* bu dataSize = ySize = cSize = cStride = 0; int32_t fmt = buffer->format; + bool usingRGBAOverride = usingRGBAToJpegOverride(fmt, readerFormat); fmt = applyFormatOverrides(fmt, readerFormat); switch (fmt) { case HAL_PIXEL_FORMAT_YCbCr_420_888: @@ -416,7 +425,7 @@ static void Image_getLockedBufferInfo(JNIEnv* env, CpuConsumer::LockedBuffer* bu ALOG_ASSERT(buffer->height == 1, "JPEG should has height value %d", buffer->height); pData = buffer->data; - dataSize = Image_getJpegSize(buffer); + dataSize = Image_getJpegSize(buffer, usingRGBAOverride); break; case HAL_PIXEL_FORMAT_RAW_SENSOR: // Single plane 16bpp bayer data. @@ -912,7 +921,7 @@ static jobject Image_getByteBuffer(JNIEnv* env, jobject thiz, int idx, int reade if (size > static_cast<uint32_t>(INT32_MAX)) { // Byte buffer have 'int capacity', so check the range jniThrowExceptionFmt(env, "java/lang/IllegalStateException", - "Size too large for bytebuffer capacity " PRIu32, size); + "Size too large for bytebuffer capacity %" PRIu32, size); return NULL; } |