diff options
-rw-r--r-- | live.c | 4 | ||||
-rw-r--r-- | videoout.c | 49 | ||||
-rw-r--r-- | videoout.h | 1 |
3 files changed, 33 insertions, 21 deletions
@@ -535,9 +535,11 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu exit_code = EXIT_SUCCESS; cleanup: - /* Cleanup the ISP resources. */ + /* Cleanup the ISP and video output resources. */ if (isp) omap3_isp_close(isp); + if (vo) + vo_cleanup(vo); return exit_code; } @@ -55,15 +55,23 @@ struct videoout *vo_init(const char *devname, const struct video_out_operations *ops, unsigned int width, unsigned int height) { - struct v4l2_buffers_pool *pool = NULL; - struct v4l2_device *dev = NULL; struct v4l2_pix_format pixfmt; struct v4l2_format fmt; struct v4l2_rect crop; + struct videoout *vo; int ret; - dev = v4l2_open(devname); - if (dev == NULL) { + /* Allocate the video output object. */ + vo = malloc(sizeof *vo); + if (vo == NULL) + return NULL; + + memset(vo, 0, sizeof *vo); + vo->ops = ops; + + /* Open and configure the V4L2 device. */ + vo->dev = v4l2_open(devname); + if (vo->dev == NULL) { perror("Failed to open display device\n"); goto error; } @@ -73,7 +81,7 @@ struct videoout *vo_init(const char *devname, crop.width = width; crop.height = height; - ret = v4l2_set_crop(dev, &crop); + ret = v4l2_set_crop(vo->dev, &crop); if (ret < 0) { perror("VIDIOC_S_CROP\n"); goto error; @@ -84,7 +92,7 @@ struct videoout *vo_init(const char *devname, pixfmt.height = height; pixfmt.field = V4L2_FIELD_ANY; - ret = v4l2_set_format(dev, &pixfmt); + ret = v4l2_set_format(vo->dev, &pixfmt); if (ret < 0) { perror("VIDIOC_S_FMT(output)\n"); goto error; @@ -95,40 +103,41 @@ struct videoout *vo_init(const char *devname, fmt.fmt.win.w.top = 0; fmt.fmt.win.w.width = width; fmt.fmt.win.w.height = height; - ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt); + ret = ioctl(vo->dev->fd, VIDIOC_S_FMT, &fmt); if (ret < 0) { perror("VIDIOC_S_FMT(overlay)\n"); goto error; } - pool = v4l2_buffers_pool_new(NUM_BUFFERS); - if (pool == NULL) { + /* Allocate buffers. */ + vo->pool = v4l2_buffers_pool_new(NUM_BUFFERS); + if (vo->pool == NULL) { printf("error: unable to allocate buffers pool for display.\n"); goto error; } - ret = v4l2_alloc_buffers(dev, pool, V4L2_MEMORY_MMAP); + ret = v4l2_alloc_buffers(vo->dev, vo->pool, V4L2_MEMORY_MMAP); if (ret < 0) { printf("error: unable to allocate buffers pool for display.\n"); goto error; } - struct videoout *vo = malloc(sizeof *vo); - memset(vo, 0, sizeof *vo); - vo->dev = dev; - vo->pool = pool; - vo->ops = ops; - return vo; error: - if (dev) - v4l2_close(dev); - if (pool) - v4l2_buffers_pool_delete(pool); + vo_cleanup(vo); return NULL; } +void vo_cleanup(struct videoout *vo) +{ + if (vo->dev) + v4l2_close(vo->dev); + if (vo->pool) + v4l2_buffers_pool_delete(vo->pool); + free(vo); +} + int vo_enable_colorkey(struct videoout *vo, unsigned int val) { struct v4l2_framebuffer framebuffer; @@ -35,6 +35,7 @@ struct video_out_operations { struct videoout *vo_init(const char *devname, const struct video_out_operations *ops, unsigned int width, unsigned int height); +void vo_cleanup(struct videoout *vo); int vo_enable_colorkey(struct videoout *vo, unsigned int val); struct v4l2_buffers_pool *vo_get_pool(struct videoout *vo); int vo_dequeue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer); |