2001-12-23 15:31:15 +00:00
|
|
|
/* G-Streamer BT8x8/V4L frame grabber plugin
|
2002-01-31 22:22:42 +00:00
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2001-12-17 19:03:14 +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
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
#include <string.h>
|
2001-12-23 15:31:15 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include "v4lsrc_calls.h"
|
2003-07-06 20:49:52 +00:00
|
|
|
#include <gst/video/video.h>
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2001-12-17 19:03:14 +00:00
|
|
|
static GstElementDetails gst_v4lsrc_details = {
|
2001-12-23 15:31:15 +00:00
|
|
|
"Video (video4linux/raw) Source",
|
2001-12-17 19:03:14 +00:00
|
|
|
"Source/Video",
|
2002-09-18 19:02:52 +00:00
|
|
|
"LGPL",
|
2001-12-23 15:31:15 +00:00
|
|
|
"Reads raw frames from a video4linux (BT8x8) device",
|
2001-12-17 19:03:14 +00:00
|
|
|
VERSION,
|
2001-12-23 15:31:15 +00:00
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
|
|
|
|
"(C) 2001",
|
2001-12-17 19:03:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* V4lSrc signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
2003-05-02 21:16:55 +00:00
|
|
|
SIGNAL_FRAME_CAPTURE,
|
|
|
|
SIGNAL_FRAME_DROP,
|
|
|
|
SIGNAL_FRAME_INSERT,
|
2001-12-17 19:03:14 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* arguments */
|
2001-12-17 19:03:14 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
2002-01-07 09:31:34 +00:00
|
|
|
ARG_NUMBUFS,
|
2003-05-02 21:16:55 +00:00
|
|
|
ARG_BUFSIZE,
|
|
|
|
ARG_USE_FIXED_FPS
|
2001-12-17 19:03:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* init functions */
|
|
|
|
static void gst_v4lsrc_class_init (GstV4lSrcClass *klass);
|
|
|
|
static void gst_v4lsrc_init (GstV4lSrc *v4lsrc);
|
|
|
|
|
|
|
|
/* pad/buffer functions */
|
2002-09-16 21:01:42 +00:00
|
|
|
static gboolean gst_v4lsrc_srcconvert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value);
|
2003-05-02 21:16:55 +00:00
|
|
|
static GstPadLinkReturn gst_v4lsrc_srcconnect (GstPad *pad,
|
2002-01-15 15:52:09 +00:00
|
|
|
GstCaps *caps);
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstCaps* gst_v4lsrc_getcaps (GstPad *pad,
|
|
|
|
GstCaps *caps);
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstBuffer* gst_v4lsrc_get (GstPad *pad);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* get/set params */
|
|
|
|
static void gst_v4lsrc_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_v4lsrc_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* state handling */
|
|
|
|
static GstElementStateReturn gst_v4lsrc_change_state (GstElement *element);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* bufferpool functions */
|
|
|
|
static GstBuffer* gst_v4lsrc_buffer_new (GstBufferPool *pool,
|
2002-07-08 22:18:49 +00:00
|
|
|
guint64 offset,
|
|
|
|
guint size,
|
2001-12-23 15:31:15 +00:00
|
|
|
gpointer user_data);
|
2002-07-08 22:18:49 +00:00
|
|
|
static void gst_v4lsrc_buffer_free (GstBufferPool *pool,
|
|
|
|
GstBuffer *buf,
|
|
|
|
gpointer user_data);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
/* set_clock function for a/V sync */
|
|
|
|
static void gst_v4lsrc_set_clock (GstElement *element,
|
|
|
|
GstClock *clock);
|
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstPadTemplate *src_template = NULL;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2003-05-02 21:16:55 +00:00
|
|
|
static guint gst_v4lsrc_signals[LAST_SIGNAL] = { 0 };
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_v4lsrc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4lsrc_type = 0;
|
|
|
|
|
|
|
|
if (!v4lsrc_type) {
|
|
|
|
static const GTypeInfo v4lsrc_info = {
|
2001-12-23 15:31:15 +00:00
|
|
|
sizeof(GstV4lSrcClass),
|
|
|
|
NULL,
|
2001-12-17 19:03:14 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_v4lsrc_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstV4lSrc),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_v4lsrc_init,
|
|
|
|
NULL
|
|
|
|
};
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc_type = g_type_register_static(GST_TYPE_V4LELEMENT, "GstV4lSrc", &v4lsrc_info, 0);
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
return v4lsrc_type;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
|
|
|
gst_v4lsrc_class_init (GstV4lSrcClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
parent_class = g_type_class_ref(GST_TYPE_V4LELEMENT);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2002-01-07 09:31:34 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NUMBUFS,
|
2003-05-02 21:16:55 +00:00
|
|
|
g_param_spec_int("num_buffers","Num Buffers","Number of buffers",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READABLE));
|
2002-01-07 09:31:34 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFSIZE,
|
2003-05-02 21:16:55 +00:00
|
|
|
g_param_spec_int("buffer_size","Buffer Size","Size of buffers",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_USE_FIXED_FPS,
|
|
|
|
g_param_spec_boolean("use_fixed_fps", "Use Fixed FPS",
|
|
|
|
"Drop/Insert frames to reach a certain FPS (TRUE) "
|
|
|
|
"or adapt FPS to suit the number of frabbed frames",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_CAPTURE] =
|
|
|
|
g_signal_new("frame_capture", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lSrcClass, frame_capture),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_DROP] =
|
|
|
|
g_signal_new("frame_drop", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lSrcClass, frame_drop),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_INSERT] =
|
|
|
|
g_signal_new("frame_insert", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lSrcClass, frame_insert),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_v4lsrc_set_property;
|
|
|
|
gobject_class->get_property = gst_v4lsrc_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_v4lsrc_change_state;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
gstelement_class->set_clock = gst_v4lsrc_set_clock;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
|
|
|
gst_v4lsrc_init (GstV4lSrc *v4lsrc)
|
|
|
|
{
|
2003-05-21 06:33:18 +00:00
|
|
|
GST_FLAG_SET(GST_ELEMENT(v4lsrc), GST_ELEMENT_THREAD_SUGGESTED);
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
v4lsrc->srcpad = gst_pad_new_from_template (src_template, "src");
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(v4lsrc), v4lsrc->srcpad);
|
|
|
|
|
|
|
|
gst_pad_set_get_function (v4lsrc->srcpad, gst_v4lsrc_get);
|
2003-05-10 14:36:34 +00:00
|
|
|
gst_pad_set_getcaps_function (v4lsrc->srcpad, gst_v4lsrc_getcaps);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (v4lsrc->srcpad, gst_v4lsrc_srcconnect);
|
2002-09-16 21:01:42 +00:00
|
|
|
gst_pad_set_convert_function (v4lsrc->srcpad, gst_v4lsrc_srcconvert);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-07-08 22:18:49 +00:00
|
|
|
v4lsrc->bufferpool = gst_buffer_pool_new(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-12-20 23:14:41 +00:00
|
|
|
(GstBufferPoolBufferNewFunction)gst_v4lsrc_buffer_new,
|
2002-09-20 09:28:46 +00:00
|
|
|
NULL,
|
2002-12-20 23:14:41 +00:00
|
|
|
(GstBufferPoolBufferFreeFunction)gst_v4lsrc_buffer_free,
|
2002-07-08 22:18:49 +00:00
|
|
|
v4lsrc);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
v4lsrc->buffer_size = 0;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
/* no clock */
|
|
|
|
v4lsrc->clock = NULL;
|
|
|
|
|
|
|
|
/* fps */
|
|
|
|
v4lsrc->use_fixed_fps = TRUE;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
static gfloat
|
2003-05-02 21:16:55 +00:00
|
|
|
gst_v4lsrc_get_fps (GstV4lSrc *v4lsrc)
|
2002-09-16 21:01:42 +00:00
|
|
|
{
|
|
|
|
gint norm;
|
2003-07-06 20:49:52 +00:00
|
|
|
gfloat fps;
|
2002-09-16 21:01:42 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
if (!v4lsrc->use_fixed_fps &&
|
|
|
|
v4lsrc->clock != NULL &&
|
|
|
|
v4lsrc->handled > 0) {
|
|
|
|
/* try to get time from clock master and calculate fps */
|
|
|
|
GstClockTime time = gst_clock_get_time(v4lsrc->clock) - v4lsrc->substract_time;
|
|
|
|
return v4lsrc->handled * GST_SECOND / time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if that failed ... */
|
2002-09-16 21:01:42 +00:00
|
|
|
|
|
|
|
if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lsrc)))
|
2003-05-02 21:16:55 +00:00
|
|
|
return 0.;
|
2002-09-16 21:01:42 +00:00
|
|
|
|
|
|
|
if (!gst_v4l_get_chan_norm(GST_V4LELEMENT(v4lsrc), NULL, &norm))
|
2003-05-02 21:16:55 +00:00
|
|
|
return 0.;
|
2002-09-16 21:01:42 +00:00
|
|
|
|
|
|
|
if (norm == VIDEO_MODE_NTSC)
|
|
|
|
fps = 30000/1001;
|
|
|
|
else
|
|
|
|
fps = 25.;
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
return fps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4lsrc_srcconvert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value)
|
|
|
|
{
|
|
|
|
GstV4lSrc *v4lsrc;
|
|
|
|
gdouble fps;
|
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if ((fps = gst_v4lsrc_get_fps(v4lsrc)) == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-09-16 21:01:42 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value * fps / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-05-24 10:46:31 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-09-16 21:01:42 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / fps;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_v4lsrc_palette_to_caps (int palette,
|
|
|
|
GstPropsEntry *width,
|
2003-07-06 20:49:52 +00:00
|
|
|
GstPropsEntry *height,
|
|
|
|
GstPropsEntry *fps)
|
2003-05-10 14:36:34 +00:00
|
|
|
{
|
|
|
|
guint32 fourcc;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
switch (palette) {
|
|
|
|
case VIDEO_PALETTE_YUV422:
|
|
|
|
case VIDEO_PALETTE_YUYV:
|
|
|
|
fourcc = GST_MAKE_FOURCC('Y','U','Y','2');
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_YUV420P:
|
|
|
|
fourcc = GST_MAKE_FOURCC('I','4','2','0');
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_UYVY:
|
|
|
|
fourcc = GST_MAKE_FOURCC('U','Y','V','Y');
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_YUV411:
|
|
|
|
fourcc = GST_MAKE_FOURCC('Y','4','1','P');
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB555:
|
|
|
|
case VIDEO_PALETTE_RGB565:
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
|
|
|
case VIDEO_PALETTE_RGB32:
|
|
|
|
fourcc = GST_MAKE_FOURCC('R','G','B',' ');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fourcc == GST_MAKE_FOURCC('R','G','B',' ')) {
|
2003-07-06 20:49:52 +00:00
|
|
|
gint depth = 0, endianness = 0;
|
2003-05-10 14:36:34 +00:00
|
|
|
guint32 r_mask = 0, g_mask = 0, b_mask = 0;
|
|
|
|
|
|
|
|
switch (palette) {
|
|
|
|
case VIDEO_PALETTE_RGB555:
|
2003-07-06 20:49:52 +00:00
|
|
|
depth = 15; endianness = G_BYTE_ORDER;
|
2003-05-10 14:36:34 +00:00
|
|
|
r_mask = 0x7c00; g_mask = 0x03e0; b_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB565:
|
2003-07-06 20:49:52 +00:00
|
|
|
depth = 16; endianness = G_BYTE_ORDER;
|
2003-05-10 14:36:34 +00:00
|
|
|
r_mask = 0xf800; g_mask = 0x07f0; b_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
2003-07-06 20:49:52 +00:00
|
|
|
depth = 24; endianness = G_BIG_ENDIAN;
|
|
|
|
r_mask = R_MASK_24; g_mask = G_MASK_24; b_mask = B_MASK_24;
|
2003-05-10 14:36:34 +00:00
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB32:
|
2003-07-06 20:49:52 +00:00
|
|
|
depth = 32; endianness = G_BIG_ENDIAN;
|
|
|
|
r_mask = R_MASK_32; g_mask = G_MASK_32; b_mask = B_MASK_32;
|
2003-05-10 14:36:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps = GST_CAPS_NEW("v4lsrc_rgb_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-rgb",
|
2003-05-10 14:36:34 +00:00
|
|
|
"bpp", GST_PROPS_INT((depth+1) & ~1),
|
|
|
|
"depth", GST_PROPS_INT(depth),
|
|
|
|
"endianness", GST_PROPS_INT(G_BYTE_ORDER),
|
|
|
|
"red_mask", GST_PROPS_INT(r_mask),
|
|
|
|
"green_mask", GST_PROPS_INT(g_mask),
|
|
|
|
"blue_mask", GST_PROPS_INT(b_mask),
|
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
caps = GST_CAPS_NEW("v4lsrc_yuv_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-yuv",
|
2003-05-10 14:36:34 +00:00
|
|
|
"format", GST_PROPS_FOURCC(fourcc),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_props_add_entry(caps->properties, width);
|
|
|
|
gst_props_add_entry(caps->properties, height);
|
2003-07-06 20:49:52 +00:00
|
|
|
gst_props_add_entry(caps->properties, fps);
|
2003-05-10 14:36:34 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
#define gst_v4lsrc_palette_to_caps_fixed(palette, width, height, fps) \
|
2003-05-10 14:36:34 +00:00
|
|
|
gst_v4lsrc_palette_to_caps(palette, \
|
|
|
|
gst_props_entry_new("width", \
|
|
|
|
GST_PROPS_INT(width)), \
|
|
|
|
gst_props_entry_new("height", \
|
2003-07-06 20:49:52 +00:00
|
|
|
GST_PROPS_INT(height)), \
|
|
|
|
gst_props_entry_new("framerate", \
|
|
|
|
GST_PROPS_FLOAT(fps)) \
|
2003-05-10 14:36:34 +00:00
|
|
|
)
|
|
|
|
#define gst_v4lsrc_palette_to_caps_range(palette, min_w, max_w, min_h, max_h) \
|
|
|
|
gst_v4lsrc_palette_to_caps(palette, \
|
|
|
|
gst_props_entry_new("width", \
|
|
|
|
GST_PROPS_INT_RANGE(min_w, \
|
|
|
|
max_w)), \
|
|
|
|
gst_props_entry_new("height", \
|
|
|
|
GST_PROPS_INT_RANGE(min_h, \
|
2003-07-06 20:49:52 +00:00
|
|
|
max_h)), \
|
|
|
|
gst_props_entry_new("framerate", \
|
|
|
|
GST_PROPS_FLOAT_RANGE(0., \
|
|
|
|
G_MAXFLOAT)) \
|
2003-05-10 14:36:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#define gst_caps_get_int_range(caps, name, min, max) \
|
|
|
|
gst_props_entry_get_int_range(gst_props_get_entry((caps)->properties, \
|
|
|
|
name), \
|
|
|
|
min, max)
|
2002-09-16 21:01:42 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-15 15:52:09 +00:00
|
|
|
gst_v4lsrc_srcconnect (GstPad *pad,
|
|
|
|
GstCaps *vscapslist)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2003-01-10 13:38:32 +00:00
|
|
|
GstPadLinkReturn ret_val;
|
2001-12-17 19:03:14 +00:00
|
|
|
GstV4lSrc *v4lsrc;
|
2002-01-15 15:52:09 +00:00
|
|
|
GstCaps *caps, *newcaps;
|
2002-01-20 12:27:11 +00:00
|
|
|
gint palette;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
/* in case the buffers are active (which means that we already
|
|
|
|
* did capsnego before and didn't clean up), clean up anyways */
|
|
|
|
if (GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lsrc)))
|
2002-09-18 10:57:56 +00:00
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
if (!gst_v4lsrc_capture_deinit(v4lsrc))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-18 10:57:56 +00:00
|
|
|
}
|
|
|
|
else if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lsrc)))
|
|
|
|
{
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-09-18 10:57:56 +00:00
|
|
|
}
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
/* TODO: caps = gst_caps_normalize(capslist); */
|
|
|
|
for (caps = vscapslist ; caps != NULL ; caps = vscapslist = vscapslist->next)
|
|
|
|
{
|
2002-03-30 17:06:26 +00:00
|
|
|
guint32 fourcc;
|
2003-05-10 14:36:34 +00:00
|
|
|
gint depth, w, h;
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (!strcmp(gst_caps_get_mime(caps), "video/x-raw-yuv"))
|
|
|
|
gst_caps_get_fourcc_int (caps, "format", &fourcc);
|
|
|
|
else
|
|
|
|
fourcc = GST_MAKE_FOURCC('R','G','B',' ');
|
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
if (gst_caps_has_property(caps, "width")) {
|
|
|
|
if (gst_caps_has_fixed_property(caps, "width")) {
|
|
|
|
gst_caps_get_int(caps, "width", &w);
|
|
|
|
} else {
|
2003-05-21 06:33:18 +00:00
|
|
|
int min;
|
|
|
|
gst_caps_get_int_range(caps, "width", &min, &w);
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-10 14:36:34 +00:00
|
|
|
if (gst_caps_has_property(caps, "height")) {
|
|
|
|
if (gst_caps_has_fixed_property(caps, "height")) {
|
|
|
|
gst_caps_get_int(caps, "height", &h);
|
|
|
|
} else {
|
2003-05-21 06:33:18 +00:00
|
|
|
int min;
|
|
|
|
gst_caps_get_int_range(caps, "height", &min, &h);
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
switch (fourcc)
|
|
|
|
{
|
|
|
|
case GST_MAKE_FOURCC('I','4','2','0'):
|
|
|
|
case GST_MAKE_FOURCC('I','Y','U','V'):
|
|
|
|
palette = VIDEO_PALETTE_YUV420P;
|
|
|
|
v4lsrc->buffer_size = ((w+1)&~1) * ((h+1)&~1) * 1.5;
|
|
|
|
goto try_caps;
|
|
|
|
case GST_MAKE_FOURCC('Y','U','Y','2'):
|
|
|
|
palette = VIDEO_PALETTE_YUV422;
|
|
|
|
v4lsrc->buffer_size = ((w+1)&~1) * h * 2;
|
|
|
|
goto try_caps;
|
|
|
|
case GST_MAKE_FOURCC('U','Y','V','Y'):
|
|
|
|
palette = VIDEO_PALETTE_UYVY;
|
|
|
|
v4lsrc->buffer_size = ((w+1)&~1) * h * 2;
|
|
|
|
goto try_caps;
|
|
|
|
case GST_MAKE_FOURCC('Y','4','1','P'):
|
|
|
|
palette = VIDEO_PALETTE_YUV411;
|
|
|
|
v4lsrc->buffer_size = ((w+3)&~3) * h * 1.5;
|
|
|
|
goto try_caps;
|
|
|
|
case GST_MAKE_FOURCC('R','G','B',' '):
|
|
|
|
depth = gst_caps_get_int (caps, "depth", &depth);
|
|
|
|
switch (depth)
|
|
|
|
{
|
|
|
|
case 15:
|
|
|
|
palette = VIDEO_PALETTE_RGB555;
|
|
|
|
v4lsrc->buffer_size = w * h * 2;
|
|
|
|
goto try_caps;
|
|
|
|
case 16:
|
|
|
|
palette = VIDEO_PALETTE_RGB565;
|
|
|
|
v4lsrc->buffer_size = w * h * 2;
|
|
|
|
goto try_caps;
|
|
|
|
case 24:
|
|
|
|
palette = VIDEO_PALETTE_RGB24;
|
|
|
|
v4lsrc->buffer_size = w * h * 3;
|
|
|
|
goto try_caps;
|
|
|
|
case 32:
|
|
|
|
palette = VIDEO_PALETTE_RGB32;
|
|
|
|
v4lsrc->buffer_size = w * h * 4;
|
|
|
|
goto try_caps;
|
|
|
|
default:
|
|
|
|
goto try_next;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
goto try_next;
|
|
|
|
}
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
/* if this caps wasn't useful, try the next one */
|
|
|
|
try_next:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* if this caps was useful, try it out */
|
|
|
|
try_caps:
|
2002-09-20 09:28:46 +00:00
|
|
|
/* try the current 'palette' out on the video device */
|
|
|
|
if (!gst_v4lsrc_try_palette(v4lsrc, palette))
|
2002-01-15 15:52:09 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* try to connect the pad/caps with the actual width/height */
|
2003-07-06 20:49:52 +00:00
|
|
|
newcaps = gst_v4lsrc_palette_to_caps_fixed(palette, w, h,
|
|
|
|
gst_v4lsrc_get_fps(v4lsrc));
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2002-03-03 00:53:25 +00:00
|
|
|
gst_caps_debug (newcaps, "new caps to set on v4lsrc's src pad");
|
2002-01-20 16:03:10 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
if ((ret_val = gst_pad_try_set_caps(v4lsrc->srcpad, newcaps)) == GST_PAD_LINK_REFUSED)
|
2002-01-15 15:52:09 +00:00
|
|
|
continue;
|
2003-01-10 10:22:25 +00:00
|
|
|
else if (ret_val == GST_PAD_LINK_DELAYED)
|
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
if (!gst_v4lsrc_set_capture(v4lsrc, w, h, palette))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-20 09:28:46 +00:00
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
if (!gst_v4lsrc_capture_init(v4lsrc))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DONE;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
/* still nothing - no good caps */
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_v4lsrc_getcaps (GstPad *pad,
|
|
|
|
GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstCaps *list = NULL;
|
|
|
|
GstV4lSrc *v4lsrc = GST_V4LSRC(gst_pad_get_parent(pad));
|
|
|
|
int palette[] = {
|
|
|
|
VIDEO_PALETTE_YUV422,
|
|
|
|
VIDEO_PALETTE_YUV420P,
|
|
|
|
VIDEO_PALETTE_UYVY,
|
|
|
|
VIDEO_PALETTE_YUV411P,
|
|
|
|
VIDEO_PALETTE_RGB555,
|
|
|
|
VIDEO_PALETTE_RGB565,
|
|
|
|
VIDEO_PALETTE_RGB24,
|
|
|
|
VIDEO_PALETTE_RGB32,
|
|
|
|
}, i;
|
|
|
|
struct video_capability *vcap = &GST_V4LELEMENT(v4lsrc)->vcap;
|
|
|
|
|
|
|
|
if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lsrc))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
GstCaps *one;
|
|
|
|
one = gst_v4lsrc_palette_to_caps_range(palette[i],
|
|
|
|
vcap->minwidth, vcap->maxwidth,
|
|
|
|
vcap->minheight, vcap->maxheight);
|
|
|
|
list = gst_caps_append(list, one);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static GstBuffer*
|
|
|
|
gst_v4lsrc_get (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstV4lSrc *v4lsrc;
|
2001-12-23 15:31:15 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
gint num;
|
2003-05-02 21:16:55 +00:00
|
|
|
gdouble fps = 0.;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
if (v4lsrc->use_fixed_fps &&
|
|
|
|
(fps = gst_v4lsrc_get_fps(v4lsrc)) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
buf = gst_buffer_new_from_pool(v4lsrc->bufferpool, 0, 0);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
gst_element_error(GST_ELEMENT(v4lsrc),
|
|
|
|
"Failed to create a new GstBuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
if (v4lsrc->need_writes > 0) {
|
|
|
|
/* use last frame */
|
|
|
|
num = v4lsrc->last_frame;
|
|
|
|
v4lsrc->need_writes--;
|
|
|
|
} else if (v4lsrc->clock && v4lsrc->use_fixed_fps) {
|
|
|
|
GstClockTime time;
|
|
|
|
gboolean have_frame = FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* by default, we use the frame once */
|
|
|
|
v4lsrc->need_writes = 1;
|
|
|
|
|
|
|
|
/* grab a frame from the device */
|
|
|
|
if (!gst_v4lsrc_grab_frame(v4lsrc, &num))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
v4lsrc->last_frame = num;
|
2003-05-21 06:33:18 +00:00
|
|
|
time = v4lsrc->timestamp_sync - v4lsrc->substract_time;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
/* decide how often we're going to write the frame - set
|
|
|
|
* v4lsrc->need_writes to (that-1) and have_frame to TRUE
|
|
|
|
* if we're going to write it - else, just continue.
|
|
|
|
*
|
|
|
|
* time is generally the system or audio clock. Let's
|
|
|
|
* say that we've written one second of audio, then we want
|
|
|
|
* to have written one second of video too, within the same
|
|
|
|
* timeframe. This means that if time - begin_time = X sec,
|
|
|
|
* we want to have written X*fps frames. If we've written
|
|
|
|
* more - drop, if we've written less - dup... */
|
2003-05-21 06:33:18 +00:00
|
|
|
if (v4lsrc->handled * (GST_SECOND/fps) - time > 1.5 * (GST_SECOND/fps)) {
|
2003-05-02 21:16:55 +00:00
|
|
|
/* yo dude, we've got too many frames here! Drop! DROP! */
|
|
|
|
v4lsrc->need_writes--; /* -= (v4lsrc->handled - (time / fps)); */
|
|
|
|
g_signal_emit(G_OBJECT(v4lsrc),
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_DROP], 0);
|
2003-05-21 06:33:18 +00:00
|
|
|
} else if (v4lsrc->handled * (GST_SECOND/fps) - time < - 1.5 * (GST_SECOND/fps)) {
|
2003-05-02 21:16:55 +00:00
|
|
|
/* this means we're lagging far behind */
|
|
|
|
v4lsrc->need_writes++; /* += ((time / fps) - v4lsrc->handled); */
|
|
|
|
g_signal_emit(G_OBJECT(v4lsrc),
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_INSERT], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v4lsrc->need_writes > 0) {
|
|
|
|
have_frame = TRUE;
|
|
|
|
v4lsrc->use_num_times[num] = v4lsrc->need_writes;
|
|
|
|
v4lsrc->need_writes--;
|
|
|
|
} else {
|
|
|
|
gst_v4lsrc_requeue_frame(v4lsrc, num);
|
|
|
|
}
|
|
|
|
} while (!have_frame);
|
|
|
|
} else {
|
|
|
|
/* grab a frame from the device */
|
|
|
|
if (!gst_v4lsrc_grab_frame(v4lsrc, &num))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
v4lsrc->use_num_times[num] = 1;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_BUFFER_DATA(buf) = gst_v4lsrc_get_buffer(v4lsrc, num);
|
|
|
|
GST_BUFFER_SIZE(buf) = v4lsrc->buffer_size;
|
2003-05-02 21:16:55 +00:00
|
|
|
if (v4lsrc->use_fixed_fps)
|
|
|
|
GST_BUFFER_TIMESTAMP(buf) = v4lsrc->handled * GST_SECOND / fps;
|
|
|
|
else /* calculate time based on our own clock */
|
2003-05-21 06:33:18 +00:00
|
|
|
GST_BUFFER_TIMESTAMP(buf) = v4lsrc->timestamp_sync - v4lsrc->substract_time;
|
2002-05-08 20:21:45 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
v4lsrc->handled++;
|
|
|
|
g_signal_emit(G_OBJECT(v4lsrc),
|
|
|
|
gst_v4lsrc_signals[SIGNAL_FRAME_CAPTURE], 0);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lsrc_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lSrc *v4lsrc;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
g_return_if_fail(GST_IS_V4LSRC(object));
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc = GST_V4LSRC(object);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-05-02 21:16:55 +00:00
|
|
|
case ARG_USE_FIXED_FPS:
|
|
|
|
if (!GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lsrc))) {
|
|
|
|
v4lsrc->use_fixed_fps = g_value_get_boolean(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-17 19:03:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lsrc_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lSrc *v4lsrc;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
g_return_if_fail(GST_IS_V4LSRC(object));
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc = GST_V4LSRC(object);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-01-07 09:31:34 +00:00
|
|
|
case ARG_NUMBUFS:
|
|
|
|
g_value_set_int(value, v4lsrc->mbuf.frames);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_BUFSIZE:
|
2002-04-14 10:27:10 +00:00
|
|
|
if (v4lsrc->mbuf.frames == 0)
|
|
|
|
g_value_set_int(value, 0);
|
|
|
|
else
|
|
|
|
g_value_set_int(value, v4lsrc->mbuf.size/(v4lsrc->mbuf.frames*1024));
|
2002-01-07 09:31:34 +00:00
|
|
|
break;
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
case ARG_USE_FIXED_FPS:
|
|
|
|
g_value_set_boolean(value, v4lsrc->use_fixed_fps);
|
|
|
|
break;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-17 19:03:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_v4lsrc_change_state (GstElement *element)
|
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lSrc *v4lsrc;
|
2003-05-02 21:16:55 +00:00
|
|
|
GTimeVal time;
|
2002-01-20 16:03:10 +00:00
|
|
|
gint transition = GST_STATE_TRANSITION (element);
|
2002-01-04 23:58:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(GST_IS_V4LSRC(element), GST_STATE_FAILURE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC(element);
|
|
|
|
|
2002-01-20 16:03:10 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2003-05-02 21:16:55 +00:00
|
|
|
v4lsrc->handled = 0;
|
|
|
|
v4lsrc->need_writes = 0;
|
|
|
|
v4lsrc->last_frame = 0;
|
|
|
|
v4lsrc->substract_time = 0;
|
2002-09-09 07:12:29 +00:00
|
|
|
/* buffer setup used to be done here, but I moved it to
|
|
|
|
* capsnego */
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2001-12-23 15:31:15 +00:00
|
|
|
/* queue all buffer, start streaming capture */
|
|
|
|
if (!gst_v4lsrc_capture_start(v4lsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
2003-05-02 21:16:55 +00:00
|
|
|
g_get_current_time(&time);
|
|
|
|
v4lsrc->substract_time = GST_TIMEVAL_TO_TIME(time) - v4lsrc->substract_time;
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
/* de-queue all queued buffers */
|
|
|
|
if (!gst_v4lsrc_capture_stop(v4lsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
2003-05-02 21:16:55 +00:00
|
|
|
g_get_current_time(&time);
|
|
|
|
v4lsrc->substract_time = GST_TIMEVAL_TO_TIME(time) - v4lsrc->substract_time;
|
2001-12-28 19:54:23 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
/* stop capturing, unmap all buffers */
|
|
|
|
if (!gst_v4lsrc_capture_deinit(v4lsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
break;
|
2002-01-20 16:03:10 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2002-01-04 23:58:11 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2003-05-02 21:16:55 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2002-01-04 23:58:11 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstBuffer*
|
|
|
|
gst_v4lsrc_buffer_new (GstBufferPool *pool,
|
2002-07-08 22:18:49 +00:00
|
|
|
guint64 offset,
|
|
|
|
guint size,
|
2001-12-23 15:31:15 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
2002-09-20 09:28:46 +00:00
|
|
|
GstV4lSrc *v4lsrc = GST_V4LSRC(user_data);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2002-09-20 09:28:46 +00:00
|
|
|
if (!GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lsrc)))
|
|
|
|
return NULL;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
buffer = gst_buffer_new();
|
2002-09-20 09:28:46 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* TODO: add interlacing info to buffer as metadata
|
|
|
|
* (height>288 or 240 = topfieldfirst, else noninterlaced) */
|
|
|
|
GST_BUFFER_MAXSIZE(buffer) = v4lsrc->mbuf.size / v4lsrc->mbuf.frames;
|
|
|
|
GST_BUFFER_FLAG_SET(buffer, GST_BUFFER_DONTFREE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return buffer;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
2002-07-08 22:18:49 +00:00
|
|
|
gst_v4lsrc_buffer_free (GstBufferPool *pool, GstBuffer *buf, gpointer user_data)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2002-07-08 22:18:49 +00:00
|
|
|
GstV4lSrc *v4lsrc = GST_V4LSRC (user_data);
|
2001-12-23 15:31:15 +00:00
|
|
|
int n;
|
|
|
|
|
2002-09-20 09:28:46 +00:00
|
|
|
if (gst_element_get_state(GST_ELEMENT(v4lsrc)) != GST_STATE_PLAYING)
|
|
|
|
return; /* we've already cleaned up ourselves */
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
for (n=0;n<v4lsrc->mbuf.frames;n++)
|
|
|
|
if (GST_BUFFER_DATA(buf) == gst_v4lsrc_get_buffer(v4lsrc, n))
|
|
|
|
{
|
2003-05-02 21:16:55 +00:00
|
|
|
v4lsrc->use_num_times[n]--;
|
|
|
|
if (v4lsrc->use_num_times[n] <= 0) {
|
|
|
|
gst_v4lsrc_requeue_frame(v4lsrc, n);
|
|
|
|
}
|
2002-09-20 09:28:46 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2002-09-20 09:28:46 +00:00
|
|
|
if (n == v4lsrc->mbuf.frames)
|
|
|
|
gst_element_error(GST_ELEMENT(v4lsrc),
|
|
|
|
"Couldn\'t find the buffer");
|
|
|
|
|
|
|
|
/* free struct */
|
|
|
|
gst_buffer_default_free(buf);
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
static void
|
|
|
|
gst_v4lsrc_set_clock (GstElement *element,
|
|
|
|
GstClock *clock)
|
|
|
|
{
|
|
|
|
GST_V4LSRC(element)->clock = clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static gboolean
|
2001-12-23 15:31:15 +00:00
|
|
|
plugin_init (GModule *module,
|
|
|
|
GstPlugin *plugin)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* create an elementfactory for the v4lsrc */
|
2002-04-11 20:42:27 +00:00
|
|
|
factory = gst_element_factory_new("v4lsrc",GST_TYPE_V4LSRC,
|
2001-12-17 19:03:14 +00:00
|
|
|
&gst_v4lsrc_details);
|
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2002-04-11 20:42:27 +00:00
|
|
|
src_template = gst_pad_template_new (
|
2002-01-15 15:52:09 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-05-10 14:36:34 +00:00
|
|
|
NULL);
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2002-04-11 20:42:27 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, src_template);
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"v4lsrc",
|
|
|
|
plugin_init
|
|
|
|
};
|