hardware: samsung_slsi: libcamera2: Fixed JPEG related problems
authorSungjoong Kang <sj3.kang@samsung.com>
Thu, 23 Aug 2012 23:35:08 +0000 (16:35 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Tue, 28 Aug 2012 16:41:08 +0000 (09:41 -0700)
1. Fixes crash after capturing multiple snapshots
2. Supports EXIF tags
3. Supports Thumbnails

Change-Id: I60fed4eb64ffbb2c49ceaafb44877d5e23da8562
Signed-off-by: Sungjoong Kang <sj3.kang@samsung.com>
libcamera2/ExynosCameraHWInterface2.cpp
libcamera2/ExynosCameraHWInterface2.h
libcamera2/ExynosJpegEncoderForCamera.cpp
libcamera2/ExynosJpegEncoderForCamera.h

index b0778a2907bb419644299d91056ec4b3884f80d6..d7202f672b1f73f202d2a12b08eafbc773677183 100644 (file)
@@ -705,9 +705,8 @@ void    RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime)
 
 uint64_t  RequestManager::GetTimestamp(int index)
 {
-
-    if (index == -1) {
-        ALOGE("ERR(%s): Cannot find entry ", __FUNCTION__);
+    if (index < 0 || index >= NUM_MAX_REQUEST_MGR_ENTRY) {
+        ALOGE("ERR(%s): Request entry outside of bounds (%d)", __FUNCTION__, index);
         return 0;
     }
 
@@ -855,6 +854,7 @@ ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_
 
 
     ALOGV("DEBUG(%s): END", __FUNCTION__);
+    m_setExifFixedAttribute();
 }
 
 ExynosCameraHWInterface2::~ExynosCameraHWInterface2()
@@ -2428,6 +2428,8 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
 
             if(isCapture) {
                     ALOGD("======= request_scc is 1");
+                    memcpy(&m_jpegMetadata, &shot_ext->shot, sizeof(struct camera2_shot));
+                    ALOGV("### Saving informationfor jpeg");
                     m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING);
 
                 for(j = 0; j < m_camera_info.isp.buffers; j++)
@@ -3070,6 +3072,9 @@ bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
 {
     unsigned char *addr;
 
+    int thumbW = 320;
+    int thumbH = 240;
+
     ExynosJpegEncoderForCamera jpegEnc;
     bool ret = false;
     int res = 0;
@@ -3102,26 +3107,36 @@ bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
         goto jpeg_encode_done;
     }
 
-    mExifInfo.enableThumb = false;
+    mExifInfo.enableThumb = true;
+
+    if (jpegEnc.setThumbnailSize(thumbW, thumbH)) {
+        ALOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, thumbW, thumbH);
+        goto jpeg_encode_done;
+    }
+
+    ALOGV("(%s):jpegEnc.setThumbnailSize(%d, %d) ", __FUNCTION__, thumbW, thumbH);
+    if (jpegEnc.setThumbnailQuality(50)) {
+        ALOGE("ERR(%s):jpegEnc.setThumbnailQuality fail", __FUNCTION__);
+        goto jpeg_encode_done;
+    }
 
+    m_setExifChangedAttribute(&mExifInfo, rect, &m_jpegMetadata);
     ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize);
-    if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), (int *)yuvSize)) {
+    if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), &(yuvBuf->virt.p), (int *)yuvSize)) {
         ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__);
         goto jpeg_encode_done;
     }
-
-    if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) {
+    if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->virt.p, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) {
         ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__);
         goto jpeg_encode_done;
     }
-    memset(jpegBuf->virt.p, 0 ,jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2]);
 
     if (jpegEnc.updateConfig()) {
         ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__);
         goto jpeg_encode_done;
     }
 
-    if (res = jpegEnc.encode((int *)&jpegBuf->size.s, NULL)) {
+    if (res = jpegEnc.encode((int *)&jpegBuf->size.s, &mExifInfo)) {
         ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res);
         goto jpeg_encode_done;
     }
@@ -3807,6 +3822,257 @@ void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode)
     }
 }
 
