2001-12-23 15:31:15 +00:00
|
|
|
/* G-Streamer generic V4L element - generic V4L calls handling
|
2002-01-31 22:22:42 +00:00
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2001-12-23 15:31:15 +00:00
|
|
|
*
|
|
|
|
* 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
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-03-09 15:07:53 +00:00
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-02 21:58:52 +00:00
|
|
|
#include <string.h>
|
2001-12-23 15:31:15 +00:00
|
|
|
#include "v4l_calls.h"
|
2003-03-02 21:58:52 +00:00
|
|
|
#include "gstv4lelement-marshal.h"
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstElementDetails gst_v4lelement_details = {
|
|
|
|
"Generic video4linux Element",
|
|
|
|
"None/Video",
|
2002-09-18 19:02:52 +00:00
|
|
|
"LGPL",
|
2001-12-23 15:31:15 +00:00
|
|
|
"Generic plugin for handling common video4linux calls",
|
|
|
|
VERSION,
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
|
|
|
|
"(C) 2001",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* V4lElement signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
2002-11-13 12:35:55 +00:00
|
|
|
SIGNAL_OPEN,
|
|
|
|
SIGNAL_CLOSE,
|
2003-03-02 21:58:52 +00:00
|
|
|
SIGNAL_SET_VIDEOWINDOW,
|
|
|
|
SIGNAL_GET_ATTRIBUTE,
|
|
|
|
SIGNAL_SET_ATTRIBUTE,
|
2001-12-23 15:31:15 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_CHANNEL,
|
2002-02-20 07:25:40 +00:00
|
|
|
ARG_CHANNEL_NAMES,
|
2001-12-23 15:31:15 +00:00
|
|
|
ARG_NORM,
|
2002-02-20 07:25:40 +00:00
|
|
|
ARG_NORM_NAMES,
|
2001-12-23 15:31:15 +00:00
|
|
|
ARG_HAS_TUNER,
|
|
|
|
ARG_FREQUENCY,
|
|
|
|
ARG_HAS_AUDIO,
|
2003-03-02 21:58:52 +00:00
|
|
|
ARG_ATTRIBUTES,
|
2001-12-28 19:54:23 +00:00
|
|
|
ARG_DEVICE,
|
|
|
|
ARG_DEVICE_NAME,
|
|
|
|
ARG_DEVICE_IS_CAPTURE,
|
|
|
|
ARG_DEVICE_IS_OVERLAY,
|
|
|
|
ARG_DEVICE_IS_MJPEG_CAPTURE,
|
|
|
|
ARG_DEVICE_IS_MJPEG_PLAYBACK,
|
|
|
|
ARG_DEVICE_IS_MPEG_CAPTURE,
|
2002-02-23 14:05:33 +00:00
|
|
|
ARG_DEVICE_IS_MPEG_PLAYBACK,
|
|
|
|
ARG_DISPLAY,
|
|
|
|
ARG_DO_OVERLAY,
|
2002-12-20 20:12:28 +00:00
|
|
|
ARG_SIGNAL,
|
2001-12-23 15:31:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_v4lelement_class_init (GstV4lElementClass *klass);
|
|
|
|
static void gst_v4lelement_init (GstV4lElement *v4lelement);
|
|
|
|
static void gst_v4lelement_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_v4lelement_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static GstElementStateReturn gst_v4lelement_change_state (GstElement *element);
|
|
|
|
static gboolean plugin_init (GModule *module,
|
|
|
|
GstPlugin *plugin);
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-11-13 12:35:55 +00:00
|
|
|
static guint gst_v4lelement_signals[LAST_SIGNAL] = { 0 };
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_v4lelement_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4lelement_type = 0;
|
|
|
|
|
|
|
|
if (!v4lelement_type) {
|
|
|
|
static const GTypeInfo v4lelement_info = {
|
|
|
|
sizeof(GstV4lElementClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_v4lelement_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstV4lElement),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_v4lelement_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
v4lelement_type = g_type_register_static(GST_TYPE_ELEMENT, "GstV4lElement", &v4lelement_info, 0);
|
|
|
|
}
|
|
|
|
return v4lelement_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-02 21:58:52 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l_get_attribute (GstElement *element,
|
|
|
|
const gchar *name,
|
|
|
|
int *value)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
GstV4lElement *v4lelement;
|
|
|
|
|
|
|
|
g_return_val_if_fail(element != NULL && name != NULL && value != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(GST_IS_V4LELEMENT(element), FALSE);
|
|
|
|
|
|
|
|
v4lelement = GST_V4LELEMENT(element);
|
|
|
|
|
|
|
|
for (n=0;picture_name[n]!=NULL;n++)
|
|
|
|
{
|
|
|
|
if (!strcmp(picture_name[n], name))
|
|
|
|
return gst_v4l_get_picture(v4lelement, n, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n=0;audio_name[n]!=NULL;n++)
|
|
|
|
{
|
|
|
|
if (!strcmp(audio_name[n], name))
|
|
|
|
return gst_v4l_get_audio(v4lelement, n, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_error(element, "Unknown attribute %s", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l_set_attribute (GstElement *element,
|
|
|
|
const gchar *name,
|
|
|
|
const int value)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
GstV4lElement *v4lelement;
|
|
|
|
|
|
|
|
g_return_val_if_fail(element != NULL && name != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(GST_IS_V4LELEMENT(element), FALSE);
|
|
|
|
|
|
|
|
v4lelement = GST_V4LELEMENT(element);
|
|
|
|
|
|
|
|
for (n=0;picture_name[n]!=NULL;n++)
|
|
|
|
{
|
|
|
|
if (!strcmp(picture_name[n], name))
|
|
|
|
return gst_v4l_set_picture(v4lelement, n, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n=0;audio_name[n]!=NULL;n++)
|
|
|
|
{
|
|
|
|
if (!strcmp(audio_name[n], name))
|
|
|
|
return gst_v4l_set_audio(v4lelement, n, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_error(element, "Unknown attribute %s", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4lelement_class_init (GstV4lElementClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CHANNEL,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("channel","channel","channel",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
|
2002-02-20 07:25:40 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CHANNEL_NAMES,
|
|
|
|
g_param_spec_pointer("channel_names","channel_names","channel_names",
|
|
|
|
G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NORM,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("norm","norm","norm",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
|
2002-02-20 07:25:40 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NORM_NAMES,
|
|
|
|
g_param_spec_pointer("norm_names","norm_names","norm_names",
|
|
|
|
G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HAS_TUNER,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_boolean("has_tuner","has_tuner","has_tuner",
|
|
|
|
0,G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FREQUENCY,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_ulong("frequency","frequency","frequency",
|
|
|
|
0,G_MAXULONG,0,G_PARAM_READWRITE));
|
2002-12-20 20:12:28 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SIGNAL,
|
|
|
|
g_param_spec_uint("signal","signal","signal",
|
|
|
|
0,65535,0,G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HAS_AUDIO,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_boolean("has_audio","has_audio","has_audio",
|
|
|
|
0,G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_string("device","device","device",
|
|
|
|
NULL, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_NAME,
|
|
|
|
g_param_spec_string("device_name","device_name","device_name",
|
2002-01-15 15:52:09 +00:00
|
|
|
NULL, G_PARAM_READABLE));
|
2001-12-28 19:54:23 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_CAPTURE,
|
|
|
|
g_param_spec_boolean("can_capture","can_capture","can_capture",
|
|
|
|
0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_OVERLAY,
|
|
|
|
g_param_spec_boolean("has_overlay","has_overlay","has_overlay",
|
|
|
|
0,G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_MJPEG_CAPTURE,
|
|
|
|
g_param_spec_boolean("can_capture_mjpeg","can_capture_mjpeg","can_capture_mjpeg",
|
|
|
|
0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_MJPEG_PLAYBACK,
|
|
|
|
g_param_spec_boolean("can_playback_mjpeg","can_playback_mjpeg","can_playback_mjpeg",
|
|
|
|
0,G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_MPEG_CAPTURE,
|
|
|
|
g_param_spec_boolean("can_capture_mpeg","can_capture_mpeg","can_capture_mpeg",
|
|
|
|
0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_IS_MPEG_PLAYBACK,
|
|
|
|
g_param_spec_boolean("can_playback_mpeg","can_playback_mpeg","can_playback_mpeg",
|
|
|
|
0,G_PARAM_READABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-02-23 14:05:33 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DISPLAY,
|
|
|
|
g_param_spec_string("display","display","display",
|
|
|
|
NULL, G_PARAM_WRITABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DO_OVERLAY,
|
|
|
|
g_param_spec_boolean("do_overlay","do_overlay","do_overlay",
|
|
|
|
0,G_PARAM_WRITABLE));
|
2003-03-02 21:58:52 +00:00
|
|
|
|
|
|
|
/* actions */
|
|
|
|
gst_v4lelement_signals[SIGNAL_SET_VIDEOWINDOW] =
|
|
|
|
g_signal_new ("set_videowindow",
|
|
|
|
G_TYPE_FROM_CLASS(klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET(GstV4lElementClass, set_videowindow),
|
|
|
|
NULL, NULL,
|
|
|
|
gstv4l_cclosure_marshal_BOOLEAN__INT_INT_INT_INT_POINTER_INT,
|
|
|
|
G_TYPE_BOOLEAN, 6,
|
|
|
|
G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT,
|
|
|
|
G_TYPE_POINTER, G_TYPE_INT);
|
|
|
|
klass->set_videowindow = gst_v4l_set_window;
|
|
|
|
gst_v4lelement_signals[SIGNAL_GET_ATTRIBUTE] =
|
|
|
|
g_signal_new ("get_attribute",
|
|
|
|
G_TYPE_FROM_CLASS(klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET(GstV4lElementClass, get_attribute),
|
|
|
|
NULL, NULL,
|
|
|
|
gstv4l_cclosure_marshal_BOOLEAN__STRING_POINTER,
|
|
|
|
G_TYPE_BOOLEAN, 2, G_TYPE_STRING, G_TYPE_POINTER);
|
|
|
|
klass->get_attribute = gst_v4l_get_attribute;
|
|
|
|
gst_v4lelement_signals[SIGNAL_SET_ATTRIBUTE] =
|
|
|
|
g_signal_new ("set_attribute",
|
|
|
|
G_TYPE_FROM_CLASS(klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET(GstV4lElementClass, set_attribute),
|
|
|
|
NULL, NULL,
|
|
|
|
gstv4l_cclosure_marshal_BOOLEAN__STRING_INT,
|
|
|
|
G_TYPE_BOOLEAN, 2, G_TYPE_STRING, G_TYPE_INT);
|
|
|
|
klass->set_attribute = gst_v4l_set_attribute;
|
2002-02-23 14:05:33 +00:00
|
|
|
|
2002-11-13 12:35:55 +00:00
|
|
|
/* signals */
|
|
|
|
gst_v4lelement_signals[SIGNAL_OPEN] =
|
|
|
|
g_signal_new("open", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lElementClass, open),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
|
|
|
gst_v4lelement_signals[SIGNAL_CLOSE] =
|
|
|
|
g_signal_new("close", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lElementClass, close),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
gobject_class->set_property = gst_v4lelement_set_property;
|
|
|
|
gobject_class->get_property = gst_v4lelement_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_v4lelement_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4lelement_init (GstV4lElement *v4lelement)
|
|
|
|
{
|
|
|
|
/* some default values */
|
|
|
|
v4lelement->video_fd = -1;
|
|
|
|
v4lelement->buffer = NULL;
|
|
|
|
v4lelement->videodev = NULL;
|
2002-02-23 14:05:33 +00:00
|
|
|
v4lelement->display = NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lelement->norm = -1;
|
2001-12-28 19:54:23 +00:00
|
|
|
v4lelement->channel = -1; /* the first channel */
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lelement->frequency = 0;
|
|
|
|
|
2003-03-02 21:58:52 +00:00
|
|
|
v4lelement->norm_names = NULL;
|
|
|
|
v4lelement->input_names = NULL;
|
|
|
|
v4lelement->control_specs = NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4lelement_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstV4lElement *v4lelement;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_V4LELEMENT(object));
|
|
|
|
v4lelement = GST_V4LELEMENT(object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case ARG_CHANNEL:
|
|
|
|
v4lelement->channel = g_value_get_int(value);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement) && !GST_V4L_IS_ACTIVE(v4lelement))
|
|
|
|
{
|
2001-12-28 19:54:23 +00:00
|
|
|
if (v4lelement->norm >= VIDEO_MODE_PAL &&
|
|
|
|
v4lelement->norm < VIDEO_MODE_AUTO &&
|
|
|
|
v4lelement->channel >= 0)
|
2001-12-23 15:31:15 +00:00
|
|
|
if (!gst_v4l_set_chan_norm(v4lelement, v4lelement->channel, v4lelement->norm))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARG_NORM:
|
|
|
|
v4lelement->norm = g_value_get_int(value);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement) && !GST_V4L_IS_ACTIVE(v4lelement))
|
|
|
|
{
|
2001-12-28 19:54:23 +00:00
|
|
|
if (v4lelement->norm >= VIDEO_MODE_PAL &&
|
|
|
|
v4lelement->norm < VIDEO_MODE_AUTO &&
|
|
|
|
v4lelement->channel >= 0)
|
2001-12-23 15:31:15 +00:00
|
|
|
if (!gst_v4l_set_chan_norm(v4lelement, v4lelement->channel, v4lelement->norm))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARG_FREQUENCY:
|
|
|
|
v4lelement->frequency = g_value_get_ulong(value);
|
2003-03-02 21:58:52 +00:00
|
|
|
if (gst_v4l_has_tuner(v4lelement)) {
|
2002-12-20 20:23:37 +00:00
|
|
|
if (!gst_v4l_set_frequency(v4lelement, v4lelement->frequency)){
|
2002-12-20 20:12:28 +00:00
|
|
|
return;
|
2003-03-02 21:58:52 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE:
|
|
|
|
if (v4lelement->videodev)
|
|
|
|
g_free(v4lelement->videodev);
|
|
|
|
v4lelement->videodev = g_strdup(g_value_get_string(value));
|
|
|
|
break;
|
2002-02-23 14:05:33 +00:00
|
|
|
case ARG_DO_OVERLAY:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
gst_v4l_enable_overlay(v4lelement, g_value_get_boolean(value));
|
|
|
|
break;
|
|
|
|
case ARG_DISPLAY:
|
|
|
|
if (v4lelement->display) g_free(v4lelement->display);
|
|
|
|
v4lelement->display = g_strdup(g_value_get_string(value));
|
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4lelement_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstV4lElement *v4lelement;
|
|
|
|
gint temp_i = 0;
|
|
|
|
gulong temp_ul = 0;
|
2002-02-20 07:25:40 +00:00
|
|
|
GList *list = NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_V4LELEMENT(object));
|
|
|
|
v4lelement = GST_V4LELEMENT(object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case ARG_CHANNEL:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
gst_v4l_get_chan_norm(v4lelement, &temp_i, NULL);
|
|
|
|
g_value_set_int(value, temp_i);
|
|
|
|
break;
|
2002-02-20 07:25:40 +00:00
|
|
|
case ARG_CHANNEL_NAMES:
|
2002-01-15 15:52:09 +00:00
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
2002-02-20 07:25:40 +00:00
|
|
|
list = gst_v4l_get_chan_names(v4lelement);
|
|
|
|
g_value_set_pointer(value, (gpointer)list);
|
2002-01-15 15:52:09 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_NORM:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
gst_v4l_get_chan_norm(v4lelement, NULL, &temp_i);
|
|
|
|
g_value_set_int(value, temp_i);
|
|
|
|
break;
|
2002-02-20 07:25:40 +00:00
|
|
|
case ARG_NORM_NAMES:
|
|
|
|
for (temp_i=0;norm_name[temp_i]!=NULL;temp_i++)
|
2003-03-02 21:58:52 +00:00
|
|
|
list = g_list_append(list, (gpointer)norm_name[temp_i]);
|
2002-02-20 07:25:40 +00:00
|
|
|
g_value_set_pointer(value, (gpointer)list);
|
2002-01-15 15:52:09 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_HAS_TUNER:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
if (gst_v4l_has_tuner(v4lelement))
|
|
|
|
g_value_set_boolean(value, TRUE);
|
|
|
|
break;
|
|
|
|
case ARG_FREQUENCY:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
2001-12-28 19:54:23 +00:00
|
|
|
if (gst_v4l_has_tuner(v4lelement))
|
|
|
|
gst_v4l_get_frequency(v4lelement, &temp_ul);
|
2001-12-23 15:31:15 +00:00
|
|
|
g_value_set_ulong(value, temp_ul);
|
|
|
|
break;
|
2002-12-20 20:12:28 +00:00
|
|
|
case ARG_SIGNAL:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
if (gst_v4l_has_tuner(v4lelement))
|
|
|
|
gst_v4l_get_signal(v4lelement, &temp_i);
|
|
|
|
g_value_set_uint(value, temp_i);
|
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_HAS_AUDIO:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
if (gst_v4l_has_audio(v4lelement))
|
|
|
|
g_value_set_boolean(value, TRUE);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE:
|
2003-03-02 21:58:52 +00:00
|
|
|
g_value_set_string(value, v4lelement->videodev?v4lelement->videodev:"/dev/video");
|
2001-12-28 19:54:23 +00:00
|
|
|
break;
|
|
|
|
case ARG_DEVICE_NAME:
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
2003-03-02 21:58:52 +00:00
|
|
|
g_value_set_string(value, v4lelement->vcap.name);
|
2001-12-28 19:54:23 +00:00
|
|
|
else
|
2003-03-02 21:58:52 +00:00
|
|
|
g_value_set_string(value, "None");
|
2001-12-28 19:54:23 +00:00
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_CAPTURE:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_CAPTURE);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_OVERLAY:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_OVERLAY);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_MJPEG_CAPTURE:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_MJPEG_ENCODER);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_MJPEG_PLAYBACK:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_MJPEG_DECODER);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_MPEG_CAPTURE:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_MPEG_ENCODER);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_IS_MPEG_PLAYBACK:
|
|
|
|
g_value_set_boolean(value, FALSE);
|
|
|
|
if (GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
g_value_set_boolean(value, v4lelement->vcap.type & VID_TYPE_MPEG_DECODER);
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_v4lelement_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstV4lElement *v4lelement;
|
|
|
|
|
2002-01-04 23:58:11 +00:00
|
|
|
g_return_val_if_fail(GST_IS_V4LELEMENT(element), GST_STATE_FAILURE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lelement = GST_V4LELEMENT(element);
|
|
|
|
|
|
|
|
/* if going down into NULL state, close the device if it's open
|
|
|
|
* if going to READY, open the device (and set some options)
|
|
|
|
*/
|
2001-12-28 19:54:23 +00:00
|
|
|
switch (GST_STATE_TRANSITION(element))
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
{
|
2002-02-23 14:05:33 +00:00
|
|
|
if (v4lelement->display)
|
|
|
|
gst_v4l_set_overlay(v4lelement, v4lelement->display);
|
|
|
|
|
2001-12-28 19:54:23 +00:00
|
|
|
if (!gst_v4l_open(v4lelement))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
|
|
|
|
/* now, sync options */
|
|
|
|
if (v4lelement->norm >= VIDEO_MODE_PAL &&
|
|
|
|
v4lelement->norm < VIDEO_MODE_AUTO &&
|
|
|
|
v4lelement->channel >= 0)
|
|
|
|
{
|
2003-03-01 13:12:41 +00:00
|
|
|
if (!gst_v4l_set_chan_norm(v4lelement, v4lelement->channel,
|
|
|
|
v4lelement->norm)) {
|
|
|
|
gst_v4l_close(v4lelement);
|
2001-12-23 15:31:15 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2003-03-01 13:12:41 +00:00
|
|
|
}
|
2001-12-28 19:54:23 +00:00
|
|
|
}
|
|
|
|
if (v4lelement->frequency > 0 && gst_v4l_has_tuner(v4lelement))
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2003-03-01 13:12:41 +00:00
|
|
|
if (!gst_v4l_set_frequency(v4lelement, v4lelement->frequency)) {
|
|
|
|
gst_v4l_close(v4lelement);
|
2001-12-23 15:31:15 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2003-03-01 13:12:41 +00:00
|
|
|
}
|
2001-12-28 19:54:23 +00:00
|
|
|
}
|
2003-03-01 13:12:41 +00:00
|
|
|
|
|
|
|
g_signal_emit(G_OBJECT(v4lelement),
|
|
|
|
gst_v4lelement_signals[SIGNAL_OPEN], 0,
|
|
|
|
v4lelement->videodev);
|
2001-12-28 19:54:23 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
if (!gst_v4l_close(v4lelement))
|
|
|
|
return GST_STATE_FAILURE;
|
2002-11-13 12:35:55 +00:00
|
|
|
|
|
|
|
g_signal_emit(G_OBJECT(v4lelement),
|
|
|
|
gst_v4lelement_signals[SIGNAL_CLOSE], 0,
|
|
|
|
v4lelement->videodev);
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS(parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS(parent_class)->change_state(element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module,
|
|
|
|
GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
|
|
|
/* create an elementfactory for the v4lelement */
|
2002-04-11 20:42:27 +00:00
|
|
|
factory = gst_element_factory_new("v4lelement", GST_TYPE_V4LELEMENT,
|
2001-12-23 15:31:15 +00:00
|
|
|
&gst_v4lelement_details);
|
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
2002-02-04 19:45:56 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"v4lelement",
|
|
|
|
plugin_init
|
|
|
|
};
|