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...) \
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)
50 if (v4l2element->display)
51 g_free (v4l2element->display);
52 v4l2element->display = g_strdup (g_getenv ("DISPLAY"));
54 DEBUG ("trying to set overlay to '%s'", v4l2element->display);
57 buff = g_strdup_printf ("v4l-conf -q -c %s -d %s",
58 v4l2element->device, v4l2element->display);
60 switch (system (buff)) {
62 GST_ELEMENT_ERROR (v4l2element, RESOURCE, FAILED,
63 (_("Could not start v4l-conf.")), GST_ERROR_SYSTEM);
69 GST_ELEMENT_ERROR (v4l2element, RESOURCE, FAILED,
70 (_("Executing v4l-conf failed.")), GST_ERROR_SYSTEM);
80 /******************************************************
81 * gst_v4l2_set_window():
82 * sets the window where to display the video overlay
83 * return value: TRUE on success, FALSE on error
84 ******************************************************/
87 gst_v4l2_set_window (GstElement * element,
88 gint x, gint y, gint w, gint h, struct v4l2_clip * clips, gint num_clips)
90 struct v4l2_format fmt;
91 GstV4l2Element *v4l2element = GST_V4L2ELEMENT (element);
93 DEBUG ("trying to set video window to %dx%d,%d,%d", x, y, w, h);
94 GST_V4L2_CHECK_OVERLAY (v4l2element);
95 GST_V4L2_CHECK_OPEN (v4l2element);
97 fmt.type = V4L2_CAP_VIDEO_OVERLAY;
98 fmt.fmt.win.clipcount = 0;
99 fmt.fmt.win.w.left = x;
100 fmt.fmt.win.w.top = y;
101 fmt.fmt.win.w.width = w;
102 fmt.fmt.win.w.height = h;
103 fmt.fmt.win.clips = clips;
104 fmt.fmt.win.clipcount = num_clips;
105 fmt.fmt.win.bitmap = NULL;
107 if (ioctl (v4l2element->video_fd, VIDIOC_S_FMT, &fmt) < 0) {
108 GST_ELEMENT_ERROR (v4l2element, RESOURCE, TOO_LAZY, (NULL),
109 ("Failed to set the video window: %s", g_strerror (errno)));
117 /******************************************************
118 * gst_v4l_set_overlay():
119 * enables/disables actual video overlay display
120 * return value: TRUE on success, FALSE on error
121 ******************************************************/
124 gst_v4l2_enable_overlay (GstV4l2Element * v4l2element, gboolean enable)
126 gint doit = enable ? 1 : 0;
128 DEBUG ("trying to %s overlay display", enable ? "enable" : "disable");
129 GST_V4L2_CHECK_OPEN (v4l2element);
130 GST_V4L2_CHECK_OVERLAY (v4l2element);
132 if (ioctl (v4l2element->video_fd, VIDIOC_OVERLAY, &doit) < 0) {
133 GST_ELEMENT_ERROR (v4l2element, RESOURCE, TOO_LAZY, (NULL),
134 ("Failed to %s overlay display: %s",
135 enable ? "enable" : "disable", g_strerror (errno)));