Camera: Set the snapshot buffer offsets and size as required for the gemini offline
encoder.
Get the required Y offcet, CbCr offset and the rawHeap size from the
encoder and use the same while registering the buffer with driver, as
part of gemini offline encoder requirement for different rotation values.
Change-Id: Ie1d218af7ba397ee192f0b5e62848e335fd2cc64
diff --git a/QualcommCameraHardware.cpp b/QualcommCameraHardware.cpp
index dbd116a..a510ba1 100644
--- a/QualcommCameraHardware.cpp
+++ b/QualcommCameraHardware.cpp
@@ -101,6 +101,10 @@
int8_t (*LINK_jpeg_encoder_setMainImageQuality)(uint32_t quality);
int8_t (*LINK_jpeg_encoder_setThumbnailQuality)(uint32_t quality);
int8_t (*LINK_jpeg_encoder_setRotation)(uint32_t rotation);
+int8_t (*LINK_jpeg_encoder_get_buffer_offset)(uint32_t width, uint32_t height,
+ uint32_t* p_y_offset,
+ uint32_t* p_cbcr_offset,
+ uint32_t* p_buf_size);
int8_t (*LINK_jpeg_encoder_setLocation)(const camera_position_type *location);
const struct camera_size_type *(*LINK_default_sensor_get_snapshot_sizes)(int *len);
int (*LINK_launch_cam_conf_thread)(void);
@@ -125,6 +129,7 @@
#define LINK_jpeg_encoder_setMainImageQuality jpeg_encoder_setMainImageQuality
#define LINK_jpeg_encoder_setThumbnailQuality jpeg_encoder_setThumbnailQuality
#define LINK_jpeg_encoder_setRotation jpeg_encoder_setRotation
+#define LINK_jpeg_encoder_get_buffer_offset jpeg_encoder_get_buffer_offset
#define LINK_jpeg_encoder_setLocation jpeg_encoder_setLocation
#define LINK_default_sensor_get_snapshot_sizes default_sensor_get_snapshot_sizes
#define LINK_launch_cam_conf_thread launch_cam_conf_thread
@@ -1251,6 +1256,9 @@
*(void**)&LINK_jpeg_encoder_setRotation =
::dlsym(libmmcamera, "jpeg_encoder_setRotation");
+ *(void**)&LINK_jpeg_encoder_get_buffer_offset =
+ ::dlsym(libmmcamera, "jpeg_encoder_get_buffer_offset");
+
/* Disabling until support is available.
*(void**)&LINK_jpeg_encoder_setLocation =
::dlsym(libmmcamera, "jpeg_encoder_setLocation");
@@ -1859,12 +1867,14 @@
}
}
- int rotation = mParameters.getInt("rotation");
- if (rotation >= 0) {
- LOGV("native_jpeg_encode, rotation = %d", rotation);
- if(!LINK_jpeg_encoder_setRotation(rotation)) {
- LOGE("native_jpeg_encode set rotation failed");
- return false;
+ if(mCurrentTarget != TARGET_MSM7630) {
+ int rotation = mParameters.getInt("rotation");
+ if (rotation >= 0) {
+ LOGV("native_jpeg_encode, rotation = %d", rotation);
+ if(!LINK_jpeg_encoder_setRotation(rotation)) {
+ LOGE("native_jpeg_encode set rotation failed");
+ return false;
+ }
}
}
@@ -2179,6 +2189,7 @@
int cnt = 0;
mPreviewFrameSize = previewWidth * previewHeight * 3/2;
+ int CbCrOffset = PAD_TO_WORD(previewWidth * previewHeight);
dstOffset = 0;
mPreviewHeap = new PmemPool("/dev/pmem_adsp",
MemoryHeapBase::READ_ONLY | MemoryHeapBase::NO_CACHING,
@@ -2187,6 +2198,8 @@
mPreviewFrameSize,
kPreviewBufferCountActual,
mPreviewFrameSize,
+ CbCrOffset,
+ 0,
"preview");
if (!mPreviewHeap->initialized()) {
@@ -2207,6 +2220,8 @@
mPreviewFrameSize,
1,
mPreviewFrameSize,
+ CbCrOffset,
+ 0,
"postview");
if (!mPostViewHeap->initialized()) {
@@ -2235,7 +2250,7 @@
frames[cnt].buffer =
(uint32_t)mPreviewHeap->mHeap->base() + mPreviewHeap->mAlignedBufferSize * cnt;
frames[cnt].y_off = 0;
- frames[cnt].cbcr_off = previewWidth * previewHeight;
+ frames[cnt].cbcr_off = CbCrOffset;
frames[cnt].path = OUTPUT_TYPE_P; // MSM_FRAME_ENC;
}
@@ -2321,6 +2336,8 @@
rawSnapshotSize,
1,
rawSnapshotSize,
+ 0,
+ 0,
"raw pmem snapshot camera");
if (!mRawSnapShotPmemHeap->initialized()) {
@@ -2371,7 +2388,8 @@
thumbnailBufferSize = mDimension.ui_thumbnail_width *
mDimension.ui_thumbnail_height * 3 / 2;
-
+ int CbCrOffsetThumb = PAD_TO_WORD(mDimension.ui_thumbnail_width *
+ mDimension.ui_thumbnail_height);
// mDimension will be filled with thumbnail_width, thumbnail_height,
// orig_picture_dx, and orig_picture_dy after this function call. We need to
// keep it for jpeg_encoder_encode.
@@ -2389,12 +2407,32 @@
// Snapshot
mRawSize = rawWidth * rawHeight * 3 / 2;
+ int CbCrOffsetRaw = PAD_TO_WORD(rawWidth * rawHeight);
if( mCurrentTarget == TARGET_MSM7627 )
mJpegMaxSize = CEILING16(rawWidth) * CEILING16(rawHeight) * 3 / 2;
else
mJpegMaxSize = rawWidth * rawHeight * 3 / 2;
+ //For offline jpeg hw encoder, jpeg encoder will provide us the
+ //required offsets and buffer size depending on the rotation.
+ int yOffset = 0;
+ if( mCurrentTarget == TARGET_MSM7630 ) {
+ int rotation = mParameters.getInt("rotation");
+ if (rotation >= 0) {
+ LOGV("initRaw, jpeg_rotation = %d", rotation);
+ if(!LINK_jpeg_encoder_setRotation(rotation)) {
+ LOGE("native_jpeg_encode set rotation failed");
+ return false;
+ }
+ }
+ LINK_jpeg_encoder_get_buffer_offset(rawWidth, rawHeight, (uint32_t *)&yOffset,
+ (uint32_t *)&CbCrOffsetRaw, (uint32_t *)&mRawSize);
+ LOGV("initRaw: yOffset = %d, CbCrOffsetRaw = %d, mRawSize = %d",
+ yOffset, CbCrOffsetRaw, mRawSize);
+ mJpegMaxSize = mRawSize;
+ }
+
LOGV("initRaw: initializing mRawHeap.");
mRawHeap =
new PmemPool("/dev/pmem_adsp",
@@ -2404,6 +2442,8 @@
mJpegMaxSize,
kRawBufferCount,
mRawSize,
+ CbCrOffsetRaw,
+ yOffset,
"snapshot camera");
if (!mRawHeap->initialized()) {
@@ -2443,6 +2483,8 @@
thumbnailBufferSize,
1,
thumbnailBufferSize,
+ CbCrOffsetThumb,
+ 0,
"thumbnail");
if (!mThumbnailHeap->initialized()) {
@@ -3375,6 +3417,7 @@
else
pmem_region = "/dev/pmem_adsp";
+ int CbCrOffset = PAD_TO_WORD(mDimension.video_width * mDimension.video_height);
mRecordHeap = new PmemPool(pmem_region,
MemoryHeapBase::READ_ONLY | MemoryHeapBase::NO_CACHING,
mCameraControlFd,
@@ -3382,6 +3425,8 @@
mRecordFrameSize,
kRecordBufferCount,
mRecordFrameSize,
+ CbCrOffset,
+ 0,
"record");
if (!mRecordHeap->initialized()) {
@@ -4466,6 +4511,8 @@
static bool register_buf(int camfd,
int size,
int frame_size,
+ int cbcr_offset,
+ int yoffset,
int pmempreviewfd,
uint32_t offset,
uint8_t *buf,
@@ -4478,13 +4525,15 @@
int camera_control_fd,
int pmem_type,
int buffer_size, int num_buffers,
- int frame_size,
- const char *name) :
+ int frame_size, int cbcr_offset,
+ int yOffset, const char *name) :
QualcommCameraHardware::MemPool(buffer_size,
num_buffers,
frame_size,
name),
mPmemType(pmem_type),
+ mCbCrOffset(cbcr_offset),
+ myOffset(yOffset),
mCameraControlFd(dup(camera_control_fd))
{
LOGV("constructing MemPool %s backed by pmem pool %s: "
@@ -4549,7 +4598,7 @@
}
register_buf(mCameraControlFd,
mBufferSize,
- mFrameSize,
+ mFrameSize, mCbCrOffset, myOffset,
mHeap->getHeapID(),
mAlignedBufferSize * cnt,
(uint8_t *)mHeap->base() + mAlignedBufferSize * cnt,
@@ -4578,6 +4627,8 @@
register_buf(mCameraControlFd,
mBufferSize,
mFrameSize,
+ mCbCrOffset,
+ myOffset,
mHeap->getHeapID(),
mAlignedBufferSize * cnt,
(uint8_t *)mHeap->base() + mAlignedBufferSize * cnt,
@@ -4606,6 +4657,8 @@
static bool register_buf(int camfd,
int size,
int frame_size,
+ int cbcr_offset,
+ int yoffset,
int pmempreviewfd,
uint32_t offset,
uint8_t *buf,
@@ -4620,12 +4673,8 @@
pmemBuf.offset = offset;
pmemBuf.len = size;
pmemBuf.vaddr = buf;
- pmemBuf.y_off = 0;
-
- if(pmem_type == MSM_PMEM_RAW_MAINIMG)
- pmemBuf.cbcr_off = 0;
- else
- pmemBuf.cbcr_off = PAD_TO_WORD(frame_size * 2 / 3);
+ pmemBuf.y_off = yoffset;
+ pmemBuf.cbcr_off = cbcr_offset;
pmemBuf.active = vfe_can_write;
diff --git a/QualcommCameraHardware.h b/QualcommCameraHardware.h
index 0a51f9d..9404c29 100644
--- a/QualcommCameraHardware.h
+++ b/QualcommCameraHardware.h
@@ -172,11 +172,13 @@
PmemPool(const char *pmem_pool,
int control_camera_fd, int flags, int pmem_type,
int buffer_size, int num_buffers,
- int frame_size,
- const char *name);
+ int frame_size, int cbcr_offset,
+ int yoffset, const char *name);
virtual ~PmemPool();
int mFd;
int mPmemType;
+ int mCbCrOffset;
+ int myOffset;
int mCameraControlFd;
uint32_t mAlignedSize;
struct pmem_region mSize;