Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 534046d2 authored by Zhijun He's avatar Zhijun He
Browse files

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
parent 7601e31d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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)
+36 −3
Original line number Diff line number Diff line
@@ -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) ||