summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorZhijun He <zhijunhe@google.com>2013-07-01 11:03:41 -0700
committerZhijun He <zhijunhe@google.com>2013-07-01 11:03:41 -0700
commit534046d2b12fd13776ad782b982649cb0bea9b79 (patch)
treed81f2dbb71a35dae748e57c2b516270ea0633c48 /media
parent7601e31d140046aa759cdc5299447b298a5f0c85 (diff)
downloadframeworks_base-534046d2b12fd13776ad782b982649cb0bea9b79.zip
frameworks_base-534046d2b12fd13776ad782b982649cb0bea9b79.tar.gz
frameworks_base-534046d2b12fd13776ad782b982649cb0bea9b79.tar.bz2
ImageReader: get correct jpeg size.
the jpeg size was set to the buffer width, which is the max jpeg buffer size. the right size can be obtained by parsing the camera3_jpeg_blob data sent by hal. Also correct the buffer size check when crop is not set. Bug: 9254294 Change-Id: Ic73de47ef97efa4eb356a399c1576715e2eacbfd
Diffstat (limited to 'media')
-rw-r--r--media/jni/Android.mk2
-rw-r--r--media/jni/android_media_ImageReader.cpp39
2 files changed, 38 insertions, 3 deletions
diff --git a/media/jni/Android.mk b/media/jni/Android.mk
index 01b3174..63a61e2 100644
--- a/media/jni/Android.mk
+++ b/media/jni/Android.mk
@@ -57,6 +57,8 @@ LOCAL_C_INCLUDES += \
frameworks/av/media/libstagefright/codecs/amrnb/common/include \
frameworks/av/media/mtp \
frameworks/native/include/media/openmax \
+ $(call include-path-for, libhardware)/hardware \
+ system/media/camera/include \
$(PV_INCLUDES) \
$(JNI_H_INCLUDE) \
$(call include-path-for, corecg graphics)
diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp
index bdb07a6..7866df4 100644
--- a/media/jni/android_media_ImageReader.cpp
+++ b/media/jni/android_media_ImageReader.cpp
@@ -24,6 +24,7 @@
#include <gui/CpuConsumer.h>
#include <gui/Surface.h>
+#include <camera3.h>
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_view_Surface.h>
@@ -268,6 +269,29 @@ static int Image_getPixelFormat(JNIEnv* env, int format)
return format;
}
+static uint32_t Image_getJpegSize(CpuConsumer::LockedBuffer* buffer)
+{
+ ALOG_ASSERT(buffer != NULL, "Input buffer is NULL!!!");
+ uint32_t size = 0;
+ uint32_t width = buffer->width;
+ uint8_t* jpegBuffer = buffer->data;
+
+ // 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);
+ if (blob->jpeg_blob_id == CAMERA3_JPEG_BLOB_ID) {
+ size = blob->jpeg_size;
+ ALOGV("%s: Jpeg size = %d", __FUNCTION__, size);
+ }
+
+ // failed to find size, default to whole buffer
+ if (size == 0) {
+ size = width;
+ }
+
+ return size;
+}
+
static void Image_getLockedBufferInfo(JNIEnv* env, CpuConsumer::LockedBuffer* buffer, int idx,
uint8_t **base, uint32_t *size)
{
@@ -353,7 +377,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 = buffer->width;
+ dataSize = Image_getJpegSize(buffer);
break;
case HAL_PIXEL_FORMAT_RAW_SENSOR:
// Single plane 16bpp bayer data.
@@ -624,8 +648,17 @@ static jboolean 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->crop.getWidth() + 1;
- int outputHeight = buffer->crop.getHeight() + 1;
+ int outputWidth = buffer->width;
+ int outputHeight = buffer->height;
+
+ // Correct with/height when crop is set.
+ if (buffer->crop.getWidth() > 0) {
+ outputWidth = buffer->crop.getWidth() + 1;
+ }
+ if (buffer->crop.getHeight() > 0) {
+ outputHeight = buffer->crop.getHeight() + 1;
+ }
+
int imageReaderWidth = ctx->getBufferWidth();
int imageReaderHeight = ctx->getBufferHeight();
if ((imageReaderWidth != outputWidth) ||