feat(video): slightly faster video acquisition with O_NONBLOCK
This commit is contained in:
@@ -137,4 +137,3 @@ make -f Makefile.dev release-arch
|
|||||||
- [ ] Fixes
|
- [ ] Fixes
|
||||||
- [ ] Try to write NanoKontrol config
|
- [ ] Try to write NanoKontrol config
|
||||||
- [ ] Investigate video device fps loss (bad unregister ?)
|
- [ ] Investigate video device fps loss (bad unregister ?)
|
||||||
- explore libv4l directly [github](https://github.com/philips/libv4l) (with `-lv4l2`)
|
|
||||||
+8
-10
@@ -57,7 +57,7 @@ static void compute_fps(bool trace_fps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_context(const Parameters *params, unsigned int in_count) {
|
static void init_context(const Parameters *params) {
|
||||||
state_init(context, &project.state_config, params->demo, params->auto_random,
|
state_init(context, &project.state_config, params->demo, params->auto_random,
|
||||||
params->auto_random_cycle, params->base_tempo, params->load_state);
|
params->auto_random_cycle, params->base_tempo, params->load_state);
|
||||||
|
|
||||||
@@ -66,14 +66,6 @@ static void init_context(const Parameters *params, unsigned int in_count) {
|
|||||||
memset(context->input_resolutions, 0, sizeof(context->input_resolutions));
|
memset(context->input_resolutions, 0, sizeof(context->input_resolutions));
|
||||||
memset(context->input_formats, 0, sizeof(context->input_formats));
|
memset(context->input_formats, 0, sizeof(context->input_formats));
|
||||||
memset(context->input_fps, 0, sizeof(context->input_fps));
|
memset(context->input_fps, 0, sizeof(context->input_fps));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < in_count; i++) {
|
|
||||||
if (!inputs.values[i].error) {
|
|
||||||
context->input_resolutions[i][0] = inputs.values[i].width;
|
|
||||||
context->input_resolutions[i][1] = inputs.values[i].height;
|
|
||||||
context->input_formats[i] = inputs.values[i].pixelformat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_context() { shared_close_context(context); }
|
static void free_context() { shared_close_context(context); }
|
||||||
@@ -88,6 +80,12 @@ static void init_inputs(const StringArray *video_in, unsigned int video_size) {
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < video_in->length; i++) {
|
for (unsigned int i = 0; i < video_in->length; i++) {
|
||||||
video_init(&inputs.values[i], video_in->values[i], video_size);
|
video_init(&inputs.values[i], video_in->values[i], video_size);
|
||||||
|
|
||||||
|
if (!inputs.values[i].error) {
|
||||||
|
context->input_resolutions[i][0] = inputs.values[i].width;
|
||||||
|
context->input_resolutions[i][1] = inputs.values[i].height;
|
||||||
|
context->input_formats[i] = inputs.values[i].pixelformat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +176,7 @@ void forge_run(const Parameters *params) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_context(params, project.in_count);
|
init_context(params);
|
||||||
|
|
||||||
#ifdef VIDEO_IN
|
#ifdef VIDEO_IN
|
||||||
init_inputs(¶ms->video_in, params->video_size);
|
init_inputs(¶ms->video_in, params->video_size);
|
||||||
|
|||||||
+10
-17
@@ -74,7 +74,7 @@ static void open_device(VideoCapture *video_capture, const char *name) {
|
|||||||
video_capture->fd = -1;
|
video_capture->fd = -1;
|
||||||
video_capture->exp_fd = -1;
|
video_capture->exp_fd = -1;
|
||||||
|
|
||||||
video_capture->fd = open(name, O_RDWR);
|
video_capture->fd = open(name, O_RDWR | O_NONBLOCK);
|
||||||
if (video_capture->fd == -1) {
|
if (video_capture->fd == -1) {
|
||||||
log_warn("(%s) Cannot open device", name);
|
log_warn("(%s) Cannot open device", name);
|
||||||
video_capture->error = true;
|
video_capture->error = true;
|
||||||
@@ -265,6 +265,8 @@ static void create_image_buffer(VideoCapture *video_capture) {
|
|||||||
video_capture->buf.memory = V4L2_MEMORY_MMAP;
|
video_capture->buf.memory = V4L2_MEMORY_MMAP;
|
||||||
video_capture->buf.index = 0;
|
video_capture->buf.index = 0;
|
||||||
|
|
||||||
|
ioctl(video_capture->fd, VIDIOC_PREPARE_BUF);
|
||||||
|
|
||||||
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,21 +275,13 @@ static void close_stream(const VideoCapture *video_capture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool read_video(VideoCapture *video_capture) {
|
static bool read_video(VideoCapture *video_capture) {
|
||||||
if (ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) == -1) {
|
bool result;
|
||||||
ioctl_error(video_capture, "VIDIOC_DQBUF",
|
|
||||||
"buffer type not supported or no buffer allocated or the index "
|
|
||||||
"is out of bounds");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf) == -1) {
|
result = ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) != -1;
|
||||||
ioctl_error(video_capture, "VIDIOC_QBUF",
|
|
||||||
"buffer type not supported or no buffer allocated or the index "
|
|
||||||
"is out of bounds");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_init(VideoCapture *video_capture, const char *name,
|
void video_init(VideoCapture *video_capture, const char *name,
|
||||||
@@ -343,9 +337,8 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
|||||||
pid);
|
pid);
|
||||||
timer_init(&timer, 30);
|
timer_init(&timer, 30);
|
||||||
|
|
||||||
while (!context->stop && read_video(video_capture)) {
|
while (!context->stop) {
|
||||||
// repeat infinitely
|
if (read_video(video_capture) && timer_inc(&timer)) {
|
||||||
if (timer_inc(&timer)) {
|
|
||||||
fps = timer_reset(&timer);
|
fps = timer_reset(&timer);
|
||||||
|
|
||||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||||
|
|||||||
Reference in New Issue
Block a user