Improve supported formats
This commit is contained in:
parent
b5d519e6d1
commit
b15d5b28af
@ -53,10 +53,16 @@ log_options_t log_options = {
|
||||
option_value_t camera_formats[] = {
|
||||
{ "DEFAULT", 0 },
|
||||
{ "YUYV", V4L2_PIX_FMT_YUYV },
|
||||
{ "YUV420", V4L2_PIX_FMT_YUV420 },
|
||||
{ "YUYV", V4L2_PIX_FMT_YUYV },
|
||||
{ "MJPG", V4L2_PIX_FMT_MJPEG },
|
||||
{ "MJPEG", V4L2_PIX_FMT_MJPEG },
|
||||
{ "H264", V4L2_PIX_FMT_H264 },
|
||||
{ "RG10", V4L2_PIX_FMT_SRGGB10P },
|
||||
{ "RGB565", V4L2_PIX_FMT_RGB565 },
|
||||
{ "RGBP", V4L2_PIX_FMT_RGB565 },
|
||||
{ "RGB24", V4L2_PIX_FMT_RGB24 },
|
||||
{ "RGB", V4L2_PIX_FMT_RGB24 },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -78,6 +78,12 @@ camera_t *camera_open(camera_options_t *options)
|
||||
|
||||
switch (camera->camera->capture_list->fmt_format) {
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
case V4L2_PIX_FMT_YVYU:
|
||||
case V4L2_PIX_FMT_VYUY:
|
||||
case V4L2_PIX_FMT_UYVY:
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
case V4L2_PIX_FMT_RGB565:
|
||||
case V4L2_PIX_FMT_RGB24:
|
||||
if (camera_configure_direct(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
@ -103,7 +109,8 @@ camera_t *camera_open(camera_options_t *options)
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR(camera, "Unsupported camera format=%s", fourcc_to_string(camera->options.format).buf);
|
||||
LOG_ERROR(camera, "Unsupported camera format=%s",
|
||||
fourcc_to_string(camera->camera->capture_list->fmt_format).buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -18,24 +18,41 @@ int libcamera_buffer_open(buffer_t *buf)
|
||||
if (buf->libcamera->request->addBuffer(stream, buffer.get()) < 0) {
|
||||
LOG_ERROR(buf, "Can't set buffer for request");
|
||||
}
|
||||
|
||||
for (auto const &plane : buffer->planes()) {
|
||||
if (buf->start) {
|
||||
LOG_ERROR(buf, "Too many planes open.");
|
||||
}
|
||||
|
||||
buf->start = mmap(NULL, plane.length, PROT_READ | PROT_WRITE, MAP_SHARED, plane.fd.get(), 0);
|
||||
buf->length = plane.length;
|
||||
buf->used = 0;
|
||||
buf->dma_fd = plane.fd.get();
|
||||
|
||||
if (!buf->start) {
|
||||
LOG_ERROR(buf, "Failed to mmap DMA buffer");
|
||||
}
|
||||
|
||||
LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%d, fd=%d",
|
||||
buf->start, buf->length, buf->dma_fd);
|
||||
if (buf->start) {
|
||||
LOG_ERROR(buf, "Too many streams.");
|
||||
}
|
||||
|
||||
if (buffer->planes().empty()) {
|
||||
LOG_ERROR(buf, "No planes allocated");
|
||||
}
|
||||
|
||||
uint64_t offset = buffer->planes()[0].offset;
|
||||
uint64_t length = 0;
|
||||
libcamera::SharedFD dma_fd = buffer->planes()[0].fd;
|
||||
|
||||
// Require that planes are continuous
|
||||
for (auto const &plane : buffer->planes()) {
|
||||
if (plane.fd != dma_fd) {
|
||||
LOG_ERROR(buf, "Plane does not share FD: fd=%d, expected=%d", plane.fd.get(), dma_fd.get());
|
||||
}
|
||||
|
||||
if (offset + length != plane.offset) {
|
||||
LOG_ERROR(buf, "Plane is not continuous: offset=%lld, expected=%lld", plane.offset, offset + length);
|
||||
}
|
||||
|
||||
length += plane.length;
|
||||
}
|
||||
|
||||
buf->start = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, dma_fd.get(), offset);
|
||||
if (!buf->start || buf->start == MAP_FAILED) {
|
||||
LOG_ERROR(buf, "Failed to mmap DMA buffer");
|
||||
}
|
||||
|
||||
buf->dma_fd = dma_fd.get();
|
||||
buf->length = length;
|
||||
|
||||
LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%d, fd=%d, planes=%d",
|
||||
buf->start, buf->length, buf->dma_fd, buffer->planes().size());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -102,11 +102,6 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig
|
||||
buf_list->fmt_bytesperline = fmt.fmt.pix.bytesperline;
|
||||
}
|
||||
|
||||
if (bytesperline > 0 && buf_list->fmt_bytesperline != bytesperline) {
|
||||
LOG_ERROR(buf_list, "Requested bytesperline=%u. Got %u.",
|
||||
bytesperline, buf_list->fmt_bytesperline);
|
||||
}
|
||||
|
||||
if (buf_list->fmt_width != width || buf_list->fmt_height != height) {
|
||||
if (bytesperline) {
|
||||
LOG_ERROR(buf_list, "Requested resolution=%ux%u is unavailable. Got %ux%u.",
|
||||
@ -123,6 +118,11 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig
|
||||
fourcc_to_string(buf_list->fmt_format).buf);
|
||||
}
|
||||
|
||||
if (bytesperline > 0 && buf_list->fmt_bytesperline != bytesperline) {
|
||||
LOG_ERROR(buf_list, "Requested bytesperline=%u. Got %u.",
|
||||
bytesperline, buf_list->fmt_bytesperline);
|
||||
}
|
||||
|
||||
// Some devices require setting pad size via media-controller
|
||||
if (buf_list->do_capture) {
|
||||
v4l2_device_set_pad_format(dev, width, height, format);
|
||||
|
Loading…
x
Reference in New Issue
Block a user