summaryrefslogtreecommitdiff
authorjiyu.yang <jiyu.yang@amlogic.com>2012-11-30 02:59:55 (GMT)
committer jiyu.yang <jiyu.yang@amlogic.com>2012-12-14 18:31:13 (GMT)
commit48c3839419f84eac69666f6998398746b64823e9 (patch)
treee640fc3887c4d9fffb393183b362bc8110a6028a
parent2934542b6494c258f5ec071cf3a5bd098b715412 (diff)
downloadcamera-48c3839419f84eac69666f6998398746b64823e9.zip
camera-48c3839419f84eac69666f6998398746b64823e9.tar.gz
camera-48c3839419f84eac69666f6998398746b64823e9.tar.bz2
focus start & stop msg
get the status of the conti-mode, and send focus start or stop msg
Diffstat
-rwxr-xr-xAppCallbackNotifier.cpp12
-rwxr-xr-xBaseCameraAdapter.cpp43
-rwxr-xr-xCameraHal.cpp11
-rwxr-xr-xV4LCameraAdapter/V4LCameraAdapter.cpp76
-rwxr-xr-xinc/BaseCameraAdapter.h10
-rwxr-xr-xinc/CameraHal.h8
-rwxr-xr-xinc/V4LCameraAdapter/V4LCameraAdapter.h9
7 files changed, 158 insertions, 11 deletions
diff --git a/AppCallbackNotifier.cpp b/AppCallbackNotifier.cpp
index 61f063e..2b3a7ff 100755
--- a/AppCallbackNotifier.cpp
+++ b/AppCallbackNotifier.cpp
@@ -329,6 +329,7 @@ void AppCallbackNotifier::notifyEvent()
CameraHalEvent::FocusEventData *focusEvtData;
CameraHalEvent::ZoomEventData *zoomEvtData;
CameraHalEvent::FaceEventData faceEvtData;
+ CameraHalEvent::FocusMoveEventData *focusMoveEvtData;
if(mNotifierState != AppCallbackNotifier::NOTIFIER_STARTED)
{
@@ -384,6 +385,17 @@ void AppCallbackNotifier::notifyEvent()
break;
+ case CameraHalEvent::EVENT_FOCUS_MOVE:
+
+ focusMoveEvtData = &evt->mEventData->focusMoveEvent;
+ if ( ( NULL != mCameraHal ) &&
+ ( NULL != mNotifyCb ))
+ {
+ mNotifyCb(CAMERA_MSG_FOCUS_MOVE, focusMoveEvtData->focusStart, 0, mCallbackCookie);
+ }
+
+ break;
+
case CameraHalEvent::EVENT_ZOOM_INDEX_REACHED:
zoomEvtData = &evt->mEventData->zoomEvent;
diff --git a/BaseCameraAdapter.cpp b/BaseCameraAdapter.cpp
index 64ef828..a11c04b 100755
--- a/BaseCameraAdapter.cpp
+++ b/BaseCameraAdapter.cpp
@@ -50,6 +50,7 @@ BaseCameraAdapter::BaseCameraAdapter()
mPreviewDataBuffersLength = 0;
mAdapterState = INTIALIZED_STATE;
+ mFocusMoveEnabled = false;
#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
mStartFocus.tv_sec = 0;
@@ -71,9 +72,11 @@ BaseCameraAdapter::~BaseCameraAdapter()
mRawSubscribers.clear();
mVideoSubscribers.clear();
mFocusSubscribers.clear();
+ mFocusMoveSubscribers.clear();
mShutterSubscribers.clear();
mZoomSubscribers.clear();
mFaceSubscribers.clear();
+ mFocusMoveEnabled = false;
LOG_FUNCTION_NAME_EXIT;
}
@@ -157,6 +160,7 @@ void BaseCameraAdapter::enableMsgType(int32_t msgs, frame_callback callback, eve
else if ( CameraHalEvent::ALL_EVENTS == msgs)
{
mFocusSubscribers.add((int) cookie, eventCb);
+ mFocusMoveSubscribers.add((int) cookie, eventCb);
mShutterSubscribers.add((int) cookie, eventCb);
mZoomSubscribers.add((int) cookie, eventCb);
mFaceSubscribers.add((int) cookie, eventCb);
@@ -208,6 +212,7 @@ void BaseCameraAdapter::disableMsgType(int32_t msgs, void* cookie)
//Subscribe only for focus
//TODO: Process case by case
mFocusSubscribers.removeItem((int) cookie);
+ mFocusMoveSubscribers.removeItem((int) cookie);
mShutterSubscribers.removeItem((int) cookie);
mZoomSubscribers.removeItem((int) cookie);
mFaceSubscribers.removeItem((int) cookie);
@@ -978,6 +983,9 @@ status_t BaseCameraAdapter::sendCommand(CameraCommands operation, int value1, in
ret = disableMirror(value1);
break;
+ case CameraAdapter::CAMERA_FOCUS_MOVE_MSG:
+ mFocusMoveEnabled = true;
+ break;
default:
CAMHAL_LOGEB("Command 0x%x unsupported!", operation);
break;
@@ -1030,6 +1038,41 @@ status_t BaseCameraAdapter::notifyFocusSubscribers(bool status)
return ret;
}
+status_t BaseCameraAdapter::notifyFocusMoveSubscribers(int status)
+{
+ event_callback eventCb;
+ CameraHalEvent focusMoveEvent;
+ status_t ret = NO_ERROR;
+
+ LOG_FUNCTION_NAME;
+
+ if ( mFocusMoveSubscribers.size() == 0 ) {
+ CAMHAL_LOGDA("No Focus Move Subscribers!");
+ return NO_INIT;
+ }
+
+ focusMoveEvent.mEventData = new CameraHalEvent::CameraHalEventData();
+ if ( NULL == focusMoveEvent.mEventData.get() ) {
+ return -ENOMEM;
+ }
+
+ focusMoveEvent.mEventType = CameraHalEvent::EVENT_FOCUS_MOVE;
+ focusMoveEvent.mEventData->focusMoveEvent.focusStart = (status == FOCUS_MOVE_START);
+
+ for (unsigned int i = 0 ; i < mFocusMoveSubscribers.size(); i++ )
+ {
+ focusMoveEvent.mCookie = (void *) mFocusMoveSubscribers.keyAt(i);
+ eventCb = (event_callback) mFocusMoveSubscribers.valueAt(i);
+ eventCb ( &focusMoveEvent );
+ }
+
+ focusMoveEvent.mEventData.clear();
+
+ LOG_FUNCTION_NAME_EXIT;
+
+ return ret;
+}
+
status_t BaseCameraAdapter::notifyShutterSubscribers()
{
CameraHalEvent shutterEvent;
diff --git a/CameraHal.cpp b/CameraHal.cpp
index e5b5956..63e3336 100755
--- a/CameraHal.cpp
+++ b/CameraHal.cpp
@@ -217,6 +217,9 @@ void CameraHal::enableMsgType(int32_t msgType)
if (msgType & CAMERA_MSG_FOCUS) {
msgType &= ~CAMERA_MSG_FOCUS;
}
+ if (msgType & CAMERA_MSG_FOCUS_MOVE ) {
+ msgType &= ~CAMERA_MSG_FOCUS_MOVE;
+ }
{
Mutex::Autolock lock(mLock);
@@ -2849,6 +2852,14 @@ status_t CameraHal::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
break;
+ case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG:
+
+ mMsgEnabled |= CAMERA_MSG_FOCUS_MOVE;
+
+ ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_FOCUS_MOVE_MSG);
+
+ break;
+
default:
break;
};
diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp
index bc38191..50b782f 100755
--- a/V4LCameraAdapter/V4LCameraAdapter.cpp
+++ b/V4LCameraAdapter/V4LCameraAdapter.cpp
@@ -94,6 +94,12 @@ namespace android {
#define V4L2_ROTATE_ID 0x980922 //V4L2_CID_ROTATE
+#define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30)
+#define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0)
+#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0)
+#define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1)
+#define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2)
+
Mutex gAdapterLock;
extern "C" int set_night_mode(int camera_fd,const char *snm);
@@ -389,8 +395,6 @@ status_t V4LCameraAdapter::IoctlStateProbe(void)
mIoctlSupport |= IOCTL_MASK_EFFECT;
}
-#ifdef AMLOGIC_USB_CAMERA_SUPPORT
- //jb-amlogic must delete this macro limit
memset(&qc, 0, sizeof(struct v4l2_queryctrl));
qc.id = V4L2_CID_POWER_LINE_FREQUENCY;
ret = ioctl (mCameraHandle, VIDIOC_QUERYCTRL, &qc);
@@ -401,10 +405,6 @@ status_t V4LCameraAdapter::IoctlStateProbe(void)
mIoctlSupport |= IOCTL_MASK_BANDING;
}
mAntiBanding = qc.default_value;
-#else
- mIoctlSupport |= IOCTL_MASK_BANDING;
- mAntiBanding = CAM_ANTIBANDING_50HZ;
-#endif
memset(&qc, 0, sizeof(struct v4l2_queryctrl));
qc.id = V4L2_CID_FOCUS_AUTO;
@@ -416,6 +416,15 @@ status_t V4LCameraAdapter::IoctlStateProbe(void)
mIoctlSupport |= IOCTL_MASK_FOCUS;
}
+ memset(&qc, 0, sizeof(struct v4l2_queryctrl));
+ qc.id = V4L2_CID_AUTO_FOCUS_STATUS;
+ ret = ioctl (mCameraHandle, VIDIOC_QUERYCTRL, &qc);
+ if((qc.flags == V4L2_CTRL_FLAG_DISABLED) ||( ret < 0)){
+ mIoctlSupport &= ~IOCTL_MASK_FOCUS_MOVE;
+ }else{
+ mIoctlSupport |= IOCTL_MASK_FOCUS_MOVE;
+ }
+
LOG_FUNCTION_NAME_EXIT;
return ret;
@@ -601,6 +610,8 @@ status_t V4LCameraAdapter::setParameters(const CameraParameters &params)
if(ioctl(mCameraHandle, VIDIOC_S_CTRL, &ctl)<0){
CAMHAL_LOGDA("failed to set CAM_FOCUS_MODE_CONTI_VID!\n");
}
+ mFocusWaitCount = FOCUS_PROCESS_FRAMES;
+ bFocusMoveState = true;
cur_focus_mode_for_conti = CAM_FOCUS_MODE_CONTI_VID;
}else if( (CAM_FOCUS_MODE_CONTI_VID != cur_focus_mode_for_conti)&&
(CAM_FOCUS_MODE_AUTO != cur_focus_mode) &&
@@ -1210,6 +1221,7 @@ status_t V4LCameraAdapter::stopPreview()
}
mPreviewing = false;
+ mFocusMoveEnabled = false;
mPreviewThread->requestExitAndWait();
mPreviewThread.clear();
@@ -1577,6 +1589,10 @@ int V4LCameraAdapter::previewThread()
ret = sendFrameToSubscribers(&frame);
//LOGD("previewThread /sendFrameToSubscribers ret=%d", ret);
}
+ if( (mIoctlSupport & IOCTL_MASK_FOCUS_MOVE) && mFocusMoveEnabled ){
+ getFocusMoveStatus();
+ }
+
return ret;
}
@@ -2464,11 +2480,9 @@ static bool getCameraAutoFocus(int camera_fd, char* focus_mode_str, char*def_foc
memset(&qm, 0, sizeof(qm));
qm.id = V4L2_CID_FOCUS_AUTO;
qm.index = qc.default_value;
-
strcpy(def_focus_mode, "auto");
- int index = 0;
- //for (index = 0; index <= menu_num; index++) {
- for (index = qc.minimum; index <= qc.maximum; index+= qc.step) {
+
+ for (int index = qc.minimum; index <= qc.maximum; index+= qc.step) {
memset(&qm, 0, sizeof(struct v4l2_querymenu));
qm.id = V4L2_CID_FOCUS_AUTO;
qm.index = index;
@@ -3140,6 +3154,48 @@ extern "C" int V4LCameraAdapter::set_white_balance(int camera_fd,const char *swb
CAMHAL_LOGEB("AMLOGIC CAMERA Set white balance fail: %s. ret=%d", strerror(errno),ret);
return ret ;
}
+
+status_t V4LCameraAdapter::getFocusMoveStatus()
+{
+ struct v4l2_control ctl;
+ int ret;
+
+ if( (cur_focus_mode != CAM_FOCUS_MODE_CONTI_VID) &&
+ (cur_focus_mode != CAM_FOCUS_MODE_CONTI_PIC) &&
+ (cur_focus_mode != CAM_FOCUS_MODE_AUTO)){
+ mFocusMoveEnabled = false;
+ return 0;
+ }
+
+ mFocusWaitCount --;
+ if(mFocusWaitCount >= 0){
+ return 0;
+ }
+ mFocusWaitCount = 0;
+
+ memset( &ctl, 0, sizeof(ctl));
+ ctl.id =V4L2_CID_AUTO_FOCUS_STATUS;
+ ret = ioctl(mCameraHandle, VIDIOC_G_CTRL, &ctl);
+ if ( 0 > ret ){
+ CAMHAL_LOGDA("V4L2_CID_AUTO_FOCUS_STATUS failed\n");
+ return -EINVAL;
+ }
+
+ if( ctl.value == V4L2_AUTO_FOCUS_STATUS_BUSY ){
+ if(!bFocusMoveState){
+ bFocusMoveState = true;
+ notifyFocusMoveSubscribers(FOCUS_MOVE_START);
+ }
+ }else {
+ mFocusWaitCount = FOCUS_PROCESS_FRAMES;
+ if(bFocusMoveState){
+ bFocusMoveState = false;
+ notifyFocusMoveSubscribers(FOCUS_MOVE_STOP);
+ }
+ }
+
+ return ctl.value;
+}
/*
* use id V4L2_CID_EXPOSURE_AUTO to set exposure mode
* 0: Auto Mode, commit failure @20120504
diff --git a/inc/BaseCameraAdapter.h b/inc/BaseCameraAdapter.h
index 3df57f0..82068fa 100755
--- a/inc/BaseCameraAdapter.h
+++ b/inc/BaseCameraAdapter.h
@@ -147,6 +147,7 @@ protected:
// ---------------------Interface ends-----------------------------------
status_t notifyFocusSubscribers(bool status);
+ status_t notifyFocusMoveSubscribers(int status);
status_t notifyShutterSubscribers();
status_t notifyZoomSubscribers(int zoomIdx, bool targetReached);
status_t notifyFaceSubscribers(sp<CameraFDResult> &faces);
@@ -194,6 +195,13 @@ protected:
ERROR
};
+ typedef enum FocusState_e{
+ FOCUS_AUTO_FAILED = 0,
+ FOCUS_AUTO_SUCCESS = 1,
+ FOCUS_MOVE_START = 2,
+ FOCUS_MOVE_STOP = 3,
+ }FocusState_t;
+
#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
struct timeval mStartFocus;
@@ -215,6 +223,7 @@ protected:
KeyedVector<int, frame_callback> mImageSubscribers;
KeyedVector<int, frame_callback> mRawSubscribers;
KeyedVector<int, event_callback> mFocusSubscribers;
+ KeyedVector<int, event_callback> mFocusMoveSubscribers;
KeyedVector<int, event_callback> mZoomSubscribers;
KeyedVector<int, event_callback> mShutterSubscribers;
KeyedVector<int, event_callback> mFaceSubscribers;
@@ -256,6 +265,7 @@ protected:
void *mReleaseData;
void *mEndCaptureData;
bool mRecording;
+ bool mFocusMoveEnabled;
uint32_t mFramesWithDucati;
uint32_t mFramesWithDisplay;
diff --git a/inc/CameraHal.h b/inc/CameraHal.h
index f4825d3..b804436 100755
--- a/inc/CameraHal.h
+++ b/inc/CameraHal.h
@@ -351,6 +351,7 @@ public:
EVENT_ZOOM_INDEX_REACHED = 0x4,
EVENT_SHUTTER = 0x8,
EVENT_FACE = 0x10,
+ EVENT_FOCUS_MOVE = 0x20,
///@remarks Future enum related to display, like frame displayed event, could be added here
ALL_EVENTS = 0xFFFF ///Maximum of 16 event types supported
};
@@ -370,6 +371,11 @@ public:
int currentFocusValue;
} FocusEventData;
+ typedef struct FocusMoveEventData_t {
+ bool focusStart;
+ int currentFocusValue;
+ } FocusMoveEventData;
+
///Zoom specific event data
typedef struct ZoomEventData_t {
int currentZoomIndex;
@@ -391,6 +397,7 @@ public:
public:
CameraHalEvent::FocusEventData focusEvent;
+ CameraHalEvent::FocusMoveEventData focusMoveEvent;
CameraHalEvent::ZoomEventData zoomEvent;
CameraHalEvent::ShutterEventData shutterEvent;
CameraHalEvent::FaceEventData faceEvent;
@@ -782,6 +789,7 @@ public:
CAMERA_STOP_FD = 23,
CAMERA_SWITCH_TO_EXECUTING = 24,
CAMERA_DISABLE_MIRROR = 25,
+ CAMERA_FOCUS_MOVE_MSG = 26,
};
diff --git a/inc/V4LCameraAdapter/V4LCameraAdapter.h b/inc/V4LCameraAdapter/V4LCameraAdapter.h
index 7ac728d..40da2be 100755
--- a/inc/V4LCameraAdapter/V4LCameraAdapter.h
+++ b/inc/V4LCameraAdapter/V4LCameraAdapter.h
@@ -215,6 +215,7 @@ typedef enum camera_focus_mode_e {
#define IOCTL_MASK_EFFECT (1<<6)
#define IOCTL_MASK_BANDING (1<<7)
#define IOCTL_MASK_ROTATE (1<<8)
+#define IOCTL_MASK_FOCUS_MOVE (1<<9)
/**
* Class which completely abstracts the camera hardware interaction from camera hal
@@ -274,7 +275,7 @@ protected:
//-----------------------------------------------------------------------------
status_t disableMirror(bool bDisable);
status_t setMirrorEffect();
-
+ status_t getFocusMoveStatus();
private:
@@ -379,6 +380,8 @@ private:
camera_focus_mode_t cur_focus_mode;
camera_focus_mode_t cur_focus_mode_for_conti;
+ bool bFocusMoveState;
+
bool mEnableContiFocus;
camera_flashlight_status_t mFlashMode;
unsigned int mIoctlSupport;
@@ -389,6 +392,10 @@ private:
int mEVmin;
int mEVmax;
int mAntiBanding;
+ int mFocusWaitCount;
+ //suppose every 17frames to check the focus is running;
+ //in continuous mode
+ static const int FOCUS_PROCESS_FRAMES = 17;
#ifdef AMLOGIC_CAMERA_NONBLOCK_SUPPORT
int mPreviewFrameRate;