From 972cb1c49b47a4c8775e24024c5b825a0990ee65 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 21 Jun 2012 13:23:10 +0200 Subject: videout: Add support for disabling chroma keying And make vo_enable_colorkey() return 0 on success and a negative error code otherwise. Signed-off-by: Laurent Pinchart --- videoout.c | 49 +++++++++++++++++++++++++++++++++++++------------ videoout.h | 3 +++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/videoout.c b/videoout.c index df580c0..f3d3a22 100644 --- a/videoout.c +++ b/videoout.c @@ -136,37 +136,62 @@ int vo_enable_colorkey(struct videoout *vo, unsigned int val) struct v4l2_format fmt; int ret; + ret = ioctl(vo->dev->fd, VIDIOC_G_FBUF, &framebuffer); + if (ret < 0) { + perror("VIDIOC_G_FBUF"); + return -errno; + } + + if (!(framebuffer.capability & V4L2_FBUF_CAP_CHROMAKEY)) + return -ENOTSUP; + fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; ret = ioctl(vo->dev->fd, VIDIOC_G_FMT, &fmt); if (ret < 0) { perror("VIDIOC_G_FMT\n"); - return 0; + return -errno; } fmt.fmt.win.chromakey = val; ret = ioctl(vo->dev->fd, VIDIOC_S_FMT, &fmt); if (ret < 0) { perror("VIDIOC_G_FMT\n"); - return 0; + return -errno; + } + + framebuffer.flags |= V4L2_FBUF_FLAG_CHROMAKEY; + framebuffer.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA; + ret = ioctl(vo->dev->fd, VIDIOC_S_FBUF, &framebuffer); + if (ret < 0) { + perror("VIDIOC_S_FBUF"); + return -errno; } + return 0; +} + +int vo_disable_colorkey(struct videoout *vo) +{ + struct v4l2_framebuffer framebuffer; + int ret; + ret = ioctl(vo->dev->fd, VIDIOC_G_FBUF, &framebuffer); if (ret < 0) { perror("VIDIOC_G_FBUF"); - return 0; + return -errno; } - if (framebuffer.capability & V4L2_FBUF_CAP_CHROMAKEY) { - framebuffer.flags |= V4L2_FBUF_FLAG_CHROMAKEY; - framebuffer.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA; - ret = ioctl(vo->dev->fd, VIDIOC_S_FBUF, &framebuffer); - if (ret < 0) { - perror("VIDIOC_S_FBUF"); - return 0; - } + if (!(framebuffer.capability & V4L2_FBUF_CAP_CHROMAKEY)) + return 0; + + framebuffer.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY; + ret = ioctl(vo->dev->fd, VIDIOC_S_FBUF, &framebuffer); + if (ret < 0) { + perror("VIDIOC_S_FBUF"); + return -errno; } - return 1; + return 0; } struct v4l2_buffers_pool *vo_get_pool(struct videoout *vo) diff --git a/videoout.h b/videoout.h index cf20025..0f4cc4c 100644 --- a/videoout.h +++ b/videoout.h @@ -39,7 +39,10 @@ struct videoout *vo_init(const char *devname, unsigned int buffers, struct v4l2_pix_format *format); void vo_cleanup(struct videoout *vo); + int vo_enable_colorkey(struct videoout *vo, unsigned int val); +int vo_disable_colorkey(struct videoout *vo); + struct v4l2_buffers_pool *vo_get_pool(struct videoout *vo); int vo_dequeue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer); int vo_queue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer); -- cgit v1.2.3