2001-12-23 15:31:15 +00:00
|
|
|
/* G-Streamer BT8x8/V4L frame grabber plugin
|
|
|
|
* Copyright (C) 2001 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2001-12-23 15:31:15 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include "v4lsrc_calls.h"
|
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",
|
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 */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* arguments */
|
2001-12-17 19:03:14 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_WIDTH,
|
|
|
|
ARG_HEIGHT,
|
2002-01-07 09:31:34 +00:00
|
|
|
ARG_PALETTE,
|
|
|
|
ARG_PALETTE_NAME,
|
|
|
|
ARG_NUMBUFS,
|
|
|
|
ARG_BUFSIZE
|
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 */
|
|
|
|
static GstPadNegotiateReturn gst_v4lsrc_negotiate (GstPad *pad,
|
|
|
|
GstCaps **caps,
|
|
|
|
gpointer *user_data);
|
|
|
|
static GstCaps* gst_v4lsrc_create_caps (GstV4lSrc *v4lsrc);
|
|
|
|
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,
|
|
|
|
gint64 location,
|
|
|
|
gint size,
|
|
|
|
gpointer user_data);
|
|
|
|
static GstBuffer* gst_v4lsrc_buffer_copy (GstBuffer *srcbuf);
|
|
|
|
static void gst_v4lsrc_buffer_free (GstBuffer *buf);
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstElementClass *parent_class = NULL;\
|
|
|
|
//static guint gst_v4lsrc_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
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
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDTH,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("width","width","width",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
|
2001-12-17 19:03:14 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HEIGHT,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("height","height","height",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PALETTE,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("palette","palette","palette",
|
2002-01-07 09:31:34 +00:00
|
|
|
0,G_MAXUSHORT,0,G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PALETTE_NAME,
|
|
|
|
g_param_spec_string("palette_name","palette_name","palette_name",
|
|
|
|
NULL, G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NUMBUFS,
|
|
|
|
g_param_spec_int("num_buffers","num_buffers","num_buffers",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFSIZE,
|
|
|
|
g_param_spec_int("buffer_size","buffer_size","buffer_size",
|
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_READABLE));
|
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;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static void
|
|
|
|
gst_v4lsrc_init (GstV4lSrc *v4lsrc)
|
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->srcpad = gst_pad_new("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad(GST_ELEMENT(v4lsrc), v4lsrc->srcpad);
|
|
|
|
|
|
|
|
gst_pad_set_get_function (v4lsrc->srcpad, gst_v4lsrc_get);
|
|
|
|
gst_pad_set_negotiate_function (v4lsrc->srcpad, gst_v4lsrc_negotiate);
|
|
|
|
|
|
|
|
v4lsrc->bufferpool = gst_buffer_pool_new();
|
|
|
|
gst_buffer_pool_set_buffer_new_function(v4lsrc->bufferpool, gst_v4lsrc_buffer_new);
|
|
|
|
gst_buffer_pool_set_buffer_copy_function(v4lsrc->bufferpool, gst_v4lsrc_buffer_copy);
|
|
|
|
gst_buffer_pool_set_buffer_free_function(v4lsrc->bufferpool, gst_v4lsrc_buffer_free);
|
|
|
|
gst_buffer_pool_set_user_data(v4lsrc->bufferpool, v4lsrc);
|
|
|
|
|
|
|
|
v4lsrc->palette = VIDEO_PALETTE_YUV420P;
|
|
|
|
v4lsrc->width = 160;
|
|
|
|
v4lsrc->height = 120;
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * 1.5;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->init = TRUE;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static GstPadNegotiateReturn
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lsrc_negotiate (GstPad *pad,
|
|
|
|
GstCaps **caps,
|
|
|
|
gpointer *user_data)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
|
|
|
GstV4lSrc *v4lsrc;
|
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (!*caps) {
|
|
|
|
return GST_PAD_NEGOTIATE_FAIL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gint width, height;
|
|
|
|
gulong format;
|
|
|
|
|
|
|
|
width = gst_caps_get_int (*caps, "width");
|
|
|
|
height = gst_caps_get_int (*caps, "height");
|
2001-12-23 15:31:15 +00:00
|
|
|
format = gst_caps_get_fourcc_int (*caps, "format");
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
gint depth;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
depth = gst_caps_get_int (*caps, "depth");
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
switch (depth) {
|
2001-12-17 19:03:14 +00:00
|
|
|
case 15:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_RGB555;
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->buffer_size = width * height * 2;
|
|
|
|
break;
|
|
|
|
case 16:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_RGB565;
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->buffer_size = width * height * 2;
|
|
|
|
break;
|
|
|
|
case 24:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_RGB24;
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->buffer_size = width * height * 3;
|
|
|
|
break;
|
|
|
|
case 32:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_RGB32;
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->buffer_size = width * height * 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*caps = NULL;
|
|
|
|
return GST_PAD_NEGOTIATE_TRY;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_YUV420P;
|
|
|
|
v4lsrc->buffer_size = width * height * 1.5;
|
|
|
|
break;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
case GST_MAKE_FOURCC ('U','Y','V','Y'):
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_UYVY; //YUV422?;
|
|
|
|
v4lsrc->buffer_size = width * height * 2;
|
|
|
|
break;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y','U','Y','2'):
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->palette = VIDEO_PALETTE_YUYV; //YUV422?;
|
|
|
|
v4lsrc->buffer_size = width * height * 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* TODO: add YUV4:2:2 planar and YUV4:2:0 packed, maybe also YUV4:1:1? */
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
default:
|
|
|
|
*caps = NULL;
|
|
|
|
return GST_PAD_NEGOTIATE_TRY;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* if we get here, it's okay */
|
2001-12-17 19:03:14 +00:00
|
|
|
v4lsrc->width = width;
|
|
|
|
v4lsrc->height = height;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return GST_PAD_NEGOTIATE_AGREE;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GST_PAD_NEGOTIATE_FAIL;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
static GstCaps*
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lsrc_create_caps (GstV4lSrc *v4lsrc)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstCaps *caps = NULL;
|
2001-12-17 19:03:14 +00:00
|
|
|
gulong fourcc = 0;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
switch (v4lsrc->palette) {
|
|
|
|
case VIDEO_PALETTE_RGB555:
|
|
|
|
case VIDEO_PALETTE_RGB565:
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
|
|
|
case VIDEO_PALETTE_RGB32:
|
|
|
|
{
|
|
|
|
int depth=0, bpp=0;
|
|
|
|
|
|
|
|
fourcc = GST_STR_FOURCC ("RGB ");
|
|
|
|
|
|
|
|
switch (v4lsrc->palette) {
|
|
|
|
case VIDEO_PALETTE_RGB555:
|
|
|
|
depth = 15;
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB565:
|
|
|
|
depth = 16;
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
|
|
|
depth = 24;
|
|
|
|
bpp = 3;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB32:
|
|
|
|
depth = 32;
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps = GST_CAPS_NEW (
|
|
|
|
"v4lsrc_caps",
|
|
|
|
"video/raw",
|
|
|
|
"format", GST_PROPS_FOURCC (fourcc),
|
|
|
|
"width", GST_PROPS_INT (v4lsrc->width),
|
|
|
|
"height", GST_PROPS_INT (v4lsrc->height),
|
|
|
|
"bpp", GST_PROPS_INT (bpp),
|
|
|
|
"depth", GST_PROPS_INT (depth)
|
|
|
|
);
|
|
|
|
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * bpp;
|
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
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
case VIDEO_PALETTE_YUV422:
|
|
|
|
case VIDEO_PALETTE_YUV420P:
|
|
|
|
{
|
|
|
|
switch (v4lsrc->palette) {
|
|
|
|
case VIDEO_PALETTE_YUV422:
|
|
|
|
fourcc = (G_BYTE_ORDER == G_BIG_ENDIAN) ?
|
|
|
|
GST_STR_FOURCC("UYVY") : GST_STR_FOURCC("YUY2");
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * 2;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_YUYV:
|
|
|
|
fourcc = GST_STR_FOURCC("YUY2");
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * 2;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_UYVY:
|
|
|
|
fourcc = GST_STR_FOURCC("UYVY");
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * 2;
|
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_YUV420P:
|
|
|
|
fourcc = GST_STR_FOURCC("I420");
|
|
|
|
v4lsrc->buffer_size = v4lsrc->width * v4lsrc->height * 1.5;
|
|
|
|
break;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
caps = GST_CAPS_NEW (
|
2001-12-23 15:31:15 +00:00
|
|
|
"v4lsrc_caps",
|
|
|
|
"video/raw",
|
|
|
|
"format", GST_PROPS_FOURCC (fourcc),
|
|
|
|
"width", GST_PROPS_INT (v4lsrc->width),
|
|
|
|
"height", GST_PROPS_INT (v4lsrc->height)
|
|
|
|
);
|
|
|
|
|
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
|
|
|
default:
|
2001-12-23 15:31:15 +00:00
|
|
|
return NULL;
|
2001-12-17 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
|
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;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
if (v4lsrc->init) {
|
2001-12-17 19:03:14 +00:00
|
|
|
gst_pad_set_caps (v4lsrc->srcpad, gst_v4lsrc_create_caps (v4lsrc));
|
|
|
|
v4lsrc->init = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!gst_pad_get_caps (v4lsrc->srcpad) &&
|
|
|
|
!gst_pad_renegotiate (v4lsrc->srcpad)) {
|
|
|
|
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
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* grab a frame from the device */
|
|
|
|
if (!gst_v4lsrc_grab_frame(v4lsrc, &num))
|
|
|
|
return NULL;
|
|
|
|
GST_BUFFER_DATA(buf) = gst_v4lsrc_get_buffer(v4lsrc, num);
|
|
|
|
GST_BUFFER_SIZE(buf) = v4lsrc->buffer_size;
|
2001-12-23 19:14:18 +00:00
|
|
|
buf->timestamp = v4lsrc->timestamp_soft_sync[num].tv_sec * 1000000000 +
|
|
|
|
v4lsrc->timestamp_soft_sync[num].tv_usec * 1000;
|
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) {
|
|
|
|
case ARG_WIDTH:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->width = g_value_get_int(value);
|
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
|
|
|
case ARG_HEIGHT:
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lsrc->height = g_value_get_int(value);
|
2001-12-17 19:03:14 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
case ARG_PALETTE:
|
|
|
|
v4lsrc->palette = g_value_get_int(value);
|
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
|
|
|
default:
|
2001-12-28 19:54:23 +00:00
|
|
|
/*parent_class->set_property(object, prop_id, value, 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) {
|
|
|
|
case ARG_WIDTH:
|
2001-12-23 15:31:15 +00:00
|
|
|
g_value_set_int(value, v4lsrc->mmap.width);
|
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
|
|
|
case ARG_HEIGHT:
|
2001-12-23 15:31:15 +00:00
|
|
|
g_value_set_int(value, v4lsrc->mmap.height);
|
2001-12-17 19:03:14 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
case ARG_PALETTE:
|
|
|
|
g_value_set_int(value, v4lsrc->mmap.format);
|
2001-12-17 19:03:14 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-01-07 09:31:34 +00:00
|
|
|
case ARG_PALETTE_NAME:
|
|
|
|
g_value_set_string(value, g_strdup(palette_name[v4lsrc->mmap.format]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_NUMBUFS:
|
|
|
|
g_value_set_int(value, v4lsrc->mbuf.frames);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_BUFSIZE:
|
|
|
|
g_value_set_int(value, v4lsrc->mbuf.size/(v4lsrc->mbuf.frames*1024));
|
|
|
|
break;
|
|
|
|
|
2001-12-17 19:03:14 +00:00
|
|
|
default:
|
2001-12-28 19:54:23 +00:00
|
|
|
/*parent_class->get_property(object, prop_id, value, 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;
|
2002-01-04 23:58:11 +00:00
|
|
|
GstElementStateReturn parent_value;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_IS_V4LSRC(element), GST_STATE_FAILURE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lsrc = GST_V4LSRC(element);
|
|
|
|
|
2001-12-28 19:54:23 +00:00
|
|
|
switch (GST_STATE_TRANSITION(element)) {
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
/* set capture parameters and mmap the buffers */
|
|
|
|
if (!gst_v4lsrc_set_capture(v4lsrc, v4lsrc->width, v4lsrc->height, v4lsrc->palette))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
v4lsrc->init = TRUE;
|
|
|
|
if (!gst_v4lsrc_capture_init(v4lsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
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;
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
/* stop capturing, unmap all buffers */
|
|
|
|
if (!gst_v4lsrc_capture_deinit(v4lsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
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)
|
|
|
|
parent_value = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
if (GST_STATE_TRANSITION(element) == GST_STATE_NULL_TO_READY)
|
|
|
|
{
|
|
|
|
if ((GST_V4LELEMENT(v4lsrc)->norm >= VIDEO_MODE_PAL ||
|
|
|
|
GST_V4LELEMENT(v4lsrc)->norm < VIDEO_MODE_AUTO) ||
|
|
|
|
GST_V4LELEMENT(v4lsrc)->channel < 0)
|
|
|
|
if (!gst_v4l_set_chan_norm(GST_V4LELEMENT(v4lsrc),
|
|
|
|
0, GST_V4LELEMENT(v4lsrc)->norm))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return parent_value;
|
|
|
|
|
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,
|
|
|
|
gint64 location,
|
|
|
|
gint size,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
buffer = gst_buffer_new();
|
|
|
|
if (!buffer) return NULL;
|
|
|
|
buffer->pool_private = user_data;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* TODO: add interlacing info to buffer as metadata (height>288 or 240 = topfieldfirst, else noninterlaced) */
|
2001-12-17 19:03:14 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
static GstBuffer*
|
|
|
|
gst_v4lsrc_buffer_copy (GstBuffer *srcbuf)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstBuffer *buffer;
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
buffer = gst_buffer_new();
|
|
|
|
if (!buffer) return NULL;
|
|
|
|
GST_BUFFER_DATA(buffer) = g_malloc(GST_BUFFER_SIZE(srcbuf));
|
|
|
|
if (!GST_BUFFER_DATA(buffer)) return NULL;
|
|
|
|
GST_BUFFER_SIZE(buffer) = GST_BUFFER_SIZE(srcbuf);
|
|
|
|
memcpy(GST_BUFFER_DATA(buffer), GST_BUFFER_DATA(srcbuf), GST_BUFFER_SIZE(srcbuf));
|
|
|
|
GST_BUFFER_TIMESTAMP(buffer) = GST_BUFFER_TIMESTAMP(srcbuf);
|
|
|
|
|
|
|
|
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
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lsrc_buffer_free (GstBuffer *buf)
|
2001-12-17 19:03:14 +00:00
|
|
|
{
|
2001-12-23 15:31:15 +00:00
|
|
|
GstV4lSrc *v4lsrc = buf->pool_private;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n=0;n<v4lsrc->mbuf.frames;n++)
|
|
|
|
if (GST_BUFFER_DATA(buf) == gst_v4lsrc_get_buffer(v4lsrc, n))
|
|
|
|
{
|
|
|
|
gst_v4lsrc_requeue_frame(v4lsrc, n);
|
|
|
|
return;
|
|
|
|
}
|
2001-12-17 19:03:14 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_element_error(GST_ELEMENT(v4lsrc),
|
|
|
|
"Couldn't find the 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 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 */
|
2001-12-17 19:03:14 +00:00
|
|
|
factory = gst_elementfactory_new("v4lsrc",GST_TYPE_V4LSRC,
|
|
|
|
&gst_v4lsrc_details);
|
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
|
|
|
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
|
|
|
|
};
|