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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user