mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-13 15:29:45 +03:00
android: camera_device: Refactor descriptor status and sendCaptureResults()
Currently, we use Camera3RequestDescriptor::Status to determine: - When the descriptor has been completely processed by HAL - Whether any errors were encountered, during its processing Both of these are essential to know whether the descriptor is eligible to call process_capture_results() through sendCaptureResults(). When a status(Success/Error) is set on the descriptor, it is ready to be sent back via sendCaptureResults(). However, this might lead to undesired results especially when sendCaptureResults() runs in a different thread (for e.g. stream's post-processor async completion slot). This patch decouples the descriptor status (Success/Error) from the descriptor's completion status (pending or complete). The advantage of this is we can set the completion status when the descriptor has been processed fully by the layer and we can set the error status on the descriptor wherever an error is encountered, throughout the lifetime of the descriptor in the HAL layer. While at it, introduce a wrapper completeDescriptor() around sendCaptureResults(). completeDescriptor() as the name suggests will mark the descriptor as complete, so it is ready to be sent back. The locking mechanism is moved from sendCaptureResults() to this wrapper since the intention is to use completeDescriptor() in place of existing sendCaptureResults() calls. Also make sure the sequence of abortRequest() call happens in the same order at all places i.e. after its added to the descriptors_ queue. Fix one of the abortRequest() call accordingly. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
This commit is contained in:
parent
ed9eb080e9
commit
64bcbd0e2c
4 changed files with 19 additions and 19 deletions
|
@ -982,13 +982,13 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
|
||||||
MutexLocker stateLock(stateMutex_);
|
MutexLocker stateLock(stateMutex_);
|
||||||
|
|
||||||
if (state_ == State::Flushing) {
|
if (state_ == State::Flushing) {
|
||||||
abortRequest(descriptor.get());
|
Camera3RequestDescriptor *rawDescriptor = descriptor.get();
|
||||||
{
|
{
|
||||||
MutexLocker descriptorsLock(descriptorsMutex_);
|
MutexLocker descriptorsLock(descriptorsMutex_);
|
||||||
descriptors_.push(std::move(descriptor));
|
descriptors_.push(std::move(descriptor));
|
||||||
}
|
}
|
||||||
|
abortRequest(rawDescriptor);
|
||||||
sendCaptureResults();
|
completeDescriptor(rawDescriptor);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1079,7 +1079,7 @@ void CameraDevice::requestComplete(Request *request)
|
||||||
<< request->status();
|
<< request->status();
|
||||||
|
|
||||||
abortRequest(descriptor);
|
abortRequest(descriptor);
|
||||||
sendCaptureResults();
|
completeDescriptor(descriptor);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1129,6 +1129,7 @@ void CameraDevice::requestComplete(Request *request)
|
||||||
buffer.status = Camera3RequestDescriptor::Status::Error;
|
buffer.status = Camera3RequestDescriptor::Status::Error;
|
||||||
notifyError(descriptor->frameNumber_, stream->camera3Stream(),
|
notifyError(descriptor->frameNumber_, stream->camera3Stream(),
|
||||||
CAMERA3_MSG_ERROR_BUFFER);
|
CAMERA3_MSG_ERROR_BUFFER);
|
||||||
|
descriptor->status_ = Camera3RequestDescriptor::Status::Error;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1145,27 +1146,27 @@ void CameraDevice::requestComplete(Request *request)
|
||||||
buffer.status = Camera3RequestDescriptor::Status::Error;
|
buffer.status = Camera3RequestDescriptor::Status::Error;
|
||||||
notifyError(descriptor->frameNumber_, stream->camera3Stream(),
|
notifyError(descriptor->frameNumber_, stream->camera3Stream(),
|
||||||
CAMERA3_MSG_ERROR_BUFFER);
|
CAMERA3_MSG_ERROR_BUFFER);
|
||||||
|
descriptor->status_ = Camera3RequestDescriptor::Status::Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor->status_ = Camera3RequestDescriptor::Status::Success;
|
completeDescriptor(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraDevice::completeDescriptor(Camera3RequestDescriptor *descriptor)
|
||||||
|
{
|
||||||
|
MutexLocker lock(descriptorsMutex_);
|
||||||
|
descriptor->complete_ = true;
|
||||||
|
|
||||||
sendCaptureResults();
|
sendCaptureResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraDevice::sendCaptureResults()
|
void CameraDevice::sendCaptureResults()
|
||||||
{
|
{
|
||||||
MutexLocker lock(descriptorsMutex_);
|
|
||||||
while (!descriptors_.empty() && !descriptors_.front()->isPending()) {
|
while (!descriptors_.empty() && !descriptors_.front()->isPending()) {
|
||||||
auto descriptor = std::move(descriptors_.front());
|
auto descriptor = std::move(descriptors_.front());
|
||||||
descriptors_.pop();
|
descriptors_.pop();
|
||||||
|
|
||||||
/*
|
|
||||||
* \todo Releasing and re-acquiring the critical section for
|
|
||||||
* every request completion (grain-locking) might have an
|
|
||||||
* impact on performance which should be measured.
|
|
||||||
*/
|
|
||||||
lock.unlock();
|
|
||||||
|
|
||||||
camera3_capture_result_t captureResult = {};
|
camera3_capture_result_t captureResult = {};
|
||||||
|
|
||||||
captureResult.frame_number = descriptor->frameNumber_;
|
captureResult.frame_number = descriptor->frameNumber_;
|
||||||
|
@ -1201,8 +1202,6 @@ void CameraDevice::sendCaptureResults()
|
||||||
captureResult.partial_result = 1;
|
captureResult.partial_result = 1;
|
||||||
|
|
||||||
callbacks_->process_capture_result(callbacks_, &captureResult);
|
callbacks_->process_capture_result(callbacks_, &captureResult);
|
||||||
|
|
||||||
lock.lock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ private:
|
||||||
void notifyError(uint32_t frameNumber, camera3_stream_t *stream,
|
void notifyError(uint32_t frameNumber, camera3_stream_t *stream,
|
||||||
camera3_error_msg_code code) const;
|
camera3_error_msg_code code) const;
|
||||||
int processControls(Camera3RequestDescriptor *descriptor);
|
int processControls(Camera3RequestDescriptor *descriptor);
|
||||||
|
void completeDescriptor(Camera3RequestDescriptor *descriptor);
|
||||||
void sendCaptureResults();
|
void sendCaptureResults();
|
||||||
std::unique_ptr<CameraMetadata> getResultMetadata(
|
std::unique_ptr<CameraMetadata> getResultMetadata(
|
||||||
const Camera3RequestDescriptor &descriptor) const;
|
const Camera3RequestDescriptor &descriptor) const;
|
||||||
|
|
|
@ -36,7 +36,7 @@ Camera3RequestDescriptor::Camera3RequestDescriptor(
|
||||||
static_cast<CameraStream *>(buffer.stream->priv);
|
static_cast<CameraStream *>(buffer.stream->priv);
|
||||||
|
|
||||||
buffers_.push_back({ stream, buffer.buffer, nullptr,
|
buffers_.push_back({ stream, buffer.buffer, nullptr,
|
||||||
buffer.acquire_fence, Status::Pending });
|
buffer.acquire_fence, Status::Success });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clone the controls associated with the camera3 request. */
|
/* Clone the controls associated with the camera3 request. */
|
||||||
|
|
|
@ -26,7 +26,6 @@ class Camera3RequestDescriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Status {
|
enum class Status {
|
||||||
Pending,
|
|
||||||
Success,
|
Success,
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
@ -43,7 +42,7 @@ public:
|
||||||
const camera3_capture_request_t *camera3Request);
|
const camera3_capture_request_t *camera3Request);
|
||||||
~Camera3RequestDescriptor();
|
~Camera3RequestDescriptor();
|
||||||
|
|
||||||
bool isPending() const { return status_ == Status::Pending; }
|
bool isPending() const { return !complete_; }
|
||||||
|
|
||||||
uint32_t frameNumber_ = 0;
|
uint32_t frameNumber_ = 0;
|
||||||
|
|
||||||
|
@ -53,7 +52,8 @@ public:
|
||||||
std::unique_ptr<CaptureRequest> request_;
|
std::unique_ptr<CaptureRequest> request_;
|
||||||
std::unique_ptr<CameraMetadata> resultMetadata_;
|
std::unique_ptr<CameraMetadata> resultMetadata_;
|
||||||
|
|
||||||
Status status_ = Status::Pending;
|
bool complete_ = false;
|
||||||
|
Status status_ = Status::Success;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LIBCAMERA_DISABLE_COPY(Camera3RequestDescriptor)
|
LIBCAMERA_DISABLE_COPY(Camera3RequestDescriptor)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue