Fix camera-vflip/hflip
support on arm32v7
This adds `buffer_list_alloc_buffers` and `buffer_list_free_buffers` to delay buffers allocation for `libcamera`. Doing this allows to setup RAW stream afterwards.
This commit is contained in:
parent
6e89ac9663
commit
f742c1a7fc
@ -4,31 +4,19 @@
|
||||
#include "util/opts/log.h"
|
||||
#include "util/opts/fourcc.h"
|
||||
|
||||
buffer_list_t *buffer_list_open(const char *name, int index, struct device_s *dev, const char *path, buffer_format_t fmt, bool do_capture, bool do_mmap)
|
||||
static int buffer_list_alloc_buffers2(buffer_list_t *buf_list, int got_bufs)
|
||||
{
|
||||
buffer_list_t *buf_list = calloc(1, sizeof(buffer_list_t));
|
||||
|
||||
buf_list->dev = dev;
|
||||
buf_list->name = strdup(name);
|
||||
if (path) {
|
||||
buf_list->path = strdup(path);
|
||||
}
|
||||
buf_list->do_capture = do_capture;
|
||||
buf_list->do_mmap = do_mmap;
|
||||
buf_list->fmt = fmt;
|
||||
buf_list->index = index;
|
||||
|
||||
int got_bufs = dev->hw->buffer_list_open(buf_list);
|
||||
if (got_bufs < 0) {
|
||||
goto error;
|
||||
if (buf_list->bufs || got_bufs <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_INFO(
|
||||
buf_list,
|
||||
"Using: %ux%u/%s, bytesperline=%d, sizeimage=%.1fMiB",
|
||||
"Using: %ux%u/%s, buffers=%d, bytesperline=%d, sizeimage=%.1fMiB",
|
||||
buf_list->fmt.width,
|
||||
buf_list->fmt.height,
|
||||
fourcc_to_string(buf_list->fmt.format).buf,
|
||||
got_bufs,
|
||||
buf_list->fmt.bytesperline,
|
||||
buf_list->fmt.sizeimage / 1024.0f / 1024.0f
|
||||
);
|
||||
@ -56,6 +44,35 @@ buffer_list_t *buffer_list_open(const char *name, int index, struct device_s *de
|
||||
}
|
||||
|
||||
LOG_INFO(buf_list, "Opened %u buffers. Memory used: %.1f MiB", buf_list->nbufs, mem_used / 1024.0f / 1024.0f);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
buffer_list_free_buffers(buf_list);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_list_t *buffer_list_open(const char *name, int index, struct device_s *dev, const char *path, buffer_format_t fmt, bool do_capture, bool do_mmap)
|
||||
{
|
||||
buffer_list_t *buf_list = calloc(1, sizeof(buffer_list_t));
|
||||
|
||||
buf_list->dev = dev;
|
||||
buf_list->name = strdup(name);
|
||||
if (path) {
|
||||
buf_list->path = strdup(path);
|
||||
}
|
||||
buf_list->do_capture = do_capture;
|
||||
buf_list->do_mmap = do_mmap;
|
||||
buf_list->fmt = fmt;
|
||||
buf_list->index = index;
|
||||
|
||||
int err = dev->hw->buffer_list_open(buf_list);
|
||||
if (err > 0) {
|
||||
err = buffer_list_alloc_buffers2(buf_list, err);
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return buf_list;
|
||||
|
||||
@ -64,20 +81,48 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int buffer_list_alloc_buffers(buffer_list_t *buf_list)
|
||||
{
|
||||
if (buf_list->bufs) {
|
||||
return 0;
|
||||
}
|
||||
if (!buf_list->dev->hw->buffer_list_alloc_buffers) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int got_bufs = buf_list->dev->hw->buffer_list_alloc_buffers(buf_list);
|
||||
if (got_bufs < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return buffer_list_alloc_buffers2(buf_list, got_bufs);
|
||||
}
|
||||
|
||||
void buffer_list_free_buffers(buffer_list_t *buf_list)
|
||||
{
|
||||
if (!buf_list->bufs) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < buf_list->nbufs; i++) {
|
||||
buffer_close(buf_list->bufs[i]);
|
||||
}
|
||||
free(buf_list->bufs);
|
||||
buf_list->bufs = NULL;
|
||||
buf_list->nbufs = 0;
|
||||
|
||||
if (buf_list->dev->hw->buffer_list_free_buffers) {
|
||||
buf_list->dev->hw->buffer_list_free_buffers(buf_list);
|
||||
}
|
||||
}
|
||||
|
||||
void buffer_list_close(buffer_list_t *buf_list)
|
||||
{
|
||||
if (!buf_list) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf_list->bufs) {
|
||||
for (int i = 0; i < buf_list->nbufs; i++) {
|
||||
buffer_close(buf_list->bufs[i]);
|
||||
}
|
||||
free(buf_list->bufs);
|
||||
buf_list->bufs = NULL;
|
||||
buf_list->nbufs = 0;
|
||||
}
|
||||
buffer_list_free_buffers(buf_list);
|
||||
|
||||
buf_list->dev->hw->buffer_list_close(buf_list);
|
||||
free(buf_list->name);
|
||||
|
@ -56,6 +56,8 @@ typedef struct buffer_list_s {
|
||||
|
||||
buffer_list_t *buffer_list_open(const char *name, int index, struct device_s *dev, const char *path, buffer_format_t fmt, bool do_capture, bool do_mmap);
|
||||
void buffer_list_close(buffer_list_t *buf_list);
|
||||
int buffer_list_alloc_buffers(buffer_list_t *buf_list);
|
||||
void buffer_list_free_buffers(buffer_list_t *buf_list);
|
||||
|
||||
int buffer_list_set_stream(buffer_list_t *buf_list, bool do_on);
|
||||
|
||||
|
@ -58,18 +58,6 @@ static int camera_configure_input_libcamera(camera_t *camera)
|
||||
|
||||
camera->camera->opts.allow_dma = camera->options.allow_dma;
|
||||
|
||||
buffer_format_t raw_fmt = {
|
||||
.width = camera->options.width,
|
||||
.height = camera->options.height,
|
||||
.nbufs = camera->options.nbufs,
|
||||
.type = BUFFER_TYPE_RAW
|
||||
};
|
||||
|
||||
buffer_list_t *raw_capture = device_open_buffer_list(camera->camera, true, raw_fmt, true);
|
||||
if (!raw_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_format_t capture_fmt = {
|
||||
.width = camera->options.width,
|
||||
.height = camera->options.height,
|
||||
@ -91,6 +79,25 @@ static int camera_configure_input_libcamera(camera_t *camera)
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_format_t raw_fmt = {
|
||||
.width = camera->options.width,
|
||||
.height = camera->options.height,
|
||||
.nbufs = camera->options.nbufs,
|
||||
.type = BUFFER_TYPE_RAW
|
||||
};
|
||||
|
||||
buffer_list_t *raw_capture = device_open_buffer_list(camera->camera, true, raw_fmt, true);
|
||||
if (!raw_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_list_alloc_buffers(camera_capture) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (buffer_list_alloc_buffers(raw_capture) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return camera_configure_pipeline(camera, camera_capture);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ typedef struct device_hw_s {
|
||||
|
||||
int (*buffer_list_open)(buffer_list_t *buf_list);
|
||||
void (*buffer_list_close)(buffer_list_t *buf_list);
|
||||
int (*buffer_list_alloc_buffers)(buffer_list_t *buf_list);
|
||||
void (*buffer_list_free_buffers)(buffer_list_t *buf_list);
|
||||
int (*buffer_list_set_stream)(buffer_list_t *buf_list, bool do_on);
|
||||
} device_hw_t;
|
||||
|
||||
|
@ -117,7 +117,16 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list)
|
||||
buf_list->fmt.height = configuration.size.height;
|
||||
buf_list->fmt.format = libcamera_to_fourcc(configuration.pixelFormat);
|
||||
buf_list->fmt.bytesperline = configuration.stride;
|
||||
buf_list->fmt.nbufs = configuration.bufferCount;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int libcamera_buffer_list_alloc_buffers(buffer_list_t *buf_list)
|
||||
{
|
||||
auto &configurations = buf_list->dev->libcamera->configuration;
|
||||
auto &configuration = configurations->at(buf_list->index);
|
||||
|
||||
if (buf_list->dev->libcamera->allocator->allocate(configuration.stream()) < 0) {
|
||||
LOG_ERROR(buf_list, "Can't allocate buffers");
|
||||
@ -126,15 +135,20 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list)
|
||||
{
|
||||
int allocated = buf_list->dev->libcamera->allocator->buffers(
|
||||
configuration.stream()).size();
|
||||
buf_list->fmt.nbufs = std::min<unsigned>(buf_list->fmt.nbufs, allocated);
|
||||
return std::min<int>(buf_list->fmt.nbufs, allocated);
|
||||
}
|
||||
|
||||
return buf_list->fmt.nbufs;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
void libcamera_buffer_list_free_buffers(buffer_list_t *buf_list)
|
||||
{
|
||||
auto &configurations = buf_list->dev->libcamera->configuration;
|
||||
auto &configuration = configurations->at(buf_list->index);
|
||||
buf_list->dev->libcamera->allocator->free(configuration.stream());
|
||||
}
|
||||
|
||||
void libcamera_buffer_list_close(buffer_list_t *buf_list)
|
||||
{
|
||||
if (buf_list->libcamera) {
|
||||
|
@ -17,6 +17,8 @@ device_hw_t libcamera_device_hw = {
|
||||
.buffer_list_pollfd = libcamera_buffer_list_pollfd,
|
||||
.buffer_list_open = libcamera_buffer_list_open,
|
||||
.buffer_list_close = libcamera_buffer_list_close,
|
||||
.buffer_list_alloc_buffers = libcamera_buffer_list_alloc_buffers,
|
||||
.buffer_list_free_buffers = libcamera_buffer_list_free_buffers,
|
||||
.buffer_list_set_stream = libcamera_buffer_list_set_stream
|
||||
};
|
||||
|
||||
|
@ -72,5 +72,7 @@ int libcamera_buffer_list_pollfd(buffer_list_t *buf_list, struct pollfd *pollfd,
|
||||
|
||||
int libcamera_buffer_list_open(buffer_list_t *buf_list);
|
||||
void libcamera_buffer_list_close(buffer_list_t *buf_list);
|
||||
int libcamera_buffer_list_alloc_buffers(buffer_list_t *buf_list);
|
||||
void libcamera_buffer_list_free_buffers(buffer_list_t *buf_list);
|
||||
int libcamera_buffer_list_set_stream(buffer_list_t *buf_list, bool do_on);
|
||||
#endif // USE_LIBCAMERA
|
||||
|
2
env-distcc
Normal file
2
env-distcc
Normal file
@ -0,0 +1,2 @@
|
||||
export DISTCC_HOSTS="rocknas.home/2"
|
||||
export CCACHE="ccache distcc"
|
BIN
video_90.mkv
Normal file
BIN
video_90.mkv
Normal file
Binary file not shown.
BIN
video_flip.mkv
Normal file
BIN
video_flip.mkv
Normal file
Binary file not shown.
BIN
video_raw.mkv
Normal file
BIN
video_raw.mkv
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user