Camera: Adding normal and macro auto focus modes
Support for Normal and Macro auto focus modes added
Enabling Auto focus support based on sensor type
diff --git a/QualcommCameraHardware.cpp b/QualcommCameraHardware.cpp
index 0da585f..d55d0b8 100755
--- a/QualcommCameraHardware.cpp
+++ b/QualcommCameraHardware.cpp
@@ -482,8 +482,10 @@
#define DONT_CARE 0
static const str_map focus_modes[] = {
- { CameraParameters::FOCUS_MODE_AUTO, DONT_CARE },
- { CameraParameters::FOCUS_MODE_INFINITY, DONT_CARE }
+ { CameraParameters::FOCUS_MODE_AUTO, AF_MODE_AUTO},
+ { CameraParameters::FOCUS_MODE_INFINITY, DONT_CARE },
+ { CameraParameters::FOCUS_MODE_NORMAL, AF_MODE_NORMAL },
+ { CameraParameters::FOCUS_MODE_MACRO, AF_MODE_MACRO }
};
static const str_map lensshade[] = {
@@ -491,6 +493,20 @@
{ CameraParameters::LENSSHADE_DISABLE, FALSE }
};
+struct SensorType {
+ const char *name;
+ int rawPictureWidth;
+ int rawPictureHeight;
+ bool hasAutoFocusSupport;
+};
+
+static SensorType sensorTypes[] = {
+ { "5mp", 2608, 1960, true },
+ { "3mp", 2064, 1544, false },
+ { "2mp", 3200, 1200, false } };
+
+static SensorType * sensorType;
+
static bool parameter_string_initialized = false;
static String8 preview_size_values;
static String8 picture_size_values;
@@ -574,6 +590,7 @@
// Initialize constant parameter strings. This will happen only once in the
// lifetime of the mediaserver process.
if (!parameter_string_initialized) {
+ findSensorType();
antibanding_values = create_values_str(
antibanding, sizeof(antibanding) / sizeof(str_map));
effect_values = create_values_str(
@@ -588,8 +605,10 @@
picture_sizes, PICTURE_SIZE_COUNT);
flash_values = create_values_str(
flash, sizeof(flash) / sizeof(str_map));
- focus_mode_values = create_values_str(
- focus_modes, sizeof(focus_modes) / sizeof(str_map));
+ if(sensorType->hasAutoFocusSupport){
+ focus_mode_values = create_values_str(
+ focus_modes, sizeof(focus_modes) / sizeof(str_map));
+ }
iso_values = create_values_str(
iso,sizeof(iso)/sizeof(str_map));
lensshade_values = create_values_str(
@@ -670,6 +689,26 @@
LOGV("initDefaultParameters X");
}
+void QualcommCameraHardware::findSensorType(){
+ mDimension.picture_width = DEFAULT_PICTURE_WIDTH;
+ mDimension.picture_height = DEFAULT_PICTURE_HEIGHT;
+ bool ret = native_set_parm(CAMERA_SET_PARM_DIMENSION,
+ sizeof(cam_ctrl_dimension_t), &mDimension);
+ if (ret) {
+ unsigned int i;
+ for (i = 0; i < sizeof(sensorTypes) / sizeof(SensorType); i++) {
+ if (sensorTypes[i].rawPictureHeight
+ == mDimension.raw_picture_height) {
+ sensorType = sensorTypes + i;
+ return;
+ }
+ }
+ }
+ //default to 5 mp
+ sensorType = sensorTypes;
+ return;
+}
+
#define ROUND_TO_PAGE(x) (((x)+0xfff)&~0xfff)
bool QualcommCameraHardware::startCamera()
@@ -1533,6 +1572,7 @@
{
bool status = true;
void *libhandle = NULL;
+ isp3a_af_mode_t afMode;
mAutoFocusThreadLock.lock();
// Skip autofocus if focus mode is infinity.
@@ -1568,9 +1608,13 @@
}
#endif
+ afMode = (isp3a_af_mode_t)attr_lookup(focus_modes,
+ sizeof(focus_modes) / sizeof(str_map),
+ mParameters.get(CameraParameters::KEY_FOCUS_MODE));
+
/* This will block until either AF completes or is cancelled. */
- LOGV("af start (fd %d)", mAutoFocusFd);
- status = native_set_afmode(mAutoFocusFd, AF_MODE_AUTO);
+ LOGV("af start (fd %d mode %d)", mAutoFocusFd, afMode);
+ status = native_set_afmode(mAutoFocusFd, afMode);
LOGV("af done: %d", (int)status);
close(mAutoFocusFd);
mAutoFocusFd = -1;
@@ -1599,6 +1643,11 @@
{
LOGV("cancelAutoFocusInternal E");
+ if(!sensorType->hasAutoFocusSupport){
+ LOGV("cancelAutoFocusInternal X");
+ return NO_ERROR;
+ }
+
#if 0
if (mAutoFocusFd < 0) {
LOGV("cancelAutoFocusInternal X: not in progress");
@@ -1631,6 +1680,11 @@
LOGV("autoFocus E");
Mutex::Autolock l(&mLock);
+ if(!sensorType->hasAutoFocusSupport){
+ LOGV("autoFocus X");
+ return NO_ERROR;
+ }
+
if (mCameraControlFd < 0) {
LOGE("not starting autofocus: main control fd %d", mCameraControlFd);
return UNKNOWN_ERROR;