Remove dependency on output_list
and capture_list
to create a pipeline
This commit is contained in:
parent
4497c91ae8
commit
d7c263bae9
@ -4,7 +4,7 @@
|
||||
#include "opts/log.h"
|
||||
#include "opts/fourcc.h"
|
||||
|
||||
buffer_list_t *buffer_list_open(const char *name, struct device_s *dev, const char *path, buffer_format_t fmt, bool do_capture, bool do_mmap)
|
||||
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));
|
||||
|
||||
@ -16,6 +16,7 @@ buffer_list_t *buffer_list_open(const char *name, struct device_s *dev, const ch
|
||||
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) {
|
||||
|
@ -19,6 +19,7 @@ typedef struct buffer_list_s {
|
||||
device_t *dev;
|
||||
buffer_t **bufs;
|
||||
int nbufs;
|
||||
int index;
|
||||
|
||||
buffer_format_t fmt;
|
||||
bool do_mmap, do_capture, do_timestamps;
|
||||
@ -34,7 +35,7 @@ typedef struct buffer_list_s {
|
||||
int frames;
|
||||
} buffer_list_t;
|
||||
|
||||
buffer_list_t *buffer_list_open(const char *name, struct device_s *dev, const char *path, buffer_format_t fmt, bool do_capture, bool do_mmap);
|
||||
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_set_stream(buffer_list_t *buf_list, bool do_on);
|
||||
|
@ -38,6 +38,13 @@ typedef struct camera_options_s {
|
||||
} h264;
|
||||
} camera_options_t;
|
||||
|
||||
typedef struct camera_pipeline_s {
|
||||
int index;
|
||||
buffer_list_t *capture;
|
||||
unsigned width, height, format;
|
||||
float res_factor;
|
||||
} camera_pipeline_t;
|
||||
|
||||
typedef struct camera_s {
|
||||
const char *name;
|
||||
|
||||
|
@ -9,60 +9,60 @@
|
||||
#include "device/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
int camera_configure_decoder(camera_t *camera, buffer_list_t *camera_src)
|
||||
int camera_configure_decoder(camera_t *camera, buffer_list_t *camera_capture)
|
||||
{
|
||||
buffer_list_t *src = camera_src;
|
||||
buffer_list_t *src = camera_capture;
|
||||
device_video_force_key(camera->camera);
|
||||
|
||||
camera->decoder = device_v4l2_open("DECODER", "/dev/video10");
|
||||
|
||||
if (!device_open_buffer_list_output(camera->decoder, src)) {
|
||||
return -1;
|
||||
buffer_list_t *decoder_output = device_open_buffer_list_output(camera->decoder, src);
|
||||
buffer_list_t *decoder_capture = device_open_buffer_list_capture(camera->decoder, decoder_output, 1.0, 0, true);
|
||||
|
||||
link_t *links = camera->links;
|
||||
link_t *camera_link = &*links++;
|
||||
link_t *decoder_link = &*links++;
|
||||
|
||||
*camera_link = (link_t){ camera_capture, { decoder_output }, {} };
|
||||
*decoder_link = (link_t){ decoder_capture, { }, { } };
|
||||
buffer_list_t **decoder_sinks = &decoder_link->sinks[0];
|
||||
|
||||
if (camera_capture->fmt.format == V4L2_PIX_FMT_MJPEG || camera_capture->fmt.format == V4L2_PIX_FMT_JPEG) {
|
||||
camera_link->callbacks.on_buffer = http_jpeg_capture;
|
||||
camera_link->callbacks.validate_buffer = http_jpeg_needs_buffer;
|
||||
} else {
|
||||
camera->codec_jpeg = device_v4l2_open("JPEG", "/dev/video31");
|
||||
|
||||
buffer_list_t *jpeg_output = device_open_buffer_list_output(camera->codec_jpeg, decoder_capture);
|
||||
buffer_list_t *jpeg_capture = device_open_buffer_list_capture(camera->codec_jpeg, jpeg_output, 1.0, V4L2_PIX_FMT_JPEG, true);
|
||||
|
||||
if (!jpeg_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*decoder_sinks++ = jpeg_output;
|
||||
*links++ = (link_t){ jpeg_capture, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
}
|
||||
|
||||
if (!device_open_buffer_list_capture(camera->decoder, NULL, 1.0, 0, true)) {
|
||||
return -1;
|
||||
if (camera_capture->fmt.format == V4L2_PIX_FMT_H264) {
|
||||
camera_link->callbacks.on_buffer = http_h264_capture;
|
||||
camera_link->callbacks.validate_buffer = http_h264_needs_buffer;
|
||||
} else {
|
||||
camera->codec_h264 = device_v4l2_open("H264", "/dev/video11");
|
||||
|
||||
buffer_list_t *h264_output = device_open_buffer_list_output(camera->codec_jpeg, decoder_capture);
|
||||
buffer_list_t *h264_capture = device_open_buffer_list_capture(camera->codec_jpeg, h264_output, 1.0, V4L2_PIX_FMT_H264, true);
|
||||
|
||||
if (!h264_output) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*decoder_sinks++ = h264_output;
|
||||
*links++ = (link_t){ h264_capture, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
}
|
||||
|
||||
if (device_set_decoder_start(camera->decoder, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
src = camera->decoder->capture_list;
|
||||
|
||||
if (camera_src->fmt.format != V4L2_PIX_FMT_MJPEG && camera_src->fmt.format != V4L2_PIX_FMT_JPEG) {
|
||||
camera->codec_jpeg = device_v4l2_open("JPEG", "/dev/video31");
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_jpeg, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (camera_src->fmt.format != V4L2_PIX_FMT_H264) {
|
||||
camera->codec_h264 = device_v4l2_open("H264", "/dev/video11");
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_h264, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
if (camera_src->fmt.format == V4L2_PIX_FMT_MJPEG || camera_src->fmt.format == V4L2_PIX_FMT_JPEG) {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
} else if (camera_src->fmt.format == V4L2_PIX_FMT_H264) {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list }, { http_h264_capture, http_h264_needs_buffer }};
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_jpeg->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
} else {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list } };
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,28 +9,24 @@
|
||||
#include "device/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
int camera_configure_direct(camera_t *camera, buffer_list_t *src)
|
||||
int camera_configure_direct(camera_t *camera, buffer_list_t *camera_capture)
|
||||
{
|
||||
camera->codec_jpeg = device_v4l2_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_v4l2_open("H264", "/dev/video11");
|
||||
|
||||
buffer_list_t *jpeg_output = device_open_buffer_list_output(camera->codec_jpeg, src);
|
||||
buffer_list_t *h264_output = device_open_buffer_list_output(camera->codec_h264, src);
|
||||
if (!jpeg_output || !h264_output) {
|
||||
return -1;
|
||||
}
|
||||
buffer_list_t *jpeg_output = device_open_buffer_list_output(camera->codec_jpeg, camera_capture);
|
||||
buffer_list_t *jpeg_capture = device_open_buffer_list_capture(camera->codec_jpeg, jpeg_output, 1.0, V4L2_PIX_FMT_JPEG, true);
|
||||
|
||||
if (!device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true)) {
|
||||
return -1;
|
||||
}
|
||||
buffer_list_t *h264_output = device_open_buffer_list_output(camera->codec_h264, camera_capture);
|
||||
buffer_list_t *h264_capture = device_open_buffer_list_capture(camera->codec_h264, h264_output, 1.0, V4L2_PIX_FMT_H264, true);
|
||||
|
||||
if (!device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true)) {
|
||||
if (!jpeg_capture || !h264_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
*links++ = (link_t){ src, { jpeg_output, h264_output} };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
*links++ = (link_t){ camera_capture, { jpeg_output, h264_output} };
|
||||
*links++ = (link_t){ jpeg_capture, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ h264_capture, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,38 +11,36 @@
|
||||
|
||||
void write_yuvu(buffer_t *buffer);
|
||||
|
||||
int camera_configure_isp(camera_t *camera, buffer_list_t *src, float high_div, float low_div)
|
||||
int camera_configure_isp(camera_t *camera, buffer_list_t *camera_capture, float high_div, float low_div)
|
||||
{
|
||||
link_t *links = camera->links;
|
||||
|
||||
camera->isp_srgb = device_v4l2_open("ISP", "/dev/video13");
|
||||
camera->isp_yuuv = device_v4l2_open("ISP-YUUV", "/dev/video14");
|
||||
if (camera->isp_yuuv) {
|
||||
camera->isp_yuuv->output_device = camera->isp_srgb;
|
||||
}
|
||||
camera->codec_jpeg = device_v4l2_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_v4l2_open("H264", "/dev/video11");
|
||||
|
||||
if (!device_open_buffer_list_output(camera->isp_srgb, src) ||
|
||||
!device_open_buffer_list_capture(camera->isp_yuuv, camera->isp_srgb->output_list, high_div, V4L2_PIX_FMT_YUYV, true)) {
|
||||
buffer_list_t *isp_output = device_open_buffer_list_output(camera->isp_srgb, camera_capture);
|
||||
buffer_list_t *isp_capture = device_open_buffer_list_capture(camera->isp_yuuv, isp_output, high_div, V4L2_PIX_FMT_YUYV, true);
|
||||
|
||||
*links++ = (link_t){ camera_capture, { isp_output } };
|
||||
|
||||
buffer_list_t *jpeg_output = device_open_buffer_list_output(camera->codec_jpeg, isp_capture);
|
||||
buffer_list_t *jpeg_capture = device_open_buffer_list_capture(camera->codec_jpeg, jpeg_output, 1.0, V4L2_PIX_FMT_JPEG, true);
|
||||
|
||||
buffer_list_t *h264_output = device_open_buffer_list_output(camera->codec_h264, isp_capture);
|
||||
buffer_list_t *h264_capture = device_open_buffer_list_capture(camera->codec_h264, h264_output, 1.0, V4L2_PIX_FMT_H264, true);
|
||||
|
||||
if (!jpeg_capture || !h264_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
camera->isp_yuuv->output_device = camera->isp_srgb;
|
||||
|
||||
link_t *links = camera->links;
|
||||
*links++ = (link_t){ src, { camera->isp_srgb->output_list } };
|
||||
|
||||
src = camera->isp_yuuv->capture_list;
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_jpeg, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_h264, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*links++ = (link_t){ camera->isp_yuuv->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
*links++ = (link_t){ isp_capture, { jpeg_output, h264_output }, { write_yuvu } };
|
||||
*links++ = (link_t){ jpeg_capture, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ h264_capture, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
|
||||
// all done
|
||||
if (low_div < 1) {
|
||||
@ -50,28 +48,26 @@ int camera_configure_isp(camera_t *camera, buffer_list_t *src, float high_div, f
|
||||
}
|
||||
|
||||
camera->isp_yuuv_lowres = device_v4l2_open("ISP-YUUV-LOW", "/dev/video15");
|
||||
if (camera->isp_yuuv_lowres) {
|
||||
camera->isp_yuuv_lowres->output_device = camera->isp_srgb;
|
||||
}
|
||||
camera->codec_jpeg_lowres = device_v4l2_open("JPEG-LOW", "/dev/video31");
|
||||
camera->codec_h264_lowres = device_v4l2_open("H264-LOW", "/dev/video11");
|
||||
|
||||
if (!device_open_buffer_list_capture(camera->isp_yuuv_lowres, camera->camera->capture_list, low_div, V4L2_PIX_FMT_YUYV, true)) {
|
||||
buffer_list_t *isp_lowres_capture = device_open_buffer_list_capture(camera->isp_yuuv_lowres, isp_output, low_div, V4L2_PIX_FMT_YUYV, true);
|
||||
|
||||
buffer_list_t *jpeg_lowres_output = device_open_buffer_list_output(camera->codec_jpeg_lowres, isp_lowres_capture);
|
||||
buffer_list_t *jpeg_lowres_capture = device_open_buffer_list_capture(camera->codec_jpeg_lowres, jpeg_lowres_output, 1.0, V4L2_PIX_FMT_JPEG, true);
|
||||
|
||||
buffer_list_t *h264_lowres_output = device_open_buffer_list_output(camera->codec_h264_lowres, isp_lowres_capture);
|
||||
buffer_list_t *h264_lowres_capture = device_open_buffer_list_capture(camera->codec_h264_lowres, h264_lowres_output, 1.0, V4L2_PIX_FMT_H264, true);
|
||||
|
||||
if (!jpeg_lowres_capture || !h264_lowres_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
camera->isp_yuuv_lowres->output_device = camera->isp_srgb;
|
||||
src = camera->isp_yuuv_lowres->capture_list;
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_jpeg_lowres, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_jpeg_lowres, src, 1.0, V4L2_PIX_FMT_JPEG, true)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_h264_lowres, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_h264_lowres, src, 1.0, V4L2_PIX_FMT_H264, true)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*links++ = (link_t){ camera->isp_yuuv_lowres->capture_list, { camera->codec_jpeg_lowres->output_list, camera->codec_h264_lowres->output_list }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->codec_jpeg_lowres->capture_list, { }, { http_jpeg_lowres_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264_lowres->capture_list, { }, { http_h264_lowres_capture, http_h264_needs_buffer } };
|
||||
*links++ = (link_t){ isp_capture, { jpeg_lowres_output, h264_lowres_output }, { write_yuvu } };
|
||||
*links++ = (link_t){ jpeg_lowres_capture, { }, { http_jpeg_lowres_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ h264_lowres_capture, { }, { http_h264_lowres_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,34 +21,29 @@ void write_yuvu(buffer_t *buffer)
|
||||
#endif
|
||||
}
|
||||
|
||||
int camera_configure_legacy_isp(camera_t *camera, buffer_list_t *src, float div)
|
||||
int camera_configure_legacy_isp(camera_t *camera, buffer_list_t *camera_capture, float div)
|
||||
{
|
||||
camera->legacy_isp = device_v4l2_open("ISP", "/dev/video12");
|
||||
camera->codec_jpeg = device_v4l2_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_v4l2_open("H264", "/dev/video11");
|
||||
|
||||
if (!device_open_buffer_list_output(camera->legacy_isp, src) ||
|
||||
!device_open_buffer_list_capture(camera->legacy_isp, src, div, V4L2_PIX_FMT_YUYV, true)) {
|
||||
return -1;
|
||||
}
|
||||
buffer_list_t *isp_output = device_open_buffer_list_output(camera->legacy_isp, camera_capture);
|
||||
buffer_list_t *isp_capture = device_open_buffer_list_capture(camera->legacy_isp, isp_output, div, V4L2_PIX_FMT_YUYV, true);
|
||||
|
||||
src = camera->legacy_isp->capture_list;
|
||||
buffer_list_t *jpeg_output = device_open_buffer_list_output(camera->codec_jpeg, isp_capture);
|
||||
buffer_list_t *jpeg_capture = device_open_buffer_list_capture(camera->codec_jpeg, jpeg_output, 1.0, V4L2_PIX_FMT_JPEG, true);
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_jpeg, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true)) {
|
||||
return -1;
|
||||
}
|
||||
buffer_list_t *h264_output = device_open_buffer_list_output(camera->codec_h264, isp_capture);
|
||||
buffer_list_t *h264_capture = device_open_buffer_list_capture(camera->codec_h264, h264_output, 1.0, V4L2_PIX_FMT_H264, true);
|
||||
|
||||
if (!device_open_buffer_list_output(camera->codec_h264, src) ||
|
||||
!device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true)) {
|
||||
if (!jpeg_capture || !h264_capture) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->legacy_isp->output_list } };
|
||||
*links++ = (link_t){ camera->legacy_isp->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu, NULL } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
*links++ = (link_t){ camera_capture, { isp_output } };
|
||||
*links++ = (link_t){ isp_capture, { jpeg_output, h264_output }, { write_yuvu, NULL } };
|
||||
*links++ = (link_t){ jpeg_capture, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ h264_capture, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,17 +16,17 @@ int camera_configure_libcamera(camera_t *camera)
|
||||
|
||||
camera->camera->opts.allow_dma = camera->options.allow_dma;
|
||||
|
||||
buffer_list_t *src = 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);
|
||||
if (!src) {
|
||||
buffer_list_t *camera_capture = 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);
|
||||
if (!camera_capture) {
|
||||
goto error;
|
||||
}
|
||||
src->do_timestamps = true;
|
||||
camera_capture->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
src->fmt.interval_us = 1000 * 1000 / camera->options.fps;
|
||||
camera_capture->fmt.interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
if (camera_configure_direct(camera, src) < 0) {
|
||||
if (camera_configure_direct(camera, camera_capture) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -21,17 +21,17 @@ int camera_configure_v4l2(camera_t *camera)
|
||||
camera->camera->opts.allow_dma = false;
|
||||
}
|
||||
|
||||
buffer_list_t *src = device_open_buffer_list(camera->camera, true, camera->options.width, camera->options.height, camera->options.format, 0, camera->options.nbufs, true);
|
||||
if (!src) {
|
||||
buffer_list_t *camera_capture = device_open_buffer_list(camera->camera, true, camera->options.width, camera->options.height, camera->options.format, 0, camera->options.nbufs, true);
|
||||
if (!camera_capture) {
|
||||
goto error;
|
||||
}
|
||||
src->do_timestamps = true;
|
||||
camera_capture->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
src->fmt.interval_us = 1000 * 1000 / camera->options.fps;
|
||||
camera_capture->fmt.interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
switch (src->fmt.format) {
|
||||
switch (camera_capture->fmt.format) {
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
case V4L2_PIX_FMT_YVYU:
|
||||
case V4L2_PIX_FMT_VYUY:
|
||||
@ -39,25 +39,25 @@ int camera_configure_v4l2(camera_t *camera)
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
case V4L2_PIX_FMT_RGB565:
|
||||
case V4L2_PIX_FMT_RGB24:
|
||||
if (camera_configure_direct(camera, src) < 0) {
|
||||
if (camera_configure_direct(camera, camera_capture) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_MJPEG:
|
||||
case V4L2_PIX_FMT_H264:
|
||||
if (camera_configure_decoder(camera, src) < 0) {
|
||||
if (camera_configure_decoder(camera, camera_capture) < 0) {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_SRGGB10P:
|
||||
#if 1
|
||||
if (camera_configure_isp(camera, src, camera->options.high_res_factor, camera->options.low_res_factor) < 0) {
|
||||
if (camera_configure_isp(camera, camera_capture, camera->options.high_res_factor, camera->options.low_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#else
|
||||
if (camera_configure_legacy_isp(camera, src, camera->options.high_res_factor) < 0) {
|
||||
if (camera_configure_legacy_isp(camera, camera_capture, camera->options.high_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
@ -65,7 +65,7 @@ int camera_configure_v4l2(camera_t *camera)
|
||||
|
||||
default:
|
||||
LOG_ERROR(camera, "Unsupported camera format=%s",
|
||||
fourcc_to_string(src->fmt.format).buf);
|
||||
fourcc_to_string(camera_capture->fmt.format).buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,13 @@ void device_close(device_t *dev) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev->capture_list) {
|
||||
buffer_list_close(dev->capture_list);
|
||||
dev->capture_list = NULL;
|
||||
if (dev->capture_lists) {
|
||||
for (int i = 0; i < dev->n_capture_list; i++) {
|
||||
buffer_list_close(dev->capture_lists[i]);
|
||||
dev->capture_lists[i] = NULL;
|
||||
}
|
||||
free(dev->capture_lists);
|
||||
dev->capture_lists = NULL;
|
||||
}
|
||||
|
||||
if (dev->output_list) {
|
||||
@ -47,7 +51,8 @@ buffer_list_t *device_open_buffer_list(device_t *dev, bool do_capture, unsigned
|
||||
{
|
||||
unsigned type;
|
||||
char name[64];
|
||||
struct buffer_list_s **buf_list = NULL;
|
||||
int index = 0;
|
||||
buffer_list_t *buf_list;
|
||||
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
@ -58,16 +63,13 @@ buffer_list_t *device_open_buffer_list(device_t *dev, bool do_capture, unsigned
|
||||
}
|
||||
|
||||
if (do_capture) {
|
||||
buf_list = &dev->capture_list;
|
||||
index = dev->n_capture_list;
|
||||
|
||||
if (dev->capture_list) {
|
||||
LOG_ERROR(dev, "The capture_list is already created.");
|
||||
}
|
||||
|
||||
sprintf(name, "%s:capture", dev->name);
|
||||
if (index > 0)
|
||||
sprintf(name, "%s:capture:%d", dev->name, index);
|
||||
else
|
||||
sprintf(name, "%s:capture", dev->name);
|
||||
} else {
|
||||
buf_list = &dev->output_list;
|
||||
|
||||
if (dev->output_list) {
|
||||
LOG_ERROR(dev, "The output_list is already created.");
|
||||
}
|
||||
@ -83,21 +85,31 @@ buffer_list_t *device_open_buffer_list(device_t *dev, bool do_capture, unsigned
|
||||
.nbufs = nbufs
|
||||
};
|
||||
|
||||
*buf_list = buffer_list_open(name, dev, NULL, fmt, do_capture, do_mmap);
|
||||
if (!*buf_list) {
|
||||
buf_list = buffer_list_open(name, index, dev, NULL, fmt, do_capture, do_mmap);
|
||||
if (!buf_list) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return *buf_list;
|
||||
if (do_capture) {
|
||||
dev->capture_lists = reallocarray(dev->capture_lists, dev->n_capture_list+1, sizeof(buffer_list_t*));
|
||||
dev->capture_lists[dev->n_capture_list++] = buf_list;
|
||||
} else {
|
||||
dev->output_list = buf_list;
|
||||
}
|
||||
|
||||
return buf_list;
|
||||
|
||||
error:
|
||||
buffer_list_close(*buf_list);
|
||||
*buf_list = NULL;
|
||||
buffer_list_close(buf_list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer_list_t *device_open_buffer_list_output(device_t *dev, buffer_list_t *capture_list)
|
||||
{
|
||||
if (!dev || !capture_list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return device_open_buffer_list(dev, false,
|
||||
capture_list->fmt.width, capture_list->fmt.height,
|
||||
capture_list->fmt.format, capture_list->fmt.bytesperline,
|
||||
@ -107,10 +119,7 @@ buffer_list_t *device_open_buffer_list_output(device_t *dev, buffer_list_t *capt
|
||||
|
||||
buffer_list_t *device_open_buffer_list_capture(device_t *dev, buffer_list_t *output_list, float div, unsigned format, bool do_mmap)
|
||||
{
|
||||
if (!output_list) {
|
||||
output_list = dev->output_list;
|
||||
}
|
||||
if (!output_list) {
|
||||
if (!dev || !output_list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -130,8 +139,8 @@ int device_set_stream(device_t *dev, bool do_on)
|
||||
ioctl_retried(dev_name(dev), dev->v4l2->dev_fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub);
|
||||
#endif
|
||||
|
||||
if (dev->capture_list) {
|
||||
if (buffer_list_set_stream(dev->capture_list, do_on) < 0) {
|
||||
for (int i = 0; i < dev->n_capture_list; i++) {
|
||||
if (buffer_list_set_stream(dev->capture_lists[i], do_on) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ typedef struct device_s {
|
||||
char bus_info[64];
|
||||
|
||||
device_hw_t *hw;
|
||||
buffer_list_t *capture_list;
|
||||
int n_capture_list;
|
||||
buffer_list_t **capture_lists;
|
||||
buffer_list_t *output_list;
|
||||
|
||||
struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user