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
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-12-23 15:31:15 +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>
|
2003-06-29 19:46:12 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/tuner/tuner.h>
|
|
|
|
#include <gst/colorbalance/colorbalance.h>
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
#include "v4l_calls.h"
|
2003-10-10 12:47:41 +00:00
|
|
|
#include "gstv4ltuner.h"
|
|
|
|
#include "gstv4lcolorbalance.h"
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-11-09 20:54:24 +00:00
|
|
|
#include "gstv4lsrc.h"
|
|
|
|
#include "gstv4lmjpegsrc.h"
|
|
|
|
#include "gstv4lmjpegsink.h"
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
#define DEBUG(format, args...) \
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG_OBJECT (\
|
2002-09-09 07:12:29 +00:00
|
|
|
GST_ELEMENT(v4lelement), \
|
2002-09-17 17:45:19 +00:00
|
|
|
"V4L: " format, ##args)
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
static const char *picture_name[] = {
|
2003-03-02 21:58:52 +00:00
|
|
|
"Hue",
|
|
|
|
"Brightness",
|
|
|
|
"Contrast",
|
|
|
|
"Saturation",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2003-11-12 02:47:50 +00:00
|
|
|
G_GNUC_UNUSED static const char *audio_name[] = {
|
2003-03-02 21:58:52 +00:00
|
|
|
"Volume",
|
|
|
|
"Mute",
|
|
|
|
"Mode",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
static const char *norm_name[] = {
|
2003-03-02 21:58:52 +00:00
|
|
|
"PAL",
|
|
|
|
"NTSC",
|
|
|
|
"SECAM",
|
|
|
|
NULL
|
|
|
|
};
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_capabilities():
|
|
|
|
* get the device's capturing capabilities
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l_get_capabilities (GstV4lElement *v4lelement)
|
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting capabilities");
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGCAP, &(v4lelement->vcap)) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("error getting capabilities %s of from device %s",
|
|
|
|
g_strerror (errno), v4lelement->videodev));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_open():
|
|
|
|
* open the video device (v4lelement->videodev)
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_open (GstV4lElement *v4lelement)
|
|
|
|
{
|
2003-03-02 21:58:52 +00:00
|
|
|
int num;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("opening device %s", v4lelement->videodev);
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_NOT_OPEN(v4lelement);
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE(v4lelement);
|
|
|
|
|
|
|
|
/* be sure we have a device */
|
2003-10-10 12:47:41 +00:00
|
|
|
if (!v4lelement->videodev) {
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, NOT_FOUND,
|
|
|
|
(_("No device specified")), NULL);
|
2003-10-10 12:47:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* open the device */
|
2002-02-13 18:40:15 +00:00
|
|
|
v4lelement->video_fd = open(v4lelement->videodev, O_RDWR);
|
2001-12-23 15:31:15 +00:00
|
|
|
if (!GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, OPEN_READ_WRITE,
|
2004-01-19 15:45:55 +00:00
|
|
|
(_("Could not open device \"%s\" for reading and writing"), v4lelement->videodev),
|
2004-01-18 21:46:58 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get capabilities */
|
|
|
|
if (!gst_v4l_get_capabilities(v4lelement))
|
|
|
|
{
|
|
|
|
close(v4lelement->video_fd);
|
|
|
|
v4lelement->video_fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-09 20:54:24 +00:00
|
|
|
/* device type check */
|
|
|
|
if ((GST_IS_V4LSRC(v4lelement) &&
|
|
|
|
!(v4lelement->vcap.type & VID_TYPE_CAPTURE)) ||
|
|
|
|
(GST_IS_V4LMJPEGSRC(v4lelement) &&
|
|
|
|
!(v4lelement->vcap.type & VID_TYPE_MJPEG_ENCODER)) ||
|
|
|
|
(GST_IS_V4LMJPEGSINK(v4lelement) &&
|
|
|
|
!(v4lelement->vcap.type & VID_TYPE_MJPEG_DECODER))) {
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Device opened, but wrong type (0x%x)",
|
|
|
|
v4lelement->vcap.type));
|
2003-11-09 20:54:24 +00:00
|
|
|
close(v4lelement->video_fd);
|
|
|
|
v4lelement->video_fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-02-20 07:25:40 +00:00
|
|
|
gst_info("Opened device \'%s\' (\'%s\') successfully\n",
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lelement->vcap.name, v4lelement->videodev);
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
/* norms + inputs, for the tuner interface */
|
|
|
|
for (num=0;norm_name[num]!=NULL;num++) {
|
|
|
|
GstV4lTunerNorm *v4lnorm = g_object_new (GST_TYPE_V4L_TUNER_NORM,
|
|
|
|
NULL);
|
|
|
|
GstTunerNorm *norm = GST_TUNER_NORM (v4lnorm);
|
|
|
|
|
|
|
|
norm->label = g_strdup (norm_name[num]);
|
|
|
|
norm->fps = (num == 1) ? (30000./1001) : 25.;
|
|
|
|
v4lnorm->index = num;
|
|
|
|
v4lelement->norms = g_list_append(v4lelement->norms,
|
|
|
|
(gpointer) norm);
|
|
|
|
}
|
|
|
|
v4lelement->channels = gst_v4l_get_chan_names(v4lelement);
|
2003-03-02 21:58:52 +00:00
|
|
|
|
|
|
|
for (num=0;picture_name[num]!=NULL;num++)
|
|
|
|
{
|
2003-10-10 12:47:41 +00:00
|
|
|
GstV4lColorBalanceChannel *v4lchannel =
|
|
|
|
g_object_new (GST_TYPE_V4L_COLOR_BALANCE_CHANNEL, NULL);
|
|
|
|
GstColorBalanceChannel *channel = GST_COLOR_BALANCE_CHANNEL (v4lchannel);
|
|
|
|
channel->label = g_strdup (picture_name[num]);
|
|
|
|
channel->min_value = 0;
|
|
|
|
channel->max_value = 65535;
|
|
|
|
v4lchannel->index = num;
|
|
|
|
v4lelement->colors = g_list_append(v4lelement->colors, channel);
|
2003-03-02 21:58:52 +00:00
|
|
|
}
|
2003-10-10 12:47:41 +00:00
|
|
|
|
|
|
|
DEBUG("Setting default norm/input");
|
|
|
|
gst_v4l_set_chan_norm (v4lelement, 0, 0);
|
2003-03-02 21:58:52 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_close():
|
|
|
|
* close the video device (v4lelement->video_fd)
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_close (GstV4lElement *v4lelement)
|
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("closing device");
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE(v4lelement);
|
|
|
|
|
|
|
|
close(v4lelement->video_fd);
|
|
|
|
v4lelement->video_fd = -1;
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
g_list_foreach (v4lelement->channels, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (v4lelement->channels);
|
|
|
|
v4lelement->channels = NULL;
|
|
|
|
|
|
|
|
g_list_foreach (v4lelement->norms, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (v4lelement->norms);
|
|
|
|
v4lelement->norms = NULL;
|
|
|
|
|
|
|
|
g_list_foreach (v4lelement->colors, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (v4lelement->colors);
|
|
|
|
v4lelement->colors = NULL;
|
2003-03-02 21:58:52 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_num_chans()
|
|
|
|
* return value: the numver of video input channels
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gint
|
|
|
|
gst_v4l_get_num_chans (GstV4lElement *v4lelement)
|
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting number of channels");
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
|
|
|
return v4lelement->vcap.channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-20 07:25:40 +00:00
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_chan_names()
|
|
|
|
* return value: a GList containing the channel names
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
GList *
|
|
|
|
gst_v4l_get_chan_names (GstV4lElement *v4lelement)
|
|
|
|
{
|
|
|
|
struct video_channel vchan;
|
2003-10-10 12:47:41 +00:00
|
|
|
const GList *pads = gst_element_get_pad_list (GST_ELEMENT (v4lelement));
|
2002-02-20 07:25:40 +00:00
|
|
|
GList *list = NULL;
|
|
|
|
gint i;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting channel names");
|
2002-02-20 07:25:40 +00:00
|
|
|
|
|
|
|
if (!GST_V4L_IS_OPEN(v4lelement))
|
|
|
|
return NULL;
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
/* sinks don't have inputs in v4l */
|
|
|
|
if (pads && g_list_length ((GList *) pads) == 1)
|
|
|
|
if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == GST_PAD_SINK)
|
|
|
|
return NULL;
|
|
|
|
|
2002-02-20 07:25:40 +00:00
|
|
|
for (i=0;i<gst_v4l_get_num_chans(v4lelement);i++)
|
|
|
|
{
|
2003-10-10 12:47:41 +00:00
|
|
|
GstV4lTunerChannel *v4lchannel = g_object_new (GST_TYPE_V4L_TUNER_CHANNEL,
|
|
|
|
NULL);
|
|
|
|
GstTunerChannel *channel = GST_TUNER_CHANNEL (v4lchannel);
|
|
|
|
|
2002-02-20 07:25:40 +00:00
|
|
|
vchan.channel = i;
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGCHAN, &vchan) < 0)
|
2003-10-10 12:47:41 +00:00
|
|
|
return NULL; /* memleak... */
|
|
|
|
channel->label = g_strdup (vchan.name);
|
|
|
|
channel->flags = GST_TUNER_CHANNEL_INPUT;
|
|
|
|
v4lchannel->index = i;
|
|
|
|
if (vchan.flags & VIDEO_VC_TUNER) {
|
|
|
|
struct video_tuner vtun;
|
|
|
|
gint n;
|
|
|
|
|
|
|
|
for (n = 0; ; n++) {
|
|
|
|
vtun.tuner = n;
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGTUNER, &vtun) < 0)
|
|
|
|
break; /* no more tuners */
|
|
|
|
if (!strcmp(vtun.name, vchan.name)) {
|
|
|
|
v4lchannel->tuner = n;
|
|
|
|
channel->flags |= GST_TUNER_CHANNEL_FREQUENCY;
|
|
|
|
channel->min_frequency = vtun.rangelow;
|
|
|
|
channel->max_frequency = vtun.rangehigh;
|
|
|
|
channel->min_signal = 0;
|
|
|
|
channel->max_signal = 0xffff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vchan.flags & VIDEO_VC_AUDIO) {
|
|
|
|
struct video_audio vaud;
|
|
|
|
gint n;
|
|
|
|
|
|
|
|
for (n = 0; n < v4lelement->vcap.audios; n++) {
|
|
|
|
vaud.audio = n;
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGAUDIO, &vaud) < 0)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(vaud.name, vchan.name)) {
|
|
|
|
v4lchannel->audio = n;
|
|
|
|
channel->flags |= GST_TUNER_CHANNEL_AUDIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list = g_list_append(list, (gpointer) channel);
|
2002-02-20 07:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_chan_norm():
|
|
|
|
* get the currently active video-channel and it's
|
|
|
|
* norm (VIDEO_MODE_{PAL|NTSC|SECAM|AUTO})
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_get_chan_norm (GstV4lElement *v4lelement,
|
|
|
|
gint *channel,
|
|
|
|
gint *norm)
|
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting current channel and norm");
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
|
|
|
if (channel)
|
2002-01-15 15:52:09 +00:00
|
|
|
*channel = v4lelement->vchan.channel;
|
2001-12-23 15:31:15 +00:00
|
|
|
if (norm)
|
2002-01-15 15:52:09 +00:00
|
|
|
*norm = v4lelement->vchan.norm;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_chan_norm():
|
|
|
|
* set a new active channel and it's norm
|
|
|
|
* (VIDEO_MODE_{PAL|NTSC|SECAM|AUTO})
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_set_chan_norm (GstV4lElement *v4lelement,
|
|
|
|
gint channel,
|
|
|
|
gint norm)
|
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("setting channel = %d, norm = %d (%s)",
|
2001-12-23 15:31:15 +00:00
|
|
|
channel, norm, norm_name[norm]);
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE(v4lelement);
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
v4lelement->vchan.channel = channel;
|
|
|
|
v4lelement->vchan.norm = norm;
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCSCHAN, &(v4lelement->vchan)) < 0)
|
2001-12-28 19:54:23 +00:00
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting the channel/norm settings: %s",
|
|
|
|
g_strerror(errno)));
|
2001-12-28 19:54:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGCHAN, &(v4lelement->vchan)) < 0)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting the channel/norm settings: %s",
|
|
|
|
g_strerror(errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-20 20:12:28 +00:00
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_signal():
|
|
|
|
* get the current signal
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_get_signal (GstV4lElement *v4lelement,
|
2003-10-10 12:47:41 +00:00
|
|
|
gint tunernum,
|
|
|
|
guint *signal)
|
2002-12-20 20:12:28 +00:00
|
|
|
{
|
2003-10-10 12:47:41 +00:00
|
|
|
struct video_tuner tuner;
|
2002-12-20 20:12:28 +00:00
|
|
|
|
|
|
|
DEBUG("getting tuner signal");
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
tuner.tuner = tunernum;
|
2002-12-20 20:12:28 +00:00
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGTUNER, &tuner) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting tuner signal: %s", g_strerror (errno)));
|
2002-12-20 20:12:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*signal = tuner.signal;
|
|
|
|
|
|
|
|
return TRUE;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_frequency():
|
|
|
|
* get the current frequency
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_get_frequency (GstV4lElement *v4lelement,
|
2003-10-10 12:47:41 +00:00
|
|
|
gint tunernum,
|
2001-12-23 15:31:15 +00:00
|
|
|
gulong *frequency)
|
|
|
|
{
|
2003-10-10 12:47:41 +00:00
|
|
|
struct video_tuner vtun;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting tuner frequency");
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
/* check that this is the current input */
|
|
|
|
vtun.tuner = tunernum;
|
|
|
|
if (ioctl (v4lelement->video_fd, VIDIOCGTUNER, &vtun) < 0)
|
|
|
|
return FALSE;
|
|
|
|
if (strcmp(vtun.name, v4lelement->vchan.name))
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGFREQ, frequency) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting tuner frequency: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_frequency():
|
|
|
|
* set frequency
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_set_frequency (GstV4lElement *v4lelement,
|
2003-10-10 12:47:41 +00:00
|
|
|
gint tunernum,
|
|
|
|
gulong frequency)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2003-10-10 12:47:41 +00:00
|
|
|
struct video_tuner vtun;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("setting tuner frequency to %lu", frequency);
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
2003-10-10 12:47:41 +00:00
|
|
|
|
|
|
|
/* check that this is the current input */
|
|
|
|
vtun.tuner = tunernum;
|
|
|
|
if (ioctl (v4lelement->video_fd, VIDIOCGTUNER, &vtun) < 0)
|
|
|
|
return FALSE;
|
|
|
|
if (strcmp(vtun.name, v4lelement->vchan.name))
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCSFREQ, &frequency) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting tuner frequency: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_picture():
|
|
|
|
* get a picture value
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_get_picture (GstV4lElement *v4lelement,
|
|
|
|
GstV4lPictureType type,
|
|
|
|
gint *value)
|
|
|
|
{
|
|
|
|
struct video_picture vpic;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting picture property type %d (%s)",
|
2001-12-23 15:31:15 +00:00
|
|
|
type, picture_name[type]);
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGPICT, &vpic) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting picture parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case V4L_PICTURE_HUE:
|
|
|
|
*value = vpic.hue;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_BRIGHTNESS:
|
|
|
|
*value = vpic.brightness;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_CONTRAST:
|
|
|
|
*value = vpic.contrast;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_SATURATION:
|
|
|
|
*value = vpic.colour;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting picture parameters: unknown type %d", type));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_picture():
|
|
|
|
* set a picture value
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_set_picture (GstV4lElement *v4lelement,
|
|
|
|
GstV4lPictureType type,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
struct video_picture vpic;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("setting picture type %d (%s) to value %d",
|
2001-12-23 15:31:15 +00:00
|
|
|
type, picture_name[type], value);
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGPICT, &vpic) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting picture parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case V4L_PICTURE_HUE:
|
|
|
|
vpic.hue = value;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_BRIGHTNESS:
|
|
|
|
vpic.brightness = value;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_CONTRAST:
|
|
|
|
vpic.contrast = value;
|
|
|
|
break;
|
|
|
|
case V4L_PICTURE_SATURATION:
|
|
|
|
vpic.colour = value;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting picture parameters: unknown type %d", type));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCSPICT, &vpic) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting picture parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_get_audio():
|
|
|
|
* get some audio value
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_get_audio (GstV4lElement *v4lelement,
|
2003-10-10 12:47:41 +00:00
|
|
|
gint audionum,
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lAudioType type,
|
|
|
|
gint *value)
|
|
|
|
{
|
|
|
|
struct video_audio vau;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("getting audio parameter type %d (%s)",
|
2001-12-23 15:31:15 +00:00
|
|
|
type, audio_name[type]);
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
vau.audio = audionum;
|
2001-12-23 15:31:15 +00:00
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGAUDIO, &vau) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting audio parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case V4L_AUDIO_MUTE:
|
|
|
|
*value = (vau.flags & VIDEO_AUDIO_MUTE);
|
|
|
|
break;
|
|
|
|
case V4L_AUDIO_VOLUME:
|
|
|
|
*value = vau.volume;
|
|
|
|
break;
|
|
|
|
case V4L_AUDIO_MODE:
|
|
|
|
*value = vau.mode;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting audio parameters: unknown type %d", type));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l_set_audio():
|
|
|
|
* set some audio value
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l_set_audio (GstV4lElement *v4lelement,
|
2003-10-10 12:47:41 +00:00
|
|
|
gint audionum,
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lAudioType type,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
struct video_audio vau;
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
DEBUG("setting audio parameter type %d (%s) to value %d",
|
2001-12-23 15:31:15 +00:00
|
|
|
type, audio_name[type], value);
|
|
|
|
GST_V4L_CHECK_OPEN(v4lelement);
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
vau.audio = audionum;
|
2001-12-23 15:31:15 +00:00
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCGAUDIO, &vau) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error getting audio parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case V4L_AUDIO_MUTE:
|
|
|
|
if (!(vau.flags & VIDEO_AUDIO_MUTABLE))
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, CORE, NOT_IMPLEMENTED, NULL,
|
|
|
|
("Error setting audio mute: (un)setting mute is not supported"));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (value)
|
|
|
|
vau.flags |= VIDEO_AUDIO_MUTE;
|
|
|
|
else
|
|
|
|
vau.flags &= ~VIDEO_AUDIO_MUTE;
|
|
|
|
break;
|
|
|
|
case V4L_AUDIO_VOLUME:
|
|
|
|
if (!(vau.flags & VIDEO_AUDIO_VOLUME))
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, CORE, NOT_IMPLEMENTED, NULL,
|
|
|
|
("Error setting audio volume: setting volume is not supported"));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
vau.volume = value;
|
|
|
|
break;
|
|
|
|
case V4L_AUDIO_MODE:
|
|
|
|
vau.mode = value;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting audio parameters: unknown type %d", type));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(v4lelement->video_fd, VIDIOCSAUDIO, &vau) < 0)
|
|
|
|
{
|
2004-01-18 21:46:58 +00:00
|
|
|
gst_element_error (v4lelement, RESOURCE, SETTINGS, NULL,
|
|
|
|
("Error setting audio parameters: %s", g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|