2001-12-23 15:31:15 +00:00
|
|
|
/* G-Streamer hardware MJPEG video source plugin
|
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 <string.h>
|
|
|
|
#include "v4lmjpegsrc_calls.h"
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstElementDetails gst_v4lmjpegsrc_details = {
|
|
|
|
"Video (video4linux/MJPEG) Source",
|
|
|
|
"Source/Video",
|
|
|
|
"Reads MJPEG-encoded frames from a zoran MJPEG/video4linux device",
|
2003-11-02 14:47:52 +00:00
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>"
|
2001-12-23 15:31:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* V4lMjpegSrc signals and args */
|
|
|
|
enum {
|
2003-05-02 21:16:55 +00:00
|
|
|
SIGNAL_FRAME_CAPTURE,
|
|
|
|
SIGNAL_FRAME_DROP,
|
|
|
|
SIGNAL_FRAME_INSERT,
|
|
|
|
SIGNAL_FRAME_LOST,
|
2001-12-23 15:31:15 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* arguments */
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2003-05-10 14:36:34 +00:00
|
|
|
#if 0
|
2001-12-23 15:31:15 +00:00
|
|
|
ARG_X_OFFSET,
|
|
|
|
ARG_Y_OFFSET,
|
|
|
|
ARG_F_WIDTH,
|
|
|
|
ARG_F_HEIGHT,
|
2003-05-10 14:36:34 +00:00
|
|
|
/* normally, we would want to use subframe capture, however,
|
|
|
|
* for the time being it's easier if we disable it first */
|
|
|
|
#endif
|
2001-12-23 15:31:15 +00:00
|
|
|
ARG_QUALITY,
|
|
|
|
ARG_NUMBUFS,
|
2003-05-21 06:33:18 +00:00
|
|
|
ARG_BUFSIZE,
|
2003-05-02 21:16:55 +00:00
|
|
|
ARG_USE_FIXED_FPS
|
2001-12-23 15:31:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* init functions */
|
2003-11-02 14:47:52 +00:00
|
|
|
static void gst_v4lmjpegsrc_base_init (gpointer g_class);
|
2001-12-23 15:31:15 +00:00
|
|
|
static void gst_v4lmjpegsrc_class_init (GstV4lMjpegSrcClass *klass);
|
|
|
|
static void gst_v4lmjpegsrc_init (GstV4lMjpegSrc *v4lmjpegsrc);
|
|
|
|
|
|
|
|
/* pad/buffer functions */
|
2002-09-16 21:01:42 +00:00
|
|
|
static gboolean gst_v4lmjpegsrc_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_v4lmjpegsrc_srcconnect (GstPad *pad,
|
2002-01-15 15:52:09 +00:00
|
|
|
GstCaps *caps);
|
2003-10-08 16:08:22 +00:00
|
|
|
static GstData* gst_v4lmjpegsrc_get (GstPad *pad);
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstCaps* gst_v4lmjpegsrc_getcaps (GstPad *pad,
|
|
|
|
GstCaps *caps);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* get/set params */
|
|
|
|
static void gst_v4lmjpegsrc_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_v4lmjpegsrc_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
/* set_clock function for A/V sync */
|
|
|
|
static void gst_v4lmjpegsrc_set_clock (GstElement *element,
|
|
|
|
GstClock *clock);
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* state handling */
|
|
|
|
static GstElementStateReturn gst_v4lmjpegsrc_change_state (GstElement *element);
|
|
|
|
|
|
|
|
/* bufferpool functions */
|
|
|
|
static GstBuffer* gst_v4lmjpegsrc_buffer_new (GstBufferPool *pool,
|
2003-05-24 10:46:31 +00:00
|
|
|
guint64 offset,
|
2002-07-08 22:18:49 +00:00
|
|
|
guint size,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gst_v4lmjpegsrc_buffer_free (GstBufferPool *pool,
|
|
|
|
GstBuffer *buf,
|
2001-12-23 15:31:15 +00:00
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
static GstCaps *capslist = NULL;
|
|
|
|
static GstPadTemplate *src_template;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2003-05-02 21:16:55 +00:00
|
|
|
static guint gst_v4lmjpegsrc_signals[LAST_SIGNAL] = { 0 };
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_v4lmjpegsrc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4lmjpegsrc_type = 0;
|
|
|
|
|
|
|
|
if (!v4lmjpegsrc_type) {
|
|
|
|
static const GTypeInfo v4lmjpegsrc_info = {
|
|
|
|
sizeof(GstV4lMjpegSrcClass),
|
2003-11-02 14:47:52 +00:00
|
|
|
gst_v4lmjpegsrc_base_init,
|
2001-12-23 15:31:15 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_v4lmjpegsrc_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstV4lMjpegSrc),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_v4lmjpegsrc_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
v4lmjpegsrc_type = g_type_register_static(GST_TYPE_V4LELEMENT, "GstV4lMjpegSrc", &v4lmjpegsrc_info, 0);
|
|
|
|
}
|
|
|
|
return v4lmjpegsrc_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-02 14:47:52 +00:00
|
|
|
static void
|
|
|
|
gst_v4lmjpegsrc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (gstelement_class, &gst_v4lmjpegsrc_details);
|
|
|
|
|
|
|
|
caps = gst_caps_new ("v4lmjpegsrc_caps",
|
|
|
|
"video/x-jpeg",
|
|
|
|
gst_props_new (
|
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT),
|
|
|
|
NULL )
|
|
|
|
);
|
|
|
|
capslist = gst_caps_append(capslist, caps);
|
|
|
|
|
|
|
|
src_template = gst_pad_template_new (
|
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
capslist, NULL);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, src_template);
|
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
static void
|
|
|
|
gst_v4lmjpegsrc_class_init (GstV4lMjpegSrcClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_V4LELEMENT);
|
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
#if 0
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_X_OFFSET,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("x_offset","x_offset","x_offset",
|
2003-05-02 21:16:55 +00:00
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_WRITABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_Y_OFFSET,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("y_offset","y_offset","y_offset",
|
2003-05-02 21:16:55 +00:00
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_WRITABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_F_WIDTH,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("frame_width","frame_width","frame_width",
|
2003-05-02 21:16:55 +00:00
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_WRITABLE));
|
2001-12-23 15:31:15 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_F_HEIGHT,
|
2001-12-28 19:54:23 +00:00
|
|
|
g_param_spec_int("frame_height","frame_height","frame_height",
|
2003-05-02 21:16:55 +00:00
|
|
|
G_MININT,G_MAXINT,0,G_PARAM_WRITABLE));
|
2003-05-10 14:36:34 +00:00
|
|
|
#endif
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_QUALITY,
|
2003-11-09 20:04:08 +00:00
|
|
|
g_param_spec_int("quality","Quality","JPEG frame quality",
|
|
|
|
1,100,50,G_PARAM_READWRITE));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NUMBUFS,
|
2003-05-21 06:33:18 +00:00
|
|
|
g_param_spec_int("num_buffers","Num Buffers","Number of Buffers",
|
2003-11-09 20:04:08 +00:00
|
|
|
1,256,64,G_PARAM_READWRITE));
|
2003-05-21 06:33:18 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFSIZE,
|
|
|
|
g_param_spec_int("buffer_size", "Buffer Size", "Size of buffers",
|
2003-11-09 20:04:08 +00:00
|
|
|
0, 512*1024, 128*1024, G_PARAM_READABLE));
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
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_v4lmjpegsrc_signals[SIGNAL_FRAME_CAPTURE] =
|
|
|
|
g_signal_new("frame_capture", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lMjpegSrcClass, frame_capture),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_DROP] =
|
|
|
|
g_signal_new("frame_drop", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lMjpegSrcClass, frame_drop),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_INSERT] =
|
|
|
|
g_signal_new("frame_insert", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lMjpegSrcClass, frame_insert),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_LOST] =
|
|
|
|
g_signal_new("frame_lost", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET(GstV4lMjpegSrcClass, frame_lost),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__INT,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_INT);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_v4lmjpegsrc_set_property;
|
|
|
|
gobject_class->get_property = gst_v4lmjpegsrc_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_v4lmjpegsrc_change_state;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
gstelement_class->set_clock = gst_v4lmjpegsrc_set_clock;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4lmjpegsrc_init (GstV4lMjpegSrc *v4lmjpegsrc)
|
|
|
|
{
|
2003-05-21 06:33:18 +00:00
|
|
|
GST_FLAG_SET(GST_ELEMENT(v4lmjpegsrc), GST_ELEMENT_THREAD_SUGGESTED);
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
v4lmjpegsrc->srcpad = gst_pad_new_from_template (src_template, "src");
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(v4lmjpegsrc), v4lmjpegsrc->srcpad);
|
|
|
|
|
|
|
|
gst_pad_set_get_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_get);
|
2003-05-10 14:36:34 +00:00
|
|
|
gst_pad_set_getcaps_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_getcaps);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_srcconnect);
|
2002-09-16 21:01:42 +00:00
|
|
|
gst_pad_set_convert_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_srcconvert);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2002-07-08 22:18:49 +00:00
|
|
|
v4lmjpegsrc->bufferpool = gst_buffer_pool_new(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-12-20 23:14:41 +00:00
|
|
|
(GstBufferPoolBufferNewFunction)gst_v4lmjpegsrc_buffer_new,
|
2002-09-20 09:28:46 +00:00
|
|
|
NULL,
|
2002-12-20 23:14:41 +00:00
|
|
|
(GstBufferPoolBufferFreeFunction)gst_v4lmjpegsrc_buffer_free,
|
2002-07-08 22:18:49 +00:00
|
|
|
v4lmjpegsrc);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
#if 0
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lmjpegsrc->frame_width = 0;
|
|
|
|
v4lmjpegsrc->frame_height = 0;
|
|
|
|
v4lmjpegsrc->x_offset = -1;
|
|
|
|
v4lmjpegsrc->y_offset = -1;
|
2003-05-10 14:36:34 +00:00
|
|
|
#endif
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lmjpegsrc->quality = 50;
|
|
|
|
|
|
|
|
v4lmjpegsrc->numbufs = 64;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
/* no clock */
|
|
|
|
v4lmjpegsrc->clock = NULL;
|
|
|
|
|
|
|
|
/* fps */
|
|
|
|
v4lmjpegsrc->use_fixed_fps = TRUE;
|
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_v4lmjpegsrc_get_fps (GstV4lMjpegSrc *v4lmjpegsrc)
|
2002-09-16 21:01:42 +00:00
|
|
|
{
|
|
|
|
gint norm;
|
2003-07-06 20:49:52 +00:00
|
|
|
gfloat fps;
|
2003-05-02 21:16:55 +00:00
|
|
|
|
|
|
|
if (!v4lmjpegsrc->use_fixed_fps &&
|
|
|
|
v4lmjpegsrc->clock != NULL &&
|
|
|
|
v4lmjpegsrc->handled > 0) {
|
|
|
|
/* try to get time from clock master and calculate fps */
|
|
|
|
GstClockTime time = gst_clock_get_time(v4lmjpegsrc->clock) - v4lmjpegsrc->substract_time;
|
|
|
|
return v4lmjpegsrc->handled * GST_SECOND / time;
|
|
|
|
}
|
2002-09-16 21:01:42 +00:00
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
/* if that failed ... */
|
2002-09-16 21:01:42 +00:00
|
|
|
|
|
|
|
if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lmjpegsrc)))
|
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(v4lmjpegsrc), 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_v4lmjpegsrc_srcconvert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc;
|
|
|
|
gdouble fps;
|
|
|
|
|
|
|
|
v4lmjpegsrc = GST_V4LMJPEGSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if ((fps = gst_v4lmjpegsrc_get_fps(v4lmjpegsrc)) == 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 inline gulong
|
|
|
|
calc_bufsize (int hor_dec,
|
|
|
|
int ver_dec)
|
|
|
|
{
|
|
|
|
guint8 div = hor_dec * ver_dec;
|
|
|
|
guint32 num = (1024 * 512) / (div);
|
|
|
|
guint32 result = 2;
|
|
|
|
|
|
|
|
num--;
|
|
|
|
while (num) {
|
|
|
|
num >>= 1;
|
|
|
|
result <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result > (512 * 1024))
|
|
|
|
return (512 * 1024);
|
|
|
|
if (result < 8192)
|
|
|
|
return 8192;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-15 15:52:09 +00:00
|
|
|
gst_v4lmjpegsrc_srcconnect (GstPad *pad,
|
|
|
|
GstCaps *caps)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2003-01-10 13:38:32 +00:00
|
|
|
GstPadLinkReturn ret_val;
|
2003-05-10 14:36:34 +00:00
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc = GST_V4LMJPEGSRC(gst_pad_get_parent(pad));
|
|
|
|
gint hor_dec, ver_dec;
|
|
|
|
gint w, h;
|
|
|
|
gint max_w = GST_V4LELEMENT(v4lmjpegsrc)->vcap.maxwidth,
|
|
|
|
max_h = GST_V4LELEMENT(v4lmjpegsrc)->vcap.maxheight;
|
|
|
|
gulong bufsize;
|
2003-07-06 20:49:52 +00:00
|
|
|
gfloat fps = gst_v4lmjpegsrc_get_fps(v4lmjpegsrc);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
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(v4lmjpegsrc)))
|
2002-09-18 10:57:56 +00:00
|
|
|
{
|
2002-09-09 07:12:29 +00:00
|
|
|
if (!gst_v4lmjpegsrc_capture_deinit(v4lmjpegsrc))
|
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(v4lmjpegsrc)))
|
|
|
|
{
|
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
|
|
|
|
|
|
|
/* Note: basically, we don't give a damn about the opposite caps here.
|
|
|
|
* that might seem odd, but it isn't. we know that the opposite caps is
|
2003-07-06 20:49:52 +00:00
|
|
|
* either NULL or has mime type video/x-jpeg, and in both cases, we'll set
|
2002-09-09 07:12:29 +00:00
|
|
|
* our own mime type back and it'll work. Other properties are to be set
|
|
|
|
* by the src, not by the opposite caps */
|
|
|
|
|
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 {
|
|
|
|
int max;
|
2003-05-21 06:33:18 +00:00
|
|
|
gst_caps_get_int_range(caps, "width", &max, &w);
|
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 {
|
|
|
|
int max;
|
2003-05-21 06:33:18 +00:00
|
|
|
gst_caps_get_int_range(caps, "height", &max, &h);
|
2003-05-10 14:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* figure out decimation */
|
|
|
|
if (w >= max_w) {
|
|
|
|
hor_dec = 1;
|
|
|
|
} else if (w*2 >= max_w) {
|
|
|
|
hor_dec = 2;
|
|
|
|
} else {
|
|
|
|
hor_dec = 4;
|
|
|
|
}
|
|
|
|
if (h >= max_h) {
|
|
|
|
ver_dec = 1;
|
|
|
|
} else if (h*2 >= max_h) {
|
|
|
|
ver_dec = 2;
|
|
|
|
} else {
|
|
|
|
ver_dec = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate bufsize */
|
|
|
|
bufsize = calc_bufsize(hor_dec, ver_dec);
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
/* set buffer info */
|
2003-05-10 14:36:34 +00:00
|
|
|
if (!gst_v4lmjpegsrc_set_buffer(v4lmjpegsrc,
|
|
|
|
v4lmjpegsrc->numbufs, bufsize)) {
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-05-10 14:36:34 +00:00
|
|
|
}
|
2002-09-09 07:12:29 +00:00
|
|
|
|
|
|
|
/* set capture parameters and mmap the buffers */
|
2003-05-10 14:36:34 +00:00
|
|
|
if (hor_dec == ver_dec) {
|
|
|
|
if (!gst_v4lmjpegsrc_set_capture(v4lmjpegsrc,
|
|
|
|
hor_dec,
|
|
|
|
v4lmjpegsrc->quality)) {
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!gst_v4lmjpegsrc_set_capture_m(v4lmjpegsrc,
|
|
|
|
0, 0, max_w, max_h,
|
|
|
|
hor_dec, ver_dec,
|
|
|
|
v4lmjpegsrc->quality)) {
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
2002-09-09 07:12:29 +00:00
|
|
|
if (!v4lmjpegsrc->frame_width && !v4lmjpegsrc->frame_height &&
|
|
|
|
v4lmjpegsrc->x_offset < 0 && v4lmjpegsrc->y_offset < 0 &&
|
|
|
|
v4lmjpegsrc->horizontal_decimation == v4lmjpegsrc->vertical_decimation)
|
|
|
|
{
|
|
|
|
if (!gst_v4lmjpegsrc_set_capture(v4lmjpegsrc,
|
|
|
|
v4lmjpegsrc->horizontal_decimation, v4lmjpegsrc->quality))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-09 07:12:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!gst_v4lmjpegsrc_set_capture_m(v4lmjpegsrc,
|
|
|
|
v4lmjpegsrc->x_offset, v4lmjpegsrc->y_offset,
|
|
|
|
v4lmjpegsrc->frame_width, v4lmjpegsrc->frame_height,
|
|
|
|
v4lmjpegsrc->horizontal_decimation, v4lmjpegsrc->vertical_decimation,
|
|
|
|
v4lmjpegsrc->quality))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-09 07:12:29 +00:00
|
|
|
}
|
2003-05-10 14:36:34 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
/* we now have an actual width/height - *set it* */
|
|
|
|
caps = gst_caps_new("v4lmjpegsrc_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-jpeg",
|
2002-09-09 07:12:29 +00:00
|
|
|
gst_props_new(
|
2003-07-06 20:49:52 +00:00
|
|
|
"width", GST_PROPS_INT(v4lmjpegsrc->end_width),
|
|
|
|
"height", GST_PROPS_INT(v4lmjpegsrc->end_height),
|
|
|
|
"framerate", GST_PROPS_FLOAT(fps),
|
2002-09-09 07:12:29 +00:00
|
|
|
NULL ) );
|
2003-01-10 10:22:25 +00:00
|
|
|
if ((ret_val = gst_pad_try_set_caps(v4lmjpegsrc->srcpad, caps)) == GST_PAD_LINK_REFUSED)
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
else if (ret_val == GST_PAD_LINK_DELAYED)
|
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-09-18 10:57:56 +00:00
|
|
|
|
2002-09-09 07:12:29 +00:00
|
|
|
if (!gst_v4lmjpegsrc_capture_init(v4lmjpegsrc))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DONE;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
static GstData*
|
2001-12-23 15:31:15 +00:00
|
|
|
gst_v4lmjpegsrc_get (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc;
|
|
|
|
GstBuffer *buf;
|
|
|
|
gint num;
|
2003-05-02 21:16:55 +00:00
|
|
|
gdouble fps = 0;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
|
|
|
|
v4lmjpegsrc = GST_V4LMJPEGSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
if (v4lmjpegsrc->use_fixed_fps &&
|
|
|
|
(fps = gst_v4lmjpegsrc_get_fps(v4lmjpegsrc)) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
buf = gst_buffer_new_from_pool(v4lmjpegsrc->bufferpool, 0, 0);
|
|
|
|
if (!buf)
|
|
|
|
{
|
2003-09-16 10:00:02 +00:00
|
|
|
gst_element_error(GST_ELEMENT(v4lmjpegsrc),
|
|
|
|
"Failed to create a new GstBuffer");
|
2001-12-23 15:31:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
if (v4lmjpegsrc->need_writes > 0) {
|
|
|
|
/* use last frame */
|
|
|
|
num = v4lmjpegsrc->last_frame;
|
|
|
|
v4lmjpegsrc->need_writes--;
|
|
|
|
} else if (v4lmjpegsrc->clock && v4lmjpegsrc->use_fixed_fps) {
|
|
|
|
GstClockTime time;
|
|
|
|
gboolean have_frame = FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* by default, we use the frame once */
|
|
|
|
v4lmjpegsrc->need_writes = 1;
|
|
|
|
|
|
|
|
/* grab a frame from the device */
|
|
|
|
if (!gst_v4lmjpegsrc_grab_frame(v4lmjpegsrc, &num, &v4lmjpegsrc->last_size))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
v4lmjpegsrc->last_frame = num;
|
|
|
|
time = GST_TIMEVAL_TO_TIME(v4lmjpegsrc->bsync.timestamp) -
|
|
|
|
v4lmjpegsrc->substract_time;
|
|
|
|
|
|
|
|
/* first check whether we lost any frames according to the device */
|
|
|
|
if (v4lmjpegsrc->last_seq != 0) {
|
|
|
|
if (v4lmjpegsrc->bsync.seq - v4lmjpegsrc->last_seq > 1) {
|
|
|
|
v4lmjpegsrc->need_writes = v4lmjpegsrc->bsync.seq - v4lmjpegsrc->last_seq;
|
|
|
|
g_signal_emit(G_OBJECT(v4lmjpegsrc),
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_LOST], 0,
|
|
|
|
v4lmjpegsrc->bsync.seq - v4lmjpegsrc->last_seq - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v4lmjpegsrc->last_seq = v4lmjpegsrc->bsync.seq;
|
|
|
|
|
|
|
|
/* decide how often we're going to write the frame - set
|
|
|
|
* v4lmjpegsrc->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 (v4lmjpegsrc->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! */
|
|
|
|
v4lmjpegsrc->need_writes--; /* -= (v4lmjpegsrc->handled - (time / fps)); */
|
|
|
|
g_signal_emit(G_OBJECT(v4lmjpegsrc),
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_DROP], 0);
|
2003-05-21 06:33:18 +00:00
|
|
|
} else if (v4lmjpegsrc->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 */
|
|
|
|
v4lmjpegsrc->need_writes++; /* += ((time / fps) - v4lmjpegsrc->handled); */
|
|
|
|
g_signal_emit(G_OBJECT(v4lmjpegsrc),
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_INSERT], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v4lmjpegsrc->need_writes > 0) {
|
|
|
|
have_frame = TRUE;
|
|
|
|
v4lmjpegsrc->use_num_times[num] = v4lmjpegsrc->need_writes;
|
|
|
|
v4lmjpegsrc->need_writes--;
|
|
|
|
} else {
|
|
|
|
gst_v4lmjpegsrc_requeue_frame(v4lmjpegsrc, num);
|
|
|
|
}
|
|
|
|
} while (!have_frame);
|
|
|
|
} else {
|
|
|
|
/* grab a frame from the device */
|
|
|
|
if (!gst_v4lmjpegsrc_grab_frame(v4lmjpegsrc, &num, &v4lmjpegsrc->last_size))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
v4lmjpegsrc->use_num_times[num] = 1;
|
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
GST_BUFFER_DATA(buf) = gst_v4lmjpegsrc_get_buffer(v4lmjpegsrc, num);
|
2003-05-02 21:16:55 +00:00
|
|
|
GST_BUFFER_SIZE(buf) = v4lmjpegsrc->last_size;
|
|
|
|
if (v4lmjpegsrc->use_fixed_fps)
|
|
|
|
GST_BUFFER_TIMESTAMP(buf) = v4lmjpegsrc->handled * GST_SECOND / fps;
|
|
|
|
else /* calculate time based on our own clock */
|
|
|
|
GST_BUFFER_TIMESTAMP(buf) = GST_TIMEVAL_TO_TIME(v4lmjpegsrc->bsync.timestamp) -
|
|
|
|
v4lmjpegsrc->substract_time;
|
|
|
|
|
|
|
|
v4lmjpegsrc->handled++;
|
|
|
|
g_signal_emit(G_OBJECT(v4lmjpegsrc),
|
|
|
|
gst_v4lmjpegsrc_signals[SIGNAL_FRAME_CAPTURE], 0);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
return GST_DATA (buf);
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-10 14:36:34 +00:00
|
|
|
static GstCaps*
|
|
|
|
gst_v4lmjpegsrc_getcaps (GstPad *pad,
|
|
|
|
GstCaps *_caps)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc = GST_V4LMJPEGSRC(gst_pad_get_parent(pad));
|
|
|
|
struct video_capability *vcap = &GST_V4LELEMENT(v4lmjpegsrc)->vcap;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lmjpegsrc))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps = GST_CAPS_NEW("v4lmjpegsrc_jpeg_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-jpeg",
|
2003-05-10 14:36:34 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE(vcap->maxwidth/4,
|
|
|
|
vcap->maxwidth),
|
|
|
|
"height", GST_PROPS_INT_RANGE(vcap->maxheight/4,
|
|
|
|
vcap->maxheight),
|
2003-07-06 20:49:52 +00:00
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE(0, G_MAXFLOAT),
|
2003-05-10 14:36:34 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
static void
|
|
|
|
gst_v4lmjpegsrc_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc;
|
|
|
|
|
|
|
|
g_return_if_fail(GST_IS_V4LMJPEGSRC(object));
|
|
|
|
v4lmjpegsrc = GST_V4LMJPEGSRC(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-05-10 14:36:34 +00:00
|
|
|
#if 0
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_X_OFFSET:
|
|
|
|
v4lmjpegsrc->x_offset = g_value_get_int(value);
|
|
|
|
break;
|
|
|
|
case ARG_Y_OFFSET:
|
|
|
|
v4lmjpegsrc->y_offset = g_value_get_int(value);
|
|
|
|
break;
|
|
|
|
case ARG_F_WIDTH:
|
|
|
|
v4lmjpegsrc->frame_width = g_value_get_int(value);
|
|
|
|
break;
|
|
|
|
case ARG_F_HEIGHT:
|
|
|
|
v4lmjpegsrc->frame_height = g_value_get_int(value);
|
|
|
|
break;
|
2003-05-10 14:36:34 +00:00
|
|
|
#endif
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_QUALITY:
|
|
|
|
v4lmjpegsrc->quality = g_value_get_int(value);
|
|
|
|
break;
|
|
|
|
case ARG_NUMBUFS:
|
|
|
|
v4lmjpegsrc->numbufs = g_value_get_int(value);
|
|
|
|
break;
|
2003-05-02 21:16:55 +00:00
|
|
|
case ARG_USE_FIXED_FPS:
|
|
|
|
if (!GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lmjpegsrc))) {
|
|
|
|
v4lmjpegsrc->use_fixed_fps = g_value_get_boolean(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_v4lmjpegsrc_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc;
|
|
|
|
|
|
|
|
g_return_if_fail(GST_IS_V4LMJPEGSRC(object));
|
|
|
|
v4lmjpegsrc = GST_V4LMJPEGSRC(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-05-10 14:36:34 +00:00
|
|
|
#if 0
|
2002-02-20 07:25:40 +00:00
|
|
|
case ARG_X_OFFSET:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->x_offset);
|
|
|
|
break;
|
|
|
|
case ARG_Y_OFFSET:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->y_offset);
|
|
|
|
break;
|
|
|
|
case ARG_F_WIDTH:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->frame_width);
|
|
|
|
break;
|
|
|
|
case ARG_F_HEIGHT:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->frame_height);
|
|
|
|
break;
|
2003-05-10 14:36:34 +00:00
|
|
|
#endif
|
2002-02-20 07:25:40 +00:00
|
|
|
case ARG_QUALITY:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->quality);
|
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
case ARG_NUMBUFS:
|
2003-11-09 20:04:08 +00:00
|
|
|
if (GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lmjpegsrc)))
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->breq.count);
|
|
|
|
else
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->numbufs);
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
2003-05-21 06:33:18 +00:00
|
|
|
case ARG_BUFSIZE:
|
|
|
|
g_value_set_int(value, v4lmjpegsrc->breq.size);
|
|
|
|
break;
|
2003-05-02 21:16:55 +00:00
|
|
|
case ARG_USE_FIXED_FPS:
|
|
|
|
g_value_set_boolean(value, v4lmjpegsrc->use_fixed_fps);
|
|
|
|
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 GstElementStateReturn
|
|
|
|
gst_v4lmjpegsrc_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc;
|
2003-05-02 21:16:55 +00:00
|
|
|
GTimeVal time;
|
2002-01-04 23:58:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(GST_IS_V4LMJPEGSRC(element), GST_STATE_FAILURE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lmjpegsrc = GST_V4LMJPEGSRC(element);
|
|
|
|
|
2001-12-28 19:54:23 +00:00
|
|
|
switch (GST_STATE_TRANSITION(element)) {
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2002-09-09 07:12:29 +00:00
|
|
|
/* actual buffer set-up used to be done here - but I moved
|
|
|
|
* it to capsnego itself */
|
2003-05-02 21:16:55 +00:00
|
|
|
v4lmjpegsrc->handled = 0;
|
|
|
|
v4lmjpegsrc->need_writes = 0;
|
|
|
|
v4lmjpegsrc->last_frame = 0;
|
|
|
|
v4lmjpegsrc->substract_time = 0;
|
2002-01-06 21:38:22 +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_v4lmjpegsrc_capture_start(v4lmjpegsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
2003-05-02 21:16:55 +00:00
|
|
|
g_get_current_time(&time);
|
|
|
|
v4lmjpegsrc->substract_time = GST_TIMEVAL_TO_TIME(time) -
|
|
|
|
v4lmjpegsrc->substract_time;
|
|
|
|
v4lmjpegsrc->last_seq = 0;
|
2001-12-23 15:31:15 +00:00
|
|
|
break;
|
2001-12-28 19:54:23 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2003-05-02 21:16:55 +00:00
|
|
|
g_get_current_time(&time);
|
|
|
|
v4lmjpegsrc->substract_time = GST_TIMEVAL_TO_TIME(time) -
|
|
|
|
v4lmjpegsrc->substract_time;
|
2001-12-28 19:54:23 +00:00
|
|
|
/* de-queue all queued buffers */
|
|
|
|
if (!gst_v4lmjpegsrc_capture_stop(v4lmjpegsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
/* stop capturing, unmap all buffers */
|
|
|
|
if (!gst_v4lmjpegsrc_capture_deinit(v4lmjpegsrc))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
2002-01-04 23:58:11 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2003-10-10 12:47:41 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2002-01-04 23:58:11 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-02 21:16:55 +00:00
|
|
|
static void
|
|
|
|
gst_v4lmjpegsrc_set_clock (GstElement *element,
|
|
|
|
GstClock *clock)
|
|
|
|
{
|
|
|
|
GST_V4LMJPEGSRC(element)->clock = clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
static GstBuffer*
|
|
|
|
gst_v4lmjpegsrc_buffer_new (GstBufferPool *pool,
|
2003-05-24 10:46:31 +00:00
|
|
|
guint64 offset,
|
2002-07-08 22:18:49 +00:00
|
|
|
guint size,
|
2001-12-23 15:31:15 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
2002-09-20 09:28:46 +00:00
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc = GST_V4LMJPEGSRC(user_data);
|
|
|
|
|
|
|
|
if (!GST_V4L_IS_ACTIVE(GST_V4LELEMENT(v4lmjpegsrc)))
|
|
|
|
return NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
buffer = gst_buffer_new();
|
2002-09-20 09:28:46 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* TODO: add interlacing info to buffer as metadata */
|
2002-09-20 09:28:46 +00:00
|
|
|
GST_BUFFER_MAXSIZE(buffer) = v4lmjpegsrc->breq.size;
|
|
|
|
GST_BUFFER_FLAG_SET(buffer, GST_BUFFER_DONTFREE);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-07-08 22:18:49 +00:00
|
|
|
gst_v4lmjpegsrc_buffer_free (GstBufferPool *pool, GstBuffer *buf, gpointer user_data)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2002-07-08 22:18:49 +00:00
|
|
|
GstV4lMjpegSrc *v4lmjpegsrc = GST_V4LMJPEGSRC (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(v4lmjpegsrc)) != GST_STATE_PLAYING)
|
|
|
|
return; /* we've already cleaned up ourselves */
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
for (n=0;n<v4lmjpegsrc->breq.count;n++)
|
|
|
|
if (GST_BUFFER_DATA(buf) == gst_v4lmjpegsrc_get_buffer(v4lmjpegsrc, n))
|
|
|
|
{
|
2003-05-02 21:16:55 +00:00
|
|
|
v4lmjpegsrc->use_num_times[n]--;
|
|
|
|
if (v4lmjpegsrc->use_num_times[n] <= 0) {
|
|
|
|
gst_v4lmjpegsrc_requeue_frame(v4lmjpegsrc, n);
|
|
|
|
}
|
2002-09-20 09:28:46 +00:00
|
|
|
break;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 09:28:46 +00:00
|
|
|
if (n == v4lmjpegsrc->breq.count)
|
2003-09-16 10:00:02 +00:00
|
|
|
gst_element_error(GST_ELEMENT(v4lmjpegsrc),
|
|
|
|
"Couldn't find the buffer");
|
2002-09-20 09:28:46 +00:00
|
|
|
|
|
|
|
/* free the buffer struct et all */
|
|
|
|
gst_buffer_default_free(buf);
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|