summaryrefslogtreecommitdiff
path: root/videoout.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-10-05 15:57:15 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-10-05 16:26:01 +0200
commitacd2b7a13e607a46a2185125b7b3fbac81324985 (patch)
tree0d41d1e2efaffc8cc00adf064faacbeb91f41369 /videoout.c
parent1f78a50ce5667c540d53dfe274ec068141c132fd (diff)
videoout: Add vo_cleanup() function to close the video output device
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'videoout.c')
-rw-r--r--videoout.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/videoout.c b/videoout.c
index 6f68b30..f6fbbe7 100644
--- a/videoout.c
+++ b/videoout.c
@@ -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;