From e3f2d7db71dfb14441648033eb6cf3324ccc98b3 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 17 Oct 2011 14:42:08 -0300 Subject: [PATCH] baseparse: add getcaps function Adds a getcaps function to the sink pad to make parsers propagate downstream caps restrictions to upstream. The pipeline "audiotestsrc num-buffers=100 ! faac ! aacparse ! "audio/mpeg, version=(int)4, stream-format=(string)adts" ! filesink" wouldn't work because aacparse wouldn't propagate the adts restriction upstream to faac. This patch adds a default getcaps to the sink pad to simply proxy downstream caps and also adds a 'get_sink_caps' function pointer to GstBaseParseClass for subclasses that need more refined getcaps. https://bugzilla.gnome.org/show_bug.cgi?id=661874 --- libs/gst/base/gstbaseparse.c | 26 ++++++++++++++++++++++++++ libs/gst/base/gstbaseparse.h | 5 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/gst/base/gstbaseparse.c b/libs/gst/base/gstbaseparse.c index 464f48505b..33451207d5 100644 --- a/libs/gst/base/gstbaseparse.c +++ b/libs/gst/base/gstbaseparse.c @@ -379,6 +379,7 @@ static gboolean gst_base_parse_src_event (GstPad * pad, GstEvent * event); static gboolean gst_base_parse_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_base_parse_query (GstPad * pad, GstQuery * query); static gboolean gst_base_parse_sink_setcaps (GstPad * pad, GstCaps * caps); +static GstCaps *gst_base_parse_sink_getcaps (GstPad * pad); static const GstQueryType *gst_base_parse_get_querytypes (GstPad * pad); static GstFlowReturn gst_base_parse_chain (GstPad * pad, GstBuffer * buffer); @@ -512,6 +513,8 @@ gst_base_parse_init (GstBaseParse * parse, GstBaseParseClass * bclass) GST_DEBUG_FUNCPTR (gst_base_parse_sink_event)); gst_pad_set_setcaps_function (parse->sinkpad, GST_DEBUG_FUNCPTR (gst_base_parse_sink_setcaps)); + gst_pad_set_getcaps_function (parse->sinkpad, + GST_DEBUG_FUNCPTR (gst_base_parse_sink_getcaps)); gst_pad_set_chain_function (parse->sinkpad, GST_DEBUG_FUNCPTR (gst_base_parse_chain)); gst_pad_set_activate_function (parse->sinkpad, @@ -3856,6 +3859,29 @@ gst_base_parse_sink_setcaps (GstPad * pad, GstCaps * caps) return res; } +static GstCaps * +gst_base_parse_sink_getcaps (GstPad * pad) +{ + GstBaseParse *parse; + GstBaseParseClass *klass; + GstCaps *caps; + + parse = GST_BASE_PARSE (gst_pad_get_parent (pad)); + klass = GST_BASE_PARSE_GET_CLASS (parse); + g_assert (pad == GST_BASE_PARSE_SINK_PAD (parse)); + + if (klass->get_sink_caps) + caps = klass->get_sink_caps (parse); + else + caps = gst_pad_proxy_getcaps (pad); + gst_object_unref (parse); + + GST_LOG_OBJECT (parse, "sink getcaps returning caps %" GST_PTR_FORMAT, caps); + + return caps; + +} + static void gst_base_parse_set_index (GstElement * element, GstIndex * index) { diff --git a/libs/gst/base/gstbaseparse.h b/libs/gst/base/gstbaseparse.h index 655ad0e4a3..e7b1db5753 100644 --- a/libs/gst/base/gstbaseparse.h +++ b/libs/gst/base/gstbaseparse.h @@ -191,6 +191,7 @@ struct _GstBaseParse { * Called when the element stops processing. * Allows closing external resources. * @set_sink_caps: allows the subclass to be notified of the actual caps set. + * @get_sink_caps: allows the subclass to do its own sink get caps if needed. * @check_valid_frame: Check if the given piece of data contains a valid * frame. * @parse_frame: Parse the already checked frame. Subclass need to @@ -252,8 +253,10 @@ struct _GstBaseParseClass { gboolean (*src_event) (GstBaseParse * parse, GstEvent * event); + GstCaps * (*get_sink_caps) (GstBaseParse * parse); + /*< private >*/ - gpointer _gst_reserved[GST_PADDING_LARGE]; + gpointer _gst_reserved[GST_PADDING_LARGE - 1]; }; GType gst_base_parse_get_type (void);