Improve recycling

This commit is contained in:
Kamil Trzcinski 2022-04-06 08:44:15 +02:00
parent 25af6875f4
commit 4d999d9426
3 changed files with 17 additions and 3 deletions

View File

@ -23,6 +23,12 @@ void camera_close(camera_t *camera)
}
}
for (int i = MAX_DEVICES; i-- > 0; ) {
if (camera->links[i].callbacks.on_buffer) {
camera->links[i].callbacks.on_buffer = NULL;
}
}
memset(camera->links, 0, sizeof(camera->links));
free(camera);
}

View File

@ -10,7 +10,7 @@ device_t *device_open(const char *name, const char *path) {
dev->subdev_fd = -1;
dev->allow_dma = true;
if(dev->fd < 0) {
E_LOG_ERROR(dev, "Can't open device");
E_LOG_ERROR(dev, "Can't open device: %s", path);
}
E_LOG_DEBUG(dev, "Querying device capabilities ...");
@ -53,6 +53,8 @@ void device_close(device_t *dev) {
close(dev->fd);
}
free(dev->name);
free(dev->path);
free(dev);
}
@ -141,8 +143,14 @@ int device_open_buffer_list_capture(device_t *dev, buffer_list_t *output_list, f
format, 0, output_list->nbufs, do_mmap);
}
int device_stream(device_t *dev, bool do_on)
int device_set_stream(device_t *dev, bool do_on)
{
struct v4l2_event_subscription sub = {0};
sub.type = V4L2_EVENT_SOURCE_CHANGE;
E_LOG_DEBUG(dev, "Subscribing to DV-timings events ...");
xioctl(dev_name(dev), dev->fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub);
if (dev->capture_list) {
if (buffer_list_stream(dev->capture_list, do_on) < 0) {
return -1;

View File

@ -27,7 +27,7 @@ int device_open_buffer_list_output(device_t *dev, struct buffer_list_s *capture_
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_stream(device_t *dev, bool do_on);
int device_set_stream(device_t *dev, bool do_on);
int device_video_force_key(device_t *dev);
int device_set_pad_format(device_t *device, unsigned width, unsigned height, unsigned format);
int device_set_option(device_t *dev, const char *name, uint32_t id, int32_t value);