From beb864bd9313ab83954af36be907d68f7e2023ce Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 7 Jun 2011 10:58:27 +0200 Subject: [PATCH] -base: use caps event instead of setcapsfunction --- gst/adder/gstadder.c | 23 ++++++++++++++--------- gst/audiorate/gstaudiorate.c | 35 ++++++++++++++++------------------- gst/encoding/gststreamcombiner.c | 25 +------------------------ gst/encoding/gststreamsplitter.c | 14 ++++++++++++-- gst/subparse/gstssaparse.c | 20 +++++++++++++++++--- 5 files changed, 60 insertions(+), 57 deletions(-) diff --git a/gst/adder/gstadder.c b/gst/adder/gstadder.c index b2e5903..27d77d8 100644 --- a/gst/adder/gstadder.c +++ b/gst/adder/gstadder.c @@ -125,7 +125,8 @@ static void gst_adder_set_property (GObject * object, guint prop_id, static void gst_adder_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static gboolean gst_adder_setcaps (GstPad * pad, GstCaps * caps); +static gboolean gst_adder_setcaps (GstAdder * adder, GstPad * pad, + GstCaps * caps); static gboolean gst_adder_query (GstPad * pad, GstQuery * query); static gboolean gst_adder_src_event (GstPad * pad, GstEvent * event); static gboolean gst_adder_sink_event (GstPad * pad, GstEvent * event); @@ -246,9 +247,8 @@ setcapsfunc (const GValue * item, IterData * data) * the other sinkpads because we can only mix streams with the same caps. */ static gboolean -gst_adder_setcaps (GstPad * pad, GstCaps * caps) +gst_adder_setcaps (GstAdder * adder, GstPad * pad, GstCaps * caps) { - GstAdder *adder; GstStructure *structure; const char *media_type; GstIterator *it; @@ -256,9 +256,7 @@ gst_adder_setcaps (GstPad * pad, GstCaps * caps) IterData idata; gboolean done; - adder = GST_ADDER (GST_PAD_PARENT (pad)); - - GST_LOG_OBJECT (adder, "setting caps on pad %p,%s to %" GST_PTR_FORMAT, pad, + GST_LOG_OBJECT (adder, "setting caps pad %p,%s to %" GST_PTR_FORMAT, pad, GST_PAD_NAME (pad), caps); it = gst_element_iterate_pads (GST_ELEMENT_CAST (adder)); @@ -786,6 +784,16 @@ gst_adder_sink_event (GstPad * pad, GstEvent * event) GST_DEBUG_PAD_NAME (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_adder_setcaps (adder, pad, caps); + gst_event_unref (event); + + goto beach; + } case GST_EVENT_FLUSH_STOP: /* we received a flush-stop. The collect_event function will push the * event past our element. We simply forward all flush-stop events, even @@ -871,8 +879,6 @@ gst_adder_init (GstAdder * adder) gst_pad_set_getcaps_function (adder->srcpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); - gst_pad_set_setcaps_function (adder->srcpad, - GST_DEBUG_FUNCPTR (gst_adder_setcaps)); gst_pad_set_query_function (adder->srcpad, GST_DEBUG_FUNCPTR (gst_adder_query)); gst_pad_set_event_function (adder->srcpad, @@ -993,7 +999,6 @@ gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ, gst_pad_set_getcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_sink_getcaps)); - gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_setcaps)); gst_collect_pads_add_pad (adder->collect, newpad, sizeof (GstCollectData)); /* FIXME: hacked way to override/extend the event function of diff --git a/gst/audiorate/gstaudiorate.c b/gst/audiorate/gstaudiorate.c index 79ac544..7ba9ddd 100644 --- a/gst/audiorate/gstaudiorate.c +++ b/gst/audiorate/gstaudiorate.c @@ -206,16 +206,11 @@ gst_audio_rate_reset (GstAudioRate * audiorate) } static gboolean -gst_audio_rate_setcaps (GstPad * pad, GstCaps * caps) +gst_audio_rate_setcaps (GstAudioRate * audiorate, GstCaps * caps) { - GstAudioRate *audiorate; GstStructure *structure; - GstPad *otherpad; - gboolean ret = FALSE; gint channels, width, rate; - audiorate = GST_AUDIO_RATE (gst_pad_get_parent (pad)); - structure = gst_caps_get_structure (caps, 0); if (!gst_structure_get_int (structure, "channels", &channels)) @@ -231,26 +226,18 @@ gst_audio_rate_setcaps (GstPad * pad, GstCaps * caps) audiorate->rate = rate; - /* the format is correct, configure caps on other pad */ - otherpad = (pad == audiorate->srcpad) ? audiorate->sinkpad : - audiorate->srcpad; - - ret = gst_pad_set_caps (otherpad, caps); - -done: - gst_object_unref (audiorate); - return ret; + return TRUE; /* ERRORS */ wrong_caps: { GST_DEBUG_OBJECT (audiorate, "could not get channels/width from caps"); - goto done; + return FALSE; } wrong_format: { GST_DEBUG_OBJECT (audiorate, "bytes_per_samples gave 0"); - goto done; + return FALSE; } } @@ -261,14 +248,12 @@ gst_audio_rate_init (GstAudioRate * audiorate) gst_pad_new_from_static_template (&gst_audio_rate_sink_template, "sink"); gst_pad_set_event_function (audiorate->sinkpad, gst_audio_rate_sink_event); gst_pad_set_chain_function (audiorate->sinkpad, gst_audio_rate_chain); - gst_pad_set_setcaps_function (audiorate->sinkpad, gst_audio_rate_setcaps); gst_pad_set_getcaps_function (audiorate->sinkpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->sinkpad); audiorate->srcpad = gst_pad_new_from_static_template (&gst_audio_rate_src_template, "src"); gst_pad_set_event_function (audiorate->srcpad, gst_audio_rate_src_event); - gst_pad_set_setcaps_function (audiorate->srcpad, gst_audio_rate_setcaps); gst_pad_set_getcaps_function (audiorate->srcpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->srcpad); @@ -309,6 +294,18 @@ gst_audio_rate_sink_event (GstPad * pad, GstEvent * event) audiorate = GST_AUDIO_RATE (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + if ((res = gst_audio_rate_setcaps (audiorate, caps))) { + res = gst_pad_push_event (audiorate->srcpad, event); + } else { + gst_event_unref (event); + } + break; + } case GST_EVENT_FLUSH_STOP: GST_DEBUG_OBJECT (audiorate, "handling FLUSH_STOP"); gst_audio_rate_reset (audiorate); diff --git a/gst/encoding/gststreamcombiner.c b/gst/encoding/gststreamcombiner.c index e93cab4..cc74ac5 100644 --- a/gst/encoding/gststreamcombiner.c +++ b/gst/encoding/gststreamcombiner.c @@ -122,7 +122,7 @@ gst_stream_combiner_sink_event (GstPad * pad, GstEvent * event) break; } - /* NEW_SEGMENT : lock, wait for other stream to EOS, select stream, unlock, push */ + /* SEGMENT : lock, wait for other stream to EOS, select stream, unlock, push */ /* EOS : lock, mark pad as unused, unlock , drop event */ /* CUSTOM_REAL_EOS : push EOS downstream */ /* FLUSH_START : lock, mark as flushing, unlock. if wasn't flushing forward */ @@ -141,26 +141,6 @@ gst_stream_combiner_sink_getcaps (GstPad * pad, GstCaps * filter) } static gboolean -gst_stream_combiner_sink_setcaps (GstPad * pad, GstCaps * caps) -{ - GstStreamCombiner *stream_combiner = - (GstStreamCombiner *) GST_PAD_PARENT (pad); - GstPad *peer; - gboolean res = FALSE; - - GST_DEBUG_OBJECT (pad, "caps:%" GST_PTR_FORMAT, caps); - - peer = gst_pad_get_peer (stream_combiner->srcpad); - if (peer) { - GST_DEBUG_OBJECT (peer, "Setting caps"); - res = gst_pad_set_caps (peer, caps); - gst_object_unref (peer); - } else - GST_WARNING_OBJECT (stream_combiner, "sourcepad has no peer !"); - return res; -} - -static gboolean gst_stream_combiner_src_event (GstPad * pad, GstEvent * event) { GstStreamCombiner *stream_combiner = @@ -225,12 +205,9 @@ gst_stream_combiner_request_new_pad (GstElement * element, GST_DEBUG_OBJECT (element, "templ:%p, name:%s", templ, name); sinkpad = gst_pad_new_from_static_template (&sink_template, name); - /* FIXME : No buffer alloc for the time being, it will resort to the fallback */ - /* gst_pad_set_bufferalloc_function (sinkpad, gst_stream_combiner_buffer_alloc); */ gst_pad_set_chain_function (sinkpad, gst_stream_combiner_chain); gst_pad_set_event_function (sinkpad, gst_stream_combiner_sink_event); gst_pad_set_getcaps_function (sinkpad, gst_stream_combiner_sink_getcaps); - gst_pad_set_setcaps_function (sinkpad, gst_stream_combiner_sink_setcaps); STREAMS_LOCK (stream_combiner); stream_combiner->sinkpads = diff --git a/gst/encoding/gststreamsplitter.c b/gst/encoding/gststreamsplitter.c index 531a8f5..f34a18e 100644 --- a/gst/encoding/gststreamsplitter.c +++ b/gst/encoding/gststreamsplitter.c @@ -43,6 +43,8 @@ G_DEFINE_TYPE (GstStreamSplitter, gst_stream_splitter, GST_TYPE_ELEMENT); static void gst_stream_splitter_dispose (GObject * object); +static gboolean gst_stream_splitter_sink_setcaps (GstPad * pad, GstCaps * caps); + static GstPad *gst_stream_splitter_request_new_pad (GstElement * element, GstPadTemplate * templ, const gchar * name, const GstCaps * caps); static void gst_stream_splitter_release_pad (GstElement * element, @@ -156,6 +158,16 @@ gst_stream_splitter_sink_event (GstPad * pad, GstEvent * event) GST_EVENT_TYPE_NAME (event)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + res = gst_stream_splitter_sink_setcaps (pad, caps); + + store = TRUE; + break; + } case GST_EVENT_FLUSH_STOP: flushpending = TRUE; toall = TRUE; @@ -378,8 +390,6 @@ gst_stream_splitter_init (GstStreamSplitter * stream_splitter) gst_stream_splitter_sink_event); gst_pad_set_getcaps_function (stream_splitter->sinkpad, gst_stream_splitter_sink_getcaps); - gst_pad_set_setcaps_function (stream_splitter->sinkpad, - gst_stream_splitter_sink_setcaps); gst_element_add_pad (GST_ELEMENT (stream_splitter), stream_splitter->sinkpad); stream_splitter->lock = g_mutex_new (); diff --git a/gst/subparse/gstssaparse.c b/gst/subparse/gstssaparse.c index 946fdda..dc75364 100644 --- a/gst/subparse/gstssaparse.c +++ b/gst/subparse/gstssaparse.c @@ -69,8 +69,6 @@ static void gst_ssa_parse_init (GstSsaParse * parse) { parse->sinkpad = gst_pad_new_from_static_template (&sink_templ, "sink"); - gst_pad_set_setcaps_function (parse->sinkpad, - GST_DEBUG_FUNCPTR (gst_ssa_parse_setcaps)); gst_pad_set_chain_function (parse->sinkpad, GST_DEBUG_FUNCPTR (gst_ssa_parse_chain)); gst_pad_set_event_function (parse->sinkpad, @@ -122,7 +120,23 @@ gst_ssa_parse_src_event (GstPad * pad, GstEvent * event) static gboolean gst_ssa_parse_sink_event (GstPad * pad, GstEvent * event) { - return gst_pad_event_default (pad, event); + gboolean res; + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + res = gst_ssa_parse_setcaps (pad, caps); + gst_event_unref (event); + break; + } + default: + res = gst_pad_event_default (pad, event); + break; + } + return res; } static gboolean -- 2.7.4