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.")),
70 GST_ELEMENT_ERROR (v4l2element, RESOURCE, FAILED,
71 (_("Executing v4l-conf failed.")),
82 /******************************************************
83 * gst_v4l2_set_window():
84 * sets the window where to display the video overlay
85 * return value: TRUE on success, FALSE on error
86 ******************************************************/
89 gst_v4l2_set_window (GstElement *element,
94 struct v4l2_clip *clips,
97 struct v4l2_format fmt;
98 GstV4l2Element *v4l2element = GST_V4L2ELEMENT(element);
100 DEBUG("trying to set video window to %dx%d,%d,%d", x,y,w,h);
101 GST_V4L2_CHECK_OVERLAY(v4l2element);
102 GST_V4L2_CHECK_OPEN(v4l2element);
104 fmt.type = V4L2_CAP_VIDEO_OVERLAY;
105 fmt.fmt.win.clipcount = 0;
106 fmt.fmt.win.w.left = x;
107 fmt.fmt.win.w.top = y;
108 fmt.fmt.win.w.width = w;
109 fmt.fmt.win.w.height = h;
110 fmt.fmt.win.clips = clips;
111 fmt.fmt.win.clipcount = num_clips;
112 fmt.fmt.win.bitmap = NULL;
114 if (ioctl(v4l2element->video_fd, VIDIOC_S_FMT, &fmt) < 0) {
115 GST_ELEMENT_ERROR (v4l2element, RESOURCE, TOO_LAZY, (NULL),
116 ("Failed to set the video window: %s", g_strerror (errno)));
124 /******************************************************
125 * gst_v4l_set_overlay():
126 * enables/disables actual video overlay display
127 * return value: TRUE on success, FALSE on error
128 ******************************************************/
131 gst_v4l2_enable_overlay (GstV4l2Element *v4l2element,
134 gint doit = enable?1:0;
136 DEBUG("trying to %s overlay display", enable?"enable":"disable");
137 GST_V4L2_CHECK_OPEN(v4l2element);
138 GST_V4L2_CHECK_OVERLAY(v4l2element);
140 if (ioctl(v4l2element->video_fd, VIDIOC_OVERLAY, &doit) < 0) {
141 GST_ELEMENT_ERROR (v4l2element, RESOURCE, TOO_LAZY, (NULL),
142 ("Failed to %s overlay display: %s",
143 enable?"enable":"disable", g_strerror (errno)));