Improve DMA handling
This commit is contained in:
@ -10,24 +10,22 @@
|
|||||||
|
|
||||||
int camera_configure_direct(camera_t *camera)
|
int camera_configure_direct(camera_t *camera)
|
||||||
{
|
{
|
||||||
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs) < 0) {
|
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_list_t *src = camera->camera->capture_list;
|
buffer_list_t *src = camera->camera->capture_list;
|
||||||
|
|
||||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||||
camera->codec_jpeg->buf_sink = true;
|
|
||||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||||
camera->codec_h264->buf_sink = true;
|
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_jpeg, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_jpeg, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_jpeg, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_JPEG, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_h264, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_h264, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_H264, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ void write_yuvu(buffer_t *buffer);
|
|||||||
|
|
||||||
int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
||||||
{
|
{
|
||||||
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs) < 0) {
|
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +22,10 @@ int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
|||||||
camera->isp.isp_yuuv = device_open("ISP-YUUV", "/dev/video14");
|
camera->isp.isp_yuuv = device_open("ISP-YUUV", "/dev/video14");
|
||||||
camera->isp.isp_yuuv->output_device = camera->isp.isp_srgb;
|
camera->isp.isp_yuuv->output_device = camera->isp.isp_srgb;
|
||||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||||
camera->codec_jpeg->buf_sink = true;
|
|
||||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||||
camera->codec_h264->buf_sink = true;
|
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->isp.isp_srgb, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->isp.isp_srgb, src) < 0 ||
|
||||||
device_open_buffer_list(camera->isp.isp_yuuv, true, src->fmt_width / high_div, src->fmt_height / high_div, V4L2_PIX_FMT_YUYV, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->isp.isp_yuuv, src, high_div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +33,7 @@ int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
|||||||
camera->isp.isp_yuuv_low = device_open("ISP-YUUV-LOW", "/dev/video15");
|
camera->isp.isp_yuuv_low = device_open("ISP-YUUV-LOW", "/dev/video15");
|
||||||
camera->isp.isp_yuuv_low->output_device = camera->isp.isp_srgb;
|
camera->isp.isp_yuuv_low->output_device = camera->isp.isp_srgb;
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->isp.isp_yuuv_low, true, src->fmt_width / low_div, src->fmt_height / low_div, V4L2_PIX_FMT_YUYV, 0, camera->nbufs) < 0) {
|
if (device_open_buffer_list_capture(camera->isp.isp_yuuv_low, src, low_div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +42,13 @@ int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
|||||||
src = camera->isp.isp_yuuv->capture_list;
|
src = camera->isp.isp_yuuv->capture_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_jpeg, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_jpeg, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_jpeg, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_JPEG, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_h264, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_h264, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_H264, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ void write_yuvu(buffer_t *buffer)
|
|||||||
|
|
||||||
int camera_configure_legacy_isp(camera_t *camera, float div)
|
int camera_configure_legacy_isp(camera_t *camera, float div)
|
||||||
{
|
{
|
||||||
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs) < 0) {
|
if (device_open_buffer_list(camera->camera, true, camera->width, camera->height, camera->format, 0, camera->nbufs, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,24 +30,22 @@ int camera_configure_legacy_isp(camera_t *camera, float div)
|
|||||||
|
|
||||||
camera->legacy_isp.isp = device_open("ISP", "/dev/video12");
|
camera->legacy_isp.isp = device_open("ISP", "/dev/video12");
|
||||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||||
camera->codec_jpeg->buf_sink = true;
|
|
||||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||||
camera->codec_h264->buf_sink = true;
|
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->legacy_isp.isp, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->legacy_isp.isp, src) < 0 ||
|
||||||
device_open_buffer_list(camera->legacy_isp.isp, true, src->fmt_width / div, src->fmt_height / div, V4L2_PIX_FMT_YUYV, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->legacy_isp.isp, src, div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
src = camera->legacy_isp.isp->capture_list;
|
src = camera->legacy_isp.isp->capture_list;
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_jpeg, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_jpeg, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_jpeg, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_JPEG, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_open_buffer_list(camera->codec_h264, false, src->fmt_width, src->fmt_height, src->fmt_format, src->fmt_bytesperline, camera->nbufs) < 0 ||
|
if (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||||
device_open_buffer_list(camera->codec_h264, true, src->fmt_width, src->fmt_height, V4L2_PIX_FMT_H264, 0, camera->nbufs) < 0) {
|
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
hw/device.c
28
hw/device.c
@ -49,26 +49,23 @@ void device_close(device_t *dev) {
|
|||||||
free(dev);
|
free(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsigned height, unsigned format, unsigned bytesperline, int nbufs)
|
int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsigned height, unsigned format, unsigned bytesperline, int nbufs, bool do_mmap)
|
||||||
{
|
{
|
||||||
unsigned type;
|
unsigned type;
|
||||||
char name[64];
|
char name[64];
|
||||||
struct buffer_list_s **buf_list = NULL;
|
struct buffer_list_s **buf_list = NULL;
|
||||||
bool do_mmap = false;
|
|
||||||
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dev->allow_dma) {
|
||||||
|
do_mmap = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (do_capture) {
|
if (do_capture) {
|
||||||
buf_list = &dev->capture_list;
|
buf_list = &dev->capture_list;
|
||||||
|
|
||||||
if (dev->buf_sink) {
|
|
||||||
do_mmap = true;
|
|
||||||
} else {
|
|
||||||
do_mmap = dev->allow_dma;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dev->capture_list) {
|
if (dev->capture_list) {
|
||||||
E_LOG_ERROR(dev, "The capture_list is already created.");
|
E_LOG_ERROR(dev, "The capture_list is already created.");
|
||||||
}
|
}
|
||||||
@ -84,7 +81,6 @@ int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsi
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf_list = &dev->output_list;
|
buf_list = &dev->output_list;
|
||||||
do_mmap = !dev->allow_dma;
|
|
||||||
|
|
||||||
if (dev->output_list) {
|
if (dev->output_list) {
|
||||||
E_LOG_ERROR(dev, "The output_list is already created.");
|
E_LOG_ERROR(dev, "The output_list is already created.");
|
||||||
@ -122,6 +118,20 @@ error:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int device_open_buffer_list_output(device_t *dev, buffer_list_t *capture_list)
|
||||||
|
{
|
||||||
|
return device_open_buffer_list(dev, false,
|
||||||
|
capture_list->fmt_width, capture_list->fmt_height,
|
||||||
|
capture_list->fmt_format, capture_list->fmt_bytesperline, capture_list->nbufs, !capture_list->do_mmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
int device_open_buffer_list_capture(device_t *dev, buffer_list_t *output_list, float div, unsigned format, bool do_mmap)
|
||||||
|
{
|
||||||
|
return device_open_buffer_list(dev, true,
|
||||||
|
output_list->fmt_width / div, output_list->fmt_height / div,
|
||||||
|
format, 0, output_list->nbufs, do_mmap);
|
||||||
|
}
|
||||||
|
|
||||||
int device_stream(device_t *dev, bool do_on)
|
int device_stream(device_t *dev, bool do_on)
|
||||||
{
|
{
|
||||||
if (dev->capture_list) {
|
if (dev->capture_list) {
|
||||||
|
@ -8,7 +8,6 @@ typedef struct device_s {
|
|||||||
int fd;
|
int fd;
|
||||||
struct v4l2_capability v4l2_cap;
|
struct v4l2_capability v4l2_cap;
|
||||||
bool allow_dma;
|
bool allow_dma;
|
||||||
bool buf_sink;
|
|
||||||
|
|
||||||
struct buffer_list_s *capture_list;
|
struct buffer_list_s *capture_list;
|
||||||
struct buffer_list_s *output_list;
|
struct buffer_list_s *output_list;
|
||||||
@ -20,7 +19,9 @@ typedef struct device_s {
|
|||||||
device_t *device_open(const char *name, const char *path);
|
device_t *device_open(const char *name, const char *path);
|
||||||
void device_close(device_t *device);
|
void device_close(device_t *device);
|
||||||
|
|
||||||
int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsigned height, unsigned format, unsigned bytesperline, int nbufs);
|
int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsigned height, unsigned format, unsigned bytesperline, int nbufs, bool do_mmap);
|
||||||
|
int device_open_buffer_list_output(device_t *dev, struct buffer_list_s *capture_list);
|
||||||
|
int device_open_buffer_list_capture(device_t *dev, struct buffer_list_s *output_list, float div, unsigned format, bool do_mmap);
|
||||||
int device_consume_event(device_t *device);
|
int device_consume_event(device_t *device);
|
||||||
|
|
||||||
int device_stream(device_t *dev, bool do_on);
|
int device_stream(device_t *dev, bool do_on);
|
||||||
|
Reference in New Issue
Block a user