+void ExynosCameraHWInterface2::m_setExifFixedAttribute(void)
+{
+    char property[PROPERTY_VALUE_MAX];
+
+    //2 0th IFD TIFF Tags
+    //3 Maker
+    property_get("ro.product.brand", property, EXIF_DEF_MAKER);
+    strncpy((char *)mExifInfo.maker, property,
+                sizeof(mExifInfo.maker) - 1);
+    mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0';
+    //3 Model
+    property_get("ro.product.model", property, EXIF_DEF_MODEL);
+    strncpy((char *)mExifInfo.model, property,
+                sizeof(mExifInfo.model) - 1);
+    mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0';
+    //3 Software
+    property_get("ro.build.id", property, EXIF_DEF_SOFTWARE);
+    strncpy((char *)mExifInfo.software, property,
+                sizeof(mExifInfo.software) - 1);
+    mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0';
+
+    //3 YCbCr Positioning
+    mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING;
+
+    //2 0th IFD Exif Private Tags
+    //3 F Number
+    mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM;
+    mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN;
+    //3 Exposure Program
+    mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM;
+    //3 Exif Version
+    memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version));
+    //3 Aperture
+    uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den);
+    mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN;
+    mExifInfo.aperture.den = EXIF_DEF_APEX_DEN;
+    //3 Maximum lens aperture
+    mExifInfo.max_aperture.num = mExifInfo.aperture.num;
+    mExifInfo.max_aperture.den = mExifInfo.aperture.den;
+    //3 Lens Focal Length
+    mExifInfo.focal_length.num = EXIF_DEF_FOCAL_LEN_NUM;
+    mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN;
+    //3 User Comments
+    strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS);
+    //3 Color Space information
+    mExifInfo.color_space = EXIF_DEF_COLOR_SPACE;
+    //3 Exposure Mode
+    mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE;
+
+    //2 0th IFD GPS Info Tags
+    unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 };
+    memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version));
+
+    //2 1th IFD TIFF Tags
+    mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION;
+    mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM;
+    mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN;
+    mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM;
+    mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN;
+    mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT;
+}
+
+void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect,
+       camera2_shot *currentEntry)
+{
+    camera2_dm *dm = &(currentEntry->dm);
+    camera2_ctl *ctl = &(currentEntry->ctl);
+
+    ALOGV("(%s): framecnt(%d) exp(%lld) iso(%d)", __FUNCTION__, ctl->request.frameCount, dm->sensor.exposureTime,dm->aa.isoValue );
+    if (!ctl->request.frameCount)
+       return;
+    //2 0th IFD TIFF Tags
+    //3 Width
+    exifInfo->width = rect->w;
+    //3 Height
+    exifInfo->height = rect->h;
+    //3 Orientation
+    switch (ctl->jpeg.orientation) {
+    case 90:
+        exifInfo->orientation = EXIF_ORIENTATION_90;
+        break;
+    case 180:
+        exifInfo->orientation = EXIF_ORIENTATION_180;
+        break;
+    case 270:
+        exifInfo->orientation = EXIF_ORIENTATION_270;
+        break;
+    case 0:
+    default:
+        exifInfo->orientation = EXIF_ORIENTATION_UP;
+        break;
+    }
+
+    //3 Date time
+    time_t rawtime;
+    struct tm *timeinfo;
+    time(&rawtime);
+    timeinfo = localtime(&rawtime);
+    strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
+
+    //2 0th IFD Exif Private Tags
+    //3 Exposure Time
+    int shutterSpeed = (dm->sensor.exposureTime/1000);
+
+    if (shutterSpeed < 0) {
+        shutterSpeed = 100;
+    }
+
+    exifInfo->exposure_time.num = 1;
+    // x us -> 1/x s */
+    //exifInfo->exposure_time.den = (uint32_t)(1000000 / shutterSpeed);
+    exifInfo->exposure_time.den = (uint32_t)((double)1000000 / shutterSpeed);
+
+    //3 ISO Speed Rating
+    exifInfo->iso_speed_rating = dm->aa.isoValue;
+
+    uint32_t av, tv, bv, sv, ev;
+    av = APEX_FNUM_TO_APERTURE((double)exifInfo->fnumber.num / exifInfo->fnumber.den);
+    tv = APEX_EXPOSURE_TO_SHUTTER((double)exifInfo->exposure_time.num / exifInfo->exposure_time.den);
+    sv = APEX_ISO_TO_FILMSENSITIVITY(exifInfo->iso_speed_rating);
+    bv = av + tv - sv;
+    ev = av + tv;
+    //ALOGD("Shutter speed=%d us, iso=%d", shutterSpeed, exifInfo->iso_speed_rating);
+    ALOGD("AV=%d, TV=%d, SV=%d", av, tv, sv);
+
+    //3 Shutter Speed
+    exifInfo->shutter_speed.num = tv * EXIF_DEF_APEX_DEN;
+    exifInfo->shutter_speed.den = EXIF_DEF_APEX_DEN;
+    //3 Brightness
+    exifInfo->brightness.num = bv*EXIF_DEF_APEX_DEN;
+    exifInfo->brightness.den = EXIF_DEF_APEX_DEN;
+    //3 Exposure Bias
+    if (ctl->aa.sceneMode== AA_SCENE_MODE_BEACH||
+        ctl->aa.sceneMode== AA_SCENE_MODE_SNOW) {
+        exifInfo->exposure_bias.num = EXIF_DEF_APEX_DEN;
+        exifInfo->exposure_bias.den = EXIF_DEF_APEX_DEN;
+    } else {
+        exifInfo->exposure_bias.num = 0;
+        exifInfo->exposure_bias.den = 0;
+    }
+    //3 Metering Mode
+    /*switch (m_curCameraInfo->metering) {
+    case METERING_MODE_CENTER:
+        exifInfo->metering_mode = EXIF_METERING_CENTER;
+        break;
+    case METERING_MODE_MATRIX:
+        exifInfo->metering_mode = EXIF_METERING_MULTISPOT;
+        break;
+    case METERING_MODE_SPOT:
+        exifInfo->metering_mode = EXIF_METERING_SPOT;
+        break;
+    case METERING_MODE_AVERAGE:
+    default:
+        exifInfo->metering_mode = EXIF_METERING_AVERAGE;
+        break;
+    }*/
+    exifInfo->metering_mode = EXIF_METERING_CENTER;
+
+    //3 Flash
+    int flash = dm->flash.flashMode;
+    if (dm->flash.flashMode == FLASH_MODE_OFF || flash < 0)
+        exifInfo->flash = EXIF_DEF_FLASH;
+    else
+        exifInfo->flash = flash;
+
+    //3 White Balance
+    if (dm->aa.awbMode == AA_AWBMODE_WB_AUTO)
+        exifInfo->white_balance = EXIF_WB_AUTO;
+    else
+        exifInfo->white_balance = EXIF_WB_MANUAL;
+
+    //3 Scene Capture Type
+    switch (ctl->aa.sceneMode) {
+    case AA_SCENE_MODE_PORTRAIT:
+        exifInfo->scene_capture_type = EXIF_SCENE_PORTRAIT;
+        break;
+    case AA_SCENE_MODE_LANDSCAPE:
+        exifInfo->scene_capture_type = EXIF_SCENE_LANDSCAPE;
+        break;
+    case AA_SCENE_MODE_NIGHT_PORTRAIT:
+        exifInfo->scene_capture_type = EXIF_SCENE_NIGHT;
+        break;
+    default:
+        exifInfo->scene_capture_type = EXIF_SCENE_STANDARD;
+        break;
+    }
+
+    //2 0th IFD GPS Info Tags
+    if (ctl->jpeg.gpsCoordinates[0] != 0 && ctl->jpeg.gpsCoordinates[1] != 0) {
+
+        if (ctl->jpeg.gpsCoordinates[0] > 0)
+            strcpy((char *)exifInfo->gps_latitude_ref, "N");
+        else
+            strcpy((char *)exifInfo->gps_latitude_ref, "S");
+
+        if (ctl->jpeg.gpsCoordinates[1] > 0)
+            strcpy((char *)exifInfo->gps_longitude_ref, "E");
+        else
+            strcpy((char *)exifInfo->gps_longitude_ref, "W");
+
+        if (ctl->jpeg.gpsCoordinates[2] > 0)
+            exifInfo->gps_altitude_ref = 0;
+        else
+            exifInfo->gps_altitude_ref = 1;
+
+        double latitude = fabs(ctl->jpeg.gpsCoordinates[0] / 10000.0);
+        double longitude = fabs(ctl->jpeg.gpsCoordinates[1] / 10000.0);
+        double altitude = fabs(ctl->jpeg.gpsCoordinates[2] / 100.0);
+
+        exifInfo->gps_latitude[0].num = (uint32_t)latitude;
+        exifInfo->gps_latitude[0].den = 1;
+        exifInfo->gps_latitude[1].num = (uint32_t)((latitude - exifInfo->gps_latitude[0].num) * 60);
+        exifInfo->gps_latitude[1].den = 1;
+        exifInfo->gps_latitude[2].num = (uint32_t)((((latitude - exifInfo->gps_latitude[0].num) * 60)
+                                        - exifInfo->gps_latitude[1].num) * 60);
+        exifInfo->gps_latitude[2].den = 1;
+
+        exifInfo->gps_longitude[0].num = (uint32_t)longitude;
+        exifInfo->gps_longitude[0].den = 1;
+        exifInfo->gps_longitude[1].num = (uint32_t)((longitude - exifInfo->gps_longitude[0].num) * 60);
+        exifInfo->gps_longitude[1].den = 1;
+        exifInfo->gps_longitude[2].num = (uint32_t)((((longitude - exifInfo->gps_longitude[0].num) * 60)
+                                        - exifInfo->gps_longitude[1].num) * 60);
+        exifInfo->gps_longitude[2].den = 1;
+
+        exifInfo->gps_altitude.num = (uint32_t)altitude;
+        exifInfo->gps_altitude.den = 1;
+
+        struct tm tm_data;
+        long timestamp;
+        timestamp = (long)ctl->jpeg.gpsTimestamp;
+        gmtime_r(&timestamp, &tm_data);
+        exifInfo->gps_timestamp[0].num = tm_data.tm_hour;
+        exifInfo->gps_timestamp[0].den = 1;
+        exifInfo->gps_timestamp[1].num = tm_data.tm_min;
+        exifInfo->gps_timestamp[1].den = 1;
+        exifInfo->gps_timestamp[2].num = tm_data.tm_sec;
+        exifInfo->gps_timestamp[2].den = 1;
+        snprintf((char*)exifInfo->gps_datestamp, sizeof(exifInfo->gps_datestamp),
+                "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday);
+
+        exifInfo->enableGps = true;
+    } else {
+        exifInfo->enableGps = false;
+    }
+
+    //2 1th IFD TIFF Tags
+    exifInfo->widthThumb = ctl->jpeg.thumbnailSize[0];
+    exifInfo->heightThumb = ctl->jpeg.thumbnailSize[1];
+}
+
 ExynosCameraHWInterface2::MainThread::~MainThread()
 {
     ALOGV("(%s):", __FUNCTION__);
index 250a34495b64981c9e35d956fede9139ce2565ed..88ce630d1448e8d06e4b218aac8195f2ed3dd6eb 100644 (file)
@@ -51,6 +51,7 @@
 #include "ExynosExif.h"
 #include "csc.h"
 #include "ExynosCamera2.h"
+#include "cutils/properties.h"
 
 namespace android {
 
@@ -487,6 +488,9 @@ class MainThread : public SignalDrivenThread {
     void            SetAfStateForService(int newState);
     int             GetAfStateForService();
     exif_attribute_t    mExifInfo;
+    void            m_setExifFixedAttribute(void);
+    void            m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect,
+                         camera2_shot *currentEntry);
     void               *m_exynosPictureCSC;
     void               *m_exynosVideoCSC;
 
@@ -543,6 +547,7 @@ class MainThread : public SignalDrivenThread {
     bool                                m_IsAfTriggerRequired;
     bool                                m_IsAfLockRequired;
     int                                 m_serviceAfState;
+    struct camera2_shot                 m_jpegMetadata;
 };
 
 }; // namespace android
index 7da99679d04f5bf7e0fdf4e24174beb12a87fd2a..2d96528cc3db1009a2c0d61a148fe8fab8e656ba 100644 (file)
@@ -43,6 +43,8 @@ ExynosJpegEncoderForCamera::ExynosJpegEncoderForCamera()
     m_ionJpegClient = 0;
     initJpegMemory(&m_stThumbInBuf, MAX_IMAGE_PLANE_NUM);
     initJpegMemory(&m_stThumbOutBuf, MAX_IMAGE_PLANE_NUM);
+    initJpegMemory(&m_stMainInBuf, MAX_IMAGE_PLANE_NUM);
+    initJpegMemory(&m_stMainOutBuf, MAX_IMAGE_PLANE_NUM);
 }
 
 ExynosJpegEncoderForCamera::~ExynosJpegEncoderForCamera()
@@ -89,7 +91,7 @@ int ExynosJpegEncoderForCamera::create(void)
     if(m_ionJpegClient == 0) {
         return ERROR_CANNOT_CREATE_EXYNOS_JPEG_ENC_HAL;
     }
-    m_stThumbInBuf.ionClient = m_stThumbOutBuf.ionClient = m_ionJpegClient;
+    m_stMainOutBuf.ionClient = m_stMainInBuf.ionClient = m_stThumbInBuf.ionClient = m_stThumbOutBuf.ionClient = m_ionJpegClient;
 
     m_flagCreate = true;
 
@@ -113,8 +115,10 @@ int ExynosJpegEncoderForCamera::destroy(void)
 
         freeJpegMemory(&m_stThumbInBuf, MAX_IMAGE_PLANE_NUM);
         freeJpegMemory(&m_stThumbOutBuf, MAX_IMAGE_PLANE_NUM);
+        initJpegMemory(&m_stMainInBuf, MAX_IMAGE_PLANE_NUM);
+        initJpegMemory(&m_stMainOutBuf, MAX_IMAGE_PLANE_NUM);
         m_ionJpegClient = deleteIonClient(m_ionJpegClient);
-        m_stThumbInBuf.ionClient = m_stThumbOutBuf.ionClient = m_ionJpegClient;
+        m_stMainOutBuf.ionClient = m_stMainInBuf.ionClient = m_stThumbInBuf.ionClient = m_stThumbOutBuf.ionClient = m_ionJpegClient;
         m_jpegThumb->destroy();
         delete m_jpegThumb;
         m_jpegThumb = NULL;
@@ -173,7 +177,7 @@ int ExynosJpegEncoderForCamera::updateConfig(void)
     return m_jpegMain->updateConfig();
 }
 
