@@ -428,8 +428,20 @@ void CameraDevice::flush()
camera_->stop();
- MutexLocker stateLock(stateMutex_);
- state_ = State::Stopped;
+ {
+ MutexLocker locker(pendingRequestMutex_);
+ pendingRequestsCv_.wait(
+ locker,
+ [&]() LIBCAMERA_TSA_REQUIRES(pendingRequestMutex_) {
+ return pendingRequests_.empty();
+ });
+ ASSERT(pendingRequests_.empty());
+ }
+
+ {
+ MutexLocker stateLock(stateMutex_);
+ state_ = State::Stopped;
+ }
}
void CameraDevice::stop()
@@ -1480,7 +1492,6 @@ void CameraDevice::completeResultDescriptor(Camera3ResultDescriptor *result)
completeRequestDescriptor(result->request_);
}
-
/**
* \brief Complete the Camera3RequestDescriptor
* \param[in] descriptor The Camera3RequestDescriptor
@@ -1526,6 +1537,12 @@ void CameraDevice::completeRequestDescriptor(Camera3RequestDescriptor *request)
pendingRequests_.pop_front();
}
+
+ if (pendingRequests_.empty()) {
+ locker.unlock();
+ pendingRequestsCv_.notify_one();
+ return;
+ }
}
void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer,
@@ -135,6 +135,8 @@ private:
std::map<CameraStream *, std::list<StreamBuffer *>> pendingStreamBuffers_
LIBCAMERA_TSA_GUARDED_BY(pendingRequestMutex_);
+ libcamera::ConditionVariable pendingRequestsCv_;
+
std::string maker_;
std::string model_;
Android requires that flush() only returns when there are no more outstanding buffers or requests left in the HAL. Add a contition variable to wait for all pending requests are completed before returning the call. Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org> --- src/android/camera_device.cpp | 23 ++++++++++++++++++++--- src/android/camera_device.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-)