libcamera: v4l2_device: Implement queue/dequeue operations

Provide queueBuffer() and dequeueBuffer() methods to interact with the
V4L2Device.

Buffers will be directly referenced from the bufferPool of the
V4L2Device based on the index in the pool.

The V4L2Device is now opened in non-blocking mode in order to avoid
blocking the dequeueBuffer() method. A signal is emitted when a buffer
is ready and has been dequeued.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Kieran Bingham
2019-02-04 12:48:45 +01:00
committed by Laurent Pinchart
parent 2843f951d5
commit dffbde33b8
2 changed files with 140 additions and 2 deletions

View File

@@ -7,15 +7,19 @@
#ifndef __LIBCAMERA_V4L2_DEVICE_H__
#define __LIBCAMERA_V4L2_DEVICE_H__
#include <atomic>
#include <string>
#include <vector>
#include <linux/videodev2.h>
#include <libcamera/signal.h>
namespace libcamera {
class Buffer;
class BufferPool;
class EventNotifier;
class MediaEntity;
struct V4L2Capability final : v4l2_capability {
@@ -96,6 +100,9 @@ public:
int exportBuffers(unsigned int count, BufferPool *pool);
int releaseBuffers();
int queueBuffer(Buffer *buffer);
Signal<Buffer *> bufferReady;
private:
int getFormatSingleplane(V4L2DeviceFormat *format);
int setFormatSingleplane(V4L2DeviceFormat *format);
@@ -107,6 +114,9 @@ private:
int createPlane(Buffer *buffer, unsigned int plane,
unsigned int length);
Buffer *dequeueBuffer();
void bufferAvailable(EventNotifier *notifier);
std::string deviceNode_;
int fd_;
V4L2Capability caps_;
@@ -115,6 +125,9 @@ private:
enum v4l2_memory memoryType_;
BufferPool *bufferPool_;
std::atomic<unsigned int> queuedBuffersCount_;
EventNotifier *fdEvent_;
};
} /* namespace libcamera */