From ad48d0f0807349dd0f8e8a584411f738d9cd2155 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Tue, 30 Jun 2009 16:07:21 -0700 Subject: [PATCH 1/2] libcamera: set antibanding to 60Hz, use cropping information on snapshot -- Set the antibanding to 60Hz for the US (Should be 50Hz for the rest of the world.) -- Save the cropping info returned when taking a picture and then pass it to the JPEG encoder. This enables digital zoom for JPEG images (cropping and upsampling). Signed-off-by: Iliyan Malchev --- libcamera2/QualcommCameraHardware.cpp | 26 +++++++++++++++++++------- libcamera2/QualcommCameraHardware.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libcamera2/QualcommCameraHardware.cpp b/libcamera2/QualcommCameraHardware.cpp index c5ca2cf..00ef2fa 100644 --- a/libcamera2/QualcommCameraHardware.cpp +++ b/libcamera2/QualcommCameraHardware.cpp @@ -262,6 +262,7 @@ QualcommCameraHardware::QualcommCameraHardware() { memset(&mZoom, 0, sizeof(mZoom)); memset(&mDimension, 0, sizeof(mDimension)); + memset(&mCrop, 0, sizeof(mCrop)); LOGV("constructor EX"); } @@ -502,12 +503,13 @@ static bool native_start_preview(int camfd) return true; } -static bool native_get_picture (int camfd) +static bool native_get_picture (int camfd, common_crop_t *crop) { struct msm_ctrl_cmd ctrlCmd; ctrlCmd.timeout_ms = 5000; - ctrlCmd.length = 0; + ctrlCmd.length = sizeof(common_crop_t); + ctrlCmd.value = crop; if(ioctl(camfd, MSM_CAM_IOCTL_GET_PICTURE, &ctrlCmd) < 0) { LOGE("native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd %d error %s", @@ -516,6 +518,18 @@ static bool native_get_picture (int camfd) return false; } + LOGV("crop: in1_w %d", crop->in1_w); + LOGV("crop: in1_h %d", crop->in1_h); + LOGV("crop: out1_w %d", crop->out1_w); + LOGV("crop: out1_h %d", crop->out1_h); + + LOGV("crop: in2_w %d", crop->in2_w); + LOGV("crop: in2_h %d", crop->in2_h); + LOGV("crop: out2_w %d", crop->out2_w); + LOGV("crop: out2_h %d", crop->out2_h); + + LOGV("crop: update %d", crop->update_flag); + return true; } @@ -608,14 +622,12 @@ bool QualcommCameraHardware::native_jpeg_encode(void) jpeg_set_location(); - static common_crop_t scale; // no scaling - if (!LINK_jpeg_encoder_encode(&mDimension, (uint8_t *)mThumbnailHeap->mHeap->base(), mThumbnailHeap->mHeap->getHeapID(), (uint8_t *)mRawHeap->mHeap->base(), mRawHeap->mHeap->getHeapID(), - &scale)) { + &mCrop)) { LOGE("native_jpeg_encode: jpeg_encoder_encode failed."); return false; } @@ -1572,7 +1584,7 @@ void QualcommCameraHardware::receiveRawPicture() Mutex::Autolock cbLock(&mCallbackLock); notifyShutter(); if (mRawPictureCallback != NULL) { - if(native_get_picture(mCameraControlFd)== false) { + if(native_get_picture(mCameraControlFd, &mCrop)== false) { LOGE("getPicture failed!"); return; } @@ -1700,7 +1712,7 @@ void QualcommCameraHardware::setAntiBanding(int camfd, const char *antibanding) antibandvalue = attr_lookup(anti_banding, antibanding, - CAMERA_ANTIBANDING_OFF); + CAMERA_ANTIBANDING_60HZ); ctrlCmd.value = (void *)&antibandvalue; LOGV("In setAntiBanding: match: %s: %d", antibanding, antibandvalue); diff --git a/libcamera2/QualcommCameraHardware.h b/libcamera2/QualcommCameraHardware.h index 2ab2384..1a55132 100644 --- a/libcamera2/QualcommCameraHardware.h +++ b/libcamera2/QualcommCameraHardware.h @@ -228,6 +228,8 @@ private: pthread_t mFrameThread; pthread_t mSnapshotThread; + common_crop_t mCrop; + struct msm_frame frames[kPreviewBufferCount]; bool mInPreviewCallback; }; From 04b2c40f3c18177563dc54175e02ee042ae3ddae Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Mon, 22 Jun 2009 23:23:37 +0800 Subject: [PATCH 2/2] Change the timing of shutter callback. --- libcamera2/QualcommCameraHardware.cpp | 24 ++++++++++++++++++++---- libcamera2/QualcommCameraHardware.h | 3 +-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/libcamera2/QualcommCameraHardware.cpp b/libcamera2/QualcommCameraHardware.cpp index 00ef2fa..e8c67dd 100644 --- a/libcamera2/QualcommCameraHardware.cpp +++ b/libcamera2/QualcommCameraHardware.cpp @@ -95,6 +95,7 @@ void (**LINK_mmcamera_camframe_callback)(struct msm_frame *frame); void (**LINK_mmcamera_jpegfragment_callback)(uint8_t *buff_ptr, uint32_t buff_size); void (**LINK_mmcamera_jpeg_callback)(jpeg_event_t status); +void (**LINK_mmcamera_shutter_callback)(); #else #define LINK_cam_conf cam_conf #define LINK_cam_frame cam_frame @@ -110,6 +111,7 @@ extern void (*mmcamera_camframe_callback)(struct msm_frame *frame); extern void (*mmcamera_jpegfragment_callback)(uint8_t *buff_ptr, uint32_t buff_size); extern void (*mmcamera_jpeg_callback)(jpeg_event_t status); +extern void (*mmcamera_shutter_callback)(); #endif } // extern "C" @@ -227,6 +229,7 @@ static Mutex singleton_lock; static void receive_camframe_callback(struct msm_frame *frame); static void receive_jpeg_fragment_callback(uint8_t *buff_ptr, uint32_t buff_size); static void receive_jpeg_callback(jpeg_event_t status); +static void receive_shutter_callback(); QualcommCameraHardware::QualcommCameraHardware() : mParameters(), @@ -355,6 +358,11 @@ void QualcommCameraHardware::startCamera() *LINK_mmcamera_jpeg_callback = receive_jpeg_callback; + *(void **)&LINK_mmcamera_shutter_callback = + ::dlsym(libmmcamera, "mmcamera_shutter_callback"); + + *LINK_mmcamera_shutter_callback = receive_shutter_callback; + *(void**)&LINK_jpeg_encoder_setMainImageQuality = ::dlsym(libmmcamera, "jpeg_encoder_setMainImageQuality"); @@ -373,6 +381,7 @@ void QualcommCameraHardware::startCamera() mmcamera_camframe_callback = receive_camframe_callback; mmcamera_jpegfragment_callback = receive_jpeg_fragment_callback; mmcamera_jpeg_callback = receive_jpeg_callback; + mmcamera_shutter_callback = receive_shutter_callback; #endif // DLOPEN_LIBMMCAMERA /* The control thread is in libcamera itself. */ @@ -1569,10 +1578,18 @@ bool QualcommCameraHardware::recordingEnabled() void QualcommCameraHardware::notifyShutter() { - LOGV("notifyShutter: E"); if (mShutterCallback) mShutterCallback(mPictureCallbackCookie); - LOGV("notifyShutter: X"); +} + +static void receive_shutter_callback() +{ + LOGV("receive_shutter_callback: E"); + sp obj = QualcommCameraHardware::getInstance(); + if (obj != 0) { + obj->notifyShutter(); + } + LOGV("receive_shutter_callback: X"); } void QualcommCameraHardware::receiveRawPicture() @@ -1580,9 +1597,8 @@ void QualcommCameraHardware::receiveRawPicture() LOGV("receiveRawPicture: E"); int ret,rc,rete; -// Temporary fix for multiple snapshot issue on 8k: disabling shutter callback + Mutex::Autolock cbLock(&mCallbackLock); - notifyShutter(); if (mRawPictureCallback != NULL) { if(native_get_picture(mCameraControlFd, &mCrop)== false) { LOGE("getPicture failed!"); diff --git a/libcamera2/QualcommCameraHardware.h b/libcamera2/QualcommCameraHardware.h index 1a55132..c647fcd 100644 --- a/libcamera2/QualcommCameraHardware.h +++ b/libcamera2/QualcommCameraHardware.h @@ -60,6 +60,7 @@ public: void receiveJpegPicture(void); void jpeg_set_location(); void receiveJpegPictureFragment(uint8_t *buf, uint32_t size); + void notifyShutter(); private: @@ -181,8 +182,6 @@ private: Mutex mLock; bool mReleasedRecordingFrame; - void notifyShutter(); - void receiveRawPicture(void); Mutex mCallbackLock;