2004-06-15 09:11:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* gstv4lmjpegsink.c: hardware MJPEG video sink plugin
|
|
|
|
*
|
2002-01-31 22:22:42 +00:00
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2001-12-24 21:42: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
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-12-24 21:42:14 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "v4lmjpegsink_calls.h"
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_CATEGORY (v4lmjpegsink_debug);
|
|
|
|
#define GST_CAT_DEFAULT v4lmjpegsink_debug
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2006-03-24 10:42:11 +00:00
|
|
|
static GstElementDetails gst_v4lmjpegsink_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Video (video4linux/MJPEG) sink",
|
|
|
|
"Sink/Video",
|
|
|
|
"Writes MJPEG-encoded frames to a zoran MJPEG/video4linux device",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
/* v4lmjpegsink signals and args */
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-24 21:42:14 +00:00
|
|
|
SIGNAL_FRAME_DISPLAYED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-24 21:42:14 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_NUMBUFS,
|
|
|
|
ARG_BUFSIZE,
|
|
|
|
ARG_X_OFFSET,
|
|
|
|
ARG_Y_OFFSET,
|
|
|
|
ARG_FRAMES_DISPLAYED,
|
2004-05-21 23:53:07 +00:00
|
|
|
ARG_FRAME_TIME
|
2001-12-24 21:42:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* init functions */
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_v4lmjpegsink_base_init (gpointer g_class);
|
|
|
|
static void gst_v4lmjpegsink_class_init (GstV4lMjpegSinkClass * klass);
|
|
|
|
static void gst_v4lmjpegsink_init (GstV4lMjpegSink * v4lmjpegsink);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
/* the chain of buffers */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstPadLinkReturn gst_v4lmjpegsink_sinkconnect (GstPad * pad,
|
|
|
|
const GstCaps * vscapslist);
|
|
|
|
static void gst_v4lmjpegsink_chain (GstPad * pad, GstData * _data);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
/* get/set gst object functions */
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_v4lmjpegsink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_v4lmjpegsink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn gst_v4lmjpegsink_change_state (GstElement *
|
2004-03-14 22:34:34 +00:00
|
|
|
element);
|
|
|
|
static void gst_v4lmjpegsink_set_clock (GstElement * element, GstClock * clock);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2002-09-20 09:28:46 +00:00
|
|
|
|
2001-12-24 21:42:14 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_v4lmjpegsink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_v4lmjpegsink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4lmjpegsink_type = 0;
|
|
|
|
|
|
|
|
if (!v4lmjpegsink_type) {
|
|
|
|
static const GTypeInfo v4lmjpegsink_info = {
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstV4lMjpegSinkClass),
|
2003-11-02 14:47:52 +00:00
|
|
|
gst_v4lmjpegsink_base_init,
|
2001-12-24 21:42:14 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GClassInitFunc) gst_v4lmjpegsink_class_init,
|
2001-12-24 21:42:14 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstV4lMjpegSink),
|
2001-12-24 21:42:14 +00:00
|
|
|
0,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GInstanceInitFunc) gst_v4lmjpegsink_init,
|
2001-12-24 21:42:14 +00:00
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_V4LELEMENT, "GstV4lMjpegSink",
|
|
|
|
&v4lmjpegsink_info, 0);
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
|
|
|
return v4lmjpegsink_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 14:47:52 +00:00
|
|
|
static void
|
|
|
|
gst_v4lmjpegsink_base_init (gpointer g_class)
|
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
ext/ogg/gstoggmux.c: Basic pad template which accepts OGM tracks, speex, flac, vorbis and theora. Any is incorrect.
Original commit message from CVS:
* ext/ogg/gstoggmux.c:
Basic pad template which accepts OGM tracks, speex, flac, vorbis
and theora. Any is incorrect.
* gst/asfdemux/gstasfmux.c: (gst_asfmux_vidsink_link):
Fix caps.
* sys/v4l/gstv4lmjpegsink.c: (gst_v4lmjpegsink_base_init):
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_base_init),
(gst_v4lmjpegsrc_init), (gst_v4lmjpegsrc_srcconnect),
(gst_v4lmjpegsrc_getcaps), (gst_v4lmjpegsrc_change_state):
* sys/v4l/gstv4lmjpegsrc.h:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_src_link), (gst_v4lsrc_getcaps),
(gst_v4lsrc_change_state):
* sys/v4l/v4lmjpegsrc_calls.c: (gst_v4lmjpegsrc_capture_start),
(gst_v4lmjpegsrc_capture_stop):
Fix caps. Keep track of internal state. Work.
2004-10-24 13:41:18 +00:00
|
|
|
GST_STATIC_CAPS ("image/jpeg, "
|
2004-03-15 19:32:28 +00:00
|
|
|
"width = (int) [ 1, MAX ], "
|
2005-11-22 23:39:12 +00:00
|
|
|
"height = (int) [ 1, MAX ], " "framerate = (fraction) [ 0, MAX ]")
|
2004-03-14 22:34:34 +00:00
|
|
|
);
|
2003-11-02 14:47:52 +00:00
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (gstelement_class, &gst_v4lmjpegsink_details);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2003-11-02 14:47:52 +00:00
|
|
|
}
|
2001-12-24 21:42:14 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_class_init (GstV4lMjpegSinkClass * klass)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2006-04-08 21:02:53 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUMBUFS,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("num-buffers", "num-buffers", "num-buffers",
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BUFSIZE,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("buffer-size", "buffer-size", "buffer-size",
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_X_OFFSET,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("x-offset", "x-offset", "x-offset",
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_Y_OFFSET,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("y-offset", "y-offset", "y-offset",
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAMES_DISPLAYED,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("frames-displayed", "frames-displayed",
|
|
|
|
"frames-displayed", G_MININT, G_MAXINT, 0, G_PARAM_READABLE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAME_TIME,
|
2004-06-15 09:11:06 +00:00
|
|
|
g_param_spec_int ("frame-time", "frame-time", "frame-time", G_MININT,
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MAXINT, 0, G_PARAM_READABLE));
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (v4lmjpegsink_debug, "v4lmjpegsink", 0,
|
|
|
|
"V4L MJPEG sink element");
|
2001-12-24 21:42:14 +00:00
|
|
|
gobject_class->set_property = gst_v4lmjpegsink_set_property;
|
|
|
|
gobject_class->get_property = gst_v4lmjpegsink_get_property;
|
|
|
|
|
|
|
|
gst_v4lmjpegsink_signals[SIGNAL_FRAME_DISPLAYED] =
|
2004-03-14 22:34:34 +00:00
|
|
|
g_signal_new ("frame-displayed", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstV4lMjpegSinkClass,
|
2004-03-15 19:32:28 +00:00
|
|
|
frame_displayed), NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
2004-03-14 22:34:34 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_v4lmjpegsink_change_state;
|
2004-03-14 22:34:34 +00:00
|
|
|
gstelement_class->set_clock = gst_v4lmjpegsink_set_clock;
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_init (GstV4lMjpegSink * v4lmjpegsink)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
2004-01-02 21:57:10 +00:00
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (v4lmjpegsink);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
2004-03-15 19:32:28 +00:00
|
|
|
"sink"), "sink");
|
2001-12-24 21:42:14 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (v4lmjpegsink), v4lmjpegsink->sinkpad);
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2001-12-24 21:42:14 +00:00
|
|
|
gst_pad_set_chain_function (v4lmjpegsink->sinkpad, gst_v4lmjpegsink_chain);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_pad_set_link_function (v4lmjpegsink->sinkpad,
|
|
|
|
gst_v4lmjpegsink_sinkconnect);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2002-02-16 17:09:01 +00:00
|
|
|
v4lmjpegsink->clock = NULL;
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
v4lmjpegsink->width = -1;
|
|
|
|
v4lmjpegsink->height = -1;
|
|
|
|
|
|
|
|
v4lmjpegsink->x_offset = -1;
|
|
|
|
v4lmjpegsink->y_offset = -1;
|
|
|
|
|
|
|
|
v4lmjpegsink->numbufs = 64;
|
|
|
|
v4lmjpegsink->bufsize = 256;
|
|
|
|
|
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
Original commit message from CVS:
* examples/indexing/indexmpeg.c: (main):
* ext/cdparanoia/gstcdparanoia.c: (cdparanoia_get),
(cdparanoia_open), (cdparanoia_close), (cdparanoia_event),
(cdparanoia_convert), (cdparanoia_query):
* ext/cdparanoia/gstcdparanoia.h:
* ext/gnomevfs/gstgnomevfssink.c: (gst_gnomevfssink_init),
(gst_gnomevfssink_open_file), (gst_gnomevfssink_close_file),
(gst_gnomevfssink_chain), (gst_gnomevfssink_change_state):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_init):
* gst/audioscale/gstaudioscale.c: (gst_audioscale_init):
* gst/playback/gststreamselector.c: (gst_stream_selector_init):
* gst/tcp/gstmultifdsink.c: (gst_multifdsink_init),
(gst_multifdsink_render), (gst_multifdsink_start),
(gst_multifdsink_stop):
* gst/tcp/gstmultifdsink.h:
* gst/tcp/gsttcpclientsink.c: (gst_tcpclientsink_init),
(gst_tcpclientsink_render), (gst_tcpclientsink_start),
(gst_tcpclientsink_stop):
* gst/tcp/gsttcpclientsink.h:
* gst/tcp/gsttcpclientsrc.c: (gst_tcpclientsrc_init),
(gst_tcpclientsrc_getcaps), (gst_tcpclientsrc_create),
(gst_tcpclientsrc_start), (gst_tcpclientsrc_stop):
* gst/tcp/gsttcpclientsrc.h:
* gst/tcp/gsttcpserversink.h:
* gst/tcp/gsttcpserversrc.c: (gst_tcpserversrc_init),
(gst_tcpserversrc_create), (gst_tcpserversrc_start),
(gst_tcpserversrc_stop):
* gst/tcp/gsttcpserversrc.h:
* sys/v4l/gstv4lmjpegsink.c: (gst_v4lmjpegsink_init):
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_init):
* sys/ximage/ximagesink.c: (gst_ximagesink_init):
renamed GST_FLAGS macros to GST_OBJECT_FLAGS
moved bitshift from macro to enum definition
2005-10-12 14:32:29 +00:00
|
|
|
GST_OBJECT_FLAG_SET (v4lmjpegsink, GST_ELEMENT_THREAD_SUGGESTED);
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_sinkconnect (GstPad * pad, const GstCaps * vscapslist)
|
2002-01-15 15:52:09 +00:00
|
|
|
{
|
|
|
|
GstV4lMjpegSink *v4lmjpegsink;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2002-01-15 15:52:09 +00:00
|
|
|
|
|
|
|
v4lmjpegsink = GST_V4LMJPEGSINK (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 */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_V4L_IS_ACTIVE (GST_V4LELEMENT (v4lmjpegsink)))
|
|
|
|
if (!gst_v4lmjpegsink_playback_deinit (v4lmjpegsink))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (vscapslist, 0);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "width", &v4lmjpegsink->width);
|
|
|
|
gst_structure_get_int (structure, "height", &v4lmjpegsink->height);
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
if (!gst_v4lmjpegsink_set_playback (v4lmjpegsink, v4lmjpegsink->width, v4lmjpegsink->height, v4lmjpegsink->x_offset, v4lmjpegsink->y_offset, GST_V4LELEMENT (v4lmjpegsink)->vchan.norm, 0)) /* TODO: interlacing */
|
2003-12-22 01:47:09 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
|
|
|
|
/* set buffer info */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_set_buffer (v4lmjpegsink,
|
2004-03-15 19:32:28 +00:00
|
|
|
v4lmjpegsink->numbufs, v4lmjpegsink->bufsize))
|
2003-12-22 01:47:09 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_playback_init (v4lmjpegsink))
|
2003-12-22 01:47:09 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
2002-01-15 15:52:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 17:09:01 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_set_clock (GstElement * element, GstClock * clock)
|
2002-02-16 17:09:01 +00:00
|
|
|
{
|
|
|
|
GstV4lMjpegSink *v4mjpegsink = GST_V4LMJPEGSINK (element);
|
|
|
|
|
|
|
|
v4mjpegsink->clock = clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-24 21:42:14 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_chain (GstPad * pad, GstData * _data)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
2003-10-08 16:08:22 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-24 21:42:14 +00:00
|
|
|
GstV4lMjpegSink *v4lmjpegsink;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
v4lmjpegsink = GST_V4LMJPEGSINK (gst_pad_get_parent (pad));
|
|
|
|
|
2002-02-16 17:09:01 +00:00
|
|
|
if (v4lmjpegsink->clock) {
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_DEBUG ("videosink: clock wait: %" G_GUINT64_FORMAT,
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf));
|
2001-12-28 20:24:41 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_element_wait (GST_ELEMENT (v4lmjpegsink), GST_BUFFER_TIMESTAMP (buf));
|
2002-02-16 17:09:01 +00:00
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_BUFFER_POOL (buf) == v4lmjpegsink->bufferpool) {
|
|
|
|
num = GPOINTER_TO_INT (GST_BUFFER_POOL_PRIVATE (buf));
|
|
|
|
gst_v4lmjpegsink_play_frame (v4lmjpegsink, num);
|
|
|
|
} else {
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2002-09-20 09:28:46 +00:00
|
|
|
/* check size */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_BUFFER_SIZE (buf) > v4lmjpegsink->breq.size) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsink, RESOURCE, WRITE, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Buffer too big (%d KB), max. buffersize is %ld KB",
|
|
|
|
GST_BUFFER_SIZE (buf) / 1024, v4lmjpegsink->breq.size / 1024));
|
2002-09-20 09:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put JPEG data to the device */
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_wait_frame (v4lmjpegsink, &num);
|
|
|
|
memcpy (gst_v4lmjpegsink_get_buffer (v4lmjpegsink, num),
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_play_frame (v4lmjpegsink, num);
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_signal_emit (G_OBJECT (v4lmjpegsink),
|
|
|
|
gst_v4lmjpegsink_signals[SIGNAL_FRAME_DISPLAYED], 0);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_buffer_unref (buf);
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2002-09-20 09:28:46 +00:00
|
|
|
static GstBuffer *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_buffer_new (GstBufferPool * pool,
|
|
|
|
guint64 offset, guint size, gpointer user_data)
|
2002-09-20 09:28:46 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
GstV4lMjpegSink *v4lmjpegsink = GST_V4LMJPEGSINK (user_data);
|
2002-09-20 09:28:46 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
|
|
|
guint8 *data;
|
|
|
|
gint num;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!GST_V4L_IS_ACTIVE (GST_V4LELEMENT (v4lmjpegsink)))
|
2002-09-20 09:28:46 +00:00
|
|
|
return NULL;
|
|
|
|
if (v4lmjpegsink->breq.size < size) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("Requested buffer size is too large (%d > %ld)",
|
2004-03-15 19:32:28 +00:00
|
|
|
size, v4lmjpegsink->breq.size);
|
2002-09-20 09:28:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_wait_frame (v4lmjpegsink, &num))
|
2002-09-20 09:28:46 +00:00
|
|
|
return NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
data = gst_v4lmjpegsink_get_buffer (v4lmjpegsink, num);
|
2002-09-20 09:28:46 +00:00
|
|
|
if (!data)
|
|
|
|
return NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (buffer) = data;
|
|
|
|
GST_BUFFER_MAXSIZE (buffer) = v4lmjpegsink->breq.size;
|
|
|
|
GST_BUFFER_SIZE (buffer) = size;
|
|
|
|
GST_BUFFER_POOL (buffer) = pool;
|
|
|
|
GST_BUFFER_POOL_PRIVATE (buffer) = GINT_TO_POINTER (num);
|
2002-09-20 09:28:46 +00:00
|
|
|
|
|
|
|
/* with this flag set, we don't need our own buffer_free() function */
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_DONTFREE);
|
2002-09-20 09:28:46 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2002-09-20 09:28:46 +00:00
|
|
|
|
|
|
|
|
2001-12-24 21:42:14 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
|
|
|
GstV4lMjpegSink *v4lmjpegsink;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_V4LMJPEGSINK (object));
|
|
|
|
|
|
|
|
v4lmjpegsink = GST_V4LMJPEGSINK (object);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
switch (prop_id) {
|
2001-12-24 21:42:14 +00:00
|
|
|
case ARG_NUMBUFS:
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink->numbufs = g_value_get_int (value);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
case ARG_BUFSIZE:
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink->bufsize = g_value_get_int (value);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
case ARG_X_OFFSET:
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink->x_offset = g_value_get_int (value);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
case ARG_Y_OFFSET:
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink->y_offset = g_value_get_int (value);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
|
|
|
GstV4lMjpegSink *v4lmjpegsink;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink = GST_V4LMJPEGSINK (object);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_FRAMES_DISPLAYED:
|
|
|
|
g_value_set_int (value, v4lmjpegsink->frames_displayed);
|
|
|
|
break;
|
|
|
|
case ARG_FRAME_TIME:
|
2004-03-14 22:34:34 +00:00
|
|
|
g_value_set_int (value, v4lmjpegsink->frame_time / 1000000);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
case ARG_NUMBUFS:
|
|
|
|
g_value_set_int (value, v4lmjpegsink->numbufs);
|
|
|
|
break;
|
|
|
|
case ARG_BUFSIZE:
|
|
|
|
g_value_set_int (value, v4lmjpegsink->bufsize);
|
|
|
|
break;
|
|
|
|
default:
|
2002-01-15 15:52:09 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_v4lmjpegsink_change_state (GstElement * element, GstStateChange transition)
|
2001-12-24 21:42:14 +00:00
|
|
|
{
|
|
|
|
GstV4lMjpegSink *v4lmjpegsink;
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChangeReturn parent_value;
|
2001-12-24 21:42:14 +00:00
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
g_return_val_if_fail (GST_IS_V4LMJPEGSINK (element),
|
|
|
|
GST_STATE_CHANGE_FAILURE);
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsink = GST_V4LMJPEGSINK (element);
|
2001-12-24 21:42:14 +00:00
|
|
|
|
|
|
|
/* set up change state */
|
2005-09-02 15:43:18 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2002-09-09 07:12:29 +00:00
|
|
|
/* we used to do buffer setup here, but that's now done
|
|
|
|
* right after capsnego */
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2001-12-24 21:42:14 +00:00
|
|
|
/* start */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_playback_start (v4lmjpegsink))
|
2005-09-02 15:43:18 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2001-12-24 21:42:14 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2001-12-28 19:54:23 +00:00
|
|
|
/* de-queue all queued buffers */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_playback_stop (v4lmjpegsink))
|
2005-09-02 15:43:18 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2001-12-28 19:54:23 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2001-12-28 19:54:23 +00:00
|
|
|
/* stop playback, unmap all buffers */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsink_playback_deinit (v4lmjpegsink))
|
2005-09-02 15:43:18 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2001-12-28 19:54:23 +00:00
|
|
|
break;
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 15:14:41 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state) {
|
2005-09-02 15:43:18 +00:00
|
|
|
parent_value =
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2002-04-06 15:14:41 +00:00
|
|
|
} else {
|
2005-09-02 15:43:18 +00:00
|
|
|
parent_value = GST_STATE_CHANGE_FAILURE;
|
2002-04-06 15:14:41 +00:00
|
|
|
}
|
2002-01-04 23:58:11 +00:00
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return parent_value;
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
return GST_STATE_CHANGE_SUCCESS;
|
2001-12-24 21:42:14 +00:00
|
|
|
}
|