From 7becc902391c0eda4bd26ca00c42cd3d9cb9f3d8 Mon Sep 17 00:00:00 2001 From: KalimochoAz Date: Wed, 9 Feb 2011 18:58:14 +0100 Subject: [PATCH] Camera driver modifications Added to build jpeg in driver so now allows all android fuctionality Removed iLog Modified credits Change-Id: I15e10121ed364032ff789a263cb0f1eb8385b61b --- libcamera/Android.mk | 13 +- libcamera/QualcommCameraHardware.cpp | 433 ++++++++++++--------------- libcamera/QualcommCameraHardware.h | 20 +- libcamera/jdatadst.cpp | 186 ++++++++++++ libcamera/jdatadst.h | 53 ++++ libcamera/jpegConvert.cpp | 167 +++++++++++ libcamera/jpegConvert.h | 60 ++++ libcamera/raw2jpeg.h | 1 + 8 files changed, 670 insertions(+), 263 deletions(-) create mode 100644 libcamera/jdatadst.cpp create mode 100644 libcamera/jdatadst.h create mode 100644 libcamera/jpegConvert.cpp create mode 100644 libcamera/jpegConvert.h create mode 100644 libcamera/raw2jpeg.h diff --git a/libcamera/Android.mk b/libcamera/Android.mk index 4e1c60a..fe3d95b 100644 --- a/libcamera/Android.mk +++ b/libcamera/Android.mk @@ -13,17 +13,18 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS:=optional -LOCAL_SRC_FILES:= QualcommCameraHardware.cpp exifwriter.c +LOCAL_SRC_FILES:= QualcommCameraHardware.cpp exifwriter.c jdatadst.cpp jpegConvert.cpp LOCAL_CFLAGS:= -DDLOPEN_LIBMMCAMERA=$(DLOPEN_LIBMMCAMERA) LOCAL_C_INCLUDES+= \ - vendor/qcom/proprietary/mm-camera/common \ - vendor/qcom/proprietary/mm-camera/apps/appslib \ - external/jhead \ - vendor/qcom/proprietary/mm-camera/jpeg/inc + vendor/qcom/proprietary/mm-camera/common \ + vendor/qcom/proprietary/mm-camera/apps/appslib \ + external/jhead \ + external/jpeg \ + vendor/qcom/proprietary/mm-camera/jpeg/inc -LOCAL_SHARED_LIBRARIES:= libbinder libutils libcamera_client liblog +LOCAL_SHARED_LIBRARIES:= libbinder libutils libcamera_client liblog libjpeg ifneq ($(DLOPEN_LIBMMCAMERA),1) LOCAL_SHARED_LIBRARIES+= libmmcamera libmm-qcamera-tgt diff --git a/libcamera/QualcommCameraHardware.cpp b/libcamera/QualcommCameraHardware.cpp index c3e5f2f..15cd54b 100644 --- a/libcamera/QualcommCameraHardware.cpp +++ b/libcamera/QualcommCameraHardware.cpp @@ -30,12 +30,11 @@ #include #endif #include +#include "raw2jpeg.h" #define LIKELY(exp) __builtin_expect(!!(exp), 1) #define UNLIKELY(exp) __builtin_expect(!!(exp), 0) -#define iLog(fmt, args...) LOGD(fmt, ##args) // enable debug - extern "C" { #include "exifwriter.h" @@ -62,10 +61,8 @@ extern "C" { #define THUMBNAIL_HEIGHT 384 #define THUMBNAIL_WIDTH_STR "512" #define THUMBNAIL_HEIGHT_STR "384" -//#define DEFAULT_PICTURE_WIDTH 2048 -//#define DEFAULT_PICTURE_HEIGHT 1536 -#define DEFAULT_PICTURE_WIDTH 1024 -#define DEFAULT_PICTURE_HEIGHT 768 +#define DEFAULT_PICTURE_WIDTH 2048 +#define DEFAULT_PICTURE_HEIGHT 1536 #define THUMBNAIL_BUFFER_SIZE (THUMBNAIL_WIDTH * THUMBNAIL_HEIGHT * 3/2) #define DEFAULT_PREVIEW_SETTING 5 // QVGA #define DEFAULT_FRAMERATE 15 @@ -80,11 +77,7 @@ void* (*LINK_cam_conf)(void *data); void* (*LINK_cam_frame)(void *data); bool (*LINK_jpeg_encoder_init)(); void (*LINK_jpeg_encoder_join)(); -/*bool (*LINK_jpeg_encoder_encode)(const cam_ctrl_dimension_t *dimen, - const uint8_t *thumbnailbuf, int thumbnailfd, - const uint8_t *snapshotbuf, int snapshotfd, - common_crop_t *scaling_parms);*/ -unsigned char (*LINK_jpeg_encoder_encode)(const char* file_name, const cam_ctrl_dimension_t *dimen, +unsigned char (*LINK_jpeg_encoder_encode)(const char* file_name, const cam_ctrl_dimension_t *dimen, const unsigned char* thumbnailbuf, int thumbnailfd, const unsigned char* snapshotbuf, int snapshotfd, common_crop_t *cropInfo); int (*LINK_camframe_terminate)(void); @@ -235,7 +228,7 @@ void *opencamerafd(void *arg) { if (camerafd < 0) LOGE("Camera control %s open failed: %s!", MSM_CAMERA_CONTROL, strerror(errno)); else - iLog("opening %s fd: %d", MSM_CAMERA_CONTROL, camerafd); + LOGV("opening %s fd: %d", MSM_CAMERA_CONTROL, camerafd); return NULL; } @@ -270,14 +263,14 @@ QualcommCameraHardware::QualcommCameraHardware() } memset(&mDimension, 0, sizeof(mDimension)); memset(&mCrop, 0, sizeof(mCrop)); - iLog("constructor EX"); + LOGV("constructor EX"); } void QualcommCameraHardware::initDefaultParameters() { CameraParameters p; - iLog("initDefaultParameters E"); + LOGV("initDefaultParameters E"); preview_size_type *ps = &preview_sizes[DEFAULT_PREVIEW_SETTING]; p.setPreviewSize(ps->width, ps->height); @@ -324,7 +317,7 @@ void QualcommCameraHardware::initDefaultParameters() LOGE("Failed to set default parameters?!"); } - iLog("initDefaultParameters X"); + LOGV("initDefaultParameters X"); } @@ -368,17 +361,17 @@ void QualcommCameraHardware::startCamera() { unsigned char sync_value; - iLog("startCamera E"); + LOGV("startCamera E"); #if DLOPEN_LIBMMCAMERA libmmcamera = ::dlopen("libmmcamera.so", RTLD_NOW); - iLog("loading libmmcamera at %p", libmmcamera); + LOGV("loading libmmcamera at %p", libmmcamera); if (!libmmcamera) { LOGE("FATAL ERROR: could not dlopen liboemcamera.so: %s", dlerror()); return; } libmmcamera_target = ::dlopen("libmm-qcamera-tgt.so", RTLD_NOW); - iLog("loading libmm-qcamera-tgt at %p", libmmcamera_target); + LOGV("loading libmm-qcamera-tgt at %p", libmmcamera_target); if (!libmmcamera_target) { LOGE("FATAL ERROR: could not dlopen libmm-qcamera_target.so: %s", dlerror()); return; @@ -399,13 +392,9 @@ void QualcommCameraHardware::startCamera() *(void **)&LINK_jpeg_encoder_join = ::dlsym(libmmcamera, "jpeg_encoder_join"); -// *(void **)&LINK_mmcamera_camframe_callback = -// ::dlsym(libmmcamera, "mmframe_cb"); - *(void **)&LINK_mmcamera_camframe_callback = ::dlsym(libmmcamera, "mmframe_cb"); - *LINK_mmcamera_camframe_callback = receive_camframe_callback; *(void **)&LINK_mmcamera_jpegfragment_callback = @@ -430,7 +419,7 @@ void QualcommCameraHardware::startCamera() #endif // DLOPEN_LIBMMCAMERA /* The control thread is in libcamera itself. */ - iLog("pthread_join on control thread"); + LOGV("pthread_join on control thread"); if (pthread_join(w_thread, NULL) != 0) { LOGE("Camera open thread exit failed"); return; @@ -445,9 +434,9 @@ void QualcommCameraHardware::startCamera() if ((pthread_create(&mCamConfigThread, NULL, LINK_cam_conf, NULL)) != 0) LOGE("Config thread creation failed!"); else - iLog("cam_conf thread created"); + LOGV("cam_conf thread created"); - iLog("startCamera X"); + LOGV("startCamera X"); } status_t QualcommCameraHardware::dump(int fd, @@ -501,7 +490,7 @@ static bool native_set_afmode(int camfd, isp3a_af_mode_t af_type) camfd, strerror(errno)); - iLog("native_set_afmode: ctrlCmd.status == %d\n", ctrlCmd.status); + LOGV("native_set_afmode: ctrlCmd.status == %d\n", ctrlCmd.status); return rc >= 0 && ctrlCmd.status == CAMERA_EXIT_CB_DONE; } @@ -529,12 +518,15 @@ static bool native_start_preview(int camfd) ctrlCmd.type = CAMERA_START_PREVIEW; ctrlCmd.length = 0; + LOGV("Kalim: Iniciado Start_preview EEEEEEEEEEEEEEEEEEEEEE"); + if (ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) { LOGE("native_start_preview: MSM_CAM_IOCTL_CTRL_COMMAND fd %d error %s", camfd, strerror(errno)); return false; } + LOGV("Kalim: Finalizado Start_preview XXXXXXXXXXXXXXXXXXXX"); return true; } @@ -554,17 +546,17 @@ static bool native_get_picture(int camfd, common_crop_t *crop) return false; } - iLog("crop: in1_w %d", crop->in1_w); - iLog("crop: in1_h %d", crop->in1_h); - iLog("crop: out1_w %d", crop->out1_w); - iLog("crop: out1_h %d", crop->out1_h); + 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); - iLog("crop: in2_w %d", crop->in2_w); - iLog("crop: in2_h %d", crop->in2_h); - iLog("crop: out2_w %d", crop->out2_w); - iLog("crop: out2_h %d", crop->out2_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); - iLog("crop: update %d", crop->update_flag); + LOGV("crop: update %d", crop->update_flag); return true; @@ -577,12 +569,15 @@ static bool native_stop_preview(int camfd) ctrlCmd.type = CAMERA_STOP_PREVIEW; ctrlCmd.length = 0; + LOGV("Kalim: Iniciado Stop_preview EEEEEEEEEEEEEEEEEEEEEE"); + if(ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) { LOGE("native_stop_preview: ioctl fd %d error %s", camfd, strerror(errno)); return false; } + LOGV("Kalim: Finalizado Start_preview XXXXXXXXXXXXXXXXXXXXXX"); return true; } @@ -623,7 +618,7 @@ static bool native_stop_snapshot (int camfd) return true; } -void *jpeg_encoder_thread( void *user ) +void *jpeg_encoder_thread( void *user ) { LOGD("jpeg_encoder_thread E"); sp obj = QualcommCameraHardware::getInstance(); @@ -640,7 +635,7 @@ bool QualcommCameraHardware::native_jpeg_encode(void) { int jpeg_quality = mParameters.getInt("jpeg-quality"); if (jpeg_quality >= 0) { - iLog("native_jpeg_encode, current jpeg main img quality =%d", + LOGV("native_jpeg_encode, current jpeg main img quality =%d", jpeg_quality); if(!LINK_jpeg_encoder_setMainImageQuality(jpeg_quality)) { LOGE("native_jpeg_encode set jpeg-quality failed"); @@ -650,13 +645,13 @@ bool QualcommCameraHardware::native_jpeg_encode(void) int thumbnail_quality = mParameters.getInt("jpeg-thumbnail-quality"); if (thumbnail_quality >= 0) { - iLog("native_jpeg_encode, current jpeg thumbnail quality =%d", + LOGV("native_jpeg_encode, current jpeg thumbnail quality =%d", thumbnail_quality); } int rotation = mParameters.getInt("rotation"); if (rotation >= 0) { - iLog("native_jpeg_encode, rotation = %d", rotation); + LOGV("native_jpeg_encode, rotation = %d", rotation); } char jpegFileName[256] = {0}; static int snapshotCntr = 0; @@ -666,7 +661,7 @@ bool QualcommCameraHardware::native_jpeg_encode(void) // ******************************** SACADO DE NOPY ********************************************* - iLog("picture_width %d, picture_height = %d, display_width = %d, display_height = %d, filler = %d, filler2 = %d, ui_thumbnail_height = %d , ui_thumbnail_width = %d, filler3 = %d, filler4 = %d, filler5 = %d, filler6 = %d, filler7 = %d, filler8 = %d\n" , + LOGV("picture_width %d, picture_height = %d, display_width = %d, display_height = %d, filler = %d, filler2 = %d, ui_thumbnail_height = %d , ui_thumbnail_width = %d, filler3 = %d, filler4 = %d, filler5 = %d, filler6 = %d, filler7 = %d, filler8 = %d\n" , mDimension.picture_width,mDimension.picture_height, mDimension.display_width,mDimension.display_height, mDimension.filler, mDimension.filler2, @@ -686,38 +681,15 @@ bool QualcommCameraHardware::native_jpeg_encode(void) NULL); // ********************************************************************************************* -/* sprintf(jpegFileName, "snapshot_%d.jpg", ++snapshotCntr); - if ( !LINK_jpeg_encoder_encode(jpegFileName, &mDimension, - (uint8_t *)mThumbnailHeap->mHeap->base(), mThumbnailHeap->mHeap->getHeapID(), - (uint8_t *)mRawHeap->mHeap->base(), mRawHeap->mHeap->getHeapID(), - &mCrop)) { - LOGE("native_jpeg_encode:%d@%s: jpeg_encoder_encode failed.\n", __LINE__, __FILE__); - return false; - }*/ - - -/* jpeg_set_location(); - - if (!LINK_jpeg_encoder_encode(&mDimension, - (uint8_t *)mThumbnailHeap->mHeap->base(), - mThumbnailHeap->mHeap->getHeapID(), - (uint8_t *)mRawHeap->mHeap->base(), - mRawHeap->mHeap->getHeapID(), - &mCrop)) { - //LOGE("native_jpeg_encode: jpeg_encoder_encode failed."); - iLog("FAKE ENCODER "); - return true; - // FAKE return false; - }*/ return true; } bool QualcommCameraHardware::native_set_dimension(cam_ctrl_dimension_t *value) { - iLog("native_set_dimension: E"); + LOGV("native_set_dimension: E"); return native_set_parm(CAMERA_SET_PARM_DIMENSION, sizeof(cam_ctrl_dimension_t), value); - iLog("native_set_dimension: X"); + LOGV("native_set_dimension: X"); } bool QualcommCameraHardware::native_set_parm( @@ -731,7 +703,7 @@ bool QualcommCameraHardware::native_set_parm( ctrlCmd.length = length; ctrlCmd.value = value; - iLog("native_set_parm: type: %d, length=%d", type, length); + LOGV("native_set_parm: type: %d, length=%d", type, length); rc = ioctl(mCameraControlFd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd); if(rc < 0 || ctrlCmd.status != CAM_CTRL_SUCCESS) { @@ -750,7 +722,7 @@ void QualcommCameraHardware::jpeg_set_location() #define PARSE_LOCATION(what,type,fmt,desc) do { \ pt.what = 0; \ const char *what##_str = mParameters.get("gps-"#what); \ - iLog("GPS PARM %s --> [%s]", "gps-"#what, what##_str); \ + LOGV("GPS PARM %s --> [%s]", "gps-"#what, what##_str); \ if (what##_str) { \ type what = 0; \ if (sscanf(what##_str, fmt, &what) == 1) \ @@ -762,7 +734,7 @@ void QualcommCameraHardware::jpeg_set_location() } \ } \ else { \ - iLog("GPS " #what " not specified: " \ + LOGV("GPS " #what " not specified: " \ "defaulting to zero in EXIF header."); \ encode_location = false; \ } \ @@ -780,12 +752,12 @@ void QualcommCameraHardware::jpeg_set_location() LOGD("setting image location ALT %d LAT %lf LON %lf", pt.altitude, pt.latitude, pt.longitude); } - else iLog("not setting image location"); + else LOGV("not setting image location"); } void QualcommCameraHardware::runFrameThread(void *data) { - iLog("runFrameThread E"); + LOGV("runFrameThread E"); #if DLOPEN_LIBMMCAMERA // We need to maintain a reference to libmmcamera.so for the duration of the @@ -793,22 +765,22 @@ void QualcommCameraHardware::runFrameThread(void *data) // lifetime of this object. We do not want to dlclose() libmmcamera while // LINK_cam_frame is still running. void *libhandle = ::dlopen("libmmcamera.so", RTLD_NOW); - iLog("FRAME: loading libmmcamera at %p", libhandle); + LOGV("FRAME: loading libmmcamera at %p", libhandle); if (!libhandle) { LOGE("FATAL ERROR: could not dlopen libmmcamera.so: %s", dlerror()); } if (libhandle) #endif { - iLog("Before LINK_cam_frame"); + LOGV("Before LINK_cam_frame"); LINK_cam_frame(data); - iLog("After LINK_cam_frame"); + LOGV("After LINK_cam_frame"); } #if DLOPEN_LIBMMCAMERA if (libhandle) { ::dlclose(libhandle); - iLog("FRAME: dlclose(libmmcamera)"); + LOGV("FRAME: dlclose(libmmcamera)"); } #endif @@ -817,7 +789,7 @@ void QualcommCameraHardware::runFrameThread(void *data) mFrameThreadWait.signal(); mFrameThreadWaitLock.unlock(); - iLog("runFrameThread X"); + LOGV("runFrameThread X"); } void QualcommCameraHardware::runJpegEncodeThread(void *data) @@ -871,72 +843,39 @@ void QualcommCameraHardware::runJpegEncodeThread(void *data) } - LOGD("mJpegSize %d" , mJpegSize ) ; + LOGD("mJpegSize %d" , mJpegSize ) ; - camera_position_type *npt = &pt ; - if( ! encode_location ) { - npt = NULL ; - } + camera_position_type *npt = &pt ; + if( ! encode_location ) { + npt = NULL ; + } - // Kalim inicio conversion en JPEG ------------------------------------------------------ -/* JpegEncoder jpgEnc; - int inFormat = JPG_MODESEL_YCBCR; - int outFormat = JPG_420; + writeExif( mRawHeap->mHeap->base(), mJpegHeap->mHeap->base(), mJpegSize, &mJpegSize, rotation , npt ); - if (jpgEnc.setConfig(JPEG_SET_ENCODE_IN_FORMAT, inFormat) != JPG_SUCCESS) - LOGE("[JPEG_SET_ENCODE_IN_FORMAT] Error\n"); + int jpeg_quality = mParameters.getInt("jpeg-quality"); - if (jpgEnc.setConfig(JPEG_SET_SAMPING_MODE, outFormat) != JPG_SUCCESS) - LOGE("[JPEG_SET_SAMPING_MODE] Error\n"); + LOGV("Kalim: Inicio conversion a JPEG ----------------------------------------------------------------------------------------------"); + LOGV("KalimochoAz jpeg convert, current jpeg main img quality =%d", jpeg_quality); + LOGV("KalimochoAz jpeg convert, current jpeg main img Height =%d", mRawHeight); + LOGV("KalimochoAz jpeg convert, current jpeg main img Width =%d", mRawWidth); + if( yuv420_save2jpeg((unsigned char*) mJpegHeap->mHeap->base(), mRawHeap->mHeap->base(), mRawWidth, mRawHeight, jpeg_quality) ) + LOGV("Kalim: JpegConvetida Correctamente ***********************************************************************************************************"); + else + LOGV("Kalim: Fallo de conversion a JPEG xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - image_quality_type_t jpegQuality; - jpegQuality = JPG_QUALITY_LEVEL_1; - if (jpgEnc.setConfig(JPEG_SET_ENCODE_QUALITY, jpegQuality) != JPG_SUCCESS) - LOGE("[JPEG_SET_ENCODE_QUALITY] Error\n"); - if (jpgEnc.setConfig(JPEG_SET_ENCODE_WIDTH, 2560) != JPG_SUCCESS) - LOGE("[JPEG_SET_ENCODE_WIDTH] Error\n"); - - if (jpgEnc.setConfig(JPEG_SET_ENCODE_HEIGHT, 1920) != JPG_SUCCESS) - LOGE("[JPEG_SET_ENCODE_HEIGHT] Error\n"); - - unsigned int snapshot_size = 2560 * 1920 * 2; - unsigned char *pInBuf = (unsigned char *)jpgEnc.getInBuf(snapshot_size); - - if (pInBuf == NULL) { - LOGE("JPEG input buffer is NULL!!\n"); - // return; - } - memcpy(pInBuf, mRawHeap->mHeap->base(), snapshot_size); - - // setExifChangedAttribute(); - jpgEnc.encode(output_size, &mExifInfo); - - uint64_t outbuf_size; - unsigned char *pOutBuf = (unsigned char *)jpgEnc.getOutBuf(&outbuf_size); - - if (pOutBuf == NULL) { - LOGE("JPEG output buffer is NULL!!\n"); - //return; - } - - memcpy(jpeg_buf, pOutBuf, outbuf_size); -*/ - // -------------------------------------------------------------------------------------- - writeExif( mRawHeap->mHeap->base(), mJpegHeap->mHeap->base(), mJpegSize, &mJpegSize, rotation , npt ) ; - - receiveJpegPicture(); + receiveJpegPicture(); } void *frame_thread(void *user) { - iLog("frame_thread E"); + LOGV("frame_thread E"); sp obj = QualcommCameraHardware::getInstance(); - if (obj != 0) { - obj->runFrameThread(user); - } - else LOGW("not starting frame thread: the object went away!"); - iLog("frame_thread X"); +// if (obj != 0) { +// obj->runFrameThread(user); +// } +// else LOGW("not starting frame thread: the object went away!"); + LOGV("frame_thread X"); return NULL; } @@ -944,16 +883,16 @@ bool QualcommCameraHardware::initPreview() { // See comments in deinitPreview() for why we have to wait for the frame // thread here, and why we can't use pthread_join(). - iLog("initPreview E: preview size=%dx%d", mPreviewWidth, mPreviewHeight); + LOGV("initPreview E: preview size=%dx%d", mPreviewWidth, mPreviewHeight); mFrameThreadWaitLock.lock(); // Kalim FAKE ------------------------ ( si lo elimino no grabamos la foto ) mFrameThreadRunning = false; // ----------------------------------- while (mFrameThreadRunning) { - iLog("initPreview: waiting for old frame thread to complete."); + LOGV("initPreview: waiting for old frame thread to complete."); mFrameThreadWait.wait(mFrameThreadWaitLock); - iLog("initPreview: old frame thread completed."); + LOGV("initPreview: old frame thread completed."); } LOGI("KALIM: Wait for unlock frame"); @@ -964,9 +903,9 @@ bool QualcommCameraHardware::initPreview() while (mSnapshotThreadRunning) { LOGI("KALIM: Wait INSIDE for unlock tread to be finished"); - iLog("initPreview: waiting for old snapshot thread to complete."); + LOGV("initPreview: waiting for old snapshot thread to complete."); mSnapshotThreadWait.wait(mSnapshotThreadWaitLock); - iLog("initPreview: old snapshot thread completed."); + LOGV("initPreview: old snapshot thread completed."); } LOGI("KALIM: Wait for unlock thread AGAIN"); mSnapshotThreadWaitLock.unlock(); @@ -1022,17 +961,17 @@ bool QualcommCameraHardware::initPreview() &frames[kPreviewBufferCount-1]); ret = mFrameThreadRunning; if (ret) - iLog("Preview thread created"); + LOGV("Preview thread created"); mFrameThreadWaitLock.unlock(); } - iLog("initPreview X"); + LOGV("initPreview X"); return ret; } void QualcommCameraHardware::deinitPreview(void) { - iLog("deinitPreview E"); + LOGV("deinitPreview E"); // When we call deinitPreview(), we signal to the frame thread that it // needs to exit, but we DO NOT WAIT for it to complete here. The problem @@ -1052,15 +991,15 @@ void QualcommCameraHardware::deinitPreview(void) LOGE("failed to stop the camframe thread: %s", strerror(errno)); else - iLog("terminate frame_thread successfully"); + LOGV("terminate frame_thread successfully"); */ - iLog("deinitPreview X"); + LOGV("deinitPreview X"); } bool QualcommCameraHardware::initRaw(bool initJpegHeap) { - iLog("initRaw E: picture size=%dx%d", + LOGV("initRaw E: picture size=%dx%d", mRawWidth, mRawHeight); // 2048x1536 mDimension.picture_width = mRawWidth; @@ -1074,7 +1013,7 @@ bool QualcommCameraHardware::initRaw(bool initJpegHeap) } if (mJpegHeap != NULL) { - iLog("initRaw: clearing old mJpegHeap."); + LOGV("initRaw: clearing old mJpegHeap."); mJpegHeap.clear(); } @@ -1087,7 +1026,7 @@ bool QualcommCameraHardware::initRaw(bool initJpegHeap) // Thumbnails - iLog("initRaw: initializing mThumbHeap. with size %d", THUMBNAIL_BUFFER_SIZE); + LOGV("initRaw: initializing mThumbHeap. with size %d", THUMBNAIL_BUFFER_SIZE); mThumbnailHeap = new PmemPool("/dev/pmem_adsp", mCameraControlFd, @@ -1108,7 +1047,7 @@ bool QualcommCameraHardware::initRaw(bool initJpegHeap) // Snapshot - iLog("initRaw: initializing mRawHeap. with size %d", mRawSize); // 4718592 + LOGV("initRaw: initializing mRawHeap. with size %d", mRawSize); // 4718592 mRawHeap = new PmemPool("/dev/pmem_camera", mCameraControlFd, @@ -1137,13 +1076,13 @@ bool QualcommCameraHardware::initRaw(bool initJpegHeap) } } - iLog("do_mmap snapshot pbuf = %p, pmem_fd = %d", + LOGV("do_mmap snapshot pbuf = %p, pmem_fd = %d", (uint8_t *)mRawHeap->mHeap->base(), mRawHeap->mHeap->getHeapID()); // Jpeg if (initJpegHeap) { - iLog("initRaw: initializing mJpegHeap."); + LOGV("initRaw: initializing mJpegHeap."); mJpegHeap = new AshmemPool(mJpegMaxSize, kJpegBufferCount, @@ -1161,19 +1100,19 @@ bool QualcommCameraHardware::initRaw(bool initJpegHeap) mRawInitialized = true; - iLog("initRaw X success"); + LOGV("initRaw X success"); return true; } void QualcommCameraHardware::deinitRaw() { - iLog("deinitRaw E"); + LOGV("deinitRaw E"); mThumbnailHeap.clear(); mJpegHeap.clear(); mRawHeap.clear(); mRawInitialized = false; - iLog("deinitRaw X"); + LOGV("deinitRaw X"); } void QualcommCameraHardware::release() @@ -1194,9 +1133,9 @@ void QualcommCameraHardware::release() struct msm_ctrl_cmd_t ctrlCmd; if (mCameraRunning) { - iLog("Kalim ----------- mCameraRunning ------------"); + LOGV("Kalim ----------- mCameraRunning ------------"); //if (mMsgEnabled & CAMERA_MSG_VIDEO_FRAME) { - iLog("Kalim ----------- VIDEO ------------"); + LOGV("Kalim ----------- VIDEO ------------"); mRecordFrameLock.lock(); mReleasedRecordingFrame = true; mRecordWait.signal(); @@ -1206,12 +1145,12 @@ void QualcommCameraHardware::release() } //FIXME: crash when released - //iLog("KALIM Join IMAGE"); + //LOGV("KALIM Join IMAGE"); //LINK_jpeg_encoder_join(); if (mRawInitialized) deinitRaw(); - iLog("CAMERA_EXIT"); + LOGV("CAMERA_EXIT"); ctrlCmd.timeout_ms = 5000; ctrlCmd.length = 0; @@ -1221,33 +1160,33 @@ void QualcommCameraHardware::release() LOGE("ioctl CAMERA_EXIT fd %d error %s", mCameraControlFd, strerror(errno)); - iLog("Stopping the conf thread"); + LOGV("Stopping the conf thread"); rc = pthread_join(mCamConfigThread, NULL); if (rc) LOGE("config_thread exit failure: %s", strerror(errno)); else { - iLog("pthread_join on config_thread"); + LOGV("pthread_join on config_thread"); } - iLog("Stopping the jpeg thread"); + LOGV("Stopping the jpeg thread"); rc = pthread_join(jpegThread, NULL); if (rc) LOGE("config_thread exit failure: %s", strerror(errno)); else { - iLog("pthread_join on config_thread"); + LOGV("pthread_join on config_thread"); } close(mCameraControlFd); mCameraControlFd = -1; - iLog("Stopping the w_thread"); + LOGV("Stopping the w_thread"); pthread_detach(w_thread); - iLog("Stopping the jpegThread"); + LOGV("Stopping the jpegThread"); pthread_detach(jpegThread); - iLog("Killing the w_thread"); + LOGV("Killing the w_thread"); pthread_kill(w_thread,9); - iLog("Killing the jpegThread"); + LOGV("Killing the jpegThread"); pthread_kill(jpegThread,9); @@ -1257,12 +1196,12 @@ void QualcommCameraHardware::release() #if DLOPEN_LIBMMCAMERA if (libmmcamera) { ::dlclose(libmmcamera); - iLog("dlclose(libmmcamera)"); + LOGV("dlclose(libmmcamera)"); libmmcamera = NULL; } if (libmmcamera_target) { ::dlclose(libmmcamera_target); - iLog("dlclose(libmmcamera_target)"); + LOGV("dlclose(libmmcamera_target)"); libmmcamera_target = NULL; } #endif @@ -1274,15 +1213,15 @@ void QualcommCameraHardware::release() Mutex::Autolock lock(&singleton_lock); singleton_releasing = true; - iLog("Kalim Hardware Release ------- Empieza"); + LOGV("Kalim Hardware Release ------- Empieza"); // Mutex::Autolock lock(&singleton_lock); singleton.clear(); singleton_releasing = false; singleton_wait.signal(); - iLog("Kalim Hardware Release ------- FIN"); + LOGV("Kalim Hardware Release ------- FIN"); //FIXME: crash when released - iLog("KALIM Join IMAGE"); + LOGV("KALIM Join IMAGE"); LINK_jpeg_encoder_join(); @@ -1301,22 +1240,22 @@ QualcommCameraHardware::~QualcommCameraHardware() sp QualcommCameraHardware::getRawHeap() const { - iLog("getRawHeap"); + LOGV("getRawHeap"); return mRawHeap != NULL ? mRawHeap->mHeap : NULL; } sp QualcommCameraHardware::getPreviewHeap() const { - iLog("getPreviewHeap"); + LOGV("getPreviewHeap"); return mPreviewHeap != NULL ? mPreviewHeap->mHeap : NULL; } status_t QualcommCameraHardware::startPreviewInternal() { - iLog("startPreview E"); + LOGV("startPreview E"); if(mCameraRunning) { - iLog("startPreview X: preview already running."); + LOGV("startPreview X: preview already running."); return NO_ERROR; } @@ -1346,7 +1285,7 @@ status_t QualcommCameraHardware::startPreviewInternal() break; default: if (fds[0].revents & POLLIN) { - iLog("frame is ready!"); + LOGV("frame is ready!"); } } */ @@ -1359,7 +1298,7 @@ status_t QualcommCameraHardware::startPreviewInternal() return UNKNOWN_ERROR; } - iLog("startPreview X"); + LOGV("startPreview X"); return NO_ERROR; } @@ -1371,15 +1310,15 @@ status_t QualcommCameraHardware::startPreview() void QualcommCameraHardware::stopPreviewInternal() { - iLog("stopPreviewInternal E: %d", mCameraRunning); + LOGV("stopPreviewInternal E: %d", mCameraRunning); if (mCameraRunning) { // Cancel auto focus. if (mMsgEnabled & CAMERA_MSG_FOCUS) { - iLog("canceling autofocus"); + LOGV("canceling autofocus"); cancelAutoFocus(); } - iLog("Stopping preview"); + LOGV("Stopping preview"); mCameraRunning = !native_stop_preview(mCameraControlFd); if (!mCameraRunning && mPreviewInitialized) { deinitPreview(); @@ -1387,12 +1326,12 @@ void QualcommCameraHardware::stopPreviewInternal() } else LOGE("stopPreviewInternal: failed to stop preview"); } - iLog("stopPreviewInternal X: %d", mCameraRunning); + LOGV("stopPreviewInternal X: %d", mCameraRunning); } void QualcommCameraHardware::stopPreview() { - iLog("stopPreview: E"); + LOGV("stopPreview: E"); Mutex::Autolock l(&mLock); if(mMsgEnabled & CAMERA_MSG_VIDEO_FRAME) @@ -1400,7 +1339,7 @@ void QualcommCameraHardware::stopPreview() stopPreviewInternal(); - iLog("stopPreview: X"); + LOGV("stopPreview: X"); } void QualcommCameraHardware::runAutoFocus() @@ -1422,7 +1361,7 @@ void QualcommCameraHardware::runAutoFocus() // lifetime of this object. We do not want to dlclose() libmmcamera while // LINK_cam_frame is still running. void *libhandle = ::dlopen("libmmcamera.so", RTLD_NOW); - iLog("AF: loading libmmcamera at %p", libhandle); + LOGV("AF: loading libmmcamera at %p", libhandle); if (!libhandle) { LOGE("FATAL ERROR: could not dlopen libmmcamera.so: %s", dlerror()); close(mAutoFocusFd); @@ -1434,9 +1373,9 @@ void QualcommCameraHardware::runAutoFocus() #endif /* This will block until either AF completes or is cancelled. */ - iLog("af start (fd %d)", mAutoFocusFd); + LOGV("af start (fd %d)", mAutoFocusFd); bool status = native_set_afmode(mAutoFocusFd, AF_MODE_AUTO); - iLog("af done: %d", (int)status); + LOGV("af done: %d", (int)status); mAutoFocusThreadRunning = false; close(mAutoFocusFd); mAutoFocusFd = -1; @@ -1448,16 +1387,16 @@ void QualcommCameraHardware::runAutoFocus() #if DLOPEN_LIBMMCAMERA if (libhandle) { ::dlclose(libhandle); - iLog("AF: dlclose(libmmcamera)"); + LOGV("AF: dlclose(libmmcamera)"); } #endif } status_t QualcommCameraHardware::cancelAutoFocus() { - iLog("cancelAutoFocus E"); + LOGV("cancelAutoFocus E"); native_cancel_afmode(mCameraControlFd, mAutoFocusFd); - iLog("cancelAutoFocus X"); + LOGV("cancelAutoFocus X"); /* Needed for eclair camera PAI */ return NO_ERROR; @@ -1465,19 +1404,19 @@ status_t QualcommCameraHardware::cancelAutoFocus() void *auto_focus_thread(void *user) { - iLog("auto_focus_thread E"); + LOGV("auto_focus_thread E"); sp obj = QualcommCameraHardware::getInstance(); if (obj != 0) { obj->runAutoFocus(); } else LOGW("not starting autofocus: the object went away!"); - iLog("auto_focus_thread X"); + LOGV("auto_focus_thread X"); return NULL; } status_t QualcommCameraHardware::autoFocus() { - iLog("autoFocus E"); + LOGV("autoFocus E"); Mutex::Autolock l(&mLock); if (mCameraControlFd < 0) { @@ -1485,7 +1424,7 @@ status_t QualcommCameraHardware::autoFocus() return UNKNOWN_ERROR; } - /* Not sure this is still needed with new APIs + /* Not sure this is still needed with new APIs .. if (mMsgEnabled & CAMERA_MSG_FOCUS) { LOGW("Auto focus is already in progress"); return NO_ERROR; @@ -1514,13 +1453,13 @@ status_t QualcommCameraHardware::autoFocus() mAutoFocusThreadLock.unlock(); } - iLog("autoFocus X"); + LOGV("autoFocus X"); return NO_ERROR; } void QualcommCameraHardware::runSnapshotThread(void *data) { - iLog("runSnapshotThread E"); + LOGV("runSnapshotThread E"); if (native_start_snapshot(mCameraControlFd)) receiveRawPicture(); else @@ -1531,7 +1470,7 @@ void QualcommCameraHardware::runSnapshotThread(void *data) mSnapshotThreadWait.signal(); mSnapshotThreadWaitLock.unlock(); - iLog("runSnapshotThread X"); + LOGV("runSnapshotThread X"); } void *snapshot_thread(void *user) @@ -1548,15 +1487,15 @@ void *snapshot_thread(void *user) status_t QualcommCameraHardware::takePicture() { - iLog("takePicture: E"); + LOGV("takePicture: E"); Mutex::Autolock l(&mLock); // Wait for old snapshot thread to complete. mSnapshotThreadWaitLock.lock(); while (mSnapshotThreadRunning) { - iLog("takePicture: waiting for old snapshot thread to complete."); + LOGV("takePicture: waiting for old snapshot thread to complete."); mSnapshotThreadWait.wait(mSnapshotThreadWaitLock); - iLog("takePicture: old snapshot thread completed."); + LOGV("takePicture: old snapshot thread completed."); } stopPreviewInternal(); @@ -1579,13 +1518,13 @@ status_t QualcommCameraHardware::takePicture() NULL); mSnapshotThreadWaitLock.unlock(); - iLog("takePicture: X"); + LOGV("takePicture: X"); return mSnapshotThreadRunning ? NO_ERROR : UNKNOWN_ERROR; } status_t QualcommCameraHardware::cancelPicture() { - iLog("cancelPicture: EX"); + LOGV("cancelPicture: EX"); return NO_ERROR; } @@ -1593,7 +1532,7 @@ status_t QualcommCameraHardware::cancelPicture() status_t QualcommCameraHardware::setParameters( const CameraParameters& params) { - iLog("setParameters: E params = %p", ¶ms); + LOGV("setParameters: E params = %p", ¶ms); Mutex::Autolock l(&mLock); @@ -1602,7 +1541,7 @@ status_t QualcommCameraHardware::setParameters( { int width, height; params.getPreviewSize(&width, &height); - iLog("requested size %d x %d", width, height); + LOGV("requested size %d x %d", width, height); // Validate the preview size size_t i; for (i = 0; i < PREVIEW_SIZE_COUNT; ++i, ++ps) { @@ -1620,7 +1559,7 @@ status_t QualcommCameraHardware::setParameters( mPreviewWidth = mDimension.display_width = 240; //ps->width; mPreviewHeight = mDimension.display_height = 160; //ps->height; - iLog("actual size %d x %d", mPreviewWidth, mPreviewHeight); + LOGV("actual size %d x %d", mPreviewWidth, mPreviewHeight); // FIXME: validate snapshot sizes, params.getPictureSize(&mRawWidth, &mRawHeight); @@ -1655,21 +1594,21 @@ status_t QualcommCameraHardware::setParameters( setAntibanding(); // FIXME: set nightshot and luma adaptatiom - iLog("setParameters: X"); + LOGV("setParameters: X"); return NO_ERROR ; } CameraParameters QualcommCameraHardware::getParameters() const { - iLog("getParameters: EX"); + LOGV("getParameters: EX"); return mParameters; } extern "C" sp openCameraHardware() { - iLog("*-------------------------------------------------------------------------------------*"); - iLog("[M a@openCameraHardware: call createInstance v: %s",version); - iLog("*-------------------------------------------------------------------------------------*"); + LOGV("*-------------------------------------------------------------------------------------*"); + LOGV("[M a@openCameraHardware: call createInstance v: %s",version); + LOGV("*-------------------------------------------------------------------------------------*"); return QualcommCameraHardware::createInstance(); } @@ -1682,7 +1621,7 @@ sp QualcommCameraHardware::createInstance() { LOGD("createInstance: E"); - iLog("get into singleton lock"); + LOGV("get into singleton lock"); Mutex::Autolock lock(&singleton_lock); // Wait until the previous release is done. @@ -1722,13 +1661,13 @@ sp QualcommCameraHardware::createInstance() // For internal use only, hence the strong pointer to the derived type. sp QualcommCameraHardware::getInstance() { - iLog("getInstance: E"); + LOGV("getInstance: E"); sp hardware = singleton.promote(); if (hardware != 0) { - iLog("getInstance: X Search instance of hardware"); + LOGV("getInstance: X Search instance of hardware"); return sp(static_cast(hardware.get())); } else { - iLog("getInstance: X new instance of hardware"); + LOGV("getInstance: X new instance of hardware"); return sp(); } LOGE("Fail getInstance: X"); @@ -1736,7 +1675,7 @@ sp QualcommCameraHardware::getInstance() void QualcommCameraHardware::receivePreviewFrame(struct msm_frame_t *frame) { - iLog("receivePreviewFrame E"); + LOGV("receivePreviewFrame E"); if (!mCameraRunning) { LOGE("ignoring preview callback--camera has been stopped"); @@ -1748,7 +1687,7 @@ void QualcommCameraHardware::receivePreviewFrame(struct msm_frame_t *frame) (ssize_t)frame->buffer - (ssize_t)mPreviewHeap->mHeap->base(); offset /= mPreviewFrameSize; - iLog("offset: %lu\n", (unsigned long int)offset); + LOGV("offset: %lu\n", (unsigned long int)offset); mInPreviewCallback = true; if (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) @@ -1760,7 +1699,7 @@ void QualcommCameraHardware::receivePreviewFrame(struct msm_frame_t *frame) //mDataCb(CAMERA_MSG_VIDEO_FRAME, mPreviewHeap->mBuffers[offset], mCallbackCookie); if (mReleasedRecordingFrame != true) { - iLog("block for release frame request/command"); + LOGV("block for release frame request/command"); mRecordWait.wait(mRecordFrameLock); } mReleasedRecordingFrame = false; @@ -1768,12 +1707,12 @@ void QualcommCameraHardware::receivePreviewFrame(struct msm_frame_t *frame) mInPreviewCallback = false; - iLog("receivePreviewFrame X"); + LOGV("receivePreviewFrame X"); } status_t QualcommCameraHardware::startRecording() { - iLog("startRecording E"); + LOGV("startRecording E"); Mutex::Autolock l(&mLock); mReleasedRecordingFrame = false; @@ -1784,7 +1723,7 @@ status_t QualcommCameraHardware::startRecording() void QualcommCameraHardware::stopRecording() { - iLog("stopRecording: E"); + LOGV("stopRecording: E"); Mutex::Autolock l(&mLock); { @@ -1796,24 +1735,24 @@ void QualcommCameraHardware::stopRecording() mCameraRecording = false; if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) { - iLog("stopRecording: X, preview still in progress"); + LOGV("stopRecording: X, preview still in progress"); return; } } stopPreviewInternal(); - iLog("stopRecording: X"); + LOGV("stopRecording: X"); } void QualcommCameraHardware::releaseRecordingFrame( const sp& mem __attribute__((unused))) { - iLog("releaseRecordingFrame E"); + LOGV("releaseRecordingFrame E"); Mutex::Autolock l(&mLock); Mutex::Autolock rLock(&mRecordFrameLock); mReleasedRecordingFrame = true; mRecordWait.signal(); - iLog("releaseRecordingFrame X"); + LOGV("releaseRecordingFrame X"); } bool QualcommCameraHardware::recordingEnabled() @@ -1833,7 +1772,7 @@ void QualcommCameraHardware::notifyShutter() void QualcommCameraHardware::receiveRawPicture() { - iLog("receiveRawPicture: E"); + LOGV("receiveRawPicture: E"); notifyShutter(); @@ -1846,25 +1785,25 @@ void QualcommCameraHardware::receiveRawPicture() // By the time native_get_picture returns, picture is taken. Call mDataCb(CAMERA_MSG_RAW_IMAGE, mRawHeap->mBuffers[0], mCallbackCookie); } - else iLog("Raw-picture callback was canceled--skipping."); + else LOGV("Raw-picture callback was canceled--skipping."); if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) { mJpegSize = mRawWidth * mRawHeight * 3 / 2; if (LINK_jpeg_encoder_init()) { if(native_jpeg_encode()) { - iLog("receiveRawPicture: X (success)"); + LOGV("receiveRawPicture: X (success)"); return; } LOGE("jpeg encoding failed"); } else LOGE("receiveRawPicture X: jpeg_encoder_init failed."); } - else iLog("JPEG callback is NULL, not encoding image."); + else LOGV("JPEG callback is NULL, not encoding image."); if( mRawInitialized ) { deinitRaw(); } - iLog("receiveRawPicture: X"); + LOGV("receiveRawPicture: X"); } void QualcommCameraHardware::receiveJpegPictureFragment( @@ -1874,7 +1813,7 @@ void QualcommCameraHardware::receiveJpegPictureFragment( remaining -= mJpegSize; uint8_t *base = (uint8_t *)mJpegHeap->mHeap->base(); - iLog("receiveJpegPictureFragment size %d", buff_size); + LOGV("receiveJpegPictureFragment size %d", buff_size); if (buff_size > remaining) { LOGE("receiveJpegPictureFragment: size %d exceeds what " "remains in JPEG heap (%d), truncating", @@ -1888,7 +1827,7 @@ void QualcommCameraHardware::receiveJpegPictureFragment( void QualcommCameraHardware::receiveJpegPicture(void) { - iLog("receiveJpegPicture: E image (%d uint8_ts out of %d)", + LOGV("receiveJpegPicture: E image (%d uint8_ts out of %d)", mJpegSize, mJpegHeap->mBufferSize); LOGD("mJpegHeap->mFrameOffset %d", mJpegHeap->mFrameOffset ) ; @@ -1908,10 +1847,10 @@ void QualcommCameraHardware::receiveJpegPicture(void) mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, buffer, mCallbackCookie); buffer = NULL; } - else iLog("JPEG callback was cancelled--not delivering image."); + else LOGV("JPEG callback was cancelled--not delivering image."); // Kalim FAKE to avoid join makes fail ---------------------- - // iLog("KALIM Join IMAGE 2"); + // LOGV("KALIM Join IMAGE 2"); // LINK_jpeg_encoder_join(); // ---------------------------------------------------------- @@ -1919,7 +1858,7 @@ void QualcommCameraHardware::receiveJpegPicture(void) deinitRaw(); } - iLog("receiveJpegPicture: X callback done."); + LOGV("receiveJpegPicture: X callback done."); } bool QualcommCameraHardware::previewEnabled() @@ -2002,7 +1941,7 @@ QualcommCameraHardware::AshmemPool::AshmemPool(int buffer_size, int num_buffers, frame_offset, name) { - iLog("constructing MemPool %s backed by ashmem: " + LOGV("constructing MemPool %s backed by ashmem: " "%d frames @ %d uint8_ts, offset %d, " "buffer size %d", mName, @@ -2043,7 +1982,7 @@ QualcommCameraHardware::PmemPool::PmemPool(const char *pmem_pool, mPmemType(pmem_type), mCameraControlFd(camera_control_fd) { - iLog("constructing MemPool %s backed by pmem pool %s: " + LOGV("constructing MemPool %s backed by pmem pool %s: " "%d frames @ %d bytes, offset %d, buffer size %d", mName, pmem_pool, num_buffers, frame_size, frame_offset, @@ -2071,7 +2010,7 @@ QualcommCameraHardware::PmemPool::PmemPool(const char *pmem_pool, return; } - iLog("pmem pool %s ioctl(fd = %d, PMEM_GET_SIZE) is %ld", + LOGV("pmem pool %s ioctl(fd = %d, PMEM_GET_SIZE) is %ld", pmem_pool, mFd, mSize.len); @@ -2096,7 +2035,7 @@ QualcommCameraHardware::PmemPool::PmemPool(const char *pmem_pool, QualcommCameraHardware::PmemPool::~PmemPool() { - iLog("%s: %s E", __FUNCTION__, mName); + LOGV("%s: %s E", __FUNCTION__, mName); // Unregister preview buffers with the camera drivers. for (int cnt = 0; cnt < mNumBuffers; ++cnt) { @@ -2109,17 +2048,17 @@ QualcommCameraHardware::PmemPool::~PmemPool() false /* unregister */); } - iLog("destroying PmemPool %s: ", mName); - iLog("%s: %s X", __FUNCTION__, mName); + LOGV("destroying PmemPool %s: ", mName); + LOGV("%s: %s X", __FUNCTION__, mName); } QualcommCameraHardware::MemPool::~MemPool() { - iLog("destroying MemPool %s", mName); + LOGV("destroying MemPool %s", mName); if (mFrameSize > 0) delete [] mBuffers; mHeap.clear(); - iLog("destroying MemPool %s completed", mName); + LOGV("destroying MemPool %s completed", mName); } QualcommCameraHardware::PreviewPmemPool::PreviewPmemPool( @@ -2144,7 +2083,7 @@ QualcommCameraHardware::PreviewPmemPool::PreviewPmemPool( QualcommCameraHardware::PreviewPmemPool::~PreviewPmemPool() { - iLog("destroying PreviewPmemPool"); + LOGV("destroying PreviewPmemPool"); if (initialized()) { LOGV("releasing PreviewPmemPool memory %p from module %d", base, QDSP_MODULE_VFETASK); @@ -2168,9 +2107,9 @@ static bool register_buf(int camfd, pmemBuf.y_off = 0; pmemBuf.active = active; - if (pmem_type == MSM_PMEM_RAW_MAINIMG) + if (pmem_type == MSM_PMEM_RAW_MAINIMG) pmemBuf.cbcr_off = 0; - else + else pmemBuf.cbcr_off = ((size * 2 / 3) + 1) & ~1; LOGV("register_buf: camfd = %d, reg = %d buffer = %p", @@ -2215,41 +2154,41 @@ status_t QualcommCameraHardware::MemPool::dump(int fd, const Vector& a static void receive_camframe_callback(struct msm_frame_t *frame) { - iLog("receive_camframe_callback E"); + LOGV("receive_camframe_callback E"); sp obj = QualcommCameraHardware::getInstance(); if (obj != 0) { - iLog("receive_camframe_callback Starting PreviewFrame"); + LOGV("receive_camframe_callback Starting PreviewFrame"); obj->receivePreviewFrame(frame); } - iLog("receive_camframe_callback X"); + LOGV("receive_camframe_callback X"); } static void receive_jpeg_fragment_callback(uint8_t *buff_ptr, uint32_t buff_size) { - iLog("receive_jpeg_fragment_callback E"); + LOGV("receive_jpeg_fragment_callback E"); sp obj = QualcommCameraHardware::getInstance(); if (obj != 0) { obj->receiveJpegPictureFragment(buff_ptr, buff_size); } - iLog("receive_jpeg_fragment_callback X"); + LOGV("receive_jpeg_fragment_callback X"); } static void receive_jpeg_callback(jpeg_event_t status) { - iLog("receive_jpeg_callback E (completion status %d)", status); + LOGV("receive_jpeg_callback E (completion status %d)", status); if (status == JPEG_EVENT_DONE) { sp obj = QualcommCameraHardware::getInstance(); if (obj != 0) { obj->receiveJpegPicture(); } } - iLog("receive_jpeg_callback X"); + LOGV("receive_jpeg_callback X"); } status_t QualcommCameraHardware::sendCommand(int32_t command, int32_t arg1, int32_t arg2) { - iLog("sendCommand: EX"); + LOGV("sendCommand: EX"); return BAD_VALUE; } diff --git a/libcamera/QualcommCameraHardware.h b/libcamera/QualcommCameraHardware.h index 09794eb..a6c4593 100644 --- a/libcamera/QualcommCameraHardware.h +++ b/libcamera/QualcommCameraHardware.h @@ -1,16 +1,16 @@ /* ** Copyright 2008, Google Inc. ** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at ** -** http://www.apache.org/licenses/LICENSE-2.0 +** http://www.apache.org/licenses/LICENSE-2.0 ** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and ** limitations under the License. */ @@ -28,7 +28,7 @@ extern "C" { #include "msm_camera.h" } -#define version "10.12" +#define version "10.12.11" #define MSM_CAMERA_CONTROL "/dev/msm_camera/msm_camera0" #define JPEG_EVENT_DONE 0 /* guess */ @@ -110,7 +110,7 @@ typedef struct unsigned int in2_h; unsigned int out2_w; unsigned int out2_h; - uint8_t update_flag; + uint8_t update_flag; } common_crop_t; typedef struct diff --git a/libcamera/jdatadst.cpp b/libcamera/jdatadst.cpp new file mode 100644 index 0000000..af45e67 --- /dev/null +++ b/libcamera/jdatadst.cpp @@ -0,0 +1,186 @@ +/* + * jdatadst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains compression data destination routines for the case of + * emitting JPEG data to memory. + * While these routines are sufficient for most applications, + * some will want to use a different destination manager. + * IMPORTANT: we assume that fwrite() will correctly transcribe an array of + * unsigned chars into 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include +#include +#include +#include +#include +//#include +#include +#include "jdatadst.h" + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + + +/* Expanded data destination object for stdio output */ + +#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ + + +/* Expanded data destination object for memory output */ + +typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + unsigned char ** outbuffer; /* target buffer */ + unsigned long * outsize; + unsigned char * newbuffer; /* newly allocated buffer */ + unsigned char * buffer; /* start of buffer */ + size_t bufsize; +} my_mem_destination_mgr; + +typedef my_mem_destination_mgr * my_mem_dest_ptr; + + +/* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ + +METHODDEF(void) +init_mem_destination (j_compress_ptr cinfo) +{ + /* no work necessary here */ +} + + +/* + * Empty the output buffer --- called whenever buffer fills up. + * + * In typical applications, this should write the entire output buffer + * (ignoring the current state of next_output_byte & free_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been dumped. + * + * In applications that need to be able to suspend compression due to output + * overrun, a FALSE return indicates that the buffer cannot be emptied now. + * In this situation, the compressor will return to its caller (possibly with + * an indication that it has not accepted all the supplied scanlines). The + * application should resume compression after it has made more room in the + * output buffer. Note that there are substantial restrictions on the use of + * suspension --- see the documentation. + * + * When suspending, the compressor will back up to a convenient restart point + * (typically the start of the current MCU). next_output_byte & free_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point will be regenerated after resumption, so do not + * write it out when emptying the buffer externally. + */ + +METHODDEF(boolean) +empty_mem_output_buffer (j_compress_ptr cinfo) +{ + size_t nextsize; + unsigned char * nextbuffer; + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + /* Try to allocate new buffer with double size */ + nextsize = dest->bufsize * 2; + nextbuffer = (unsigned char *)malloc(nextsize); + + if (nextbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + + MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); + + if (dest->newbuffer != NULL) + free(dest->newbuffer); + + dest->newbuffer = nextbuffer; + + dest->pub.next_output_byte = nextbuffer + dest->bufsize; + dest->pub.free_in_buffer = dest->bufsize; + + dest->buffer = nextbuffer; + dest->bufsize = nextsize; + + return TRUE; +} + + +/* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. Usually needs to flush buffer. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + +METHODDEF(void) +term_mem_destination (j_compress_ptr cinfo) +{ + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + *dest->outbuffer = dest->buffer; + *dest->outsize = dest->bufsize - dest->pub.free_in_buffer; +} + + +/* + * Prepare for output to a memory buffer. + * The caller may supply an own initial buffer with appropriate size. + * Otherwise, or when the actual data output exceeds the given size, + * the library adapts the buffer size as necessary. + * The standard library functions malloc/free are used for allocating + * larger memory, so the buffer is available to the application after + * finishing compression, and then the application is responsible for + * freeing the requested memory. + */ + +GLOBAL(void) +jpeg_mem_dest (j_compress_ptr cinfo, + unsigned char ** outbuffer, unsigned long * outsize) +{ + my_mem_dest_ptr dest; + + if (outbuffer == NULL || outsize == NULL) /* sanity check */ + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same buffer without re-executing jpeg_mem_dest. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_mem_destination_mgr)); + } + + dest = (my_mem_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_mem_destination; + dest->pub.empty_output_buffer = empty_mem_output_buffer; + dest->pub.term_destination = term_mem_destination; + dest->outbuffer = outbuffer; + dest->outsize = outsize; + dest->newbuffer = NULL; + + if (*outbuffer == NULL || *outsize == 0) { + /* Allocate initial buffer */ + dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE); + if (dest->newbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + *outsize = OUTPUT_BUF_SIZE; + } + + dest->pub.next_output_byte = dest->buffer = *outbuffer; + dest->pub.free_in_buffer = dest->bufsize = *outsize; +} diff --git a/libcamera/jdatadst.h b/libcamera/jdatadst.h new file mode 100644 index 0000000..e555f51 --- /dev/null +++ b/libcamera/jdatadst.h @@ -0,0 +1,53 @@ +/* + * jdatadst.h + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2002-2010 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines backported from jpeglib 8 for writing + * jpeg data directly to memory. + */ + +#ifndef JDATADST_H +#define JDATADST_H + +/* + * First we include the configuration files that record how this + * installation of the JPEG library is set up. jconfig.h can be + * generated automatically for many systems. jmorecfg.h contains + * manual configuration options that most people need not worry about. + */ + +#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ +#include /* widely used configuration options */ +#endif +//#include /* seldom changed options */ +#include + + +extern "C" { + +/* Declarations for routines called by application. + * The JPP macro hides prototype parameters from compilers that can't cope. + * Note JPP requires double parentheses. + */ + +#ifdef HAVE_PROTOTYPES +#define JPP(arglist) arglist +#else +#define JPP(arglist) () +#endif + + +/* Data source and destination managers: memory buffers. */ +EXTERN(void) jpeg_mem_dest (j_compress_ptr cinfo, + unsigned char ** outbuffer, + unsigned long * outsize); +} // extern "C" + +#define SIZEOF(object) ((size_t) sizeof(object)) +#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) + +#endif /* JPEGLIB_H */ diff --git a/libcamera/jpegConvert.cpp b/libcamera/jpegConvert.cpp new file mode 100644 index 0000000..c44f296 --- /dev/null +++ b/libcamera/jpegConvert.cpp @@ -0,0 +1,167 @@ +/* + Version: 1.0 + Coded by: Josebagar 02/2011 (linux version) + Revised and Recoded: KalimochoAz 02/2011 (android conversions) Done for CyanogenMOD + Free code: feel free to use, copy, modify or criticize. But please leave it as free code always +*/ +#include +#include +#include +extern "C" { + #include +} +#if JPEG_LIB_VERSION < 80 +// The routines defined in this file have been backported from jpeglib 8.0 +#include "jdatadst.h" +#endif +#include "jpegConvert.h" +#include "raw2jpeg.h" + + +//////////////////////////////////////////////////////////////////////////////// +YuvToJpegEncoder* YuvToJpegEncoder::create(int* strides) { + // Only ImageFormat.NV21 and ImageFormat.YUY2 are supported + // for now. + return new Yuv420SpToJpegEncoder(strides); +} + +YuvToJpegEncoder::YuvToJpegEncoder(int* strides) : fStrides(strides) { +} + +bool YuvToJpegEncoder::encode(unsigned char* dest, void* inYuv, int width, + int height, int* offsets, int jpegQuality) { + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + long unsigned int image_size; + unsigned char* ucDest; + + // Warning, this is ONLY valid for YUV420SP (ImageFormat.NV21 in android) + image_size = (width*height*1.5); + + // Create JPEG compression object + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + + // Point it to the output file + jpeg_mem_dest(&cinfo, &dest, &image_size); + + setJpegCompressStruct(&cinfo, width, height, jpegQuality); + + jpeg_start_compress(&cinfo, TRUE); + + compress(&cinfo, (uint8_t*) inYuv, offsets); + + jpeg_finish_compress(&cinfo); + + return true; +} + +void YuvToJpegEncoder::setJpegCompressStruct(jpeg_compress_struct* cinfo, + int width, int height, int quality) { + cinfo->image_width = width; + cinfo->image_height = height; + cinfo->input_components = 3; + cinfo->in_color_space = JCS_YCbCr; + jpeg_set_defaults(cinfo); + + jpeg_set_quality(cinfo, quality, TRUE); + jpeg_set_colorspace(cinfo, JCS_YCbCr); + cinfo->raw_data_in = TRUE; + cinfo->dct_method = JDCT_IFAST; + configSamplingFactors(cinfo); +} + +/////////////////////////////////////////////////////////////////// +Yuv420SpToJpegEncoder::Yuv420SpToJpegEncoder(int* strides) : + YuvToJpegEncoder(strides) { + fNumPlanes = 2; +} + +void Yuv420SpToJpegEncoder::compress(jpeg_compress_struct* cinfo, + uint8_t* yuv, int* offsets) { + JSAMPROW y[16]; + JSAMPROW cb[8]; + JSAMPROW cr[8]; + JSAMPARRAY planes[3]; + planes[0] = y; + planes[1] = cb; + planes[2] = cr; + + int width = cinfo->image_width; + int height = cinfo->image_height; + uint8_t* yPlanar = yuv + offsets[0]; + uint8_t* vuPlanar = yuv + offsets[1]; //width * height; + uint8_t* uRows = new uint8_t [8 * (width >> 1)]; + uint8_t* vRows = new uint8_t [8 * (width >> 1)]; + + + // process 16 lines of Y and 8 lines of U/V each time. + while (cinfo->next_scanline < cinfo->image_height) { + //deitnerleave u and v + deinterleave(vuPlanar, uRows, vRows, cinfo->next_scanline, width); + + for (int i = 0; i < 16; i++) { + // y row + y[i] = yPlanar + (cinfo->next_scanline + i) * fStrides[0]; + + // construct u row and v row + if ((i & 1) == 0) { + // height and width are both halved because of downsampling + int offset = (i >> 1) * (width >> 1); + cb[i/2] = uRows + offset; + cr[i/2] = vRows + offset; + } + } + jpeg_write_raw_data(cinfo, planes, 16); + } + delete [] uRows; + delete [] vRows; + +} + +void Yuv420SpToJpegEncoder::deinterleave(uint8_t* vuPlanar, uint8_t* uRows, + uint8_t* vRows, int rowIndex, int width) { + for (int row = 0; row < 8; ++row) { + int offset = ((rowIndex >> 1) + row) * fStrides[1]; + uint8_t* vu = vuPlanar + offset; + for (int i = 0; i < (width >> 1); ++i) { + int index = row * (width >> 1) + i; + uRows[index] = vu[1]; + vRows[index] = vu[0]; + vu += 2; + } + } +} + +void Yuv420SpToJpegEncoder::configSamplingFactors(jpeg_compress_struct* cinfo) { + // cb and cr are horizontally downsampled and vertically downsampled as well. + cinfo->comp_info[0].h_samp_factor = 2; + cinfo->comp_info[0].v_samp_factor = 2; + cinfo->comp_info[1].h_samp_factor = 1; + cinfo->comp_info[1].v_samp_factor = 1; + cinfo->comp_info[2].h_samp_factor = 1; + cinfo->comp_info[2].v_samp_factor = 1; +} + +/////////////////////////////////////////////////////////////////////////////// + +int yuv420_save2jpeg(unsigned char *dest, void *src, int width, int height, int quality) { + int imgStrides[2], imgOffsets[2]; + + // Convert the RAW data to JPEG + imgStrides[0] = imgStrides[1] = width; + YuvToJpegEncoder* encoder = YuvToJpegEncoder::create(imgStrides); + if (encoder == NULL) { + return false; + } + + // Guessed from frameworks/base/graphics/java/android/graphics/YuvImage.java + // in android + imgOffsets[0] = 0; + imgOffsets[1] = width*height; + encoder->encode(dest, src, width, height, imgOffsets, quality); + + delete encoder; + + return true; +} \ No newline at end of file diff --git a/libcamera/jpegConvert.h b/libcamera/jpegConvert.h new file mode 100644 index 0000000..3731bbf --- /dev/null +++ b/libcamera/jpegConvert.h @@ -0,0 +1,60 @@ +#ifndef YuvToJpegEncoder_DEFINED +#define YuvToJpegEncoder_DEFINED + +extern "C" { + #include "jpeglib.h" + #include "jerror.h" +} + +class YuvToJpegEncoder { +public: + /** Create an encoder based on the YUV format. + * + * @param pixelFormat The yuv pixel format as defined in ui/PixelFormat.h. + * @param strides The number of row bytes in each image plane. + * @return an encoder based on the pixelFormat. + */ + static YuvToJpegEncoder* create(int* strides); + + YuvToJpegEncoder(int* strides); + + /** Encode YUV data to jpeg, which is output to a stream. + * + * @param dest The jpeg output stream. + * @param inYuv The input yuv data. + * @param width Width of the the Yuv data in terms of pixels. + * @param height Height of the Yuv data in terms of pixels. + * @param offsets The offsets in each image plane with respect to inYuv. + * @param jpegQuality Picture quality in [0, 100]. + * @return true if successfully compressed the stream. + */ + bool encode(unsigned char* dest, void* inYuv, int width, + int height, int* offsets, int jpegQuality); + + virtual ~YuvToJpegEncoder() {} + +protected: + int fNumPlanes; + int* fStrides; + void setJpegCompressStruct(jpeg_compress_struct* cinfo, int width, + int height, int quality); + virtual void configSamplingFactors(jpeg_compress_struct* cinfo) = 0; + virtual void compress(jpeg_compress_struct* cinfo, + uint8_t* yuv, int* offsets) = 0; +}; + +class Yuv420SpToJpegEncoder : public YuvToJpegEncoder { +public: + Yuv420SpToJpegEncoder(int* strides); + virtual ~Yuv420SpToJpegEncoder() {} + +private: + void configSamplingFactors(jpeg_compress_struct* cinfo); + void deinterleaveYuv(uint8_t* yuv, int width, int height, + uint8_t*& yPlanar, uint8_t*& uPlanar, uint8_t*& vPlanar); + void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows, + int rowIndex, int width); + void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); +}; + +#endif diff --git a/libcamera/raw2jpeg.h b/libcamera/raw2jpeg.h new file mode 100644 index 0000000..ae5209f --- /dev/null +++ b/libcamera/raw2jpeg.h @@ -0,0 +1 @@ +int yuv420_save2jpeg(unsigned char *dest, void *src, int width, int height, int quality);