-int  ExynosJpegEncoderForCamera::setInBuf(int *buf, int *size)
+int  ExynosJpegEncoderForCamera::setInBuf(int *buf, char** vBuf, int *size)
 {
     if (m_flagCreate == false) {
         return ERROR_NOT_YET_CREATED;
@@ -194,11 +198,14 @@ int  ExynosJpegEncoderForCamera::setInBuf(int *buf, int *size)
         JPEG_ERROR_LOG("%s::Fail to JPEG input buffer!!\n", __func__);
         return ret;
     }
+    m_stMainInBuf.ionBuffer[0] = buf[0];
+    m_stMainInBuf.iSize[0] = size[0];
+    m_stMainInBuf.pcBuf[0] = vBuf[0];
 
     return ERROR_NONE;
 }
 
-int  ExynosJpegEncoderForCamera::setOutBuf(int buf, int size)
+int  ExynosJpegEncoderForCamera::setOutBuf(int buf, char* vBuf, int size)
 {
     if (m_flagCreate == false) {
         return ERROR_NOT_YET_CREATED;
@@ -218,6 +225,9 @@ int  ExynosJpegEncoderForCamera::setOutBuf(int buf, int size)
         JPEG_ERROR_LOG("%s::Fail to JPEG output buffer!!\n", __func__);
         return ret;
     }
+    m_stMainOutBuf.ionBuffer[0] = buf;
+    m_stMainOutBuf.iSize[0] = size;
+    m_stMainOutBuf.pcBuf[0] = vBuf;
 
     return ERROR_NONE;
 }
