Ported goom.

Original commit message from CVS:
* configure.ac:
* gst/goom/Makefile.am:
* gst/goom/gstgoom.c: (gst_goom_init), (gst_goom_sink_setcaps),
(gst_goom_src_setcaps), (gst_goom_src_negotiate), (gst_goom_event),
(gst_goom_chain), (gst_goom_change_state), (plugin_init):
Ported goom.
Added goom and alpha to build.
This commit is contained in:
Wim Taymans 2005-05-18 09:58:13 +00:00
parent 97f9bab6e8
commit 9a43a5236c
4 changed files with 152 additions and 95 deletions

View file

@ -1,3 +1,13 @@
2005-05-18 Wim Taymans <wim@fluendo.com>
* configure.ac:
* gst/goom/Makefile.am:
* gst/goom/gstgoom.c: (gst_goom_init), (gst_goom_sink_setcaps),
(gst_goom_src_setcaps), (gst_goom_src_negotiate), (gst_goom_event),
(gst_goom_chain), (gst_goom_change_state), (plugin_init):
Ported goom.
Added goom and alpha to build.
2005-05-17 Wim Taymans <wim@fluendo.com> 2005-05-17 Wim Taymans <wim@fluendo.com>
* configure.ac: * configure.ac:

View file

@ -305,8 +305,10 @@ AC_SUBST(GST_PLUGIN_LDFLAGS)
dnl these are all the gst plug-ins, compilable without additional libs dnl these are all the gst plug-ins, compilable without additional libs
GST_PLUGINS_ALL="\ GST_PLUGINS_ALL="\
alpha \
videofilter \ videofilter \
effectv \ effectv \
goom \
law \ law \
rtp \ rtp \
rtsp \ rtsp \
@ -489,7 +491,9 @@ AC_CONFIG_FILES(
Makefile Makefile
gst-plugins.spec gst-plugins.spec
gst/Makefile gst/Makefile
gst/alpha/Makefile
gst/effectv/Makefile gst/effectv/Makefile
gst/goom/Makefile
gst/law/Makefile gst/law/Makefile
gst/rtp/Makefile gst/rtp/Makefile
gst/rtsp/Makefile gst/rtsp/Makefile

View file

@ -8,9 +8,9 @@ libgstgoom_la_SOURCES = gstgoom.c goom_core.c $(GOOM_FILTER_FILES) graphic.c lin
noinst_HEADERS = filters.h goom_core.h goom_tools.h graphic.h lines.h noinst_HEADERS = filters.h goom_core.h goom_tools.h graphic.h lines.h
libgstgoom_la_CFLAGS = $(GST_CFLAGS) $(GOOM_FILTER_CFLAGS) libgstgoom_la_CFLAGS = $(GST_CFLAGS) $(GOOM_FILTER_CFLAGS) $(GST_PLUGINS_LIBS_CFLAGS)
libgstgoom_la_LIBADD = libgstgoom_la_LIBADD =
libgstgoom_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstgoom_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS)
EXTRA_DIST = filters.c EXTRA_DIST = filters.c

View file

