1 /* G-Streamer generic V4L2 element - generic V4L2 overlay handling
2 * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
27 #include <sys/ioctl.h>
31 #include "v4l2_calls.h"
33 #define DEBUG(format, args...) \
34 GST_DEBUG_ELEMENT(GST_CAT_PLUGIN_INFO, \
35 GST_ELEMENT(v4l2element), \
36 "V4L2-overlay: " format, ##args)
39 /******************************************************
40 * gst_v4l2_set_display():
42 * return value: TRUE on success, FALSE on error
43 ******************************************************/
46 gst_v4l2_set_display (GstV4l2Element *v4l2element,
51 DEBUG("trying to set overlay to '%s'", display);
54 buff = g_strdup_printf("v4l-conf -q -c %s -d %s",
55 v4l2element->device?v4l2element->device:"/dev/video", display);
57 switch (system(buff)) {
59 gst_element_error(GST_ELEMENT(v4l2element),
60 "Could not start v4l-conf: %s", g_strerror(errno));
66 gst_element_error(GST_ELEMENT(v4l2element),
67 "v4l-conf failed to run correctly: %s", g_strerror(errno));
77 /******************************************************
78 * gst_v4l2_set_window():
79 * sets the window where to display the video overlay
80 * return value: TRUE on success, FALSE on error
81 ******************************************************/
84 gst_v4l2_set_window (GstElement *element,
89 struct v4l2_clip *clips,
92 struct v4l2_format fmt;
93 GstV4l2Element *v4l2element = GST_V4L2ELEMENT(element);
95 DEBUG("trying to set video window to %dx%d,%d,%d", x,y,w,h);
96 GST_V4L2_CHECK_OVERLAY(v4l2element);
97 GST_V4L2_CHECK_OPEN(v4l2element);
99 fmt.type = V4L2_CAP_VIDEO_OVERLAY;
100 fmt.fmt.win.clipcount = 0;
101 fmt.fmt.win.w.left = x;
102 fmt.fmt.win.w.top = y;
103 fmt.fmt.win.w.width = w;
104 fmt.fmt.win.w.height = h;
105 fmt.fmt.win.clips = clips;
106 fmt.fmt.win.clipcount = num_clips;
107 fmt.fmt.win.bitmap = NULL;
109 if (ioctl(v4l2element->video_fd, VIDIOC_S_FMT, &fmt) < 0) {
110 gst_element_error(GST_ELEMENT(v4l2element),
111 "Failed to set the video window on device %s: %s",
112 v4l2element->device, g_strerror(errno));
120 /******************************************************
121 * gst_v4l_set_overlay():
122 * enables/disables actual video overlay display
123 * return value: TRUE on success, FALSE on error
124 ******************************************************/
127 gst_v4l2_enable_overlay (GstV4l2Element *v4l2element,
130 gint doit = enable?1:0;
132 DEBUG("trying to %s overlay display", enable?"enable":"disable");
133 GST_V4L2_CHECK_OPEN(v4l2element);
134 GST_V4L2_CHECK_OVERLAY(v4l2element);
136 if (ioctl(v4l2element->video_fd, VIDIOC_OVERLAY, &doit) < 0) {
137 gst_element_error(GST_ELEMENT(v4l2element),
138 "Failed to %s overlay display for device %s: %s",
139 enable?"enable":"disable", v4l2element->device, g_strerror(errno));