Fix libcamera resolution handling
This commit is contained in:
parent
facd1fa41e
commit
fb400f3139
@ -42,77 +42,21 @@ camera_t *camera_open(camera_options_t *options)
|
||||
|
||||
switch (camera->options.type) {
|
||||
case CAMERA_V4L2:
|
||||
camera->camera = device_v4l2_open(camera->name, camera->options.path);
|
||||
if (camera_configure_v4l2(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case CAMERA_LIBCAMERA:
|
||||
camera->camera = device_libcamera_open(camera->name, camera->options.path);
|
||||
if (camera_configure_libcamera(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR(camera, "Unsupported camera type");
|
||||
}
|
||||
|
||||
if (!camera->camera) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
camera->camera->opts.allow_dma = camera->options.allow_dma;
|
||||
camera->camera->opts.width = camera->options.width;
|
||||
camera->camera->opts.height = camera->options.height;
|
||||
|
||||
if (strstr(camera->camera->bus_info, "usb")) {
|
||||
LOG_INFO(camera, "Disabling DMA since device uses USB (which is likely not working properly).");
|
||||
camera->camera->opts.allow_dma = false;
|
||||
}
|
||||
|
||||
if (device_open_buffer_list(camera->camera, true, camera->options.width, camera->options.height, camera->options.format, 0, camera->options.nbufs, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
camera->camera->capture_list->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
camera->camera->capture_list->fmt_interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_MJPEG:
|
||||
case V4L2_PIX_FMT_H264:
|
||||
if (camera_configure_decoder(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_SRGGB10P:
|
||||
#if 1
|
||||
if (camera_configure_isp(camera, camera->options.high_res_factor, camera->options.low_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#else
|
||||
if (camera_configure_legacy_isp(camera, camera->options.high_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR(camera, "Unsupported camera format=%s",
|
||||
fourcc_to_string(camera->camera->capture_list->fmt_format).buf);
|
||||
break;
|
||||
}
|
||||
|
||||
if (camera_set_params(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -70,6 +70,8 @@ int camera_set_params(camera_t *camera);
|
||||
void camera_close(camera_t *camera);
|
||||
int camera_run(camera_t *camera);
|
||||
|
||||
int camera_configure_v4l2(camera_t *camera);
|
||||
int camera_configure_libcamera(camera_t *camera);
|
||||
int camera_configure_isp(camera_t *camera, float high_div, float low_div);
|
||||
int camera_configure_legacy_isp(camera_t *camera, float div);
|
||||
int camera_configure_direct(camera_t *camera);
|
||||
|
36
device/camera/camera_libcamera.c
Normal file
36
device/camera/camera_libcamera.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "device/buffer.h"
|
||||
#include "device/buffer_list.h"
|
||||
#include "device/device.h"
|
||||
#include "device/links.h"
|
||||
#include "opts/log.h"
|
||||
#include "opts/fourcc.h"
|
||||
|
||||
int camera_configure_libcamera(camera_t *camera)
|
||||
{
|
||||
camera->camera = device_libcamera_open(camera->name, camera->options.path);
|
||||
if (!camera->camera) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
camera->camera->opts.allow_dma = camera->options.allow_dma;
|
||||
|
||||
if (device_open_buffer_list(camera->camera, true, camera->options.width / camera->options.high_res_factor, camera->options.height / camera->options.high_res_factor, camera->options.format, 0, camera->options.nbufs, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
camera->camera->capture_list->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
camera->camera->capture_list->fmt_interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
if (camera_configure_direct(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
75
device/camera/camera_v4l2.c
Normal file
75
device/camera/camera_v4l2.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "device/buffer.h"
|
||||
#include "device/buffer_list.h"
|
||||
#include "device/device.h"
|
||||
#include "device/links.h"
|
||||
#include "opts/log.h"
|
||||
#include "opts/fourcc.h"
|
||||
|
||||
int camera_configure_v4l2(camera_t *camera)
|
||||
{
|
||||
camera->camera = device_v4l2_open(camera->name, camera->options.path);
|
||||
if (!camera->camera) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
camera->camera->opts.allow_dma = camera->options.allow_dma;
|
||||
|
||||
if (strstr(camera->camera->bus_info, "usb")) {
|
||||
LOG_INFO(camera, "Disabling DMA since device uses USB (which is likely not working properly).");
|
||||
camera->camera->opts.allow_dma = false;
|
||||
}
|
||||
|
||||
if (device_open_buffer_list(camera->camera, true, camera->options.width, camera->options.height, camera->options.format, 0, camera->options.nbufs, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
camera->camera->capture_list->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
camera->camera->capture_list->fmt_interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_MJPEG:
|
||||
case V4L2_PIX_FMT_H264:
|
||||
if (camera_configure_decoder(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_SRGGB10P:
|
||||
#if 1
|
||||
if (camera_configure_isp(camera, camera->options.high_res_factor, camera->options.low_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#else
|
||||
if (camera_configure_legacy_isp(camera, camera->options.high_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR(camera, "Unsupported camera format=%s",
|
||||
fourcc_to_string(camera->camera->capture_list->fmt_format).buf);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
@ -67,7 +67,7 @@ int libcamera_device_set_fps(device_t *dev, int desired_fps)
|
||||
{
|
||||
int64_t frame_time = 1000000 / desired_fps;
|
||||
dev->libcamera->controls.set(libcamera::controls::FrameDurationLimits, { frame_time, frame_time });
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libcamera_device_set_option(device_t *dev, const char *keyp, const char *value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user