@ -62,7 +62,6 @@ struct _GstGOOM
gint width; gint width;
gint height; gint height;
gint channels; gint channels;
gboolean srcnegotiated;
gboolean disposed; gboolean disposed;
}; };
@ -121,13 +120,10 @@ static void gst_goom_dispose (GObject * object);
static GstElementStateReturn gst_goom_change_state (GstElement * element); static GstElementStateReturn gst_goom_change_state (GstElement * element);
static void gst_goom_chain (GstPad * pad, GstData * _data); static GstFlowReturn gst_goom_chain (GstPad * pad, GstBuffer * buffer);
static GstPadLinkReturn gst_goom_sinkconnect (GstPad * pad, static GstPadLinkReturn gst_goom_sink_setcaps (GstPad * pad, GstCaps * caps);
const GstCaps * caps); static GstPadLinkReturn gst_goom_src_setcaps (GstPad * pad, GstCaps * caps);
static GstPadLinkReturn gst_goom_srcconnect (GstPad * pad,
const GstCaps * caps);
static GstCaps *gst_goom_src_fixate (GstPad * pad, const GstCaps * caps);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -197,13 +193,9 @@ gst_goom_init (GstGOOM * goom)
gst_element_add_pad (GST_ELEMENT (goom), goom->sinkpad); gst_element_add_pad (GST_ELEMENT (goom), goom->sinkpad);
gst_element_add_pad (GST_ELEMENT (goom), goom->srcpad); gst_element_add_pad (GST_ELEMENT (goom), goom->srcpad);
GST_FLAG_SET (goom, GST_ELEMENT_EVENT_AWARE);
gst_pad_set_chain_function (goom->sinkpad, gst_goom_chain); gst_pad_set_chain_function (goom->sinkpad, gst_goom_chain);
gst_pad_set_link_function (goom->sinkpad, gst_goom_sinkconnect); gst_pad_set_setcaps_function (goom->sinkpad, gst_goom_sink_setcaps);
gst_pad_set_setcaps_function (goom->srcpad, gst_goom_src_setcaps);
gst_pad_set_link_function (goom->srcpad, gst_goom_srcconnect);
gst_pad_set_fixate_function (goom->srcpad, gst_goom_src_fixate);
goom->adapter = gst_adapter_new (); goom->adapter = gst_adapter_new ();
@ -216,8 +208,7 @@ gst_goom_init (GstGOOM * goom)
goom->samples_consumed = 0; goom->samples_consumed = 0;
goom->disposed = FALSE; goom->disposed = FALSE;
/* set to something */ goom_init (goom->width, goom->height);
goom_init (50, 50);
} }
static void static void
@ -236,28 +227,29 @@ gst_goom_dispose (GObject * object)
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
static GstPadLinkReturn static gboolean
gst_goom_sinkconnect (GstPad * pad, const GstCaps * caps) gst_goom_sink_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstGOOM *goom; GstGOOM *goom;
GstStructure *structure; GstStructure *structure;
goom = GST_GOOM (gst_pad_get_parent (pad)); goom = GST_GOOM (GST_PAD_PARENT (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "channels", &goom->channels); gst_structure_get_int (structure, "channels", &goom->channels);
gst_structure_get_int (structure, "rate", &goom->sample_rate); gst_structure_get_int (structure, "rate", &goom->sample_rate);
return GST_PAD_LINK_OK;
return TRUE;
} }
static GstPadLinkReturn static gboolean
gst_goom_srcconnect (GstPad * pad, const GstCaps * caps) gst_goom_src_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstGOOM *goom; GstGOOM *goom;
GstStructure *structure; GstStructure *structure;
goom = GST_GOOM (gst_pad_get_parent (pad)); goom = GST_GOOM (GST_PAD_PARENT (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
@ -266,81 +258,93 @@ gst_goom_srcconnect (GstPad * pad, const GstCaps * caps)
gst_structure_get_double (structure, "framerate", &goom->fps); gst_structure_get_double (structure, "framerate", &goom->fps);
goom_set_resolution (goom->width, goom->height); goom_set_resolution (goom->width, goom->height);
goom->srcnegotiated = TRUE;
return GST_PAD_LINK_OK; return TRUE;
} }
static GstCaps * static gboolean
gst_goom_src_fixate (GstPad * pad, const GstCaps * caps) gst_goom_src_negotiate (GstGOOM * goom)
{ {
GstCaps *newcaps; GstCaps *othercaps, *target, *intersect;
GstStructure *structure; GstStructure *structure;
const GstCaps *templ;
if (!gst_caps_is_simple (caps)) templ = gst_pad_get_pad_template_caps (goom->srcpad);
return NULL;
newcaps = gst_caps_copy (caps); /* see what the peer can do */
structure = gst_caps_get_structure (newcaps, 0); othercaps = gst_pad_peer_get_caps (goom->srcpad);
if (othercaps) {
intersect = gst_caps_intersect (othercaps, templ);
gst_caps_unref (othercaps);
if (gst_caps_structure_fixate_field_nearest_int (structure, "width", 320)) { if (gst_caps_is_empty (intersect))
return newcaps; goto no_format;
}
if (gst_caps_structure_fixate_field_nearest_int (structure, "height", 240)) { target = gst_caps_copy_nth (intersect, 0);
return newcaps; gst_caps_unref (intersect);
} } else {
if (gst_caps_structure_fixate_field_nearest_double (structure, "framerate", target = gst_caps_ref ((GstCaps *) templ);
30.0)) {
return newcaps;
} }
/* failed to fixate */ structure = gst_caps_get_structure (target, 0);
gst_caps_free (newcaps); gst_caps_structure_fixate_field_nearest_int (structure, "width", 320);
return NULL; gst_caps_structure_fixate_field_nearest_int (structure, "height", 240);
} gst_caps_structure_fixate_field_nearest_double (structure, "framerate", 30.0);
static void gst_pad_set_caps (goom->srcpad, target);
gst_goom_chain (GstPad * pad, GstData * _data) gst_caps_unref (target);
return TRUE;
no_format:
{ {
GstBuffer *bufin = GST_BUFFER (_data); gst_caps_unref (intersect);
GstGOOM *goom; gst_caps_unref (othercaps);
guint32 bytesperread; return FALSE;
gint16 *data; }
gint samples_per_frame; }
goom = GST_GOOM (gst_pad_get_parent (pad)); static gboolean
if (GST_IS_EVENT (bufin)) { gst_goom_event (GstPad * pad, GstEvent * event)
GstEvent *event = GST_EVENT (bufin); {
gboolean res;
GstGOOM *goom;
goom = GST_GOOM (GST_PAD_PARENT (pad));
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_DISCONTINUOUS: case GST_EVENT_DISCONTINUOUS:
{ {
gint64 value = 0; gint64 start = 0, stop = 0;
gst_event_discont_get_value (event, GST_FORMAT_TIME, &value); gst_event_discont_get_value (event, GST_FORMAT_TIME, &start, &stop);
gst_adapter_clear (goom->adapter); gst_adapter_clear (goom->adapter);
goom->audio_basetime = value; goom->audio_basetime = start;
goom->samples_consumed = 0; goom->samples_consumed = 0;
GST_DEBUG ("Got discont. Adjusting time to=%" G_GUINT64_FORMAT, value); GST_DEBUG ("Got discont. Adjusting time to=%" G_GUINT64_FORMAT, start);
} }
default: default:
gst_pad_event_default (pad, event); res = gst_pad_event_default (pad, event);
break; break;
} }
return; return res;
} }
if (goom->channels == 0) { static GstFlowReturn
GST_ELEMENT_ERROR (goom, CORE, NEGOTIATION, (NULL), gst_goom_chain (GstPad * pad, GstBuffer * bufin)
("Format wasn't negotiated before chain function")); {
gst_buffer_unref (bufin); GstGOOM *goom;
return; guint32 bytesperread;
} gint16 *data;
gint samples_per_frame;
GstFlowReturn ret;
if (!GST_PAD_IS_USABLE (goom->srcpad)) { goom = GST_GOOM (GST_PAD_PARENT (pad));
gst_buffer_unref (bufin);
return; GST_STREAM_LOCK (pad);
}
if (goom->channels == 0)
goto not_negotiated;
if (goom->audio_basetime == GST_CLOCK_TIME_NONE) if (goom->audio_basetime == GST_CLOCK_TIME_NONE)
goom->audio_basetime = GST_BUFFER_TIMESTAMP (bufin); goom->audio_basetime = GST_BUFFER_TIMESTAMP (bufin);
@ -358,16 +362,25 @@ gst_goom_chain (GstPad * pad, GstData * _data)
GST_BUFFER_SIZE (bufin) * sizeof (gint16) * goom->channels, GST_BUFFER_SIZE (bufin) * sizeof (gint16) * goom->channels,
GST_BUFFER_TIMESTAMP (bufin)); GST_BUFFER_TIMESTAMP (bufin));
ret = GST_FLOW_OK;
if (GST_RPAD_CAPS (goom->srcpad) == NULL) {
if (!gst_goom_src_negotiate (goom))
goto no_format;
}
/* Collect samples until we have enough for an output frame */ /* Collect samples until we have enough for an output frame */
while (gst_adapter_available (goom->adapter) > MAX (bytesperread, while (gst_adapter_available (goom->adapter) > MAX (bytesperread,
samples_per_frame * goom->channels * sizeof (gint16))) { samples_per_frame * goom->channels * sizeof (gint16))) {
const guint16 *data = const guint16 *data;
(const guint16 *) gst_adapter_peek (goom->adapter, bytesperread);
GstBuffer *bufout; GstBuffer *bufout;
guchar *out_frame; guchar *out_frame;
GstClockTimeDiff frame_duration = GST_SECOND / goom->fps; GstClockTimeDiff frame_duration;
gint i; gint i;
frame_duration = GST_SECOND / goom->fps;
data = (const guint16 *) gst_adapter_peek (goom->adapter, bytesperread);
if (goom->channels == 2) { if (goom->channels == 2) {
for (i = 0; i < GOOM_SAMPLES; i++) { for (i = 0; i < GOOM_SAMPLES; i++) {
goom->datain[0][i] = *data++; goom->datain[0][i] = *data++;
@ -380,7 +393,8 @@ gst_goom_chain (GstPad * pad, GstData * _data)
} }
} }
bufout = gst_buffer_new_and_alloc (goom->width * goom->height * 4); bufout = gst_pad_alloc_buffer (goom->srcpad, GST_BUFFER_OFFSET_NONE,
goom->width * goom->height * 4, GST_RPAD_CAPS (goom->srcpad));
GST_BUFFER_TIMESTAMP (bufout) = GST_BUFFER_TIMESTAMP (bufout) =
goom->audio_basetime + goom->audio_basetime +
(GST_SECOND * goom->samples_consumed / goom->sample_rate); (GST_SECOND * goom->samples_consumed / goom->sample_rate);
@ -393,11 +407,35 @@ gst_goom_chain (GstPad * pad, GstData * _data)
GST_DEBUG ("Pushing frame with time=%" G_GUINT64_FORMAT ", duration=%" GST_DEBUG ("Pushing frame with time=%" G_GUINT64_FORMAT ", duration=%"
G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (bufout), G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (bufout),
GST_BUFFER_DURATION (bufout)); GST_BUFFER_DURATION (bufout));
gst_pad_push (goom->srcpad, GST_DATA (bufout)); ret = gst_pad_push (goom->srcpad, bufout);
goom->samples_consumed += samples_per_frame; goom->samples_consumed += samples_per_frame;
gst_adapter_flush (goom->adapter, gst_adapter_flush (goom->adapter,
samples_per_frame * goom->channels * sizeof (gint16)); samples_per_frame * goom->channels * sizeof (gint16));
if (ret != GST_FLOW_OK)
break;
}
GST_STREAM_UNLOCK (pad);
return ret;
/* ERRORS */
not_negotiated:
{
GST_ELEMENT_ERROR (goom, CORE, NEGOTIATION, (NULL),
("Format wasn't negotiated before chain function"));
gst_buffer_unref (bufin);
GST_STREAM_UNLOCK (pad);
return GST_FLOW_NOT_NEGOTIATED;
}
no_format:
{
GST_ELEMENT_ERROR (goom, CORE, NEGOTIATION, (NULL),
("Could not negotiate format"));
gst_buffer_unref (bufin);
GST_STREAM_UNLOCK (pad);
return GST_FLOW_ERROR;
} }
} }
@ -405,35 +443,40 @@ static GstElementStateReturn
gst_goom_change_state (GstElement * element) gst_goom_change_state (GstElement * element)
{ {
GstGOOM *goom = GST_GOOM (element); GstGOOM *goom = GST_GOOM (element);
gint transition;
GstElementStateReturn ret;
switch (GST_STATE_TRANSITION (element)) { transition = GST_STATE_TRANSITION (element);
switch (transition) {
case GST_STATE_NULL_TO_READY: case GST_STATE_NULL_TO_READY:
break; break;
case GST_STATE_READY_TO_NULL:
break;
case GST_STATE_READY_TO_PAUSED: case GST_STATE_READY_TO_PAUSED:
goom->audio_basetime = GST_CLOCK_TIME_NONE; goom->audio_basetime = GST_CLOCK_TIME_NONE;
goom->srcnegotiated = FALSE;
gst_adapter_clear (goom->adapter); gst_adapter_clear (goom->adapter);
break;
case GST_STATE_PAUSED_TO_READY:
goom->channels = 0; goom->channels = 0;
break; break;
default: default:
break; break;
} }
if (GST_ELEMENT_CLASS (parent_class)->change_state) ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_STATE_SUCCESS; switch (transition) {
case GST_STATE_PAUSED_TO_READY:
break;
case GST_STATE_READY_TO_NULL:
break;
default:
break;
}
return ret;
} }
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
if (!gst_library_load ("gstbytestream"))
return FALSE;
return gst_element_register (plugin, "goom", GST_RANK_NONE, GST_TYPE_GOOM); return gst_element_register (plugin, "goom", GST_RANK_NONE, GST_TYPE_GOOM);
} }