add ported videofilter to cvs head

Original commit message from CVS:
add ported videofilter to cvs head
This commit is contained in:
Christian Schaller 2005-05-06 11:25:56 +00:00
parent 5d82e5d18d
commit 393df2e486

View file

@ -51,7 +51,7 @@ static void gst_videofilter_set_property (GObject * object, guint prop_id,
static void gst_videofilter_get_property (GObject * object, guint prop_id, static void gst_videofilter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static void gst_videofilter_chain (GstPad * pad, GstData * _data); static GstFlowReturn gst_videofilter_chain (GstPad * pad, GstBuffer * buffer);
GstCaps *gst_videofilter_class_get_capslist (GstVideofilterClass * klass); GstCaps *gst_videofilter_class_get_capslist (GstVideofilterClass * klass);
static void gst_videofilter_setup (GstVideofilter * videofilter); static void gst_videofilter_setup (GstVideofilter * videofilter);
@ -172,70 +172,56 @@ gst_videofilter_getcaps (GstPad * pad)
{ {
GstVideofilter *videofilter; GstVideofilter *videofilter;
GstVideofilterClass *klass; GstVideofilterClass *klass;
GstCaps *caps;
//GstCaps *caps; GstPad *peer;
GstCaps *othercaps; int i;
GstPad *otherpad;
//int i;
GST_DEBUG ("gst_videofilter_getcaps"); GST_DEBUG ("gst_videofilter_getcaps");
videofilter = GST_VIDEOFILTER (gst_pad_get_parent (pad)); videofilter = GST_VIDEOFILTER (GST_PAD_PARENT (pad));
klass = GST_VIDEOFILTER_CLASS (G_OBJECT_GET_CLASS (videofilter)); klass = GST_VIDEOFILTER_CLASS (G_OBJECT_GET_CLASS (videofilter));
otherpad = (pad == videofilter->srcpad) ? videofilter->sinkpad : /* we can handle anything that was registered */
videofilter->srcpad;
othercaps = gst_pad_get_allowed_caps (otherpad);
return othercaps;
#if 0
/* FIXME videofilter doesn't allow passthru of video formats it
* doesn't understand. */
/* Look through our list of caps and find those that match with
* the peer's formats. Create a list of them. */
/* FIXME optimize if peercaps == NULL */
caps = gst_caps_new_empty (); caps = gst_caps_new_empty ();
for (i = 0; i < klass->formats->len; i++) { for (i = 0; i < klass->formats->len; i++) {
GstCaps *icaps;
GstCaps *fromcaps; GstCaps *fromcaps;
fromcaps = fromcaps =
gst_caps_new_full (gst_videofilter_format_get_structure gst_caps_new_full (gst_videofilter_format_get_structure
(g_ptr_array_index (klass->formats, i)), NULL); (g_ptr_array_index (klass->formats, i)), NULL);
icaps = gst_caps_intersect (fromcaps, peercaps); gst_caps_append (caps, fromcaps);
if (icaps != NULL) { }
gst_caps_append (caps, fromcaps);
} else { peer = gst_pad_get_peer (pad);
gst_caps_free (fromcaps); if (peer) {
} GstCaps *peercaps;
if (icaps)
gst_caps_free (icaps); peercaps = gst_pad_get_caps (peer);
if (peercaps) {
GstCaps *icaps;
icaps = gst_caps_intersect (peercaps, caps);
gst_caps_unref (peercaps);
gst_caps_unref (caps);
caps = icaps;
}
//gst_object_unref (peer);
} }
gst_caps_free (peercaps);
return caps; return caps;
#endif
} }
static GstPadLinkReturn static gboolean
gst_videofilter_link (GstPad * pad, const GstCaps * caps) gst_videofilter_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstVideofilter *videofilter; GstVideofilter *videofilter;
GstStructure *structure; GstStructure *structure;
gboolean ret;
int width, height; int width, height;
double framerate; double framerate;
GstPadLinkReturn lret; int ret;
GstPad *otherpad;
GST_DEBUG ("gst_videofilter_src_link"); videofilter = GST_VIDEOFILTER (GST_PAD_PARENT (pad));
videofilter = GST_VIDEOFILTER (gst_pad_get_parent (pad));
otherpad = (pad == videofilter->srcpad) ? videofilter->sinkpad :
videofilter->srcpad;
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
@ -248,11 +234,9 @@ gst_videofilter_link (GstPad * pad, const GstCaps * caps)
ret &= gst_structure_get_double (structure, "framerate", &framerate); ret &= gst_structure_get_double (structure, "framerate", &framerate);
if (!ret) if (!ret)
return GST_PAD_LINK_REFUSED; return FALSE;
lret = gst_pad_try_set_caps (otherpad, caps); gst_pad_set_caps (videofilter->srcpad, caps);
if (GST_PAD_LINK_FAILED (lret))
return lret;
GST_DEBUG ("width %d height %d", width, height); GST_DEBUG ("width %d height %d", width, height);
@ -273,7 +257,7 @@ gst_videofilter_link (GstPad * pad, const GstCaps * caps)
gst_videofilter_setup (videofilter); gst_videofilter_setup (videofilter);
return GST_PAD_LINK_OK; return TRUE;
} }
static void static void
@ -290,7 +274,7 @@ gst_videofilter_init (GTypeInstance * instance, gpointer g_class)
videofilter->sinkpad = gst_pad_new_from_template (pad_template, "sink"); videofilter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
gst_element_add_pad (GST_ELEMENT (videofilter), videofilter->sinkpad); gst_element_add_pad (GST_ELEMENT (videofilter), videofilter->sinkpad);
gst_pad_set_chain_function (videofilter->sinkpad, gst_videofilter_chain); gst_pad_set_chain_function (videofilter->sinkpad, gst_videofilter_chain);
gst_pad_set_link_function (videofilter->sinkpad, gst_videofilter_link); gst_pad_set_setcaps_function (videofilter->sinkpad, gst_videofilter_setcaps);
gst_pad_set_getcaps_function (videofilter->sinkpad, gst_videofilter_getcaps); gst_pad_set_getcaps_function (videofilter->sinkpad, gst_videofilter_getcaps);
pad_template = pad_template =
@ -298,16 +282,14 @@ gst_videofilter_init (GTypeInstance * instance, gpointer g_class)
g_return_if_fail (pad_template != NULL); g_return_if_fail (pad_template != NULL);
videofilter->srcpad = gst_pad_new_from_template (pad_template, "src"); videofilter->srcpad = gst_pad_new_from_template (pad_template, "src");
gst_element_add_pad (GST_ELEMENT (videofilter), videofilter->srcpad); gst_element_add_pad (GST_ELEMENT (videofilter), videofilter->srcpad);
gst_pad_set_link_function (videofilter->srcpad, gst_videofilter_link);
gst_pad_set_getcaps_function (videofilter->srcpad, gst_videofilter_getcaps); gst_pad_set_getcaps_function (videofilter->srcpad, gst_videofilter_getcaps);
videofilter->inited = FALSE; videofilter->inited = FALSE;
} }
static void static GstFlowReturn
gst_videofilter_chain (GstPad * pad, GstData * _data) gst_videofilter_chain (GstPad * pad, GstBuffer * buf)
{ {
GstBuffer *buf = GST_BUFFER (_data);
GstVideofilter *videofilter; GstVideofilter *videofilter;
guchar *data; guchar *data;
gulong size; gulong size;
@ -315,19 +297,21 @@ gst_videofilter_chain (GstPad * pad, GstData * _data)
GST_DEBUG ("gst_videofilter_chain"); GST_DEBUG ("gst_videofilter_chain");
g_return_if_fail (pad != NULL); g_return_val_if_fail (pad != NULL, GST_FLOW_ERROR);
g_return_if_fail (GST_IS_PAD (pad)); g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
g_return_if_fail (buf != NULL); g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
videofilter = GST_VIDEOFILTER (gst_pad_get_parent (pad)); videofilter = GST_VIDEOFILTER (GST_PAD_PARENT (pad));
//g_return_if_fail (videofilter->inited);
data = GST_BUFFER_DATA (buf); data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf); size = GST_BUFFER_SIZE (buf);
if (videofilter->passthru) { if (videofilter->passthru) {
gst_pad_push (videofilter->srcpad, GST_DATA (buf)); return gst_pad_push (videofilter->srcpad, buf);
return; }
if (GST_PAD_CAPS (pad) == NULL) {
return GST_FLOW_NOT_NEGOTIATED;
} }
GST_DEBUG ("gst_videofilter_chain: got buffer of %ld bytes in '%s'", size, GST_DEBUG ("gst_videofilter_chain: got buffer of %ld bytes in '%s'", size,
@ -339,19 +323,19 @@ gst_videofilter_chain (GstPad * pad, GstData * _data)
videofilter->to_width, videofilter->to_height, size, videofilter->to_width, videofilter->to_height, size,
videofilter->from_buf_size, videofilter->to_buf_size); videofilter->from_buf_size, videofilter->to_buf_size);
g_return_if_fail (size >= videofilter->from_buf_size);
if (size > videofilter->from_buf_size) { if (size > videofilter->from_buf_size) {
GST_INFO ("buffer size %ld larger than expected (%d)", GST_INFO ("buffer size %ld larger than expected (%d)",
size, videofilter->from_buf_size); size, videofilter->from_buf_size);
return GST_FLOW_ERROR;
} }
outbuf = gst_pad_alloc_buffer (videofilter->srcpad, GST_BUFFER_OFFSET_NONE, outbuf = gst_pad_alloc_buffer (videofilter->srcpad, GST_BUFFER_OFFSET_NONE,
videofilter->to_buf_size); videofilter->to_buf_size, GST_RPAD_CAPS (videofilter->srcpad));
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
g_return_if_fail (videofilter->format); g_return_val_if_fail (videofilter->format, GST_FLOW_ERROR);
GST_DEBUG ("format %s", videofilter->format->fourcc); GST_DEBUG ("format %s", videofilter->format->fourcc);
videofilter->in_buf = buf; videofilter->in_buf = buf;
@ -363,9 +347,11 @@ gst_videofilter_chain (GstPad * pad, GstData * _data)
GST_DEBUG ("gst_videofilter_chain: pushing buffer of %d bytes in '%s'", GST_DEBUG ("gst_videofilter_chain: pushing buffer of %d bytes in '%s'",
GST_BUFFER_SIZE (outbuf), GST_OBJECT_NAME (videofilter)); GST_BUFFER_SIZE (outbuf), GST_OBJECT_NAME (videofilter));
gst_pad_push (videofilter->srcpad, GST_DATA (outbuf)); gst_pad_push (videofilter->srcpad, outbuf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_OK;
} }
static void static void
@ -422,7 +408,6 @@ void
gst_videofilter_set_output_size (GstVideofilter * videofilter, gst_videofilter_set_output_size (GstVideofilter * videofilter,
int width, int height) int width, int height)
{ {
int ret;
GstCaps *srccaps; GstCaps *srccaps;
GstStructure *structure; GstStructure *structure;
@ -434,17 +419,14 @@ gst_videofilter_set_output_size (GstVideofilter * videofilter,
videofilter->to_buf_size = (videofilter->to_width * videofilter->to_height videofilter->to_buf_size = (videofilter->to_width * videofilter->to_height
* videofilter->format->bpp) / 8; * videofilter->format->bpp) / 8;
srccaps = gst_caps_copy (gst_pad_get_negotiated_caps (videofilter->srcpad)); //srccaps = gst_caps_copy (gst_pad_get_negotiated_caps (videofilter->srcpad));
srccaps = gst_caps_copy (GST_PAD_CAPS (videofilter->srcpad));
structure = gst_caps_get_structure (srccaps, 0); structure = gst_caps_get_structure (srccaps, 0);
gst_structure_set (structure, "width", G_TYPE_INT, width, gst_structure_set (structure, "width", G_TYPE_INT, width,
"height", G_TYPE_INT, height, NULL); "height", G_TYPE_INT, height, NULL);
ret = gst_pad_try_set_caps (videofilter->srcpad, srccaps); gst_pad_set_caps (videofilter->srcpad, srccaps);
if (ret < 0) {
g_critical ("could not set output size");
}
} }
static void static void