From 802890e7ab775d71f9ff11a1b259778cd6b90917 Mon Sep 17 00:00:00 2001 From: "Mike J. Chen" Date: Tue, 26 Oct 2010 15:16:00 -0700 Subject: S5PC11X: libcamera: threading and error cleanup Cleanup the way the camera HAL manages its threads so that the exit path should no longer fail in a race condition. The destructor waits for all threads to exit and heaps are destroyed before closing the fd to driver. Remove deadlock case (a HAL interface should not call a callback, because the callback would try to grab a lock that is already being held). Removed mutex usage that wasn't needed (CameraServices already has a mutex). Add checks that could mess up the state of the sensor driver (setting parameters or starting preview when a capture was still in progress). We return errors in these cases instead. Change-Id: I30d832de582a002dad1c087bd7cc7de43237eb19 Signed-off-by: Mike J. Chen --- libcamera/SecCameraHWInterface.h | 49 +++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'libcamera/SecCameraHWInterface.h') diff --git a/libcamera/SecCameraHWInterface.h b/libcamera/SecCameraHWInterface.h index 5ac3e91..b3f90ac 100644 --- a/libcamera/SecCameraHWInterface.h +++ b/libcamera/SecCameraHWInterface.h @@ -32,7 +32,6 @@ public: virtual sp getPreviewHeap() const; virtual sp getRawHeap() const; -//Kamat --eclair virtual void setCallbacks(notify_callback notify_cb, data_callback data_cb, data_callback_timestamp data_cb_timestamp, @@ -89,9 +88,6 @@ private: Thread(false), #endif mHardware(hw) { } - virtual void onFirstRef() { - run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY); - } virtual bool threadLoop() { int ret = mHardware->previewThread(); // loop until we need to quit @@ -102,16 +98,45 @@ private: } }; + class PictureThread : public Thread { + CameraHardwareSec *mHardware; + public: + PictureThread(CameraHardwareSec *hw): + Thread(false), + mHardware(hw) { } + virtual bool threadLoop() { + mHardware->pictureThread(); + return false; + } + }; + + class AutoFocusThread : public Thread { + CameraHardwareSec *mHardware; + public: + AutoFocusThread(CameraHardwareSec *hw): Thread(false), mHardware(hw) { } + virtual void onFirstRef() { + run("CameraAutoFocusThread", PRIORITY_DEFAULT); + } + virtual bool threadLoop() { + mHardware->autoFocusThread(); + return true; + } + }; + void initDefaultParameters(int cameraId); void initHeapLocked(); + sp mPreviewThread; int previewThread(); + bool mPreviewRunning; - static int beginAutoFocusThread(void *cookie); + sp mAutoFocusThread; int autoFocusThread(); - static int beginPictureThread(void *cookie); + sp mPictureThread; int pictureThread(); + bool mCaptureInProgress; + int save_jpeg(unsigned char *real_jpeg, int jpeg_size); void save_postview(const char *fname, uint8_t *buf, uint32_t size); @@ -137,7 +162,13 @@ private: int *pdwJPEGSize, void *pVideo, int *pdwVideoSize); - mutable Mutex mLock; + /* used by auto focus thread to block until it's told to run */ + mutable Mutex mFocusLock; + mutable Condition mCondition; + bool mExitAutoFocusThread; + + /* used to guard threading state */ + mutable Mutex mStateLock; CameraParameters mParameters; CameraParameters mInternalParameters; @@ -150,7 +181,6 @@ private: sp mRecordBuffers[kBufferCountForRecord]; SecCamera *mSecCamera; - bool mPreviewRunning; int mPreviewFrameSize; int mRawFrameSize; int mPreviewFrameRateMicrosec; @@ -162,8 +192,6 @@ private: int mOverlayBufferIdx; #endif - // protected by mLock - sp mPreviewThread; notify_callback mNotifyCb; data_callback mDataCb; data_callback_timestamp mDataCbTimestamp; @@ -182,7 +210,6 @@ private: int mPostViewSize; #endif - int mNoHwHandle; struct timeval mTimeStart; struct timeval mTimeStop; -- cgit v1.2.3