mirror of
https://github.com/team-infusion-developers/android_hardware_samsung.git
synced 2024-11-01 15:56:32 +00:00
exynos3: libs3cjpeg: read memory configuration from kernel
This improves the flexibility (not all devices have the same FFC resolution) and also allows optimization of memory usage. We currently allocate 4 MB to the hardware JPEG encoder, but only 1 MB is actually needed if it's only used for encoding VGA images. Note that the thumbnail encoding function of the kernel driver is not used. This patch is backward compatible with older kernels, but patching is recommended. Cherry-pick the following commits: http://review.cyanogenmod.org/56791 http://review.cyanogenmod.org/56792 Change-Id: I0e89b24e56b99e8e27f5a38d5c158b23021ed035
This commit is contained in:
parent
2fccbdf3da
commit
674a4f10ca
2 changed files with 48 additions and 9 deletions
|
@ -44,8 +44,28 @@ JpegEncoder::JpegEncoder() : available(false)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be exactly 0, legacy kernel will return 1 despite
|
||||||
|
// the IOCTL being invalid
|
||||||
|
if (ioctl(mDevFd, IOCTL_JPG_GET_INFO, &mInfo) != 0) {
|
||||||
|
#ifdef LEGACY_SUPPORT
|
||||||
|
ALOGW("Unable to read driver info. Using legacy values.");
|
||||||
|
mInfo.frame_buf_size = JPG_FRAME_BUF_SIZE;
|
||||||
|
mInfo.thumb_frame_buf_size = JPG_FRAME_THUMB_BUF_SIZE;
|
||||||
|
mInfo.stream_buf_size = JPG_STREAM_BUF_SIZE;
|
||||||
|
mInfo.thumb_stream_buf_size = JPG_STREAM_THUMB_BUF_SIZE;
|
||||||
|
mInfo.total_buf_size = JPG_TOTAL_BUF_SIZE;
|
||||||
|
mInfo.max_width = MAX_JPG_WIDTH;
|
||||||
|
mInfo.max_height = MAX_JPG_HEIGHT;
|
||||||
|
mInfo.max_thumb_width = MAX_JPG_THUMBNAIL_WIDTH;
|
||||||
|
mInfo.max_thumb_height = MAX_JPG_THUMBNAIL_HEIGHT;
|
||||||
|
#else
|
||||||
|
ALOGE("Unable to read driver info.");
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
mArgs.mmapped_addr = (char *)mmap(0,
|
mArgs.mmapped_addr = (char *)mmap(0,
|
||||||
JPG_TOTAL_BUF_SIZE,
|
mInfo.total_buf_size,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED,
|
MAP_SHARED,
|
||||||
mDevFd,
|
mDevFd,
|
||||||
|
@ -82,7 +102,7 @@ JpegEncoder::JpegEncoder() : available(false)
|
||||||
JpegEncoder::~JpegEncoder()
|
JpegEncoder::~JpegEncoder()
|
||||||
{
|
{
|
||||||
if (mArgs.mmapped_addr != (char*)MAP_FAILED)
|
if (mArgs.mmapped_addr != (char*)MAP_FAILED)
|
||||||
munmap(mArgs.mmapped_addr, JPG_TOTAL_BUF_SIZE);
|
munmap(mArgs.mmapped_addr, mInfo.total_buf_size);
|
||||||
|
|
||||||
delete mArgs.enc_param;
|
delete mArgs.enc_param;
|
||||||
|
|
||||||
|
@ -101,14 +121,14 @@ jpg_return_status JpegEncoder::setConfig(jpeg_conf type, int32_t value)
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case JPEG_SET_ENCODE_WIDTH:
|
case JPEG_SET_ENCODE_WIDTH:
|
||||||
if (value < 0 || value > MAX_JPG_WIDTH)
|
if (value < 0 || value > mInfo.max_width)
|
||||||
ret = JPG_FAIL;
|
ret = JPG_FAIL;
|
||||||
else
|
else
|
||||||
mArgs.enc_param->width = value;
|
mArgs.enc_param->width = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JPEG_SET_ENCODE_HEIGHT:
|
case JPEG_SET_ENCODE_HEIGHT:
|
||||||
if (value < 0 || value > MAX_JPG_HEIGHT)
|
if (value < 0 || value > mInfo.max_height)
|
||||||
ret = JPG_FAIL;
|
ret = JPG_FAIL;
|
||||||
else
|
else
|
||||||
mArgs.enc_param->height = value;
|
mArgs.enc_param->height = value;
|
||||||
|
@ -140,14 +160,14 @@ jpg_return_status JpegEncoder::setConfig(jpeg_conf type, int32_t value)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JPEG_SET_THUMBNAIL_WIDTH:
|
case JPEG_SET_THUMBNAIL_WIDTH:
|
||||||
if (value < 0 || value > MAX_JPG_THUMBNAIL_WIDTH)
|
if (value < 0 || value > mInfo.max_thumb_width)
|
||||||
ret = JPG_FAIL;
|
ret = JPG_FAIL;
|
||||||
else
|
else
|
||||||
mArgs.thumb_enc_param->width = value;
|
mArgs.thumb_enc_param->width = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JPEG_SET_THUMBNAIL_HEIGHT:
|
case JPEG_SET_THUMBNAIL_HEIGHT:
|
||||||
if (value < 0 || value > MAX_JPG_THUMBNAIL_HEIGHT)
|
if (value < 0 || value > mInfo.max_thumb_height)
|
||||||
ret = JPG_FAIL;
|
ret = JPG_FAIL;
|
||||||
else
|
else
|
||||||
mArgs.thumb_enc_param->height = value;
|
mArgs.thumb_enc_param->height = value;
|
||||||
|
@ -169,7 +189,7 @@ void* JpegEncoder::getInBuf(uint64_t size)
|
||||||
if (!available)
|
if (!available)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (size > JPG_FRAME_BUF_SIZE) {
|
if (size > mInfo.frame_buf_size) {
|
||||||
ALOGE("The buffer size requested is too large");
|
ALOGE("The buffer size requested is too large");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +216,7 @@ void* JpegEncoder::getThumbInBuf(uint64_t size)
|
||||||
if (!available)
|
if (!available)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (size > JPG_FRAME_THUMB_BUF_SIZE) {
|
if (size > mInfo.thumb_frame_buf_size) {
|
||||||
ALOGE("The buffer size requested is too large");
|
ALOGE("The buffer size requested is too large");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +279,7 @@ jpg_return_status JpegEncoder::encode(unsigned int *size, exif_attribute_t *exif
|
||||||
bufSize = EXIF_FILE_SIZE;
|
bufSize = EXIF_FILE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mArgs.enc_param->file_size + bufSize > JPG_TOTAL_BUF_SIZE)
|
if (mArgs.enc_param->file_size + bufSize > mInfo.total_buf_size)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
exifOut = new unsigned char[bufSize];
|
exifOut = new unsigned char[bufSize];
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
#include "Exif.h"
|
#include "Exif.h"
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
|
#define LEGACY_SUPPORT
|
||||||
|
#ifdef LEGACY_SUPPORT
|
||||||
|
|
||||||
#define MAX_JPG_WIDTH 800
|
#define MAX_JPG_WIDTH 800
|
||||||
#define MAX_JPG_HEIGHT 480
|
#define MAX_JPG_HEIGHT 480
|
||||||
#define MAX_JPG_RESOLUTION (MAX_JPG_WIDTH * MAX_JPG_HEIGHT)
|
#define MAX_JPG_RESOLUTION (MAX_JPG_WIDTH * MAX_JPG_HEIGHT)
|
||||||
|
@ -66,6 +70,7 @@ namespace android {
|
||||||
#define IMG_MAIN_START (JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE)
|
#define IMG_MAIN_START (JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE)
|
||||||
#define IMG_THUMB_START (IMG_MAIN_START + JPG_FRAME_BUF_SIZE)
|
#define IMG_THUMB_START (IMG_MAIN_START + JPG_FRAME_BUF_SIZE)
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
#endif
|
||||||
|
|
||||||
#define JPG_DRIVER_NAME "/dev/s3c-jpg"
|
#define JPG_DRIVER_NAME "/dev/s3c-jpg"
|
||||||
|
|
||||||
|
@ -78,6 +83,7 @@ namespace android {
|
||||||
#define IOCTL_JPG_GET_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 6)
|
#define IOCTL_JPG_GET_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 6)
|
||||||
#define IOCTL_JPG_GET_PHY_FRMBUF _IO(JPEG_IOCTL_MAGIC, 7)
|
#define IOCTL_JPG_GET_PHY_FRMBUF _IO(JPEG_IOCTL_MAGIC, 7)
|
||||||
#define IOCTL_JPG_GET_PHY_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 8)
|
#define IOCTL_JPG_GET_PHY_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 8)
|
||||||
|
#define IOCTL_JPG_GET_INFO _IO(JPEG_IOCTL_MAGIC, 9)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JPEG_SET_ENCODE_WIDTH,
|
JPEG_SET_ENCODE_WIDTH,
|
||||||
|
@ -181,6 +187,18 @@ typedef struct {
|
||||||
jpg_enc_proc_param *thumb_enc_param;
|
jpg_enc_proc_param *thumb_enc_param;
|
||||||
} jpg_args;
|
} jpg_args;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int frame_buf_size;
|
||||||
|
unsigned int thumb_frame_buf_size;
|
||||||
|
unsigned int stream_buf_size;
|
||||||
|
unsigned int thumb_stream_buf_size;
|
||||||
|
unsigned int total_buf_size;
|
||||||
|
int max_width;
|
||||||
|
int max_height;
|
||||||
|
int max_thumb_width;
|
||||||
|
int max_thumb_height;
|
||||||
|
} jpg_info;
|
||||||
|
|
||||||
class JpegEncoder {
|
class JpegEncoder {
|
||||||
public:
|
public:
|
||||||
JpegEncoder();
|
JpegEncoder();
|
||||||
|
@ -232,6 +250,7 @@ private:
|
||||||
unsigned char *start);
|
unsigned char *start);
|
||||||
int mDevFd;
|
int mDevFd;
|
||||||
jpg_args mArgs;
|
jpg_args mArgs;
|
||||||
|
jpg_info mInfo;
|
||||||
|
|
||||||
bool available;
|
bool available;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue