2011-01-12 07:42:14 +00:00
|
|
|
/*
|
|
|
|
** 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
|
|
|
|
**
|
|
|
|
** 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
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
2011-03-13 05:49:00 +00:00
|
|
|
// NOTE VERSION_C
|
2011-03-30 21:06:24 +00:00
|
|
|
#define REVISION_C "RC3.7008.3."
|
|
|
|
// #define LOG_NDEBUG 0
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
#define LOG_TAG "QualcommCameraHardware"
|
|
|
|
#include <utils/Log.h>
|
|
|
|
|
|
|
|
#include "QualcommCameraHardware.h"
|
|
|
|
|
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <binder/MemoryHeapPmem.h>
|
|
|
|
#include <utils/String16.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2011-03-30 21:06:24 +00:00
|
|
|
#include <math.h>
|
2011-01-12 07:42:14 +00:00
|
|
|
#if HAVE_ANDROID_OS
|
|
|
|
#include <linux/android_pmem.h>
|
|
|
|
#endif
|
|
|
|
#include <linux/ioctl.h>
|
2011-02-09 17:58:14 +00:00
|
|
|
#include "raw2jpeg.h"
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
#define LIKELY(exp) __builtin_expect(!!(exp), 1)
|
|
|
|
#define UNLIKELY(exp) __builtin_expect(!!(exp), 0)
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "exifwriter.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <poll.h>
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
#include "msm_camera.h" // Tattoo kernel
|
|
|
|
|
|
|
|
// init for Tattoo
|
|
|
|
#define THUMBNAIL_WIDTH_STR "192"
|
|
|
|
#define THUMBNAIL_HEIGHT_STR "144"
|
|
|
|
// if not set, set them to the following
|
|
|
|
#define THUMBNAIL_WIDTH 192
|
|
|
|
#define THUMBNAIL_HEIGHT 144
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// actual px for snapshoting
|
2011-02-09 17:58:14 +00:00
|
|
|
#define DEFAULT_PICTURE_WIDTH 2048
|
|
|
|
#define DEFAULT_PICTURE_HEIGHT 1536
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
#define THUMBNAIL_BUFFER_SIZE (THUMBNAIL_WIDTH * THUMBNAIL_HEIGHT * 3/2)
|
2011-03-14 17:24:38 +00:00
|
|
|
#define DEFAULT_PREVIEW_SETTING 5
|
2011-03-30 21:06:24 +00:00
|
|
|
#define DEFAULT_FRAMERATE 24
|
2011-01-12 07:42:14 +00:00
|
|
|
#define PREVIEW_SIZE_COUNT (sizeof(preview_sizes)/sizeof(preview_size_type))
|
|
|
|
|
|
|
|
#define NOT_FOUND -1
|
2011-03-14 17:24:38 +00:00
|
|
|
#define LOG_PREVIEW false
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
#if DLOPEN_LIBMMCAMERA
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
void* (*LINK_cam_conf)(void *data);
|
|
|
|
void* (*LINK_cam_frame)(void *data);
|
|
|
|
bool (*LINK_jpeg_encoder_init)();
|
|
|
|
void (*LINK_jpeg_encoder_join)();
|
2011-02-09 17:58:14 +00:00
|
|
|
unsigned char (*LINK_jpeg_encoder_encode)(const char* file_name, const cam_ctrl_dimension_t *dimen,
|
2011-01-12 07:42:14 +00:00
|
|
|
const unsigned char* thumbnailbuf, int thumbnailfd,
|
2011-03-13 05:49:00 +00:00
|
|
|
const unsigned char* snapshotbuf, int snapshotfd,
|
|
|
|
common_crop_t *cropInfo);
|
|
|
|
int (*LINK_camframe_terminate)();
|
|
|
|
void (*LINK_cam_set_frame_callback)();
|
2011-03-14 17:24:38 +00:00
|
|
|
bool (*LINK_cam_release_frame)();
|
2011-01-12 07:42:14 +00:00
|
|
|
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_setLocation)(const camera_position_type *location);
|
|
|
|
//
|
|
|
|
// callbacks
|
|
|
|
void (**LINK_mmcamera_camframe_callback)(struct msm_frame_t *frame);
|
|
|
|
void (**LINK_mmcamera_jpegfragment_callback)(uint8_t *buff_ptr,
|
|
|
|
uint32_t buff_size);
|
|
|
|
void (**LINK_mmcamera_jpeg_callback)(jpeg_event_t status);
|
|
|
|
#else
|
|
|
|
#define LINK_cam_conf cam_conf
|
|
|
|
#define LINK_cam_frame cam_frame
|
|
|
|
#define LINK_jpeg_encoder_init jpeg_encoder_init
|
|
|
|
#define LINK_jpeg_encoder_join jpeg_encoder_join
|
|
|
|
#define LINK_jpeg_encoder_encode jpeg_encoder_encode
|
|
|
|
#define LINK_camframe_terminate camframe_terminate
|
2011-03-13 05:49:00 +00:00
|
|
|
#define LINK_cam_set_frame_callback cam_set_frame_callback
|
|
|
|
#define LINK_cam_release_frame cam_release_frame
|
2011-01-12 07:42:14 +00:00
|
|
|
#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_setLocation jpeg_encoder_setLocation
|
|
|
|
extern void (*mmcamera_camframe_callback)(struct msm_frame_t *frame);
|
|
|
|
extern void (*mmcamera_jpegfragment_callback)(uint8_t *buff_ptr,
|
|
|
|
uint32_t buff_size);
|
|
|
|
extern void (*mmcamera_jpeg_callback)(jpeg_event_t status);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static int exif_table_numEntries = 0;
|
|
|
|
#define MAX_EXIF_TABLE_ENTRIES 7
|
|
|
|
exif_tags_info_t exif_data[MAX_EXIF_TABLE_ENTRIES];
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
struct preview_size_type {
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
};
|
|
|
|
|
|
|
|
static preview_size_type preview_sizes[] = {
|
|
|
|
{ 480, 320 }, // HVGA
|
2011-03-13 05:49:00 +00:00
|
|
|
{ 432, 320 }, // 1.35-to-1, for photos. (Rounded up from 1.3333 to 1)
|
2011-01-12 07:42:14 +00:00
|
|
|
{ 352, 288 }, // CIF
|
2011-03-13 05:49:00 +00:00
|
|
|
{ 336, 244 },
|
|
|
|
{ 320, 320 },
|
2011-01-12 07:42:14 +00:00
|
|
|
{ 320, 240 }, // QVGA
|
2011-03-13 05:49:00 +00:00
|
|
|
{ 288, 192 },
|
|
|
|
{ 240, 240 }, // QCIF
|
2011-01-12 07:42:14 +00:00
|
|
|
{ 240, 160 }, // SQVGA
|
2011-03-30 21:06:24 +00:00
|
|
|
{ 192, 144 },
|
|
|
|
{ 176, 144 } // Used for MMS send
|
2011-01-12 07:42:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int attr_lookup(const struct str_map *const arr, const char *name)
|
|
|
|
{
|
|
|
|
if (name) {
|
|
|
|
const struct str_map *trav = arr;
|
|
|
|
while (trav->desc) {
|
|
|
|
if (!strcmp(trav->desc, name))
|
|
|
|
return trav->val;
|
|
|
|
trav++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INIT_VALUES_FOR(parm) do { \
|
|
|
|
if (!parm##_values) { \
|
|
|
|
parm##_values = (char *)malloc(sizeof(parm)/ \
|
|
|
|
sizeof(parm[0])*30); \
|
|
|
|
char *ptr = parm##_values; \
|
|
|
|
const str_map *trav; \
|
|
|
|
for (trav = parm; trav->desc; trav++) { \
|
|
|
|
int len = strlen(trav->desc); \
|
|
|
|
strcpy(ptr, trav->desc); \
|
|
|
|
ptr += len; \
|
|
|
|
*ptr++ = ','; \
|
|
|
|
} \
|
|
|
|
*--ptr = 0; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
// from aeecamera.h
|
|
|
|
static const str_map whitebalance[] = {
|
|
|
|
{ "auto", CAMERA_WB_AUTO },
|
|
|
|
{ "incandescent", CAMERA_WB_INCANDESCENT },
|
|
|
|
{ "fluorescent", CAMERA_WB_FLUORESCENT },
|
|
|
|
{ "daylight", CAMERA_WB_DAYLIGHT },
|
|
|
|
{ "cloudy", CAMERA_WB_CLOUDY_DAYLIGHT },
|
|
|
|
{ "twilight", CAMERA_WB_TWILIGHT },
|
|
|
|
{ "shade", CAMERA_WB_SHADE },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
static char *whitebalance_values;
|
|
|
|
|
|
|
|
// from camera_effect_t
|
|
|
|
static const str_map effect[] = {
|
|
|
|
{ "none", CAMERA_EFFECT_OFF }, /* This list must match aeecamera.h */
|
|
|
|
{ "mono", CAMERA_EFFECT_MONO },
|
|
|
|
{ "negative", CAMERA_EFFECT_NEGATIVE },
|
|
|
|
{ "sepia", CAMERA_EFFECT_SEPIA },
|
|
|
|
{ "whiteboard", CAMERA_EFFECT_WHITEBOARD },
|
|
|
|
{ "blackboard", CAMERA_EFFECT_BLACKBOARD },
|
|
|
|
{ "aqua", CAMERA_EFFECT_AQUA },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
static char *effect_values;
|
|
|
|
|
|
|
|
// from qcamera/common/camera.h
|
|
|
|
static const str_map antibanding[] = {
|
|
|
|
{ "off", CAMERA_ANTIBANDING_OFF },
|
|
|
|
{ "50hz", CAMERA_ANTIBANDING_50HZ },
|
|
|
|
{ "60hz", CAMERA_ANTIBANDING_60HZ },
|
|
|
|
{ "auto", CAMERA_ANTIBANDING_AUTO },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
static char *antibanding_values;
|
|
|
|
|
|
|
|
// round to the next power of two
|
|
|
|
static inline unsigned clp2(unsigned x)
|
|
|
|
{
|
|
|
|
x = x - 1;
|
|
|
|
x = x | (x >> 1);
|
|
|
|
x = x | (x >> 2);
|
|
|
|
x = x | (x >> 4);
|
|
|
|
x = x | (x >> 8);
|
|
|
|
x = x | (x >>16);
|
|
|
|
return x + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
static Mutex singleton_lock;
|
|
|
|
static bool singleton_releasing;
|
|
|
|
static Condition singleton_wait;
|
|
|
|
|
|
|
|
static void receive_camframe_callback(struct msm_frame_t *frame);
|
|
|
|
|
|
|
|
static int camerafd;
|
2011-03-14 17:24:38 +00:00
|
|
|
static int fd_frame;
|
2011-03-30 21:06:24 +00:00
|
|
|
static int32_t mMaxZoom = -1;
|
|
|
|
static const int ZOOM_STEP = 6;
|
|
|
|
static bool zoomSupported = false;
|
2011-03-14 17:24:38 +00:00
|
|
|
struct msm_frame_t *frameA;
|
|
|
|
bool bFramePresent;
|
2011-01-12 07:42:14 +00:00
|
|
|
pthread_t w_thread;
|
2011-03-13 05:49:00 +00:00
|
|
|
pthread_t jpegThread;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
void *opencamerafd(void *arg) {
|
|
|
|
camerafd = open(MSM_CAMERA_CONTROL, O_RDWR);
|
|
|
|
if (camerafd < 0)
|
|
|
|
LOGE("Camera control %s open failed: %s!", MSM_CAMERA_CONTROL, strerror(errno));
|
|
|
|
else
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("opening %s fd: %d", MSM_CAMERA_CONTROL, camerafd);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::QualcommCameraHardware()
|
|
|
|
: mParameters(),
|
|
|
|
mPreviewHeight(-1),
|
|
|
|
mPreviewWidth(-1),
|
|
|
|
mRawHeight(-1),
|
|
|
|
mRawWidth(-1),
|
|
|
|
mCameraRunning(false),
|
|
|
|
mPreviewInitialized(false),
|
2011-03-13 05:49:00 +00:00
|
|
|
mRawInitialized(false),
|
2011-01-12 07:42:14 +00:00
|
|
|
mFrameThreadRunning(false),
|
|
|
|
mSnapshotThreadRunning(false),
|
|
|
|
mReleasedRecordingFrame(false),
|
|
|
|
mNotifyCb(0),
|
|
|
|
mDataCb(0),
|
|
|
|
mDataCbTimestamp(0),
|
|
|
|
mCallbackCookie(0),
|
|
|
|
mMsgEnabled(0),
|
|
|
|
mPreviewFrameSize(0),
|
|
|
|
mRawSize(0),
|
|
|
|
mCameraControlFd(-1),
|
|
|
|
mAutoFocusThreadRunning(false),
|
|
|
|
mAutoFocusFd(-1),
|
|
|
|
mInPreviewCallback(false),
|
2011-03-30 21:06:24 +00:00
|
|
|
mCameraRecording(false),
|
|
|
|
mCurZoom(0)
|
2011-01-12 07:42:14 +00:00
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("constructor E");
|
2011-01-12 07:42:14 +00:00
|
|
|
if((pthread_create(&w_thread, NULL, opencamerafd, NULL)) != 0) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGE("Camera open thread creation failed");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
memset(&mDimension, 0, sizeof(mDimension));
|
|
|
|
memset(&mCrop, 0, sizeof(mCrop));
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("constructor X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static bool native_get_maxzoom(int camfd, void *pZm)
|
|
|
|
{
|
|
|
|
LOGV("native_get_maxzoom E");
|
|
|
|
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
int32_t *pZoom = (int32_t *)pZm;
|
|
|
|
|
|
|
|
ctrlCmd.type = CAMERA_GET_PARM_MAXZOOM;
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.length = sizeof(int32_t);
|
|
|
|
ctrlCmd.value = pZoom;
|
|
|
|
|
|
|
|
if (ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) {
|
|
|
|
LOGE("native_get_maxzoom: ioctl fd %d error %s", camfd, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("MaxZoom value is %d", *(int32_t *)ctrlCmd.value);
|
|
|
|
memcpy(pZoom, (int32_t *)ctrlCmd.value, sizeof(int32_t));
|
|
|
|
|
|
|
|
LOGV("native_get_maxzoom X");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
void QualcommCameraHardware::initDefaultParameters()
|
|
|
|
{
|
|
|
|
CameraParameters p;
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initDefaultParameters E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
preview_size_type *ps = &preview_sizes[DEFAULT_PREVIEW_SETTING];
|
|
|
|
p.setPreviewSize(ps->width, ps->height);
|
|
|
|
p.setPreviewFrameRate(DEFAULT_FRAMERATE);
|
|
|
|
p.setPreviewFormat(CameraParameters::PIXEL_FORMAT_YUV420SP); // informative
|
|
|
|
p.setPictureFormat(CameraParameters::PIXEL_FORMAT_JPEG); // informative
|
|
|
|
|
|
|
|
p.set("jpeg-quality", "100"); // maximum quality
|
|
|
|
p.set("jpeg-thumbnail-width", THUMBNAIL_WIDTH_STR); // informative
|
|
|
|
p.set("jpeg-thumbnail-height", THUMBNAIL_HEIGHT_STR); // informative
|
|
|
|
p.set("jpeg-thumbnail-quality", "85");
|
|
|
|
|
|
|
|
p.setPictureSize(DEFAULT_PICTURE_WIDTH, DEFAULT_PICTURE_HEIGHT);
|
|
|
|
p.set(CameraParameters::KEY_ANTIBANDING, CameraParameters::ANTIBANDING_OFF);
|
2011-03-30 21:06:24 +00:00
|
|
|
p.set(CameraParameters::KEY_EFFECT, CameraParameters::EFFECT_NONE+1);
|
2011-01-12 07:42:14 +00:00
|
|
|
p.set(CameraParameters::KEY_WHITE_BALANCE, CameraParameters::WHITE_BALANCE_AUTO);
|
2011-03-30 21:06:24 +00:00
|
|
|
p.set(CameraParameters::KEY_FLASH_MODE, CameraParameters::FLASH_MODE_OFF);
|
|
|
|
p.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED);
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, "yuv420sp");
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "30,24,15");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// This will happen only once in the lifetime of the mediaserver process.
|
2011-01-12 07:42:14 +00:00
|
|
|
// We do not free the _values arrays when we destroy the camera object.
|
|
|
|
INIT_VALUES_FOR(antibanding);
|
|
|
|
INIT_VALUES_FOR(effect);
|
|
|
|
INIT_VALUES_FOR(whitebalance);
|
|
|
|
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_ANTIBANDING, antibanding_values);
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_EFFECTS, effect_values);
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, whitebalance_values);
|
2011-03-30 21:06:24 +00:00
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, "2048x1536,1600x1200,1024x768,176x144");
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, "320x240,240x160,192x144,176x144");
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_FLASH_MODES, "off");
|
|
|
|
p.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, "fixed");
|
|
|
|
|
|
|
|
|
|
|
|
// Zoom parameters
|
|
|
|
p.set(CameraParameters::KEY_ZOOM_SUPPORTED, "true");
|
|
|
|
p.set(CameraParameters::KEY_ZOOM, "0");
|
|
|
|
p.set(CameraParameters::KEY_MAX_ZOOM, 3);
|
|
|
|
p.set(CameraParameters::KEY_ZOOM_RATIOS, "100,150,200,250,300");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if (setParameters(p) != NO_ERROR) {
|
|
|
|
LOGE("Failed to set default parameters?!");
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initDefaultParameters X");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setCallbacks(notify_callback notify_cb,
|
|
|
|
data_callback data_cb,
|
|
|
|
data_callback_timestamp data_cb_timestamp,
|
|
|
|
void* user)
|
|
|
|
{
|
|
|
|
Mutex::Autolock lock(mLock);
|
|
|
|
mNotifyCb = notify_cb;
|
|
|
|
mDataCb = data_cb;
|
|
|
|
mDataCbTimestamp = data_cb_timestamp;
|
|
|
|
mCallbackCookie = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::enableMsgType(int32_t msgType)
|
|
|
|
{
|
|
|
|
Mutex::Autolock lock(mLock);
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("enableMsgType(%d)", msgType);
|
2011-01-12 07:42:14 +00:00
|
|
|
mMsgEnabled |= msgType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::disableMsgType(int32_t msgType)
|
|
|
|
{
|
|
|
|
Mutex::Autolock lock(mLock);
|
|
|
|
LOGD("DisableMsgType( %d )", msgType);
|
|
|
|
mMsgEnabled &= ~msgType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::msgTypeEnabled(int32_t msgType)
|
|
|
|
{
|
|
|
|
Mutex::Autolock lock(mLock);
|
|
|
|
LOGD("msgTypeEnabled( %d )", msgType);
|
|
|
|
return (mMsgEnabled & msgType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define ROUND_TO_PAGE(x) (((x)+0xfff)&~0xfff)
|
|
|
|
|
|
|
|
void QualcommCameraHardware::startCamera()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startCamera E");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
#if DLOPEN_LIBMMCAMERA
|
|
|
|
|
|
|
|
libmmcamera_target = ::dlopen("libmm-qcamera-tgt.so", RTLD_NOW);
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("loading libmm-qcamera-tgt at %p", libmmcamera_target);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (!libmmcamera_target) {
|
|
|
|
LOGE("FATAL ERROR: could not dlopen libmm-qcamera_target.so: %s", dlerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
#if 0 // useless now
|
2011-01-12 07:42:14 +00:00
|
|
|
*(void **)&LINK_cam_frame =
|
|
|
|
::dlsym(libmmcamera, "cam_frame");
|
|
|
|
*(void **)&LINK_camframe_terminate =
|
|
|
|
::dlsym(libmmcamera, "camframe_terminate");
|
|
|
|
*(void **)&LINK_jpeg_encoder_encode =
|
|
|
|
::dlsym(libmmcamera, "jpeg_encoder_encode");
|
|
|
|
*(void **)&LINK_jpeg_encoder_join =
|
|
|
|
::dlsym(libmmcamera, "jpeg_encoder_join");
|
|
|
|
*(void **)&LINK_mmcamera_camframe_callback =
|
|
|
|
::dlsym(libmmcamera, "mmframe_cb");
|
|
|
|
*LINK_mmcamera_camframe_callback = receive_camframe_callback;
|
2011-03-30 21:06:24 +00:00
|
|
|
*(void **)&LINK_jpeg_encoder_init =
|
|
|
|
::dlsym(libmmcamera, "jpeg_encoder_init");
|
2011-01-12 07:42:14 +00:00
|
|
|
*(void **)&LINK_mmcamera_jpeg_callback =
|
|
|
|
::dlsym(libmmcamera, "mm_jpeg_callback");
|
|
|
|
*LINK_mmcamera_jpeg_callback = receive_jpeg_callback;
|
2011-03-30 21:06:24 +00:00
|
|
|
*(void **)&LINK_mmcamera_jpegfragment_callback =
|
|
|
|
::dlsym(libmmcamera, "mm_jpegfragment_callback");
|
|
|
|
*LINK_mmcamera_jpegfragment_callback = receive_jpeg_fragment_callback;
|
|
|
|
*(void **)&LINK_cam_set_frame_callback =
|
|
|
|
::dlsym(libmmcamera, "cam_set_frame_callback");
|
2011-01-12 07:42:14 +00:00
|
|
|
*(void**)&LINK_jpeg_encoder_setMainImageQuality =
|
|
|
|
::dlsym(libmmcamera, "jpeg_encoder_setMainImageQuality");
|
2011-03-30 21:06:24 +00:00
|
|
|
*(void **)&LINK_cam_release_frame =
|
|
|
|
::dlsym(libmmcamera, "cam_release_frame");
|
|
|
|
#endif
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
*(void **)&LINK_cam_conf =
|
|
|
|
::dlsym(libmmcamera_target, "cam_conf");
|
2011-03-30 21:06:24 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
#else
|
|
|
|
mmcamera_camframe_callback = receive_camframe_callback;
|
|
|
|
mmcamera_jpegfragment_callback = receive_jpeg_fragment_callback;
|
|
|
|
mmcamera_jpeg_callback = receive_jpeg_callback;
|
|
|
|
#endif // DLOPEN_LIBMMCAMERA
|
|
|
|
|
|
|
|
/* The control thread is in libcamera itself. */
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("pthread_join on control thread");
|
2011-01-12 07:42:14 +00:00
|
|
|
if (pthread_join(w_thread, NULL) != 0) {
|
|
|
|
LOGE("Camera open thread exit failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
// Opened camerafd in thread
|
|
|
|
mCameraControlFd = fd_frame = camerafd;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (fd_frame < 0)
|
|
|
|
LOGE("cam_frame_click: cannot open %s: %s",
|
|
|
|
MSM_CAMERA_CONTROL, strerror(errno));
|
2011-03-30 21:06:24 +00:00
|
|
|
else
|
2011-03-14 17:24:38 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if ((pthread_create(&mCamConfigThread, NULL, LINK_cam_conf, NULL)) != 0)
|
|
|
|
LOGE("Config thread creation failed!");
|
2011-03-14 17:24:38 +00:00
|
|
|
else
|
|
|
|
LOGV("Config thread created successfully");
|
|
|
|
|
2011-03-17 15:54:35 +00:00
|
|
|
// init this in order to avoid false preview displays
|
2011-03-14 17:24:38 +00:00
|
|
|
bFramePresent=false;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startCamera X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::dump(int fd,
|
|
|
|
const Vector<String16>& args) const
|
|
|
|
{
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
String8 result;
|
|
|
|
|
|
|
|
// Dump internal primitives.
|
|
|
|
result.append("QualcommCameraHardware::dump");
|
|
|
|
snprintf(buffer, 255, "preview width(%d) x height (%d)\n",
|
|
|
|
mPreviewWidth, mPreviewHeight);
|
|
|
|
result.append(buffer);
|
|
|
|
snprintf(buffer, 255, "raw width(%d) x height (%d)\n",
|
|
|
|
mRawWidth, mRawHeight);
|
|
|
|
result.append(buffer);
|
|
|
|
snprintf(buffer, 255,
|
|
|
|
"preview frame size(%d), raw size (%d), jpeg size (%d) "
|
|
|
|
"and jpeg max size (%d)\n", mPreviewFrameSize, mRawSize,
|
|
|
|
mJpegSize, mJpegMaxSize);
|
|
|
|
result.append(buffer);
|
|
|
|
write(fd, result.string(), result.size());
|
|
|
|
|
|
|
|
// Dump internal objects.
|
|
|
|
if (mPreviewHeap != 0) {
|
|
|
|
mPreviewHeap->dump(fd, args);
|
|
|
|
}
|
|
|
|
if (mRawHeap != 0) {
|
|
|
|
mRawHeap->dump(fd, args);
|
|
|
|
}
|
|
|
|
if (mJpegHeap != 0) {
|
|
|
|
mJpegHeap->dump(fd, args);
|
|
|
|
}
|
|
|
|
mParameters.dump(fd, args);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
bool QualcommCameraHardware::reg_unreg_buf(int camfd,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
msm_frame_t *frame,
|
|
|
|
msm_pmem_t pmem_type,
|
|
|
|
unsigned char unregister,
|
|
|
|
unsigned char active)
|
2011-01-12 07:42:14 +00:00
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
uint32_t y_size;
|
|
|
|
struct msm_pmem_info_t pmemBuf;
|
|
|
|
uint32_t ioctl_cmd;
|
|
|
|
int ioctlRetVal;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
memset(&pmemBuf, 0, sizeof(pmemBuf));
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
pmemBuf.type = pmem_type;
|
|
|
|
pmemBuf.fd = frame->fd;
|
|
|
|
pmemBuf.vaddr = (unsigned long *)frame->buffer;
|
|
|
|
pmemBuf.y_off = (frame->y_off + 3) & ~3; // aligned to 4
|
|
|
|
pmemBuf.cbcr_off = (frame->cbcr_off + 3) & ~3;
|
|
|
|
pmemBuf.active = active;
|
|
|
|
|
|
|
|
ioctl_cmd = unregister ?
|
|
|
|
MSM_CAM_IOCTL_UNREGISTER_PMEM :
|
|
|
|
MSM_CAM_IOCTL_REGISTER_PMEM;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
if ((ioctlRetVal = ioctl(camfd, ioctl_cmd, &pmemBuf)) < 0) {
|
|
|
|
LOGE("reg_unreg_buf: MSM_CAM_IOCTL_(UN)REGISTER_PMEM ioctl failed %d",
|
|
|
|
ioctlRetVal);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
void QualcommCameraHardware::native_register_preview_bufs(
|
|
|
|
int camfd,
|
|
|
|
void *pDim,
|
|
|
|
struct msm_frame_t *frame,
|
|
|
|
unsigned char active)
|
2011-01-12 07:42:14 +00:00
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
cam_ctrl_dimension_t *dimension = (cam_ctrl_dimension_t *)pDim;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
reg_unreg_buf(camfd,
|
|
|
|
dimension->display_width,
|
|
|
|
dimension->display_height,
|
|
|
|
frame,
|
|
|
|
MSM_PMEM_OUTPUT2,
|
|
|
|
false,
|
|
|
|
active);
|
|
|
|
}
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
void QualcommCameraHardware::native_unregister_preview_bufs(
|
|
|
|
int camfd,
|
|
|
|
void *pDim,
|
|
|
|
struct msm_frame_t *frame)
|
|
|
|
{
|
|
|
|
cam_ctrl_dimension_t *dimension = (cam_ctrl_dimension_t *)pDim;
|
|
|
|
|
|
|
|
reg_unreg_buf(camfd,
|
|
|
|
dimension->display_width,
|
|
|
|
dimension->display_height,
|
|
|
|
frame,
|
|
|
|
MSM_PMEM_OUTPUT2,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool native_set_afmode(int camfd, isp3a_af_mode_t af_type)
|
|
|
|
{
|
|
|
|
LOGV("Click doesn't support auto focus mode");
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// need to snapshot
|
|
|
|
static bool native_cancel_afmode(int camfd, int af_fd)
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool native_start_preview(int camfd)
|
|
|
|
{
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.type = CAMERA_START_PREVIEW;
|
|
|
|
ctrlCmd.length = 0;
|
2011-03-13 05:49:00 +00:00
|
|
|
ctrlCmd.value = NULL;
|
2011-02-09 17:58:14 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool native_get_picture(int camfd, common_crop_t *crop)
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("native_get_picture E");
|
2011-01-12 07:42:14 +00:00
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
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",
|
|
|
|
camfd,
|
|
|
|
strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
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);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
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);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("crop: update %d", crop->update_flag);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("native_get_picture status after ioctl %d", ctrlCmd.status);
|
|
|
|
LOGV("native_get_picture X");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool native_stop_preview(int camfd)
|
|
|
|
{
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.type = CAMERA_STOP_PREVIEW;
|
|
|
|
ctrlCmd.length = 0;
|
|
|
|
|
|
|
|
if(ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) {
|
|
|
|
LOGE("native_stop_preview: ioctl fd %d error %s",
|
|
|
|
camfd,
|
|
|
|
strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool native_start_snapshot(int camfd)
|
|
|
|
{
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.type = CAMERA_START_SNAPSHOT;
|
|
|
|
ctrlCmd.length = 0;
|
|
|
|
|
|
|
|
if(ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) {
|
|
|
|
LOGE("native_start_snapshot: ioctl fd %d error %s",
|
|
|
|
camfd,
|
|
|
|
strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static bool native_stop_snapshot(int camfd)
|
2011-01-12 07:42:14 +00:00
|
|
|
{
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.type = CAMERA_STOP_SNAPSHOT;
|
|
|
|
ctrlCmd.length = 0;
|
|
|
|
|
|
|
|
if (ioctl(camfd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0) {
|
|
|
|
LOGE("native_stop_snapshot: ioctl fd %d error %s",
|
|
|
|
camfd,
|
|
|
|
strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
void *jpeg_encoder_thread( void *user )
|
2011-01-12 07:42:14 +00:00
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGD("jpeg_encoder_thread E");
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
sp<QualcommCameraHardware> obj = QualcommCameraHardware::getInstance();
|
|
|
|
if (obj != 0) {
|
|
|
|
obj->runJpegEncodeThread(user);
|
|
|
|
}
|
|
|
|
else LOGW("not starting frame thread: the object went away!");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
|
|
|
LOGD("jpeg_encoder_thread X");
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
static bool mJpegThreadRunning = false;
|
2011-01-12 07:42:14 +00:00
|
|
|
bool QualcommCameraHardware::native_jpeg_encode(void)
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
int jpeg_quality = mParameters.getInt("jpeg-quality");
|
|
|
|
if (jpeg_quality >= 0) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("native_jpeg_encode, current jpeg main img quality = %d",
|
2011-01-12 07:42:14 +00:00
|
|
|
jpeg_quality);
|
|
|
|
}
|
|
|
|
|
|
|
|
int thumbnail_quality = mParameters.getInt("jpeg-thumbnail-quality");
|
|
|
|
if (thumbnail_quality >= 0) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("native_jpeg_encode, current jpeg thumbnail quality = %d",
|
2011-01-12 07:42:14 +00:00
|
|
|
thumbnail_quality);
|
|
|
|
}
|
|
|
|
|
|
|
|
int rotation = mParameters.getInt("rotation");
|
|
|
|
if (rotation >= 0) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("native_jpeg_encode, rotation = %d", rotation);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
2011-02-06 18:28:56 +00:00
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
setGpsParameters();
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
mDimension.filler7 = 2560;
|
|
|
|
mDimension.filler8 = 1920;
|
2011-02-06 18:28:56 +00:00
|
|
|
|
|
|
|
int ret = !pthread_create(&jpegThread,
|
2011-03-14 17:24:38 +00:00
|
|
|
NULL,
|
2011-02-06 18:28:56 +00:00
|
|
|
jpeg_encoder_thread,
|
|
|
|
NULL);
|
2011-03-14 17:24:38 +00:00
|
|
|
if (ret)
|
|
|
|
mJpegThreadRunning = true;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::native_set_dimension(cam_ctrl_dimension_t *value)
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("native_set_dimension: EX");
|
2011-01-12 07:42:14 +00:00
|
|
|
return native_set_parm(CAMERA_SET_PARM_DIMENSION,
|
|
|
|
sizeof(cam_ctrl_dimension_t), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::native_set_parm(
|
|
|
|
cam_ctrl_type type, uint16_t length, void *value)
|
|
|
|
{
|
|
|
|
int rc = true;
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.type = (uint16_t)type;
|
|
|
|
ctrlCmd.length = length;
|
2011-03-13 05:49:00 +00:00
|
|
|
ctrlCmd.value = value;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("native_set_parm: type: %d, length=%d", type, length);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
rc = ioctl(mCameraControlFd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd);
|
|
|
|
if(rc < 0 || ctrlCmd.status != CAM_CTRL_SUCCESS) {
|
|
|
|
LOGE("ioctl error. camfd=%d, type=%d, length=%d, rc=%d, ctrlCmd.status=%d, %s",
|
|
|
|
mCameraControlFd, type, length, rc, ctrlCmd.status, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
static void handler(int sig, siginfo_t *siginfo, void *context)
|
|
|
|
{
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set transfer preview meanwhile new preview is captured
|
|
|
|
static void *prev_frame_click(void *user)
|
|
|
|
{
|
|
|
|
while (true) {
|
|
|
|
usleep(1);
|
|
|
|
if(bFramePresent) {
|
|
|
|
if(LOG_PREVIEW)
|
|
|
|
LOGV("PREVIEW ARRIVED !!!!!!");
|
|
|
|
receive_camframe_callback(frameA);
|
|
|
|
bFramePresent=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-17 15:54:35 +00:00
|
|
|
// customized camframe_callback function based on reassembled libmmcamera.so
|
2011-03-30 21:06:24 +00:00
|
|
|
// Routine coded by fn.fyodor and corrected by KalimochoAz
|
2011-03-14 17:24:38 +00:00
|
|
|
static void *cam_frame_click(void *data)
|
2011-03-13 05:49:00 +00:00
|
|
|
{
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("Entering cam_frame_click");
|
|
|
|
|
|
|
|
frameA = (msm_frame_t *)data;
|
|
|
|
|
|
|
|
struct sigaction act;
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
pthread_mutex_t mutex_camframe = PTHREAD_MUTEX_INITIALIZER;
|
2011-03-13 05:49:00 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
fd_set readfds;
|
|
|
|
int ret;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
// found in assembled codes of all libmmcamera
|
|
|
|
memset(&readfds, 0, sizeof(readfds));
|
|
|
|
|
|
|
|
act.sa_sigaction = &handler;
|
|
|
|
act.sa_flags = SA_SIGINFO;
|
|
|
|
if (sigaction(SIGUSR1, &act, NULL) != 0) {
|
|
|
|
LOGE("sigaction in cam_frame failed");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2011-03-13 05:49:00 +00:00
|
|
|
|
|
|
|
FD_ZERO(&readfds);
|
2011-03-14 17:24:38 +00:00
|
|
|
FD_SET(fd_frame, &readfds);
|
2011-03-13 05:49:00 +00:00
|
|
|
|
|
|
|
while (true) {
|
2011-03-14 17:24:38 +00:00
|
|
|
timeout.tv_sec = 1; // This is not important JUST TIMEOUT for fail
|
2011-03-13 05:49:00 +00:00
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
ret = select(fd_frame+1, &readfds, NULL, NULL, &timeout);
|
2011-03-13 05:49:00 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
LOGE("calling select failed!");
|
|
|
|
break;
|
2011-03-14 17:24:38 +00:00
|
|
|
} else if (FD_ISSET(fd_frame, &readfds)) {
|
|
|
|
pthread_mutex_lock(&mutex_camframe);
|
2011-03-13 05:49:00 +00:00
|
|
|
// ready to get frame
|
2011-03-14 17:24:38 +00:00
|
|
|
ret = ioctl(fd_frame, MSM_CAM_IOCTL_GETFRAME, frameA);
|
2011-03-13 05:49:00 +00:00
|
|
|
if (ret >= 0) {
|
|
|
|
// put buffers to config VFE
|
2011-03-14 17:24:38 +00:00
|
|
|
if (ioctl(fd_frame, MSM_CAM_IOCTL_RELEASE_FRAMEE_BUFFER, frameA) < 0)
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGE("MSM_CAM_IOCTL_RELEASE_FRAME_BUFFER error %s", strerror(errno));
|
|
|
|
else
|
2011-03-30 21:06:24 +00:00
|
|
|
receive_camframe_callback(frameA);
|
|
|
|
//bFramePresent=true;
|
2011-03-13 05:49:00 +00:00
|
|
|
} else
|
|
|
|
LOGE("MSM_CAM_IOCTL_GETFRAME error %s", strerror(errno));
|
2011-03-14 17:24:38 +00:00
|
|
|
pthread_mutex_unlock(&mutex_camframe);
|
|
|
|
} else {
|
|
|
|
LOGV("frame is not ready! select returns %d", ret);
|
2011-03-13 05:49:00 +00:00
|
|
|
usleep(100000);
|
2011-03-14 17:24:38 +00:00
|
|
|
}
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
2011-03-14 17:24:38 +00:00
|
|
|
|
|
|
|
return NULL;
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
// ************************************************************************************************************************************
|
|
|
|
//static cam_frame_start_parms frame_parms;
|
|
|
|
static int recordingState = 0;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static rat_t latitude[3];
|
|
|
|
static rat_t longitude[3];
|
|
|
|
static char lonref[2];
|
|
|
|
static char latref[2];
|
|
|
|
static char dateTime[20];
|
|
|
|
static rat_t altitude;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static void addExifTag(exif_tag_id_t tagid, exif_tag_type_t type,
|
|
|
|
uint32_t count, uint8_t copy, void *data) {
|
|
|
|
|
|
|
|
if(exif_table_numEntries == MAX_EXIF_TABLE_ENTRIES) {
|
|
|
|
LOGE("Number of entries exceeded limit");
|
|
|
|
return;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
int index = exif_table_numEntries;
|
|
|
|
exif_data[index].tag_id = tagid;
|
|
|
|
exif_data[index].tag_entry.type = type;
|
|
|
|
exif_data[index].tag_entry.count = count;
|
|
|
|
exif_data[index].tag_entry.copy = copy;
|
|
|
|
// LOGV("AddexifTAG data %s times: %d", data, count);
|
|
|
|
if((type == EXIF_RATIONAL) && (count > 1))
|
|
|
|
exif_data[index].tag_entry.data._rats = (rat_t *)data;
|
|
|
|
if((type == EXIF_RATIONAL) && (count == 1))
|
|
|
|
exif_data[index].tag_entry.data._rat = *(rat_t *)data;
|
|
|
|
else if(type == EXIF_ASCII)
|
|
|
|
exif_data[index].tag_entry.data._ascii = (char *)data;
|
|
|
|
else if(type == EXIF_BYTE)
|
|
|
|
exif_data[index].tag_entry.data._byte = *(uint8_t *)data;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
// Increase number of entries
|
|
|
|
exif_table_numEntries++;
|
|
|
|
return;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
static void parseLatLong(const char *latlonString, int *pDegrees,
|
|
|
|
int *pMinutes, int *pSeconds ) {
|
|
|
|
|
|
|
|
double value = atof(latlonString);
|
|
|
|
value = fabs(value);
|
|
|
|
int degrees = (int) value;
|
|
|
|
|
|
|
|
LOGV("PARSELATLON E");
|
|
|
|
double remainder = value - degrees;
|
|
|
|
int minutes = (int) (remainder * 60);
|
|
|
|
int seconds = (int) (((remainder * 60) - minutes) * 60 * 1000);
|
|
|
|
|
|
|
|
*pDegrees = degrees;
|
|
|
|
*pMinutes = minutes;
|
|
|
|
*pSeconds = seconds;
|
|
|
|
|
|
|
|
LOGV("PARSELATLON E");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setLatLon(exif_tag_id_t tag, const char *latlonString) {
|
|
|
|
|
|
|
|
int degrees, minutes, seconds;
|
|
|
|
LOGV("SETLATLON E");
|
|
|
|
parseLatLong(latlonString, °rees, &minutes, &seconds);
|
|
|
|
|
|
|
|
rat_t value[3] = { {degrees, 1},
|
|
|
|
{minutes, 1},
|
|
|
|
{seconds, 1000} };
|
|
|
|
|
|
|
|
if(tag == EXIFTAGID_GPS_LATITUDE) {
|
|
|
|
memcpy(latitude, value, sizeof(latitude));
|
|
|
|
addExifTag(EXIFTAGID_GPS_LATITUDE, EXIF_RATIONAL, 3,
|
|
|
|
1, (void *)latitude);
|
|
|
|
} else {
|
|
|
|
memcpy(longitude, value, sizeof(longitude));
|
|
|
|
addExifTag(EXIFTAGID_GPS_LONGITUDE, EXIF_RATIONAL, 3,
|
|
|
|
1, (void *)longitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("SETLATLON E");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setGpsParameters() {
|
|
|
|
const char *str = NULL;
|
|
|
|
|
|
|
|
//Set Latitude
|
|
|
|
str = mParameters.get(CameraParameters::KEY_GPS_LATITUDE);
|
|
|
|
LOGV("Latitude: %s", str);
|
|
|
|
if(str != NULL) {
|
|
|
|
setLatLon(EXIFTAGID_GPS_LATITUDE, str);
|
|
|
|
//set Latitude Ref
|
|
|
|
str = NULL;
|
|
|
|
str = mParameters.get(CameraParameters::KEY_GPS_LATITUDE_REF);
|
|
|
|
if(str != NULL) {
|
|
|
|
strncpy(latref, str, 1);
|
|
|
|
latref[1] = '\0';
|
|
|
|
addExifTag(EXIFTAGID_GPS_LATITUDE_REF, EXIF_ASCII, 2,
|
|
|
|
1, (void *)latref);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
|
|
|
//set Longitude
|
|
|
|
str = NULL;
|
|
|
|
str = mParameters.get(CameraParameters::KEY_GPS_LONGITUDE);
|
|
|
|
if(str != NULL) {
|
|
|
|
setLatLon(EXIFTAGID_GPS_LONGITUDE, str);
|
|
|
|
//set Longitude Ref
|
|
|
|
str = NULL;
|
|
|
|
str = mParameters.get(CameraParameters::KEY_GPS_LONGITUDE_REF);
|
|
|
|
if(str != NULL) {
|
|
|
|
strncpy(lonref, str, 1);
|
|
|
|
lonref[1] = '\0';
|
|
|
|
addExifTag(EXIFTAGID_GPS_LONGITUDE_REF, EXIF_ASCII, 2,
|
|
|
|
1, (void *)lonref);
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
2011-03-30 21:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//set Altitude
|
|
|
|
str = NULL;
|
|
|
|
str = mParameters.get(CameraParameters::KEY_GPS_ALTITUDE);
|
|
|
|
if(str != NULL) {
|
|
|
|
double value = atoi(str);
|
|
|
|
uint32_t value_meter = value * 1000;
|
|
|
|
rat_t alt_value = {value_meter, 1000};
|
|
|
|
memcpy(&altitude, &alt_value, sizeof(altitude));
|
|
|
|
addExifTag(EXIFTAGID_GPS_ALTITUDE, EXIF_RATIONAL, 1,
|
|
|
|
1, (void *)&altitude);
|
|
|
|
//set AltitudeRef
|
|
|
|
int ref = mParameters.getInt(CameraParameters::KEY_GPS_ALTITUDE_REF);
|
|
|
|
if( !(ref < 0 || ref > 1) )
|
|
|
|
addExifTag(EXIFTAGID_GPS_ALTITUDE_REF, EXIF_BYTE, 1,
|
|
|
|
1, (void *)&ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
2011-03-30 21:06:24 +00:00
|
|
|
|
|
|
|
// **************************************************************************************************************************************************
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
void QualcommCameraHardware::runJpegEncodeThread(void *data)
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
//Reset the Gps Information
|
|
|
|
exif_table_numEntries = 0;
|
|
|
|
LOGV("runJpegEncodeThread E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
int rotation = mParameters.getInt("rotation");
|
|
|
|
LOGD("native_jpeg_encode, rotation = %d", rotation);
|
|
|
|
|
|
|
|
bool encode_location = true;
|
2011-03-30 21:06:24 +00:00
|
|
|
camera_position_type pt;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-17 15:54:35 +00:00
|
|
|
#define PARSE_LOCATION(what,type,fmt,desc) do { \
|
|
|
|
pt.what = 0; \
|
|
|
|
const char *what##_str = mParameters.get("gps-"#what); \
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("GPS PARM %s --> [%s]", "gps-"#what, what##_str); \
|
2011-03-17 15:54:35 +00:00
|
|
|
if (what##_str) { \
|
|
|
|
type what = 0; \
|
|
|
|
if (sscanf(what##_str, fmt, &what) == 1) \
|
|
|
|
pt.what = what; \
|
|
|
|
else { \
|
|
|
|
LOGE("GPS " #what " %s could not" \
|
|
|
|
" be parsed as a " #desc, what##_str); \
|
|
|
|
encode_location = false; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
LOGD("GPS " #what " not specified: " \
|
|
|
|
"defaulting to zero in EXIF header."); \
|
|
|
|
encode_location = false; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
PARSE_LOCATION(timestamp, long, "%ld", "long");
|
|
|
|
if (!pt.timestamp) pt.timestamp = time(NULL);
|
|
|
|
PARSE_LOCATION(altitude, short, "%hd", "short");
|
|
|
|
PARSE_LOCATION(latitude, double, "%lf", "double float");
|
|
|
|
PARSE_LOCATION(longitude, double, "%lf", "double float");
|
|
|
|
|
2011-03-17 15:54:35 +00:00
|
|
|
#undef PARSE_LOCATION
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if (encode_location) {
|
|
|
|
LOGD("setting image location ALT %d LAT %lf LON %lf",
|
|
|
|
pt.altitude, pt.latitude, pt.longitude);
|
|
|
|
}
|
|
|
|
else {
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("FAIL LOCATE PICTURE: not setting image location");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
camera_position_type *npt = &pt;
|
2011-03-13 05:49:00 +00:00
|
|
|
if(!encode_location) {
|
|
|
|
npt = NULL;
|
2011-03-30 21:06:24 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
}
|
2011-02-06 18:28:56 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
int jpeg_quality = mParameters.getInt("jpeg-quality");
|
2011-03-30 21:06:24 +00:00
|
|
|
|
|
|
|
// Receive and convert to jpeg internaly, without using privative app
|
2011-03-13 05:49:00 +00:00
|
|
|
if (yuv420_save2jpeg((unsigned char*) mJpegHeap->mHeap->base(),
|
|
|
|
mRawHeap->mHeap->base(), mRawWidth, mRawHeight, jpeg_quality, &mJpegSize))
|
|
|
|
LOGV("jpegConvert done! ExifWriter...");
|
2011-02-09 17:58:14 +00:00
|
|
|
else
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGE("jpegConvert failed!");
|
2011-02-18 15:49:31 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
writeExif(mJpegHeap->mHeap->base(), mJpegHeap->mHeap->base(), mJpegSize,
|
|
|
|
&mJpegSize, rotation, npt);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
receiveJpegPicture();
|
2011-03-30 21:06:24 +00:00
|
|
|
|
|
|
|
mJpegThreadRunning = false;
|
|
|
|
LOGV("runJpegEncodeThread X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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().
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initPreview E: preview size=%dx%d", mPreviewWidth, mPreviewHeight);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
mFrameThreadWaitLock.lock();
|
|
|
|
while (mFrameThreadRunning) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("initPreview: waiting for old frame thread to complete.");
|
2011-01-12 07:42:14 +00:00
|
|
|
mFrameThreadWait.wait(mFrameThreadWaitLock);
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("initPreview: old frame thread completed.");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
mFrameThreadWaitLock.unlock();
|
|
|
|
|
|
|
|
mSnapshotThreadWaitLock.lock();
|
|
|
|
while (mSnapshotThreadRunning) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initPreview: waiting for old snapshot thread to complete.");
|
2011-01-12 07:42:14 +00:00
|
|
|
mSnapshotThreadWait.wait(mSnapshotThreadWaitLock);
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("initPreview: old snapshot thread completed.");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
mSnapshotThreadWaitLock.unlock();
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
mPreviewFrameSize = mPreviewWidth * mPreviewHeight * 3/2;
|
|
|
|
mPreviewHeap = new PreviewPmemPool(mCameraControlFd,
|
|
|
|
mPreviewWidth * mPreviewHeight * 2,
|
2011-02-06 18:28:56 +00:00
|
|
|
kPreviewBufferCount,
|
|
|
|
mPreviewFrameSize,
|
|
|
|
0,
|
|
|
|
"preview");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if (!mPreviewHeap->initialized()) {
|
|
|
|
mPreviewHeap.clear();
|
|
|
|
LOGE("initPreview X: could not initialize preview heap.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
mDimension.picture_width = DEFAULT_PICTURE_WIDTH;
|
2011-01-12 07:42:14 +00:00
|
|
|
mDimension.picture_height = DEFAULT_PICTURE_HEIGHT;
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
unsigned char activeBuffer;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// (sizeof(mDimension) == 0x70) found in assembled codes
|
|
|
|
// element type was unsigned long?
|
|
|
|
if (native_set_dimension(&mDimension)) {
|
2011-01-12 07:42:14 +00:00
|
|
|
for (int cnt = 0; cnt < kPreviewBufferCount; cnt++) {
|
|
|
|
frames[cnt].fd = mPreviewHeap->mHeap->getHeapID();
|
2011-03-13 05:49:00 +00:00
|
|
|
frames[cnt].buffer = (uint32_t)mPreviewHeap->mHeap->base();
|
2011-03-30 21:06:24 +00:00
|
|
|
frames[cnt].y_off = 0;
|
|
|
|
frames[cnt].cbcr_off = mPreviewWidth * mPreviewHeight;
|
2011-03-13 05:49:00 +00:00
|
|
|
|
|
|
|
if (frames[cnt].buffer == 0) {
|
|
|
|
LOGV("frames[%d].buffer: malloc failed!", cnt);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
frames[cnt].path = MSM_FRAME_ENC;
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
activeBuffer = (cnt != kPreviewBufferCount - 1) ? 1 : 0;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
// returned type should be bool, verified from assembled codes
|
2011-03-13 05:49:00 +00:00
|
|
|
native_register_preview_bufs(mCameraControlFd,
|
|
|
|
&mDimension,
|
|
|
|
&frames[cnt],
|
|
|
|
activeBuffer);
|
|
|
|
|
|
|
|
if (cnt == kPreviewBufferCount - 1) {
|
|
|
|
LOGV("set preview callback");
|
|
|
|
|
|
|
|
mFrameThreadRunning = !pthread_create(&mFrameThread,
|
2011-03-14 17:24:38 +00:00
|
|
|
NULL,
|
|
|
|
cam_frame_click, //frame_thread,
|
2011-03-13 05:49:00 +00:00
|
|
|
&frames[cnt]);
|
|
|
|
if (mFrameThreadRunning)
|
|
|
|
LOGV("Preview thread created");
|
|
|
|
else
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGE("Preview thread error");
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
LOGE("native_set_dimension failed");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
return mFrameThreadRunning;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::deinitPreview(void)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("deinitPreview E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// is that deinitPreview is sometimes called from the frame-thread's
|
|
|
|
// callback, when the refcount on the Camera client reaches zero. If we
|
|
|
|
// called pthread_join(), we would deadlock. So, we just call
|
|
|
|
// LINK_camframe_terminate() in deinitPreview(), which makes sure that
|
|
|
|
// after the preview callback returns, the camframe thread will exit. We
|
|
|
|
// could call pthread_join() in initPreview() to join the last frame
|
|
|
|
// thread. However, we would also have to call pthread_join() in release
|
|
|
|
// as well, shortly before we destoy the object; this would cause the same
|
|
|
|
// deadlock, since release(), like deinitPreview(), may also be called from
|
|
|
|
// the frame-thread's callback. This we have to make the frame thread
|
|
|
|
// detached, and use a separate mechanism to wait for it to complete.
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
// camframe_terminate() never been used
|
|
|
|
|
|
|
|
if (mFrameThreadRunning) {
|
|
|
|
// Send a exit signal to stop the frame thread
|
|
|
|
if (!pthread_kill(mFrameThread, SIGUSR1)) {
|
|
|
|
LOGV("terminate frame_thread successfully");
|
|
|
|
mFrameThreadRunning = false;
|
|
|
|
} else
|
|
|
|
LOGE("frame_thread doesn't exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("Unregister preview buffers");
|
|
|
|
for (int cnt = 0; cnt < kPreviewBufferCount; ++cnt) {
|
|
|
|
native_unregister_preview_bufs(mCameraControlFd,
|
|
|
|
&mDimension,
|
|
|
|
&frames[cnt]);
|
|
|
|
}
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
mPreviewHeap.clear();
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("deinitPreview X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::initRaw(bool initJpegHeap)
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("initRaw E: picture size=%dx%d", mRawWidth, mRawHeight);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
mDimension.picture_width = mRawWidth;
|
|
|
|
mDimension.picture_height = mRawHeight;
|
|
|
|
mRawSize = mRawWidth * mRawHeight * 3 / 2;
|
|
|
|
mJpegMaxSize = mRawWidth * mRawHeight * 3 / 2;
|
|
|
|
|
|
|
|
if(!native_set_dimension(&mDimension)) {
|
|
|
|
LOGE("initRaw X: failed to set dimension");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mJpegHeap != NULL) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initRaw: clearing old mJpegHeap.");
|
2011-01-12 07:42:14 +00:00
|
|
|
mJpegHeap.clear();
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("initRaw: initializing mThumbHeap. with size %d", THUMBNAIL_BUFFER_SIZE);
|
2011-01-12 07:42:14 +00:00
|
|
|
mThumbnailHeap =
|
|
|
|
new PmemPool("/dev/pmem_adsp",
|
|
|
|
mCameraControlFd,
|
|
|
|
MSM_PMEM_THUMBNAIL,
|
|
|
|
THUMBNAIL_BUFFER_SIZE,
|
|
|
|
1,
|
|
|
|
THUMBNAIL_BUFFER_SIZE,
|
|
|
|
0,
|
|
|
|
"thumbnail camera");
|
|
|
|
|
|
|
|
if (!mThumbnailHeap->initialized()) {
|
|
|
|
mThumbnailHeap.clear();
|
|
|
|
mRawHeap.clear();
|
|
|
|
LOGE("initRaw X failed: error initializing mThumbnailHeap.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("initRaw: initializing mRawHeap. with size %d", mRawSize);
|
2011-01-12 07:42:14 +00:00
|
|
|
mRawHeap =
|
|
|
|
new PmemPool("/dev/pmem_camera",
|
|
|
|
mCameraControlFd,
|
|
|
|
MSM_PMEM_MAINIMG,
|
|
|
|
mJpegMaxSize,
|
|
|
|
kRawBufferCount,
|
|
|
|
mRawSize,
|
|
|
|
0,
|
|
|
|
"snapshot camera");
|
|
|
|
|
|
|
|
if (!mRawHeap->initialized()) {
|
|
|
|
LOGE("initRaw X failed with pmem_camera, trying with pmem_adsp");
|
|
|
|
mRawHeap =
|
|
|
|
new PmemPool("/dev/pmem_adsp",
|
|
|
|
mCameraControlFd,
|
|
|
|
MSM_PMEM_MAINIMG,
|
|
|
|
mJpegMaxSize,
|
|
|
|
kRawBufferCount,
|
|
|
|
mRawSize,
|
|
|
|
0,
|
|
|
|
"snapshot camera");
|
|
|
|
if (!mRawHeap->initialized()) {
|
|
|
|
mRawHeap.clear();
|
|
|
|
LOGE("initRaw X: error initializing mRawHeap");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("do_mmap snapshot pbuf = %p, pmem_fd = %d",
|
2011-01-12 07:42:14 +00:00
|
|
|
(uint8_t *)mRawHeap->mHeap->base(), mRawHeap->mHeap->getHeapID());
|
|
|
|
|
|
|
|
if (initJpegHeap) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initRaw: initializing mJpegHeap.");
|
2011-01-12 07:42:14 +00:00
|
|
|
mJpegHeap =
|
|
|
|
new AshmemPool(mJpegMaxSize,
|
|
|
|
kJpegBufferCount,
|
|
|
|
0, // we do not know how big the picture wil be
|
|
|
|
0,
|
|
|
|
"jpeg");
|
|
|
|
|
|
|
|
if (!mJpegHeap->initialized()) {
|
|
|
|
mJpegHeap.clear();
|
|
|
|
mRawHeap.clear();
|
|
|
|
LOGE("initRaw X failed: error initializing mJpegHeap.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mRawInitialized = true;
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("initRaw X success");
|
2011-01-12 07:42:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::deinitRaw()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("deinitRaw E");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
mThumbnailHeap.clear();
|
|
|
|
mJpegHeap.clear();
|
|
|
|
mRawHeap.clear();
|
|
|
|
mRawInitialized = false;
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("deinitRaw X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::release()
|
|
|
|
{
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("release E");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
#if DLOPEN_LIBMMCAMERA
|
2011-03-30 21:06:24 +00:00
|
|
|
if (libmmcamera_target == NULL) {
|
2011-01-12 07:42:14 +00:00
|
|
|
LOGE("ERROR: multiple release!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
2011-03-14 17:24:38 +00:00
|
|
|
#warning "Cannot detect multiple release when not dlopen()ing libmmcamera!"
|
2011-01-12 07:42:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
struct msm_ctrl_cmd_t ctrlCmd;
|
|
|
|
|
|
|
|
if (mCameraRunning) {
|
2011-03-13 05:49:00 +00:00
|
|
|
if (mMsgEnabled & CAMERA_MSG_VIDEO_FRAME) {
|
2011-01-12 07:42:14 +00:00
|
|
|
mRecordFrameLock.lock();
|
|
|
|
mReleasedRecordingFrame = true;
|
|
|
|
mRecordWait.signal();
|
|
|
|
mRecordFrameLock.unlock();
|
2011-03-13 05:49:00 +00:00
|
|
|
}
|
2011-01-12 07:42:14 +00:00
|
|
|
stopPreviewInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mRawInitialized) deinitRaw();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("CAMERA_EXIT");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
ctrlCmd.timeout_ms = 5000;
|
|
|
|
ctrlCmd.length = 0;
|
|
|
|
ctrlCmd.type = (uint16_t)CAMERA_EXIT;
|
|
|
|
|
|
|
|
if (ioctl(mCameraControlFd, MSM_CAM_IOCTL_CTRL_COMMAND, &ctrlCmd) < 0)
|
|
|
|
LOGE("ioctl CAMERA_EXIT fd %d error %s",
|
|
|
|
mCameraControlFd, strerror(errno));
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("Stopping the conf thread");
|
2011-01-12 07:42:14 +00:00
|
|
|
rc = pthread_join(mCamConfigThread, NULL);
|
|
|
|
if (rc)
|
|
|
|
LOGE("config_thread exit failure: %s", strerror(errno));
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (mJpegThreadRunning) {
|
|
|
|
LOGV("Stopping the jpeg thread");
|
|
|
|
rc = pthread_join(jpegThread, NULL);
|
|
|
|
if (rc)
|
|
|
|
LOGE("jpeg_thread exit failure: %s", strerror(errno));
|
2011-02-06 18:28:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
memset(&mDimension, 0, sizeof(mDimension));
|
2011-02-06 18:28:56 +00:00
|
|
|
|
|
|
|
close(mCameraControlFd);
|
|
|
|
mCameraControlFd = -1;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
close(fd_frame);
|
|
|
|
fd_frame = -1;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
#if DLOPEN_LIBMMCAMERA
|
|
|
|
if (libmmcamera_target) {
|
|
|
|
::dlclose(libmmcamera_target);
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("dlclose(libmmcamera_target)");
|
2011-01-12 07:42:14 +00:00
|
|
|
libmmcamera_target = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Mutex::Autolock lock(&singleton_lock);
|
|
|
|
singleton_releasing = true;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("release X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::~QualcommCameraHardware()
|
|
|
|
{
|
|
|
|
LOGD("~QualcommCameraHardware E");
|
|
|
|
Mutex::Autolock lock(&singleton_lock);
|
|
|
|
singleton.clear();
|
|
|
|
singleton_releasing = false;
|
|
|
|
singleton_wait.signal();
|
|
|
|
LOGD("~QualcommCameraHardware X");
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<IMemoryHeap> QualcommCameraHardware::getRawHeap() const
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("getRawHeap");
|
2011-01-12 07:42:14 +00:00
|
|
|
return mRawHeap != NULL ? mRawHeap->mHeap : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<IMemoryHeap> QualcommCameraHardware::getPreviewHeap() const
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("getPreviewHeap");
|
2011-01-12 07:42:14 +00:00
|
|
|
return mPreviewHeap != NULL ? mPreviewHeap->mHeap : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::startPreviewInternal()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startPreview E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
if (mCameraRunning) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startPreview X: preview already running.");
|
2011-01-12 07:42:14 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPreviewInitialized) {
|
|
|
|
mPreviewInitialized = initPreview();
|
|
|
|
if (!mPreviewInitialized) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGE("startPreview X initPreview failed. Not starting preview.");
|
2011-01-12 07:42:14 +00:00
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mCameraRunning = native_start_preview(mCameraControlFd);
|
|
|
|
if (!mCameraRunning) {
|
|
|
|
deinitPreview();
|
|
|
|
mPreviewInitialized = false;
|
|
|
|
LOGE("startPreview X: native_start_preview failed!");
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startPreview X");
|
2011-01-12 07:42:14 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::startPreview()
|
|
|
|
{
|
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
return startPreviewInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::stopPreviewInternal()
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("stopPreviewInternal E with mCameraRunning %d", mCameraRunning);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (mCameraRunning) {
|
|
|
|
// Cancel auto focus.
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_FOCUS) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("canceling autofocus");
|
2011-01-12 07:42:14 +00:00
|
|
|
cancelAutoFocus();
|
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("Stopping preview");
|
2011-01-12 07:42:14 +00:00
|
|
|
mCameraRunning = !native_stop_preview(mCameraControlFd);
|
|
|
|
if (!mCameraRunning && mPreviewInitialized) {
|
|
|
|
deinitPreview();
|
|
|
|
mPreviewInitialized = false;
|
|
|
|
}
|
|
|
|
else LOGE("stopPreviewInternal: failed to stop preview");
|
|
|
|
}
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("stopPreviewInternal X with mCameraRunning %d", mCameraRunning);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::stopPreview()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("stopPreview: E");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
if(mMsgEnabled & CAMERA_MSG_VIDEO_FRAME)
|
2011-03-13 05:49:00 +00:00
|
|
|
return;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (mCameraRunning)
|
|
|
|
stopPreviewInternal();
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("stopPreview: X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::runAutoFocus()
|
|
|
|
{
|
|
|
|
mAutoFocusThreadLock.lock();
|
|
|
|
mAutoFocusFd = open(MSM_CAMERA_CONTROL, O_RDWR);
|
|
|
|
if (mAutoFocusFd < 0) {
|
|
|
|
LOGE("autofocus: cannot open %s: %s",
|
|
|
|
MSM_CAMERA_CONTROL,
|
|
|
|
strerror(errno));
|
|
|
|
mAutoFocusThreadRunning = false;
|
|
|
|
mAutoFocusThreadLock.unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This will block until either AF completes or is cancelled. */
|
|
|
|
bool status = native_set_afmode(mAutoFocusFd, AF_MODE_AUTO);
|
|
|
|
mAutoFocusThreadRunning = false;
|
|
|
|
close(mAutoFocusFd);
|
|
|
|
mAutoFocusFd = -1;
|
|
|
|
mAutoFocusThreadLock.unlock();
|
|
|
|
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_FOCUS)
|
|
|
|
mNotifyCb(CAMERA_MSG_FOCUS, status, 0, mCallbackCookie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::cancelAutoFocus()
|
|
|
|
{
|
2011-03-14 17:24:38 +00:00
|
|
|
native_cancel_afmode(mCameraControlFd, mAutoFocusFd);
|
2011-01-12 07:42:14 +00:00
|
|
|
/* Needed for eclair camera PAI */
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *auto_focus_thread(void *user)
|
|
|
|
{
|
|
|
|
sp<QualcommCameraHardware> obj = QualcommCameraHardware::getInstance();
|
|
|
|
if (obj != 0) {
|
|
|
|
obj->runAutoFocus();
|
|
|
|
}
|
|
|
|
else LOGW("not starting autofocus: the object went away!");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::autoFocus()
|
|
|
|
{
|
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
if (mCameraControlFd < 0) {
|
|
|
|
LOGE("not starting autofocus: main control fd %d", mCameraControlFd);
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
mAutoFocusThreadLock.lock();
|
|
|
|
if (!mAutoFocusThreadRunning) {
|
|
|
|
// Create a detatched thread here so that we don't have to wait
|
|
|
|
// for it when we cancel AF.
|
|
|
|
pthread_t thr;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
mAutoFocusThreadRunning =
|
|
|
|
!pthread_create(&thr, &attr,
|
|
|
|
auto_focus_thread, NULL);
|
|
|
|
if (!mAutoFocusThreadRunning) {
|
|
|
|
LOGE("failed to start autofocus thread");
|
|
|
|
mAutoFocusThreadLock.unlock();
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mAutoFocusThreadLock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::runSnapshotThread(void *data)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("runSnapshotThread E");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
if (native_start_snapshot(mCameraControlFd))
|
|
|
|
receiveRawPicture();
|
|
|
|
else
|
|
|
|
LOGE("main: native_start_snapshot failed!");
|
|
|
|
|
|
|
|
mSnapshotThreadWaitLock.lock();
|
|
|
|
mSnapshotThreadRunning = false;
|
|
|
|
mSnapshotThreadWait.signal();
|
|
|
|
mSnapshotThreadWaitLock.unlock();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("runSnapshotThread X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *snapshot_thread(void *user)
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("snapshot_thread E");
|
2011-01-12 07:42:14 +00:00
|
|
|
sp<QualcommCameraHardware> obj = QualcommCameraHardware::getInstance();
|
|
|
|
if (obj != 0) {
|
|
|
|
obj->runSnapshotThread(user);
|
|
|
|
}
|
|
|
|
else LOGW("not starting snapshot thread: the object went away!");
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("snapshot_thread X");
|
2011-01-12 07:42:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::takePicture()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("takePicture: E");
|
2011-03-30 21:06:24 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
// Wait for old snapshot thread to complete.
|
|
|
|
mSnapshotThreadWaitLock.lock();
|
|
|
|
while (mSnapshotThreadRunning) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("takePicture: waiting for old snapshot thread to complete.");
|
2011-01-12 07:42:14 +00:00
|
|
|
mSnapshotThreadWait.wait(mSnapshotThreadWaitLock);
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("takePicture: old snapshot thread completed.");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (mCameraRunning)
|
|
|
|
stopPreviewInternal();
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (!initRaw(mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE)) {
|
2011-01-12 07:42:14 +00:00
|
|
|
LOGE("initRaw failed. Not taking picture.");
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
mShutterLock.lock();
|
|
|
|
mShutterPending = true;
|
|
|
|
mShutterLock.unlock();
|
|
|
|
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
mSnapshotThreadRunning = !pthread_create(&mSnapshotThread,
|
|
|
|
&attr,
|
|
|
|
snapshot_thread,
|
|
|
|
NULL);
|
|
|
|
mSnapshotThreadWaitLock.unlock();
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
// FIXME Removing this blocks capture, but adding it of course removes picture zoom
|
|
|
|
mParameters.set(CameraParameters::KEY_ZOOM, "0");
|
|
|
|
setZoom();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("takePicture: X");
|
2011-03-30 21:06:24 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
return mSnapshotThreadRunning ? NO_ERROR : UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::cancelPicture()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("cancelPicture: EX");
|
2011-01-12 07:42:14 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
void QualcommCameraHardware::initCameraParameters()
|
|
|
|
{
|
|
|
|
LOGV("initCameraParameters: E");
|
2011-03-30 21:06:24 +00:00
|
|
|
if (mCameraRunning)
|
|
|
|
{
|
|
|
|
setAntibanding();
|
|
|
|
setEffect();
|
|
|
|
setWhiteBalance();
|
|
|
|
setZoom();
|
|
|
|
}
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("initCameraParameters: X");
|
|
|
|
}
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
status_t QualcommCameraHardware::setParameters(
|
|
|
|
const CameraParameters& params)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("setParameters: E params = %p", ¶ms);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
// Set preview size.
|
|
|
|
preview_size_type *ps = preview_sizes;
|
|
|
|
{
|
|
|
|
int width, height;
|
2011-03-13 05:49:00 +00:00
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
params.getPreviewSize(&width, &height);
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("requested size %d x %d", width, height);
|
2011-03-13 05:49:00 +00:00
|
|
|
// Validate the preview sizes
|
2011-01-12 07:42:14 +00:00
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < PREVIEW_SIZE_COUNT; ++i, ++ps) {
|
|
|
|
if (width == ps->width && height == ps->height)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == PREVIEW_SIZE_COUNT) {
|
|
|
|
LOGE("Invalid preview size requested: %dx%d",
|
|
|
|
width, height);
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
mPreviewWidth = mDimension.display_width = ps->width;
|
|
|
|
mPreviewHeight = mDimension.display_height = ps->height;
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
params.getPictureSize(&mRawWidth, &mRawHeight);
|
|
|
|
mDimension.picture_width = mRawWidth;
|
|
|
|
mDimension.picture_height = mRawHeight;
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
if(setGpsLocation(params) == NO_ERROR)
|
|
|
|
LOGV("Seting GPS Parameters OK");
|
|
|
|
else
|
|
|
|
LOGE("Error Seting GPS Parameters");
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
// Set up the jpeg-thumbnail-size parameters.
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = params.getInt("jpeg-thumbnail-width");
|
|
|
|
if (val < 0) {
|
|
|
|
mDimension.ui_thumbnail_width= THUMBNAIL_WIDTH;
|
|
|
|
LOGW("jpeg-thumbnail-width is not specified: defaulting to %d",
|
|
|
|
THUMBNAIL_WIDTH);
|
|
|
|
}
|
|
|
|
else mDimension.ui_thumbnail_width = val;
|
|
|
|
|
|
|
|
val = params.getInt("jpeg-thumbnail-height");
|
|
|
|
if (val < 0) {
|
|
|
|
mDimension.ui_thumbnail_height= THUMBNAIL_HEIGHT;
|
|
|
|
LOGW("jpeg-thumbnail-height is not specified: defaulting to %d",
|
|
|
|
THUMBNAIL_HEIGHT);
|
|
|
|
}
|
|
|
|
else mDimension.ui_thumbnail_height = val;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// setParameters
|
2011-01-12 07:42:14 +00:00
|
|
|
mParameters = params;
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
initCameraParameters();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("setParameters: X");
|
2011-03-13 05:49:00 +00:00
|
|
|
return NO_ERROR;
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CameraParameters QualcommCameraHardware::getParameters() const
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("getParameters: EX");
|
2011-01-12 07:42:14 +00:00
|
|
|
return mParameters;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" sp<CameraHardwareInterface> openCameraHardware()
|
|
|
|
{
|
|
|
|
return QualcommCameraHardware::createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
wp<QualcommCameraHardware> QualcommCameraHardware::singleton;
|
|
|
|
|
|
|
|
// If the hardware already exists, return a strong pointer to the current
|
|
|
|
// object. If not, create a new hardware object, put it in the singleton,
|
|
|
|
// and return it.
|
|
|
|
sp<CameraHardwareInterface> QualcommCameraHardware::createInstance()
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGD("Revision: %s%s", REVISION_C, REVISION_H);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("createInstance: E");
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("get into singleton lock");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock lock(&singleton_lock);
|
|
|
|
|
|
|
|
// Wait until the previous release is done.
|
|
|
|
while (singleton_releasing) {
|
|
|
|
LOGD("Wait for previous release.");
|
|
|
|
singleton_wait.wait(singleton_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (singleton != 0) {
|
|
|
|
sp<CameraHardwareInterface> hardware = singleton.promote();
|
|
|
|
if (hardware != 0) {
|
|
|
|
LOGD("createInstance: X return existing hardware=%p", &(*hardware));
|
|
|
|
return hardware;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int rc = stat("/dev/oncrpc", &st);
|
|
|
|
if (rc < 0) {
|
|
|
|
LOGD("createInstance: X failed to create hardware: %s", strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware *cam = new QualcommCameraHardware();
|
|
|
|
sp<QualcommCameraHardware> hardware(cam);
|
|
|
|
singleton = hardware;
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
cam->initDefaultParameters();
|
|
|
|
cam->startCamera();
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("createInstance: X created hardware=%p", &(*hardware));
|
2011-01-12 07:42:14 +00:00
|
|
|
return hardware;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For internal use only, hence the strong pointer to the derived type.
|
|
|
|
sp<QualcommCameraHardware> QualcommCameraHardware::getInstance()
|
|
|
|
{
|
|
|
|
sp<CameraHardwareInterface> hardware = singleton.promote();
|
|
|
|
if (hardware != 0) {
|
|
|
|
return sp<QualcommCameraHardware>(static_cast<QualcommCameraHardware*>(hardware.get()));
|
|
|
|
} else {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("getInstance: X new instance of hardware");
|
2011-01-12 07:42:14 +00:00
|
|
|
return sp<QualcommCameraHardware>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// passes the Addresses to CameraService to getPreviewHeap
|
2011-01-12 07:42:14 +00:00
|
|
|
void QualcommCameraHardware::receivePreviewFrame(struct msm_frame_t *frame)
|
|
|
|
{
|
2011-03-14 17:24:38 +00:00
|
|
|
if ( LOG_PREVIEW )
|
|
|
|
LOGV("receivePreviewFrame E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if (!mCameraRunning) {
|
|
|
|
LOGE("ignoring preview callback--camera has been stopped");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the offset within the heap of the current buffer.
|
|
|
|
ssize_t offset =
|
|
|
|
(ssize_t)frame->buffer - (ssize_t)mPreviewHeap->mHeap->base();
|
|
|
|
offset /= mPreviewFrameSize;
|
|
|
|
|
|
|
|
mInPreviewCallback = true;
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME)
|
|
|
|
mDataCb(CAMERA_MSG_PREVIEW_FRAME, mPreviewHeap->mBuffers[offset], mCallbackCookie);
|
|
|
|
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_VIDEO_FRAME) {
|
|
|
|
Mutex::Autolock rLock(&mRecordFrameLock);
|
2011-03-14 17:24:38 +00:00
|
|
|
mDataCbTimestamp(systemTime(), CAMERA_MSG_VIDEO_FRAME,
|
|
|
|
mPreviewHeap->mBuffers[offset], mCallbackCookie);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
mReleasedRecordingFrame = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInPreviewCallback = false;
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if ( LOG_PREVIEW )
|
|
|
|
LOGV("receivePreviewFrame X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::startRecording()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("startRecording E");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
mReleasedRecordingFrame = false;
|
|
|
|
mCameraRecording = true;
|
|
|
|
|
|
|
|
return startPreviewInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::stopRecording()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("stopRecording: E");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
|
|
|
|
{
|
|
|
|
mRecordFrameLock.lock();
|
|
|
|
mReleasedRecordingFrame = true;
|
|
|
|
mRecordWait.signal();
|
|
|
|
mRecordFrameLock.unlock();
|
|
|
|
|
|
|
|
mCameraRecording = false;
|
|
|
|
|
|
|
|
if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("stopRecording: X, preview still in progress");
|
2011-01-12 07:42:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 17:24:38 +00:00
|
|
|
if (mCameraRunning)
|
|
|
|
stopPreviewInternal();
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("stopRecording: X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::releaseRecordingFrame(
|
|
|
|
const sp<IMemory>& mem __attribute__((unused)))
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("releaseRecordingFrame E");
|
2011-01-12 07:42:14 +00:00
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
Mutex::Autolock rLock(&mRecordFrameLock);
|
|
|
|
mReleasedRecordingFrame = true;
|
|
|
|
mRecordWait.signal();
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("releaseRecordingFrame X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::recordingEnabled()
|
|
|
|
{
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("recordingEnabled");
|
2011-01-12 07:42:14 +00:00
|
|
|
return (mCameraRunning && mCameraRecording);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::notifyShutter()
|
|
|
|
{
|
|
|
|
mShutterLock.lock();
|
|
|
|
if (mShutterPending && (mMsgEnabled & CAMERA_MSG_SHUTTER)) {
|
|
|
|
mNotifyCb(CAMERA_MSG_SHUTTER, 0, 0, mCallbackCookie);
|
|
|
|
mShutterPending = false;
|
|
|
|
}
|
|
|
|
mShutterLock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::receiveRawPicture()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveRawPicture: E");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
notifyShutter();
|
|
|
|
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_RAW_IMAGE) {
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("before native_get_picture");
|
2011-01-12 07:42:14 +00:00
|
|
|
if(native_get_picture(mCameraControlFd, &mCrop) == false) {
|
|
|
|
LOGE("getPicture failed!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDataCb(CAMERA_MSG_RAW_IMAGE, mRawHeap->mBuffers[0], mCallbackCookie);
|
|
|
|
}
|
2011-02-09 17:58:14 +00:00
|
|
|
else LOGV("Raw-picture callback was canceled--skipping.");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) {
|
2011-03-13 05:49:00 +00:00
|
|
|
mJpegSize = mRawWidth * mRawHeight * 3/2;
|
|
|
|
LOGV("Before JPEG Encoder Init");
|
2011-01-12 07:42:14 +00:00
|
|
|
if(native_jpeg_encode()) {
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveRawPicture: X (success)");
|
2011-01-12 07:42:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOGE("jpeg encoding failed");
|
|
|
|
}
|
2011-02-09 17:58:14 +00:00
|
|
|
else LOGV("JPEG callback is NULL, not encoding image.");
|
2011-03-13 05:49:00 +00:00
|
|
|
|
|
|
|
if (mRawInitialized)
|
2011-02-06 18:28:56 +00:00
|
|
|
deinitRaw();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveRawPicture: X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::receiveJpegPictureFragment(
|
|
|
|
uint8_t *buff_ptr, uint32_t buff_size)
|
|
|
|
{
|
|
|
|
uint32_t remaining = mJpegHeap->mHeap->virtualSize();
|
|
|
|
remaining -= mJpegSize;
|
|
|
|
uint8_t *base = (uint8_t *)mJpegHeap->mHeap->base();
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveJpegPictureFragment size %d", buff_size);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (buff_size > remaining) {
|
|
|
|
LOGE("receiveJpegPictureFragment: size %d exceeds what "
|
|
|
|
"remains in JPEG heap (%d), truncating",
|
|
|
|
buff_size,
|
|
|
|
remaining);
|
|
|
|
buff_size = remaining;
|
|
|
|
}
|
|
|
|
memcpy(base + mJpegSize, buff_ptr, buff_size);
|
|
|
|
mJpegSize += buff_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::receiveJpegPicture(void)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveJpegPicture: E image (%d uint8_ts out of %d)",
|
2011-01-12 07:42:14 +00:00
|
|
|
mJpegSize, mJpegHeap->mBufferSize);
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGD("mJpegHeap->mFrameOffset %d", mJpegHeap->mFrameOffset );
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
int index = 0, rc;
|
|
|
|
|
|
|
|
if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) {
|
|
|
|
// The reason we do not allocate into mJpegHeap->mBuffers[offset] is
|
|
|
|
// that the JPEG image's size will probably change from one snapshot
|
|
|
|
// to the next, so we cannot reuse the MemoryBase object.
|
|
|
|
sp<MemoryBase> buffer = new
|
2011-03-13 05:49:00 +00:00
|
|
|
MemoryBase(mJpegHeap->mHeap,
|
|
|
|
index * mJpegHeap->mBufferSize +
|
|
|
|
mJpegHeap->mFrameOffset,
|
|
|
|
mJpegSize);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
|
|
|
mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, buffer, mCallbackCookie);
|
|
|
|
buffer = NULL;
|
|
|
|
}
|
2011-02-09 17:58:14 +00:00
|
|
|
else LOGV("JPEG callback was cancelled--not delivering image.");
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
if (mRawInitialized)
|
2011-02-06 18:28:56 +00:00
|
|
|
deinitRaw();
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("receiveJpegPicture: X callback done.");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QualcommCameraHardware::previewEnabled()
|
|
|
|
{
|
|
|
|
Mutex::Autolock l(&mLock);
|
|
|
|
return (mCameraRunning && (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME));
|
|
|
|
}
|
|
|
|
|
|
|
|
int QualcommCameraHardware::getParm(
|
|
|
|
const char *parm_str, const struct str_map *const parm_map)
|
|
|
|
{
|
|
|
|
// Check if the parameter exists.
|
|
|
|
const char *str = mParameters.get(parm_str);
|
|
|
|
if (str == NULL) return NOT_FOUND;
|
|
|
|
|
|
|
|
// Look up the parameter value.
|
|
|
|
return attr_lookup(parm_map, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setEffect()
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
int32_t value = getParm(CameraParameters::KEY_EFFECT, effect);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (value != NOT_FOUND) {
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("efect: %d", value);
|
2011-01-12 07:42:14 +00:00
|
|
|
native_set_parm(CAMERA_SET_PARM_EFFECT, sizeof(value), (void *)&value);
|
2011-02-06 18:28:56 +00:00
|
|
|
}
|
2011-03-30 21:06:24 +00:00
|
|
|
else
|
|
|
|
LOGE("ERROR efect, not found: %d", value);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setWhiteBalance()
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
int32_t value = getParm(CameraParameters::KEY_WHITE_BALANCE, whitebalance);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (value != NOT_FOUND) {
|
2011-03-30 21:06:24 +00:00
|
|
|
LOGV("WhiteBalance: %d", value);
|
2011-01-12 07:42:14 +00:00
|
|
|
native_set_parm(CAMERA_SET_PARM_WB, sizeof(value), (void *)&value);
|
|
|
|
}
|
2011-03-30 21:06:24 +00:00
|
|
|
else
|
|
|
|
LOGE("ERROR WhiteBalance, not found: %d", value);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setAntibanding()
|
|
|
|
{
|
2011-03-30 21:06:24 +00:00
|
|
|
int32_t value = getParm(CameraParameters::KEY_ANTIBANDING, antibanding);
|
|
|
|
if (value != NOT_FOUND) {
|
|
|
|
LOGV("Antibanding: %d", value);
|
|
|
|
native_set_parm(CAMERA_SET_PARM_ANTIBANDING, sizeof(value), (void *)&value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LOGE("ERROR Antibanding, not found: %d", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::setZoom()
|
|
|
|
{
|
|
|
|
int32_t level = mParameters.getInt(CameraParameters::KEY_ZOOM);
|
|
|
|
|
|
|
|
|
|
|
|
if(native_get_maxzoom(mCameraControlFd,
|
|
|
|
(void *)&mMaxZoom) == true){
|
|
|
|
LOGD("Maximum zoom value is %d", mMaxZoom);
|
|
|
|
zoomSupported = true;
|
|
|
|
if(mMaxZoom > 0){
|
|
|
|
//if max zoom is available find the zoom ratios
|
|
|
|
int16_t * zoomRatios = new int16_t[mMaxZoom+1];
|
|
|
|
if(zoomRatios == NULL){
|
|
|
|
LOGE("Failed to get zoomratios...");
|
|
|
|
delete zoomRatios;
|
|
|
|
} else {
|
|
|
|
LOGE("zoom ratios failed to acquire memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zoomSupported = false;
|
|
|
|
LOGE("Failed to get maximum zoom value...setting max "
|
|
|
|
"zoom to zero");
|
|
|
|
mMaxZoom = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level > mMaxZoom) {
|
|
|
|
level = mMaxZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("Set Zoom level: %d current: %d maximum: %d", level, mCurZoom, mMaxZoom);
|
|
|
|
|
|
|
|
if (level == mCurZoom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level != -1) {
|
|
|
|
level*=ZOOM_STEP;
|
|
|
|
LOGV("Final Zoom Level: %d", level);
|
|
|
|
if (level >= 0 && level <= mMaxZoom) {
|
|
|
|
native_set_parm(CAMERA_SET_PARM_ZOOM, sizeof(level), (void *)&level);
|
|
|
|
mCurZoom = level;
|
|
|
|
}
|
|
|
|
}
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::MemPool::MemPool(int buffer_size, int num_buffers,
|
|
|
|
int frame_size,
|
|
|
|
int frame_offset,
|
|
|
|
const char *name) :
|
|
|
|
mBufferSize(buffer_size),
|
|
|
|
mNumBuffers(num_buffers),
|
|
|
|
mFrameSize(frame_size),
|
|
|
|
mFrameOffset(frame_offset),
|
|
|
|
mBuffers(NULL), mName(name)
|
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualcommCameraHardware::MemPool::completeInitialization()
|
|
|
|
{
|
|
|
|
// If we do not know how big the frame will be, we wait to allocate
|
|
|
|
// the buffers describing the individual frames until we do know their
|
|
|
|
// size.
|
|
|
|
|
|
|
|
if (mFrameSize > 0) {
|
|
|
|
mBuffers = new sp<MemoryBase>[mNumBuffers];
|
|
|
|
for (int i = 0; i < mNumBuffers; i++) {
|
|
|
|
mBuffers[i] = new
|
|
|
|
MemoryBase(mHeap,
|
|
|
|
i * mBufferSize + mFrameOffset,
|
|
|
|
mFrameSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::AshmemPool::AshmemPool(int buffer_size, int num_buffers,
|
|
|
|
int frame_size,
|
|
|
|
int frame_offset,
|
|
|
|
const char *name) :
|
|
|
|
QualcommCameraHardware::MemPool(buffer_size,
|
|
|
|
num_buffers,
|
|
|
|
frame_size,
|
|
|
|
frame_offset,
|
|
|
|
name)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("constructing MemPool %s backed by ashmem: "
|
2011-01-12 07:42:14 +00:00
|
|
|
"%d frames @ %d uint8_ts, offset %d, "
|
|
|
|
"buffer size %d",
|
|
|
|
mName,
|
|
|
|
num_buffers, frame_size, frame_offset, buffer_size);
|
|
|
|
|
|
|
|
int page_mask = getpagesize() - 1;
|
|
|
|
int ashmem_size = buffer_size * num_buffers;
|
|
|
|
ashmem_size += page_mask;
|
|
|
|
ashmem_size &= ~page_mask;
|
|
|
|
|
|
|
|
mHeap = new MemoryHeapBase(ashmem_size);
|
|
|
|
|
|
|
|
completeInitialization();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool register_buf(int camfd,
|
|
|
|
int size,
|
|
|
|
int pmempreviewfd,
|
|
|
|
uint32_t offset,
|
|
|
|
uint8_t *buf,
|
|
|
|
msm_pmem_t pmem_type,
|
|
|
|
bool active,
|
|
|
|
bool register_buffer = true);
|
|
|
|
|
|
|
|
QualcommCameraHardware::PmemPool::PmemPool(const char *pmem_pool,
|
|
|
|
int camera_control_fd,
|
|
|
|
msm_pmem_t pmem_type,
|
|
|
|
int buffer_size,
|
|
|
|
int num_buffers,
|
|
|
|
int frame_size,
|
|
|
|
int frame_offset,
|
|
|
|
const char *name) :
|
|
|
|
QualcommCameraHardware::MemPool(buffer_size,
|
|
|
|
num_buffers,
|
|
|
|
frame_size,
|
|
|
|
frame_offset,
|
|
|
|
name),
|
|
|
|
mPmemType(pmem_type),
|
|
|
|
mCameraControlFd(camera_control_fd)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("constructing MemPool %s backed by pmem pool %s: "
|
2011-01-12 07:42:14 +00:00
|
|
|
"%d frames @ %d bytes, offset %d, buffer size %d",
|
|
|
|
mName,
|
|
|
|
pmem_pool, num_buffers, frame_size, frame_offset,
|
|
|
|
buffer_size);
|
|
|
|
|
|
|
|
// Make a new mmap'ed heap that can be shared across processes.
|
|
|
|
|
|
|
|
mAlignedSize = clp2(buffer_size * num_buffers);
|
|
|
|
|
|
|
|
sp<MemoryHeapBase> masterHeap =
|
|
|
|
new MemoryHeapBase(pmem_pool, mAlignedSize, 0);
|
|
|
|
sp<MemoryHeapPmem> pmemHeap = new MemoryHeapPmem(masterHeap, 0);
|
|
|
|
if (pmemHeap->getHeapID() >= 0) {
|
|
|
|
pmemHeap->slap();
|
|
|
|
masterHeap.clear();
|
|
|
|
mHeap = pmemHeap;
|
|
|
|
pmemHeap.clear();
|
|
|
|
|
|
|
|
mFd = mHeap->getHeapID();
|
|
|
|
if (::ioctl(mFd, PMEM_GET_SIZE, &mSize)) {
|
|
|
|
LOGE("pmem pool %s ioctl(PMEM_GET_SIZE) error %s (%d)",
|
2011-03-13 05:49:00 +00:00
|
|
|
pmem_pool, ::strerror(errno), errno);
|
2011-01-12 07:42:14 +00:00
|
|
|
mHeap.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
LOGV("pmem pool %s ioctl(PMEM_GET_SIZE) is %ld", pmem_pool, mSize.len);
|
|
|
|
|
|
|
|
// Register buffers with the camera drivers.
|
|
|
|
if (mPmemType != MSM_PMEM_OUTPUT2) {
|
|
|
|
for (int cnt = 0; cnt < num_buffers; ++cnt) {
|
|
|
|
register_buf(mCameraControlFd,
|
|
|
|
buffer_size,
|
|
|
|
mHeap->getHeapID(),
|
|
|
|
0,
|
|
|
|
(uint8_t *)mHeap->base() + buffer_size * cnt,
|
|
|
|
pmem_type,
|
|
|
|
true);
|
|
|
|
}
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else LOGE("pmem pool %s error: could not create master heap!",
|
|
|
|
pmem_pool);
|
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
completeInitialization();
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::PmemPool::~PmemPool()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("%s: %s E", __FUNCTION__, mName);
|
2011-01-12 07:42:14 +00:00
|
|
|
|
2011-03-13 05:49:00 +00:00
|
|
|
// Unregister buffers with the camera drivers.
|
|
|
|
if (mPmemType != MSM_PMEM_OUTPUT2) {
|
|
|
|
for (int cnt = 0; cnt < mNumBuffers; ++cnt) {
|
|
|
|
register_buf(mCameraControlFd,
|
|
|
|
mBufferSize,
|
|
|
|
mHeap->getHeapID(),
|
|
|
|
0,
|
|
|
|
(uint8_t *)mHeap->base() + mBufferSize * cnt,
|
|
|
|
mPmemType,
|
|
|
|
true,
|
|
|
|
false /* Unregister */);
|
|
|
|
}
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("destroying PmemPool %s: ", mName);
|
|
|
|
LOGV("%s: %s X", __FUNCTION__, mName);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::MemPool::~MemPool()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("destroying MemPool %s", mName);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (mFrameSize > 0)
|
|
|
|
delete [] mBuffers;
|
|
|
|
mHeap.clear();
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("destroying MemPool %s completed", mName);
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::PreviewPmemPool::PreviewPmemPool(
|
|
|
|
int control_fd,
|
|
|
|
int buffer_size,
|
|
|
|
int num_buffers,
|
|
|
|
int frame_size,
|
|
|
|
int frame_offset,
|
|
|
|
const char *name) :
|
|
|
|
QualcommCameraHardware::PmemPool("/dev/pmem_adsp", control_fd, MSM_PMEM_OUTPUT2,
|
|
|
|
buffer_size,
|
|
|
|
num_buffers,
|
|
|
|
frame_size,
|
|
|
|
frame_offset,
|
|
|
|
name)
|
|
|
|
{
|
|
|
|
LOGV("QualcommCameraHardware::PreviewPmemPool::PreviewPmemPool");
|
|
|
|
if (initialized()) {
|
|
|
|
//NOTE : SOME PREVIEWPMEMPOOL SPECIFIC CODE MAY BE ADDED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QualcommCameraHardware::PreviewPmemPool::~PreviewPmemPool()
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("destroying PreviewPmemPool");
|
2011-01-12 07:42:14 +00:00
|
|
|
if (initialized()) {
|
2011-03-14 17:24:38 +00:00
|
|
|
LOGV("releasing PreviewPmemPool memory.");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool register_buf(int camfd,
|
|
|
|
int size,
|
|
|
|
int pmempreviewfd,
|
|
|
|
uint32_t offset,
|
|
|
|
uint8_t *buf,
|
|
|
|
msm_pmem_t pmem_type,
|
|
|
|
bool active,
|
|
|
|
bool register_buffer)
|
|
|
|
{
|
|
|
|
struct msm_pmem_info_t pmemBuf;
|
|
|
|
|
|
|
|
pmemBuf.type = pmem_type;
|
|
|
|
pmemBuf.fd = pmempreviewfd;
|
|
|
|
pmemBuf.vaddr = buf;
|
|
|
|
pmemBuf.y_off = 0;
|
|
|
|
pmemBuf.active = active;
|
|
|
|
|
2011-02-09 17:58:14 +00:00
|
|
|
if (pmem_type == MSM_PMEM_RAW_MAINIMG)
|
2011-01-12 07:42:14 +00:00
|
|
|
pmemBuf.cbcr_off = 0;
|
2011-02-09 17:58:14 +00:00
|
|
|
else
|
2011-01-12 07:42:14 +00:00
|
|
|
pmemBuf.cbcr_off = ((size * 2 / 3) + 1) & ~1;
|
|
|
|
|
|
|
|
LOGV("register_buf: camfd = %d, reg = %d buffer = %p",
|
2011-03-13 05:49:00 +00:00
|
|
|
camfd, register_buffer, buf);
|
2011-01-12 07:42:14 +00:00
|
|
|
if (ioctl(camfd,
|
|
|
|
register_buffer ?
|
|
|
|
MSM_CAM_IOCTL_REGISTER_PMEM :
|
|
|
|
MSM_CAM_IOCTL_UNREGISTER_PMEM,
|
|
|
|
&pmemBuf) < 0) {
|
|
|
|
LOGE("register_buf: MSM_CAM_IOCTL_(UN)REGISTER_PMEM fd %d error %s",
|
|
|
|
camfd,
|
|
|
|
strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:06:24 +00:00
|
|
|
status_t QualcommCameraHardware::setGpsLocation(const CameraParameters& params)
|
|
|
|
{
|
|
|
|
LOGV("SetGpsLocation E:");
|
|
|
|
|
|
|
|
const char *StatusIn = params.get(CameraParameters::KEY_GPS_STATUS);
|
|
|
|
LOGV("GPS STATUS ..................................................... %s", StatusIn);
|
|
|
|
|
|
|
|
const char *latitude = params.get(CameraParameters::KEY_GPS_LATITUDE);
|
|
|
|
if (latitude) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_LATITUDE, latitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *latitudeRef = params.get(CameraParameters::KEY_GPS_LATITUDE_REF);
|
|
|
|
if (latitudeRef) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_LATITUDE_REF, latitudeRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *longitude = params.get(CameraParameters::KEY_GPS_LONGITUDE);
|
|
|
|
if (longitude) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_LONGITUDE, longitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *longitudeRef = params.get(CameraParameters::KEY_GPS_LONGITUDE_REF);
|
|
|
|
if (longitudeRef) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_LONGITUDE_REF, longitudeRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *altitudeRef = params.get(CameraParameters::KEY_GPS_ALTITUDE_REF);
|
|
|
|
if (altitudeRef) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_ALTITUDE_REF, altitudeRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *altitude = params.get(CameraParameters::KEY_GPS_ALTITUDE);
|
|
|
|
if (altitude) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_ALTITUDE, altitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *status = params.get(CameraParameters::KEY_GPS_STATUS);
|
|
|
|
if (status) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_STATUS, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *dateTime = params.get(CameraParameters::KEY_EXIF_DATETIME);
|
|
|
|
if (dateTime) {
|
|
|
|
mParameters.set(CameraParameters::KEY_EXIF_DATETIME, dateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *timestamp = params.get(CameraParameters::KEY_GPS_TIMESTAMP);
|
|
|
|
if (timestamp) {
|
|
|
|
mParameters.set(CameraParameters::KEY_GPS_TIMESTAMP, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *StatusOut = params.get(CameraParameters::KEY_GPS_STATUS);
|
|
|
|
LOGV("GPS STATUS EXIT ................................................ %s", StatusOut);
|
|
|
|
|
|
|
|
LOGV("SetGpsLocation X:");
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-01-12 07:42:14 +00:00
|
|
|
status_t QualcommCameraHardware::MemPool::dump(int fd, const Vector<String16>& args) const
|
|
|
|
{
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
String8 result;
|
|
|
|
snprintf(buffer, 255, "QualcommCameraHardware::AshmemPool::dump\n");
|
|
|
|
result.append(buffer);
|
|
|
|
if (mName) {
|
|
|
|
snprintf(buffer, 255, "mem pool name (%s)\n", mName);
|
|
|
|
result.append(buffer);
|
|
|
|
}
|
|
|
|
if (mHeap != 0) {
|
|
|
|
snprintf(buffer, 255, "heap base(%p), size(%d), flags(%d), device(%s)\n",
|
|
|
|
mHeap->getBase(), mHeap->getSize(),
|
|
|
|
mHeap->getFlags(), mHeap->getDevice());
|
|
|
|
result.append(buffer);
|
|
|
|
}
|
|
|
|
snprintf(buffer, 255, "buffer size (%d), number of buffers (%d),"
|
|
|
|
" frame size(%d), and frame offset(%d)\n",
|
|
|
|
mBufferSize, mNumBuffers, mFrameSize, mFrameOffset);
|
|
|
|
result.append(buffer);
|
|
|
|
write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void receive_camframe_callback(struct msm_frame_t *frame)
|
|
|
|
{
|
2011-03-14 17:24:38 +00:00
|
|
|
if ( LOG_PREVIEW )
|
|
|
|
LOGV("receive_camframe_callback E");
|
2011-01-12 07:42:14 +00:00
|
|
|
sp<QualcommCameraHardware> obj = QualcommCameraHardware::getInstance();
|
|
|
|
if (obj != 0) {
|
|
|
|
obj->receivePreviewFrame(frame);
|
|
|
|
}
|
2011-03-14 17:24:38 +00:00
|
|
|
if ( LOG_PREVIEW )
|
|
|
|
LOGV("receive_camframe_callback X");
|
2011-01-12 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t QualcommCameraHardware::sendCommand(int32_t command, int32_t arg1,
|
|
|
|
int32_t arg2)
|
|
|
|
{
|
2011-02-09 17:58:14 +00:00
|
|
|
LOGV("sendCommand: EX");
|
2011-01-12 07:42:14 +00:00
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace android
|