2002-02-23 14:11:43 +00:00
|
|
|
/* G-Streamer generic V4L element - generic V4L overlay handling
|
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-03-09 15:07:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-08-11 11:45:07 +00:00
|
|
|
#include <stdlib.h>
|
2002-02-23 14:11:43 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "v4l_calls.h"
|
|
|
|
|
2002-09-17 17:45:19 +00:00
|
|
|
#define DEBUG(format, args...) \
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG_OBJECT (\
|
2002-09-17 17:45:19 +00:00
|
|
|
GST_ELEMENT(v4lelement), \
|
|
|
|
"V4L-overlay: " format, ##args)
|
|
|
|
|
2002-02-23 14:11:43 +00:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_overlay():
|
|
|
|
* calls v4l-conf
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4l_set_overlay (GstV4lElement * v4lelement)
|
2002-02-23 14:11:43 +00:00
|
|
|
{
|
|
|
|
gchar *buff;
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
if (v4lelement->display)
|
2004-03-14 22:34:34 +00:00
|
|
|
g_free (v4lelement->display);
|
|
|
|
v4lelement->display = g_strdup (g_getenv ("DISPLAY"));
|
2003-10-10 12:47:41 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
DEBUG ("setting display to '%s'", v4lelement->display);
|
|
|
|
GST_V4L_CHECK_NOT_OPEN (v4lelement);
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
if (!v4lelement->display || v4lelement->display[0] != ':')
|
|
|
|
return FALSE;
|
|
|
|
|
2002-02-23 14:11:43 +00:00
|
|
|
/* start v4l-conf */
|
2004-05-03 16:30:43 +00:00
|
|
|
buff = g_strdup_printf ("v4l-conf -q -c %s -d %s 2> /dev/null",
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lelement->videodev, v4lelement->display);
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
switch (system (buff)) {
|
2002-02-23 14:11:43 +00:00
|
|
|
case -1:
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lelement, RESOURCE, FAILED,
|
2004-03-15 19:32:28 +00:00
|
|
|
(_("Could not start v4l-conf.")), GST_ERROR_SYSTEM);
|
2004-03-14 22:34:34 +00:00
|
|
|
g_free (buff);
|
2002-02-23 14:11:43 +00:00
|
|
|
return FALSE;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lelement, RESOURCE, FAILED,
|
2004-03-15 19:32:28 +00:00
|
|
|
(_("Executing v4l-conf failed.")), GST_ERROR_SYSTEM);
|
2004-03-14 22:34:34 +00:00
|
|
|
g_free (buff);
|
2002-02-23 14:11:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_free (buff);
|
2002-02-23 14:11:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_window():
|
|
|
|
* sets the window where to display the video overlay
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4l_set_window (GstElement * element,
|
|
|
|
gint x, gint y, gint w, gint h, struct video_clip * clips, gint num_clips)
|
2002-02-23 14:11:43 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
GstV4lElement *v4lelement = GST_V4LELEMENT (element);
|
2002-09-28 11:05:39 +00:00
|
|
|
struct video_window vwin;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
DEBUG ("setting video window to position (x,y/wxh) = %d,%d/%dx%d",
|
|
|
|
x, y, w, h);
|
|
|
|
GST_V4L_CHECK_OPEN (v4lelement);
|
|
|
|
GST_V4L_CHECK_OVERLAY (v4lelement);
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2002-09-28 11:05:39 +00:00
|
|
|
vwin.x = x;
|
|
|
|
vwin.y = y;
|
|
|
|
vwin.width = w;
|
|
|
|
vwin.height = h;
|
|
|
|
vwin.flags = 0;
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (clips && !(v4lelement->vcap.type & VID_TYPE_CLIPPING)) {
|
|
|
|
DEBUG ("Device \'%s\' doesn't do clipping",
|
2004-03-15 19:32:28 +00:00
|
|
|
v4lelement->videodev ? v4lelement->videodev : "/dev/video");
|
2002-09-28 11:05:39 +00:00
|
|
|
vwin.clips = 0;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2002-09-28 11:05:39 +00:00
|
|
|
vwin.clips = clips;
|
|
|
|
vwin.clipcount = num_clips;
|
|
|
|
}
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (v4lelement->video_fd, VIDIOCSWIN, &vwin) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lelement, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Failed to set the video window: %s", g_strerror (errno)));
|
2002-02-23 14:11:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-09-28 11:05:39 +00:00
|
|
|
return TRUE;
|
2002-02-23 14:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
2004-03-06 14:56:00 +00:00
|
|
|
* gst_v4l_enable_overlay():
|
2002-02-23 14:11:43 +00:00
|
|
|
* enables/disables actual video overlay display
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4l_enable_overlay (GstV4lElement * v4lelement, gboolean enable)
|
2002-02-23 14:11:43 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
gint doit = enable ? 1 : 0;
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
DEBUG ("%s overlay", enable ? "enabling" : "disabling");
|
|
|
|
GST_V4L_CHECK_OPEN (v4lelement);
|
|
|
|
GST_V4L_CHECK_OVERLAY (v4lelement);
|
2002-02-23 14:11:43 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (v4lelement->video_fd, VIDIOCCAPTURE, &doit) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lelement, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Failed to %s overlay display: %s",
|
|
|
|
enable ? "enable" : "disable", g_strerror (errno)));
|
2002-02-23 14:11:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|