From a21ec0f3d3a1300f6ef07ac4c388a4025beaca30 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Tue, 21 Jul 2009 12:28:45 +0800 Subject: [PATCH] Make sure shutter callback is called before raw callback. --- libcamera2/QualcommCameraHardware.cpp | 32 ++++++++++++++++++--------- libcamera2/QualcommCameraHardware.h | 3 +++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libcamera2/QualcommCameraHardware.cpp b/libcamera2/QualcommCameraHardware.cpp index 247e24e..2c820a1 100644 --- a/libcamera2/QualcommCameraHardware.cpp +++ b/libcamera2/QualcommCameraHardware.cpp @@ -1263,6 +1263,14 @@ status_t QualcommCameraHardware::takePicture(shutter_callback shutter_cb, raw_cb, jpeg_cb); Mutex::Autolock l(&mLock); + // Wait for old snapshot thread to complete. + mSnapshotThreadWaitLock.lock(); + while (mSnapshotThreadRunning) { + LOGV("takePicture: waiting for old snapshot thread to complete."); + mSnapshotThreadWait.wait(mSnapshotThreadWaitLock); + LOGV("takePicture: old snapshot thread completed."); + } + stopPreviewInternal(); if (!initRaw(jpeg_cb != NULL)) { @@ -1278,12 +1286,9 @@ status_t QualcommCameraHardware::takePicture(shutter_callback shutter_cb, mPictureCallbackCookie = user; } - mSnapshotThreadWaitLock.lock(); - while (mSnapshotThreadRunning) { - LOGV("takePicture: waiting for old snapshot thread to complete."); - mSnapshotThreadWait.wait(mSnapshotThreadWaitLock); - LOGV("takePicture: old snapshot thread completed."); - } + mShutterLock.lock(); + mShutterPending = true; + mShutterLock.unlock(); pthread_attr_t attr; pthread_attr_init(&attr); @@ -1554,8 +1559,12 @@ bool QualcommCameraHardware::recordingEnabled() void QualcommCameraHardware::notifyShutter() { - if (mShutterCallback) + mShutterLock.lock(); + if (mShutterPending && mShutterCallback) { mShutterCallback(mPictureCallbackCookie); + mShutterPending = false; + } + mShutterLock.unlock(); } static void receive_shutter_callback() @@ -1572,14 +1581,17 @@ void QualcommCameraHardware::receiveRawPicture() { LOGV("receiveRawPicture: E"); - int ret,rc,rete; - Mutex::Autolock cbLock(&mCallbackLock); + if (mRawPictureCallback != NULL) { - if(native_get_picture(mCameraControlFd, &mCrop)== false) { + if(native_get_picture(mCameraControlFd, &mCrop) == false) { LOGE("getPicture failed!"); return; } + + // By the time native_get_picture returns, picture is taken. Call + // shutter callback if cam config thread has not done that. + notifyShutter(); mRawPictureCallback(mRawHeap->mBuffers[0], mPictureCallbackCookie); } diff --git a/libcamera2/QualcommCameraHardware.h b/libcamera2/QualcommCameraHardware.h index 5f63abc..a4fe43b 100644 --- a/libcamera2/QualcommCameraHardware.h +++ b/libcamera2/QualcommCameraHardware.h @@ -168,6 +168,9 @@ private: friend void *frame_thread(void *user); void runFrameThread(void *data); + bool mShutterPending; + Mutex mShutterLock; + bool mSnapshotThreadRunning; Mutex mSnapshotThreadWaitLock; Condition mSnapshotThreadWait;