@@ -245,15 +255,9 @@ int ExynosJpegEncoderForCamera::encode(int *size, exif_attribute_t *exifInfo)
         return ERROR_OUT_BUFFER_SIZE_TOO_SMALL;
     }
 
-    int iOutputSize = 0;
-    int iJpegBuffer = 0;
-    char *pcJpegBuffer = NULL;
-    ret = m_jpegMain->getOutBuf((int *)&iJpegBuffer, &iOutputSize);
-    if (ret != ERROR_NONE) {
-        return ret;
-    }
-
-    mmapJpegMemory(&iJpegBuffer, &pcJpegBuffer, &iOutputSize, MAX_OUTPUT_BUFFER_PLANE_NUM);
+    int iOutputSize = m_stMainOutBuf.iSize[0];
+    int iJpegBuffer = m_stMainOutBuf.ionBuffer[0];
+    char *pcJpegBuffer = m_stMainOutBuf.pcBuf[0];
 
     if (pcJpegBuffer[0] == NULL) {
         JPEG_ERROR_LOG("%s::pcJpegBuffer[0] is null!!\n", __func__);
@@ -305,8 +309,6 @@ int ExynosJpegEncoderForCamera::encode(int *size, exif_attribute_t *exifInfo)
         delete[] exifOut;
     }
 
