aggregator: Hide GstAggregatorPad buffer and EOS fileds

And add a getter for the EOS.

The user should always use the various getters to access
those fields

https://bugzilla.gnome.org/show_bug.cgi?id=742684
This commit is contained in:
Thibault Saunier 2015-01-26 11:25:54 +01:00 committed by Tim-Philipp Müller
parent 0588222925
commit 5f176b724b
3 changed files with 38 additions and 23 deletions

View file

@ -166,6 +166,10 @@ struct _GstAggregatorPadPrivate
gboolean pending_eos; gboolean pending_eos;
gboolean flushing; gboolean flushing;
/* Protected by the pad lock */
GstBuffer *buffer;
gboolean eos;
GCond event_cond; GCond event_cond;
GMutex stream_lock; GMutex stream_lock;
@ -177,7 +181,7 @@ gst_aggregator_pad_flush (GstAggregatorPad * aggpad, GstAggregator * agg)
GstAggregatorPadClass *klass = GST_AGGREGATOR_PAD_GET_CLASS (aggpad); GstAggregatorPadClass *klass = GST_AGGREGATOR_PAD_GET_CLASS (aggpad);
PAD_LOCK (aggpad); PAD_LOCK (aggpad);
aggpad->eos = FALSE; aggpad->priv->eos = FALSE;
aggpad->priv->flushing = FALSE; aggpad->priv->flushing = FALSE;
PAD_UNLOCK (aggpad); PAD_UNLOCK (aggpad);
@ -345,8 +349,8 @@ gst_aggregator_check_pads_ready (GstAggregator * self)
pad = l->data; pad = l->data;
PAD_LOCK (pad); PAD_LOCK (pad);
if (pad->buffer == NULL && !pad->eos) { if (pad->priv->buffer == NULL && !pad->priv->eos) {
GST_OBJECT_UNLOCK (pad); PAD_UNLOCK (pad);
goto pad_not_ready; goto pad_not_ready;
} }
PAD_UNLOCK (pad); PAD_UNLOCK (pad);
@ -862,8 +866,8 @@ gst_aggregator_default_sink_event (GstAggregator * self,
*/ */
SRC_STREAM_LOCK (self); SRC_STREAM_LOCK (self);
PAD_LOCK (aggpad); PAD_LOCK (aggpad);
if (!aggpad->buffer) { if (!aggpad->priv->buffer) {
aggpad->eos = TRUE; aggpad->priv->eos = TRUE;
} else { } else {
aggpad->priv->pending_eos = TRUE; aggpad->priv->pending_eos = TRUE;
} }
@ -1770,8 +1774,8 @@ gst_aggregator_pad_chain (GstPad * pad, GstObject * object, GstBuffer * buffer)
goto eos; goto eos;
PAD_LOCK (aggpad); PAD_LOCK (aggpad);
while (aggpad->priv->buffer
while (aggpad->buffer && g_atomic_int_get (&aggpad->priv->flushing) == FALSE) { && g_atomic_int_get (&aggpad->priv->flushing) == FALSE) {
GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed"); GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
PAD_WAIT_EVENT (aggpad); PAD_WAIT_EVENT (aggpad);
} }
@ -1786,9 +1790,9 @@ gst_aggregator_pad_chain (GstPad * pad, GstObject * object, GstBuffer * buffer)
SRC_STREAM_LOCK (self); SRC_STREAM_LOCK (self);
PAD_LOCK (aggpad); PAD_LOCK (aggpad);
if (aggpad->buffer) if (aggpad->priv->buffer)
gst_buffer_unref (aggpad->buffer); gst_buffer_unref (aggpad->priv->buffer);
aggpad->buffer = actual_buf; aggpad->priv->buffer = actual_buf;
PAD_UNLOCK (aggpad); PAD_UNLOCK (aggpad);
PAD_STREAM_UNLOCK (aggpad); PAD_STREAM_UNLOCK (aggpad);
@ -1836,7 +1840,7 @@ gst_aggregator_pad_query_func (GstPad * pad, GstObject * parent,
goto flushing; goto flushing;
} }
while (aggpad->buffer while (aggpad->priv->buffer
&& g_atomic_int_get (&aggpad->priv->flushing) == FALSE) { && g_atomic_int_get (&aggpad->priv->flushing) == FALSE) {
GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed"); GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
PAD_WAIT_EVENT (aggpad); PAD_WAIT_EVENT (aggpad);
@ -1872,7 +1876,7 @@ gst_aggregator_pad_event_func (GstPad * pad, GstObject * parent,
goto flushing; goto flushing;
} }
while (aggpad->buffer while (aggpad->priv->buffer
&& g_atomic_int_get (&aggpad->priv->flushing) == FALSE) { && g_atomic_int_get (&aggpad->priv->flushing) == FALSE) {
GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed"); GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
PAD_WAIT_EVENT (aggpad); PAD_WAIT_EVENT (aggpad);
@ -1904,7 +1908,7 @@ gst_aggregator_pad_activate_mode_func (GstPad * pad,
if (active == FALSE) { if (active == FALSE) {
PAD_LOCK (aggpad); PAD_LOCK (aggpad);
g_atomic_int_set (&aggpad->priv->flushing, TRUE); g_atomic_int_set (&aggpad->priv->flushing, TRUE);
gst_buffer_replace (&aggpad->buffer, NULL); gst_buffer_replace (&aggpad->priv->buffer, NULL);
PAD_BROADCAST_EVENT (aggpad); PAD_BROADCAST_EVENT (aggpad);
PAD_UNLOCK (aggpad); PAD_UNLOCK (aggpad);
} else { } else {
@ -1980,7 +1984,7 @@ gst_aggregator_pad_init (GstAggregatorPad * pad)
G_TYPE_INSTANCE_GET_PRIVATE (pad, GST_TYPE_AGGREGATOR_PAD, G_TYPE_INSTANCE_GET_PRIVATE (pad, GST_TYPE_AGGREGATOR_PAD,
GstAggregatorPadPrivate); GstAggregatorPadPrivate);
pad->buffer = NULL; pad->priv->buffer = NULL;
g_cond_init (&pad->priv->event_cond); g_cond_init (&pad->priv->event_cond);
g_mutex_init (&pad->priv->stream_lock); g_mutex_init (&pad->priv->stream_lock);
@ -2002,13 +2006,13 @@ gst_aggregator_pad_steal_buffer_unlocked (GstAggregatorPad * pad)
{ {
GstBuffer *buffer = NULL; GstBuffer *buffer = NULL;
if (pad->buffer) { if (pad->priv->buffer) {
GST_TRACE_OBJECT (pad, "Consuming buffer"); GST_TRACE_OBJECT (pad, "Consuming buffer");
buffer = pad->buffer; buffer = pad->priv->buffer;
pad->buffer = NULL; pad->priv->buffer = NULL;
if (pad->priv->pending_eos) { if (pad->priv->pending_eos) {
pad->priv->pending_eos = FALSE; pad->priv->pending_eos = FALSE;
pad->eos = TRUE; pad->priv->eos = TRUE;
} }
PAD_BROADCAST_EVENT (pad); PAD_BROADCAST_EVENT (pad);
GST_DEBUG_OBJECT (pad, "Consumed: %" GST_PTR_FORMAT, buffer); GST_DEBUG_OBJECT (pad, "Consumed: %" GST_PTR_FORMAT, buffer);
@ -2052,13 +2056,25 @@ gst_aggregator_pad_get_buffer (GstAggregatorPad * pad)
GstBuffer *buffer = NULL; GstBuffer *buffer = NULL;
PAD_LOCK (pad); PAD_LOCK (pad);
if (pad->buffer) if (pad->priv->buffer)
buffer = gst_buffer_ref (pad->buffer); buffer = gst_buffer_ref (pad->priv->buffer);
PAD_UNLOCK (pad); PAD_UNLOCK (pad);
return buffer; return buffer;
} }
gboolean
gst_aggregator_pad_is_eos (GstAggregatorPad * pad)
{
gboolean is_eos;
PAD_LOCK (pad);
is_eos = pad->priv->eos;
PAD_UNLOCK (pad);
return is_eos;
}
/** /**
* gst_aggregator_merge_tags: * gst_aggregator_merge_tags:
* @self: a #GstAggregator * @self: a #GstAggregator

View file

@ -70,9 +70,7 @@ struct _GstAggregatorPad
GstPad parent; GstPad parent;
/* Protected by the pad's object lock */ /* Protected by the pad's object lock */
GstBuffer * buffer;
GstSegment segment; GstSegment segment;
gboolean eos;
/* < Private > */ /* < Private > */
GstAggregatorPadPrivate * priv; GstAggregatorPadPrivate * priv;
@ -107,6 +105,7 @@ GType gst_aggregator_pad_get_type (void);
GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad); GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad);
GstBuffer * gst_aggregator_pad_steal_buffer_unlocked (GstAggregatorPad * pad); GstBuffer * gst_aggregator_pad_steal_buffer_unlocked (GstAggregatorPad * pad);
GstBuffer * gst_aggregator_pad_get_buffer (GstAggregatorPad * pad); GstBuffer * gst_aggregator_pad_get_buffer (GstAggregatorPad * pad);
gboolean gst_aggregator_pad_is_eos (GstAggregatorPad * pad);
/********************* /*********************
* GstAggregator API * * GstAggregator API *

View file

@ -84,7 +84,7 @@ gst_test_aggregator_aggregate (GstAggregator * aggregator, gboolean timeout)
case GST_ITERATOR_OK: case GST_ITERATOR_OK:
pad = g_value_get_object (&value); pad = g_value_get_object (&value);
if (pad->eos == FALSE) if (gst_aggregator_pad_is_eos (pad) == FALSE)
all_eos = FALSE; all_eos = FALSE;
buffer = gst_aggregator_pad_steal_buffer (pad); buffer = gst_aggregator_pad_steal_buffer (pad);
gst_buffer_replace (&buffer, NULL); gst_buffer_replace (&buffer, NULL);