From 918a75789e17d81648c874d73388def12271974d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 23 Feb 2005 17:32:37 +0000 Subject: [PATCH] gst/: Only call the item function in the iterator if there is an item. Original commit message from CVS: * gst/base/gstbasesink.c: (gst_basesink_get_template), (gst_basesink_base_init), (gst_basesink_class_init), (gst_basesink_pad_getcaps), (gst_basesink_pad_setcaps), (gst_basesink_pad_buffer_alloc), (gst_basesink_init), (gst_base_sink_get_template), (gst_base_sink_get_caps), (gst_base_sink_set_caps), (gst_base_sink_buffer_alloc), (gst_basesink_finish_preroll), (gst_basesink_event), (gst_basesink_get_times), (gst_basesink_do_sync), (gst_basesink_change_state): * gst/base/gstbasesink.h: * gst/gstiterator.c: (gst_iterator_init), (gst_iterator_new), (gst_list_iterator_next), (gst_list_iterator_free), (gst_iterator_new_list), (gst_iterator_pop), (gst_iterator_next), (gst_iterator_push): Only call the item function in the iterator if there is an item. Add capsnego stuff and buffer_alloc to the basesink class. Cleanups in the preroll code. --- ChangeLog | 20 +++++++ gst/base/gstbasesink.c | 102 ++++++++++++++++++++++++++++-------- gst/base/gstbasesink.h | 2 +- gst/gstiterator.c | 2 +- libs/gst/base/gstbasesink.c | 102 ++++++++++++++++++++++++++++-------- libs/gst/base/gstbasesink.h | 2 +- 6 files changed, 181 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index e652b3ebf8..55d82314e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-02-23 Wim Taymans + + * gst/base/gstbasesink.c: (gst_basesink_get_template), + (gst_basesink_base_init), (gst_basesink_class_init), + (gst_basesink_pad_getcaps), (gst_basesink_pad_setcaps), + (gst_basesink_pad_buffer_alloc), (gst_basesink_init), + (gst_base_sink_get_template), (gst_base_sink_get_caps), + (gst_base_sink_set_caps), (gst_base_sink_buffer_alloc), + (gst_basesink_finish_preroll), (gst_basesink_event), + (gst_basesink_get_times), (gst_basesink_do_sync), + (gst_basesink_change_state): + * gst/base/gstbasesink.h: + * gst/gstiterator.c: (gst_iterator_init), (gst_iterator_new), + (gst_list_iterator_next), (gst_list_iterator_free), + (gst_iterator_new_list), (gst_iterator_pop), (gst_iterator_next), + (gst_iterator_push): + Only call the item function in the iterator if there is an item. + Add capsnego stuff and buffer_alloc to the basesink class. + Cleanups in the preroll code. + 2005-02-23 Andy Wingo * gst/elements/gstidentity.c (gst_identity_event): Pause the sink diff --git a/gst/base/gstbasesink.c b/gst/base/gstbasesink.c index e780b01230..52a50fca8e 100644 --- a/gst/base/gstbasesink.c +++ b/gst/base/gstbasesink.c @@ -69,7 +69,7 @@ static void gst_basesink_get_property (GObject * object, guint prop_id, static GstStaticPadTemplate *gst_base_sink_get_template (GstBaseSink * sink); static GstCaps *gst_base_sink_get_caps (GstBaseSink * sink); static gboolean gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps); -static GstBuffer *gst_base_sink_alloc_buffer (GstBaseSink * sink, +static GstBuffer *gst_base_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size, GstCaps * caps); static void gst_basesink_get_times (GstBaseSink * basesink, GstBuffer * buffer, GstClockTime * start, GstClockTime * end); @@ -139,10 +139,56 @@ gst_basesink_class_init (GstBaseSinkClass * klass) klass->get_caps = GST_DEBUG_FUNCPTR (gst_base_sink_get_caps); klass->set_caps = GST_DEBUG_FUNCPTR (gst_base_sink_set_caps); klass->get_template = GST_DEBUG_FUNCPTR (gst_base_sink_get_template); - klass->alloc_buffer = GST_DEBUG_FUNCPTR (gst_base_sink_alloc_buffer); + klass->buffer_alloc = GST_DEBUG_FUNCPTR (gst_base_sink_buffer_alloc); klass->get_times = GST_DEBUG_FUNCPTR (gst_basesink_get_times); } +static GstCaps * +gst_basesink_pad_getcaps (GstPad * pad) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + GstCaps *caps = NULL; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->get_caps) + caps = bclass->get_caps (bsink); + + return caps; +} + +static gboolean +gst_basesink_pad_setcaps (GstPad * pad, GstCaps * caps) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + gboolean res = FALSE; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->set_caps) + res = bclass->set_caps (bsink, caps); + + return res; +} + +static GstBuffer * +gst_basesink_pad_buffer_alloc (GstPad * pad, guint64 offset, guint size, + GstCaps * caps) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + GstBuffer *buffer = NULL; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->buffer_alloc) + buffer = bclass->buffer_alloc (bsink, offset, size, caps); + + return buffer; +} + static void gst_basesink_init (GstBaseSink * basesink) { @@ -153,6 +199,12 @@ gst_basesink_init (GstBaseSink * basesink) basesink->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get (template), "sink"); + gst_pad_set_getcaps_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_getcaps)); + gst_pad_set_setcaps_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_setcaps)); + gst_pad_set_bufferalloc_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_buffer_alloc)); gst_element_add_pad (GST_ELEMENT (basesink), basesink->sinkpad); basesink->pad_mode = GST_ACTIVATE_NONE; @@ -263,7 +315,7 @@ gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps) } static GstBuffer * -gst_base_sink_alloc_buffer (GstBaseSink * sink, guint64 offset, guint size, +gst_base_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size, GstCaps * caps) { return NULL; @@ -288,15 +340,16 @@ gst_basesink_finish_preroll (GstBaseSink * basesink, GstPad * pad, if (bclass->preroll) bclass->preroll (basesink, buffer); - basesink->need_preroll = FALSE; - basesink->have_preroll = TRUE; gst_element_commit_state (GST_ELEMENT (basesink)); GST_STATE_UNLOCK (basesink); GST_DEBUG ("element %s waiting to finish preroll", GST_ELEMENT_NAME (basesink)); + basesink->need_preroll = FALSE; + basesink->have_preroll = TRUE; GST_PREROLL_WAIT (pad); GST_DEBUG ("done preroll"); + basesink->have_preroll = FALSE; GST_LOCK (pad); usable = !GST_RPAD_IS_FLUSHING (pad) && GST_RPAD_IS_ACTIVE (pad); @@ -305,7 +358,6 @@ gst_basesink_finish_preroll (GstBaseSink * basesink, GstPad * pad, goto unusable; GST_DEBUG ("done preroll"); - basesink->have_preroll = FALSE; GST_PREROLL_UNLOCK (pad); return GST_FLOW_OK; @@ -390,17 +442,20 @@ gst_basesink_event (GstPad * pad, GstEvent * event) case GST_EVENT_FLUSH: /* make sure we are not blocked on the clock also clear any pending * eos state. */ - GST_LOCK (basesink); - basesink->eos = FALSE; - if (basesink->clock_id) { - gst_clock_id_unschedule (basesink->clock_id); - } - GST_UNLOCK (basesink); + if (!GST_EVENT_FLUSH_DONE (event)) { + GST_LOCK (basesink); + basesink->eos = FALSE; + if (basesink->clock_id) { + gst_clock_id_unschedule (basesink->clock_id); + } + GST_UNLOCK (basesink); - /* unlock from a possible state change/preroll */ - GST_PREROLL_LOCK (pad); - GST_PREROLL_SIGNAL (pad); - GST_PREROLL_UNLOCK (pad); + /* unlock from a possible state change/preroll */ + GST_PREROLL_LOCK (pad); + basesink->need_preroll = TRUE; + GST_PREROLL_SIGNAL (pad); + GST_PREROLL_UNLOCK (pad); + } /* now we are completely unblocked and the _chain method * will return */ break; @@ -615,15 +670,16 @@ gst_basesink_change_state (GstElement * element) ret = GST_STATE_ASYNC; break; case GST_STATE_PAUSED_TO_PLAYING: - /* the state change completes when we are blocking on a preroll - * sample */ GST_PREROLL_LOCK (basesink->sinkpad); - if (!basesink->have_preroll) { - basesink->need_preroll = TRUE; - ret = GST_STATE_ASYNC; - } else { + if (basesink->have_preroll) { /* now let it play */ GST_PREROLL_SIGNAL (basesink->sinkpad); + } else { + /* FIXME. We do not have a preroll and we don't need it anymore + * now, this is a case we want to avoid. One way would be to make + * a 'lost state' function that makes get_state return PAUSED with + * ASYNC to indicate that we are prerolling again. */ + basesink->need_preroll = FALSE; } GST_PREROLL_UNLOCK (basesink->sinkpad); break; @@ -640,10 +696,10 @@ gst_basesink_change_state (GstElement * element) GST_UNLOCK (basesink); GST_PREROLL_LOCK (basesink->sinkpad); - basesink->need_preroll = TRUE; /* if we don't have a preroll buffer and we have not received EOS, * we need to wait for a preroll */ if (!basesink->have_preroll && !eos) { + basesink->need_preroll = TRUE; ret = GST_STATE_ASYNC; } GST_PREROLL_UNLOCK (basesink->sinkpad); diff --git a/gst/base/gstbasesink.h b/gst/base/gstbasesink.h index 5fe29335d3..b65d62a2d7 100644 --- a/gst/base/gstbasesink.h +++ b/gst/base/gstbasesink.h @@ -68,7 +68,7 @@ struct _GstBaseSinkClass { GstCaps* (*get_caps) (GstBaseSink *sink); gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps); - GstBuffer* (*alloc_buffer) (GstBaseSink *sink, guint64 offset, guint size, + GstBuffer* (*buffer_alloc) (GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps); void (*get_times) (GstBaseSink *sink, GstBuffer *buffer, diff --git a/gst/gstiterator.c b/gst/gstiterator.c index 6a7af84943..13ff873d29 100644 --- a/gst/gstiterator.c +++ b/gst/gstiterator.c @@ -209,7 +209,7 @@ restart: } result = it->next (it, elem); - if (it->item) { + if (result == GST_ITERATOR_OK && it->item) { GstIteratorItem itemres; itemres = it->item (it, *elem); diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index e780b01230..52a50fca8e 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -69,7 +69,7 @@ static void gst_basesink_get_property (GObject * object, guint prop_id, static GstStaticPadTemplate *gst_base_sink_get_template (GstBaseSink * sink); static GstCaps *gst_base_sink_get_caps (GstBaseSink * sink); static gboolean gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps); -static GstBuffer *gst_base_sink_alloc_buffer (GstBaseSink * sink, +static GstBuffer *gst_base_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size, GstCaps * caps); static void gst_basesink_get_times (GstBaseSink * basesink, GstBuffer * buffer, GstClockTime * start, GstClockTime * end); @@ -139,10 +139,56 @@ gst_basesink_class_init (GstBaseSinkClass * klass) klass->get_caps = GST_DEBUG_FUNCPTR (gst_base_sink_get_caps); klass->set_caps = GST_DEBUG_FUNCPTR (gst_base_sink_set_caps); klass->get_template = GST_DEBUG_FUNCPTR (gst_base_sink_get_template); - klass->alloc_buffer = GST_DEBUG_FUNCPTR (gst_base_sink_alloc_buffer); + klass->buffer_alloc = GST_DEBUG_FUNCPTR (gst_base_sink_buffer_alloc); klass->get_times = GST_DEBUG_FUNCPTR (gst_basesink_get_times); } +static GstCaps * +gst_basesink_pad_getcaps (GstPad * pad) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + GstCaps *caps = NULL; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->get_caps) + caps = bclass->get_caps (bsink); + + return caps; +} + +static gboolean +gst_basesink_pad_setcaps (GstPad * pad, GstCaps * caps) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + gboolean res = FALSE; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->set_caps) + res = bclass->set_caps (bsink, caps); + + return res; +} + +static GstBuffer * +gst_basesink_pad_buffer_alloc (GstPad * pad, guint64 offset, guint size, + GstCaps * caps) +{ + GstBaseSinkClass *bclass; + GstBaseSink *bsink; + GstBuffer *buffer = NULL; + + bsink = GST_BASESINK (GST_PAD_PARENT (pad)); + bclass = GST_BASESINK_GET_CLASS (bsink); + if (bclass->buffer_alloc) + buffer = bclass->buffer_alloc (bsink, offset, size, caps); + + return buffer; +} + static void gst_basesink_init (GstBaseSink * basesink) { @@ -153,6 +199,12 @@ gst_basesink_init (GstBaseSink * basesink) basesink->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get (template), "sink"); + gst_pad_set_getcaps_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_getcaps)); + gst_pad_set_setcaps_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_setcaps)); + gst_pad_set_bufferalloc_function (basesink->sinkpad, + GST_DEBUG_FUNCPTR (gst_basesink_pad_buffer_alloc)); gst_element_add_pad (GST_ELEMENT (basesink), basesink->sinkpad); basesink->pad_mode = GST_ACTIVATE_NONE; @@ -263,7 +315,7 @@ gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps) } static GstBuffer * -gst_base_sink_alloc_buffer (GstBaseSink * sink, guint64 offset, guint size, +gst_base_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size, GstCaps * caps) { return NULL; @@ -288,15 +340,16 @@ gst_basesink_finish_preroll (GstBaseSink * basesink, GstPad * pad, if (bclass->preroll) bclass->preroll (basesink, buffer); - basesink->need_preroll = FALSE; - basesink->have_preroll = TRUE; gst_element_commit_state (GST_ELEMENT (basesink)); GST_STATE_UNLOCK (basesink); GST_DEBUG ("element %s waiting to finish preroll", GST_ELEMENT_NAME (basesink)); + basesink->need_preroll = FALSE; + basesink->have_preroll = TRUE; GST_PREROLL_WAIT (pad); GST_DEBUG ("done preroll"); + basesink->have_preroll = FALSE; GST_LOCK (pad); usable = !GST_RPAD_IS_FLUSHING (pad) && GST_RPAD_IS_ACTIVE (pad); @@ -305,7 +358,6 @@ gst_basesink_finish_preroll (GstBaseSink * basesink, GstPad * pad, goto unusable; GST_DEBUG ("done preroll"); - basesink->have_preroll = FALSE; GST_PREROLL_UNLOCK (pad); return GST_FLOW_OK; @@ -390,17 +442,20 @@ gst_basesink_event (GstPad * pad, GstEvent * event) case GST_EVENT_FLUSH: /* make sure we are not blocked on the clock also clear any pending * eos state. */ - GST_LOCK (basesink); - basesink->eos = FALSE; - if (basesink->clock_id) { - gst_clock_id_unschedule (basesink->clock_id); - } - GST_UNLOCK (basesink); + if (!GST_EVENT_FLUSH_DONE (event)) { + GST_LOCK (basesink); + basesink->eos = FALSE; + if (basesink->clock_id) { + gst_clock_id_unschedule (basesink->clock_id); + } + GST_UNLOCK (basesink); - /* unlock from a possible state change/preroll */ - GST_PREROLL_LOCK (pad); - GST_PREROLL_SIGNAL (pad); - GST_PREROLL_UNLOCK (pad); + /* unlock from a possible state change/preroll */ + GST_PREROLL_LOCK (pad); + basesink->need_preroll = TRUE; + GST_PREROLL_SIGNAL (pad); + GST_PREROLL_UNLOCK (pad); + } /* now we are completely unblocked and the _chain method * will return */ break; @@ -615,15 +670,16 @@ gst_basesink_change_state (GstElement * element) ret = GST_STATE_ASYNC; break; case GST_STATE_PAUSED_TO_PLAYING: - /* the state change completes when we are blocking on a preroll - * sample */ GST_PREROLL_LOCK (basesink->sinkpad); - if (!basesink->have_preroll) { - basesink->need_preroll = TRUE; - ret = GST_STATE_ASYNC; - } else { + if (basesink->have_preroll) { /* now let it play */ GST_PREROLL_SIGNAL (basesink->sinkpad); + } else { + /* FIXME. We do not have a preroll and we don't need it anymore + * now, this is a case we want to avoid. One way would be to make + * a 'lost state' function that makes get_state return PAUSED with + * ASYNC to indicate that we are prerolling again. */ + basesink->need_preroll = FALSE; } GST_PREROLL_UNLOCK (basesink->sinkpad); break; @@ -640,10 +696,10 @@ gst_basesink_change_state (GstElement * element) GST_UNLOCK (basesink); GST_PREROLL_LOCK (basesink->sinkpad); - basesink->need_preroll = TRUE; /* if we don't have a preroll buffer and we have not received EOS, * we need to wait for a preroll */ if (!basesink->have_preroll && !eos) { + basesink->need_preroll = TRUE; ret = GST_STATE_ASYNC; } GST_PREROLL_UNLOCK (basesink->sinkpad); diff --git a/libs/gst/base/gstbasesink.h b/libs/gst/base/gstbasesink.h index 5fe29335d3..b65d62a2d7 100644 --- a/libs/gst/base/gstbasesink.h +++ b/libs/gst/base/gstbasesink.h @@ -68,7 +68,7 @@ struct _GstBaseSinkClass { GstCaps* (*get_caps) (GstBaseSink *sink); gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps); - GstBuffer* (*alloc_buffer) (GstBaseSink *sink, guint64 offset, guint size, + GstBuffer* (*buffer_alloc) (GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps); void (*get_times) (GstBaseSink *sink, GstBuffer *buffer,