-    unmapJpegMemory(&iJpegBuffer, &pcJpegBuffer, &iOutputSize, MAX_OUTPUT_BUFFER_PLANE_NUM);
-
     *size = iJpegSize;
 
     return ERROR_NONE;
@@ -497,6 +499,7 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
                 iThumbFd = -1;
             }
             thumbSize = (unsigned int)m_jpegMain->getJpegSize();
+            thumbBuf = m_stMainOutBuf.pcBuf[0];
         }
     } else {
         if (m_jpegThumb) {
@@ -505,11 +508,10 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
                 iThumbFd = -1;
             }
             thumbSize = (unsigned int)m_jpegThumb->getJpegSize();
+            thumbBuf = m_stThumbOutBuf.pcBuf[0];
         }
     }
 
-    mmapJpegMemory(&iThumbFd, &thumbBuf, &thumbBufSize, MAX_OUTPUT_BUFFER_PLANE_NUM);
-
     if (exifInfo->enableThumb && (thumbBuf != NULL) && (thumbSize != 0)) {
         exifSizeExceptThumb = tmp = LongerTagOffest;
         memcpy(pNextIfdOffset, &tmp, OFFSET_SIZE);  // NEXT IFD offset skipped on 0th IFD
@@ -567,8 +569,6 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
     unsigned char size_mm[2] = {(tmp >> 8) & 0xFF, tmp & 0xFF};
     memcpy(pApp1Start, size_mm, 2);
 
-    unmapJpegMemory(&iThumbFd, &thumbBuf, &thumbBufSize, MAX_OUTPUT_BUFFER_PLANE_NUM);
-
     return ERROR_NONE;
 }
 
