android: post_processor: Make post processing async
Introduce a dedicated worker class derived from libcamera::Thread. The worker class maintains a queue for post-processing requests and waits for a post-processing request to become available. It will process them as per FIFO before de-queuing it from the queue. The entire post-processing handling iteration is locked under streamsProcessMutex_ which helps us to queue all the post-processing request at once, before any of the post-processing completion slot (streamProcessingComplete()) is allowed to run for post-processing requests completing in parallel. This helps us to manage both synchronous and asynchronous errors encountered during the entire post processing operation. Since a post-processing operation can even complete after CameraDevice::requestComplete() has returned, we need to check and complete the descriptor from streamProcessingComplete() running in the PostProcessorWorker's thread. This patch also implements a flush() for the PostProcessorWorker class which is responsible to purge post-processing requests queued up while a camera is stopping/flushing. It is hooked with CameraStream::flush(), which isn't used currently but will be used when we handle flush/stop scenarios in greater detail subsequently (in a different patchset). The libcamera request completion handler CameraDevice::requestComplete() assumes that the request that has just completed is at the front of the queue. Now that the post-processor runs asynchronously, this isn't true anymore, a request being post-processed will stay in the queue and a new libcamera request may complete. Remove that assumption, and use the request cookie to obtain the Camera3RequestDescriptor. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -7,12 +7,16 @@
|
||||
#ifndef __ANDROID_CAMERA_STREAM_H__
|
||||
#define __ANDROID_CAMERA_STREAM_H__
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#include <hardware/camera3.h>
|
||||
|
||||
#include <libcamera/base/thread.h>
|
||||
|
||||
#include <libcamera/camera.h>
|
||||
#include <libcamera/framebuffer.h>
|
||||
#include <libcamera/framebuffer_allocator.h>
|
||||
@@ -20,9 +24,9 @@
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
#include "camera_request.h"
|
||||
#include "post_processor.h"
|
||||
|
||||
class CameraDevice;
|
||||
class PostProcessor;
|
||||
|
||||
class CameraStream
|
||||
{
|
||||
@@ -124,8 +128,38 @@ public:
|
||||
int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer);
|
||||
libcamera::FrameBuffer *getBuffer();
|
||||
void putBuffer(libcamera::FrameBuffer *buffer);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
class PostProcessorWorker : public libcamera::Thread
|
||||
{
|
||||
public:
|
||||
enum class State {
|
||||
Stopped,
|
||||
Running,
|
||||
Flushing,
|
||||
};
|
||||
|
||||
PostProcessorWorker(PostProcessor *postProcessor);
|
||||
~PostProcessorWorker();
|
||||
|
||||
void start();
|
||||
void queueRequest(Camera3RequestDescriptor::StreamBuffer *request);
|
||||
void flush();
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
PostProcessor *postProcessor_;
|
||||
|
||||
libcamera::Mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
|
||||
std::queue<Camera3RequestDescriptor::StreamBuffer *> requests_;
|
||||
State state_ = State::Stopped;
|
||||
};
|
||||
|
||||
int waitFence(int fence);
|
||||
|
||||
CameraDevice *const cameraDevice_;
|
||||
@@ -142,6 +176,8 @@ private:
|
||||
*/
|
||||
std::unique_ptr<std::mutex> mutex_;
|
||||
std::unique_ptr<PostProcessor> postProcessor_;
|
||||
|
||||
std::unique_ptr<PostProcessorWorker> worker_;
|
||||
};
|
||||
|
||||
#endif /* __ANDROID_CAMERA_STREAM__ */
|
||||
|
||||
Reference in New Issue
Block a user