From 9136abf6234b230a61967fea94a2bf133ab770af Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 4 May 2011 15:53:21 +0200 Subject: [PATCH] pad: use the context to store sticky events Store the sticky events in the context of a source pad. --- gst/gstcontext.h | 2 +- gst/gstevent.c | 2 +- gst/gstpad.c | 40 +++++++++------------------------------- gst/gstpad.h | 6 ++---- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/gst/gstcontext.h b/gst/gstcontext.h index c46af86ca8..b292b5d817 100644 --- a/gst/gstcontext.h +++ b/gst/gstcontext.h @@ -57,7 +57,7 @@ typedef struct _GstContext GstContext; * Returns: (transfer full): a writable context which may or may not be the * same as @ctx */ -#define gst_context_make_writable(ctx) GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (buf))) +#define gst_context_make_writable(ctx) GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (ctx))) /** * gst_context_replace: diff --git a/gst/gstevent.c b/gst/gstevent.c index 68ddc88b4a..9daa7de90f 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -493,7 +493,7 @@ gst_event_new_caps (GstCaps * caps) GST_CAT_INFO (GST_CAT_EVENT, "creating caps event %" GST_PTR_FORMAT, caps); - event = gst_event_new_custom (GST_EVENT_BUFFERSIZE, + event = gst_event_new_custom (GST_EVENT_CAPS, gst_structure_id_new (GST_QUARK (EVENT_CAPS), GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL)); diff --git a/gst/gstpad.c b/gst/gstpad.c index 96ad674b21..295b79d4d7 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -371,17 +371,8 @@ gst_pad_init (GstPad * pad) g_static_rec_mutex_init (pad->stream_rec_lock); pad->block_cond = g_cond_new (); -} -static void -clear_sticky_events (GstPad * pad) -{ - guint i; - - for (i = 0; i < GST_EVENT_MAX_STICKY; i++) { - GstEvent **eventp = &pad->sticky[i]; - gst_event_replace (eventp, NULL); - } + pad->context = gst_context_new (); } static void @@ -415,7 +406,7 @@ gst_pad_dispose (GObject * object) pad->block_data = NULL; } - clear_sticky_events (pad); + gst_context_clear (pad->context); G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -443,6 +434,8 @@ gst_pad_finalize (GObject * object) pad->block_cond = NULL; } + gst_context_unref (pad->context); + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -627,7 +620,7 @@ post_activate (GstPad * pad, GstActivateMode new_mode) /* ensures that streaming stops */ GST_PAD_STREAM_LOCK (pad); GST_DEBUG_OBJECT (pad, "stopped streaming"); - clear_sticky_events (pad); + gst_context_clear (pad->context); GST_PAD_STREAM_UNLOCK (pad); break; } @@ -1693,9 +1686,6 @@ gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad) GST_PAD_PEER (srcpad) = NULL; GST_PAD_PEER (sinkpad) = NULL; - /* clear the events on the sinkpad */ - clear_sticky_events (sinkpad); - GST_OBJECT_UNLOCK (sinkpad); GST_OBJECT_UNLOCK (srcpad); @@ -2013,7 +2003,6 @@ gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags) { GstPadLinkReturn result; GstElement *parent; - guint i; g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED); g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION); @@ -2043,15 +2032,6 @@ gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags) GST_PAD_PEER (srcpad) = sinkpad; GST_PAD_PEER (sinkpad) = srcpad; - /* copy the events */ - for (i = 0; i < GST_EVENT_MAX_STICKY; i++) { - GstEvent **eventp = &sinkpad->sticky[i], *event; - - if ((event = srcpad->sticky[i])) - GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_STICKY_PENDING); - gst_event_replace (eventp, event); - } - GST_OBJECT_UNLOCK (sinkpad); GST_OBJECT_UNLOCK (srcpad); @@ -3459,7 +3439,6 @@ gst_pad_chain_data_unchecked (GstPad * pad, gboolean is_buffer, void *data, GST_PAD_STREAM_LOCK (pad); -again: GST_OBJECT_LOCK (pad); if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad))) goto flushing; @@ -3469,6 +3448,7 @@ again: emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0; +#if 0 if (G_UNLIKELY (GST_PAD_IS_STICKY_PENDING (pad))) { GstPadEventFunction eventfunc; @@ -3499,6 +3479,7 @@ again: goto again; } } +#endif GST_OBJECT_UNLOCK (pad); @@ -4515,11 +4496,8 @@ gst_pad_push_event (GstPad * pad, GstEvent * event) /* store the event on the pad, but only on srcpads */ if (GST_PAD_IS_SRC (pad) && GST_EVENT_IS_STICKY (event)) { - guint idx = GST_EVENT_STICKY_IDX (event); - GstEvent **eventp = &pad->sticky[idx]; - GST_LOG_OBJECT (pad, "storing sticky event %s at index %u", - GST_EVENT_TYPE_NAME (event), idx); - gst_event_replace (eventp, event); + pad->context = gst_context_make_writable (pad->context); + gst_context_update (pad->context, event); } peerpad = GST_PAD_PEER (pad); diff --git a/gst/gstpad.h b/gst/gstpad.h index 619ddff801..e798088e26 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -509,7 +510,6 @@ typedef enum { * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now * @GST_PAD_IN_SETCAPS: GstPadSetCapsFunction() is running now * @GST_PAD_BLOCKING: is pad currently blocking on a buffer or event - * @GST_PAD_STICKY_PENDING: sticky events should be pushed * @GST_PAD_FLAG_LAST: offset to define more flags * * Pad state flags @@ -520,7 +520,6 @@ typedef enum { GST_PAD_IN_GETCAPS = (GST_OBJECT_FLAG_LAST << 2), GST_PAD_IN_SETCAPS = (GST_OBJECT_FLAG_LAST << 3), GST_PAD_BLOCKING = (GST_OBJECT_FLAG_LAST << 4), - GST_PAD_STICKY_PENDING = (GST_OBJECT_FLAG_LAST << 5), /* padding */ GST_PAD_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16) } GstPadFlags; @@ -616,7 +615,7 @@ struct _GstPad { GstPadCheckGetRangeFunction checkgetrangefunc; GstPadGetRangeFunction getrangefunc; GstPadEventFunction eventfunc; - GstEvent *sticky[GST_EVENT_MAX_STICKY]; + GstContext *context; GstActivateMode mode; @@ -699,7 +698,6 @@ struct _GstPadClass { #define GST_PAD_IS_FLUSHING(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING)) #define GST_PAD_IS_IN_GETCAPS(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS)) #define GST_PAD_IS_IN_SETCAPS(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS)) -#define GST_PAD_IS_STICKY_PENDING(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_STICKY_PENDING)) #define GST_PAD_IS_SRC(pad) (GST_PAD_DIRECTION(pad) == GST_PAD_SRC) #define GST_PAD_IS_SINK(pad) (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)