@@ -855,11 +855,6 @@ int ExynosJpegEncoderForCamera::encodeThumbnail(unsigned int *size, bool useMain
     if (useMain) {
         int iTempWidth=0;
         int iTempHeight=0;
-        int iMainInputBuf[MAX_INPUT_BUFFER_PLANE_NUM];
-        char *pcMainInputBuf[2];
-        int iMainInputSize[MAX_INPUT_BUFFER_PLANE_NUM];
-        char *pcThumbInputBuf[2];
-        int iThumbInputSize[MAX_INPUT_BUFFER_PLANE_NUM];
         int iTempColorformat = 0;
 
         iTempColorformat = m_jpegMain->getColorFormat();
@@ -870,20 +865,9 @@ int ExynosJpegEncoderForCamera::encodeThumbnail(unsigned int *size, bool useMain
             return ret;
         }
 
-        ret = m_jpegMain->getInBuf(iMainInputBuf, iMainInputSize, MAX_INPUT_BUFFER_PLANE_NUM);
-        if (ret) {
-            JPEG_ERROR_LOG("ERR(%s):Fail getInBuf\n", __func__);
-            return ret;
-        }
-
-        pcThumbInputBuf[0] = m_stThumbInBuf.pcBuf[0];
-        pcThumbInputBuf[1] = (char *)(MAP_FAILED);
-
-        mmapJpegMemory(iMainInputBuf, pcMainInputBuf, iMainInputSize, MAX_INPUT_BUFFER_PLANE_NUM);
-
         switch (iTempColorformat) {
         case V4L2_PIX_FMT_YUYV:
-            ret = scaleDownYuv422(pcMainInputBuf,
+            ret = scaleDownYuv422(m_stMainInBuf.pcBuf,
                               iTempWidth,
                               iTempHeight,
                               m_stThumbInBuf.pcBuf,
@@ -891,9 +875,7 @@ int ExynosJpegEncoderForCamera::encodeThumbnail(unsigned int *size, bool useMain
                               m_thumbnailH);
             break;
         case V4L2_PIX_FMT_NV16:
-            pcMainInputBuf[1] = pcMainInputBuf[0] + (iTempWidth*iTempHeight);
-            pcThumbInputBuf[1] = pcThumbInputBuf[0] + (m_thumbnailW*m_thumbnailH);
-            ret = scaleDownYuv422_2p(pcMainInputBuf,
+            ret = scaleDownYuv422_2p(m_stMainInBuf.pcBuf,
                               iTempWidth,
                               iTempHeight,
                               m_stThumbInBuf.pcBuf,
@@ -905,9 +887,6 @@ int ExynosJpegEncoderForCamera::encodeThumbnail(unsigned int *size, bool useMain
             break;
         }
 
-        pcMainInputBuf[1] = (char *)(MAP_FAILED);
-        unmapJpegMemory(iMainInputBuf, pcMainInputBuf, iMainInputSize, MAX_INPUT_BUFFER_PLANE_NUM);
-
         if (ret) {
             JPEG_ERROR_LOG("%s::scaleDown(%d, %d, %d, %d) fail", __func__, iTempWidth, iTempHeight, m_thumbnailW, m_thumbnailH);
             return ret;
@@ -1031,28 +1010,3 @@ void ExynosJpegEncoderForCamera::initJpegMemory(struct stJpegMem *pstMem, int iM
     pstMem->ionClient = 0;
 }
 
-void ExynosJpegEncoderForCamera::mmapJpegMemory(int *iFd, char **ppcBuf, int *piSize, int iMemoryNum)
-{
-    for (int i=0;i<iMemoryNum;i++) {
-        if (piSize[i] != 0) {
-            ppcBuf[i] = (char *)ion_map(iFd[i], piSize[i], 0);
-            if ((ppcBuf[i] == (char *)MAP_FAILED) || (ppcBuf[i] == NULL)) {
-                JPEG_ERROR_LOG("[%s]ion map failed(0x%x)\n", __func__, ppcBuf[i]);
-                ppcBuf[i] = (char *)MAP_FAILED;
-            }
-        } else {
-            ppcBuf[i] = (char *)MAP_FAILED;
-        }
-    }
-}
-
-void ExynosJpegEncoderForCamera::unmapJpegMemory(int *iFd, char **ppcBuf, int *piSize, int iMemoryNum)
-{
-    for (int i=0;i<iMemoryNum;i++) {
-        if (ppcBuf[i] != (char *)MAP_FAILED) {
-            ion_unmap(ppcBuf[i], piSize[i]);
-        }
-        ppcBuf[i] = (char *)MAP_FAILED;
-        piSize[i] = 0;
-    }
-}
index d63c4df767185e639065f19a909868becdd0e4ff..323f587eb7f38699ad1fd72ffd3b2c5dda4a57b8 100644 (file)
@@ -83,8 +83,8 @@ public :
 
     int     updateConfig(void);
 
-    int     setInBuf(int *buf, int *size);
-    int     setOutBuf(int buf, int size);
+    int     setInBuf(int *buf, char** vBuf, int *size);
+    int     setOutBuf(int buf, char* vBuf, int size);
 
     int     encode(int *size, exif_attribute_t *exifInfo);
 
@@ -141,9 +141,6 @@ private:
     void    freeJpegMemory(struct stJpegMem *pstMem, int iMemoryNum);
     void    initJpegMemory(struct stJpegMem *pstMem, int iMemoryNum);
 
-    void    mmapJpegMemory(int *iFd, char **ppcBuf, int *piSize, int iMemoryNum);
-    void    unmapJpegMemory(int *iFd, char **ppcBuf, int *piSize, int iMemoryNum);
-
     bool     m_flagCreate;
 
     ExynosJpegEncoder *m_jpegMain;
@@ -152,6 +149,8 @@ private:
     ion_client m_ionJpegClient;
     struct stJpegMem m_stThumbInBuf;
     struct stJpegMem m_stThumbOutBuf;
+    struct stJpegMem m_stMainInBuf;
+    struct stJpegMem m_stMainOutBuf;
 
     int m_thumbnailW;
     int m_thumbnailH;