commit 21f1bb9887ab34dba91ba751dfd7bb7df6151b82 Author: Sjoerd Simons Date: Sat Mar 29 21:01:53 2008 +0100 * src/rbgst-pad.c: Let Gst::Pad.link return a Gst::Pad::LinkReturn. Add query, >>, negotiated_caps, set_caps, caps= and peer functions on Gst::Pad. * src/rbgs-pad.c: Fix pad refcounting in get_caps diff --git a/gstreamer/src/rbgst-pad.c b/gstreamer/src/rbgst-pad.c index 6f4a729..b0d929f 100644 --- a/gstreamer/src/rbgst-pad.c +++ b/gstreamer/src/rbgst-pad.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2003, 2004 Laurent Sansonetti + * Copyright (C) 2006, 2008 Sjoerd Simons * * This file is part of Ruby/GStreamer. * @@ -20,6 +21,8 @@ #include "rbgst.h" +static VALUE cGstPad; + /* Class: Gst::Pad * The link between Gst::Element objects. */ @@ -110,7 +113,7 @@ static VALUE rb_gst_pad_each_query_type (VALUE self) { return rb_ary_yield (rb_gst_pad_get_query_types (self)); -} +} /* * Method: link(other_pad) @@ -118,31 +121,65 @@ rb_gst_pad_each_query_type (VALUE self) * * Links the current pad (source) to an other pad (sink). * - * Returns: true if the pads have been linked, false otherwise. + * Returns: a Gst::Pad::LinkReturn */ static VALUE rb_gst_pad_link (VALUE self, VALUE other_pad) { - GstPad *srcpad = RGST_PAD (self); - GstPad *sinkpad = RGST_PAD (other_pad); - return CBOOL2RVAL (gst_pad_link (srcpad, sinkpad)); + GstPad *srcpad = RGST_PAD (self); + GstPad *sinkpad; + + if (!rb_obj_is_kind_of(other_pad, cGstPad)) { + rb_raise(rb_eTypeError, "Not a Gst::Pad"); + } + + sinkpad = RGST_PAD (other_pad); + return GENUM2RVAL (gst_pad_link (srcpad, sinkpad), + GST_TYPE_PAD_LINK_RETURN); +} + +/* + * Method: >> other_pad + * other_pad: a Gst::Pad. + * + * Links the current pad (source) to an other pad (sink). + * + * Returns: the destination pad, or nil if the link failed. + */ +static VALUE +rb_gst_pad_link2 (VALUE self, VALUE other_pad) { + GstPad *srcpad = RGST_PAD (self); + GstPad *sinkpad; + + if (!rb_obj_is_kind_of(other_pad, cGstPad)) { + rb_raise(rb_eTypeError, "Not a Gst::Pad"); + } + + sinkpad = RGST_PAD (other_pad); + return gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK ? other_pad : Qnil; } + /* * Method: unlink(other_pad) * other_pad: a Gst::Pad. * * Unlinks the current pad (source) from an other pad (sink). * - * Returns: self. + * Returns: true if the pads were unlinked and false if the pads weren't linked. */ static VALUE rb_gst_pad_unlink(VALUE self, VALUE other_pad) { - GstPad *srcpad = RGST_PAD (self); - GstPad *sinkpad = RGST_PAD (other_pad); - gst_pad_unlink (srcpad, sinkpad); - return self; + GstPad *srcpad = RGST_PAD (self); + GstPad *sinkpad; + + if (!rb_obj_is_kind_of(other_pad, cGstPad)) { + rb_raise(rb_eTypeError, "Not a Gst::Pad"); + } + sinkpad = RGST_PAD (other_pad); + + return CBOOL2RVAL(gst_pad_unlink (srcpad, sinkpad)); } /* @@ -153,24 +190,13 @@ rb_gst_pad_unlink(VALUE self, VALUE other_pad) * * Returns: the query result value, or nil if the query could not be performed. */ -/* static VALUE */ -/* rb_gst_pad_query(VALUE self, VALUE query) */ -/* { */ -/* GstFormat gstformat; */ -/* gint64 value; */ - -/* rb_scan_args (argc, argv, "11", &query_type, &format); */ -/* gstformat = NIL_P (format) ? GST_FORMAT_DEFAULT : RVAL2GENUM (format, GST_TYPE_FORMAT); */ - -/* if (gst_pad_query (RGST_PAD(self), */ -/* RVAL2GENUM (query_type, GST_TYPE_QUERY_TYPE), */ -/* &gstformat, */ -/* &value)) { */ -/* format = GENUM2RVAL (gstformat, GST_TYPE_FORMAT); */ -/* return ULL2NUM (value); */ -/* } */ -/* return Qnil; */ -/* } */ +/* + * Method: query + */ +static VALUE +rb_gst_pad_query(VALUE self, VALUE query) { + return CBOOL2RVAL(gst_pad_query(RGST_PAD(self), RVAL2GOBJ(query))); +} /* * Method: send_event(event) @@ -198,17 +224,88 @@ rb_gst_pad_send_event (VALUE self, VALUE event) static VALUE rb_gst_pad_get_caps (VALUE self) { + VALUE ret; GstCaps *caps = gst_pad_get_caps (RGST_PAD (self)); - return caps != NULL - ? RGST_CAPS_NEW (caps) - : Qnil; + + if (caps == NULL) { + return Qnil; + } + + ret = GST_CAPS2RVAL(caps); + + /* get_caps gave us a ref we don't need, so drop it */ + gst_caps_unref (caps); + + return ret; } +/* + * Method: negotiatedcaps + * + * Gets the capabilities of the pad element. + * + * Returns: a Gst::Caps object. + */ +static VALUE +rb_gst_pad_get_negotiated_caps (VALUE self) +{ + VALUE ret; + GstCaps *caps = gst_pad_get_negotiated_caps (RGST_PAD (self)); + + if (caps == NULL) { + return Qnil; + } + + ret = GST_CAPS2RVAL(caps); + + /* get_negotiated_caps gave us a ref we don't need, so drop it */ + gst_caps_unref (caps); + + return ret; +} + +/* + * Method: set_caps + * + * Sets the capabilities of the pad element. + * + * Returns: true if the setting succeeded + */ +static VALUE +rb_gst_pad_set_caps(VALUE self, VALUE caps) { + return CBOOL2RVAL(gst_pad_set_caps(RGST_PAD(self), RGST_CAPS(caps))); +} + +/* + * Method: peer + * + * Get the peer of a pad + * + * Returns: Returns the peer pad or Qnil if there is none + */ +static VALUE +rb_gst_pad_get_peer(VALUE self) { + VALUE ret; + GstPad *pad = gst_pad_get_peer (RGST_PAD (self)); + + if (pad == NULL) { + return Qnil; + } + + ret = GOBJ2RVAL(pad); + /* gst_pad_get_peer gave us a ref, which we don't need anymore so drop it */ + g_object_unref (pad); + return ret; +} + + void Init_gst_pad (void) { VALUE c = G_DEF_CLASS (GST_TYPE_PAD, "Pad", mGst); - + + cGstPad = c; + rb_define_method (c, "direction", rb_gst_pad_get_direction, 0); rb_define_method (c, "name", rb_gst_pad_get_name, 0); rb_define_method (c, "pad_template", rb_gst_pad_get_padtemplate, 0); @@ -216,10 +313,17 @@ Init_gst_pad (void) rb_define_method (c, "query_types", rb_gst_pad_get_query_types, 0); rb_define_method (c, "each_query_type", rb_gst_pad_each_query_type, 0); rb_define_method (c, "link", rb_gst_pad_link, 1); + rb_define_method (c, ">>", rb_gst_pad_link2, 1); rb_define_method (c, "unlink", rb_gst_pad_unlink, 1); - /* rb_define_method (c, "query", rb_gst_pad_query, 1); */ + rb_define_method (c, "query", rb_gst_pad_query, 1); rb_define_method (c, "send_event", rb_gst_pad_send_event, 1); rb_define_method (c, "caps", rb_gst_pad_get_caps, 0); + rb_define_method (c, "negotiated_caps", rb_gst_pad_get_negotiated_caps, 0); + rb_define_method (c, "set_caps", rb_gst_pad_set_caps, 1); + rb_define_alias(c, "caps=", "set_caps"); + + rb_define_method (c, "peer", rb_gst_pad_get_peer, 0); + G_DEF_CLASS (GST_TYPE_PAD_LINK_RETURN, "LinkReturn", c); G_DEF_CONSTANTS (c, GST_TYPE_PAD_LINK_RETURN, "GST_PAD_");