rtpjitterbuffer: fix flush

Pass function to flush to properly free the queue items.
This commit is contained in:
Wim Taymans 2013-09-23 09:58:32 +02:00
parent 0cc887eb98
commit 479c7642fd
3 changed files with 34 additions and 27 deletions

View file

@ -654,19 +654,36 @@ gst_rtp_jitter_buffer_init (GstRtpJitterBuffer * jitterbuffer)
GST_OBJECT_FLAG_SET (jitterbuffer, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
}
static RTPJitterBufferItem *
alloc_item (void)
{
return g_slice_new (RTPJitterBufferItem);
}
static void
free_item (RTPJitterBufferItem * item)
{
if (item->data)
gst_mini_object_unref (item->data);
g_slice_free (RTPJitterBufferItem, item);
}
static void
gst_rtp_jitter_buffer_finalize (GObject * object)
{
GstRtpJitterBuffer *jitterbuffer;
GstRtpJitterBufferPrivate *priv;
jitterbuffer = GST_RTP_JITTER_BUFFER (object);
priv = jitterbuffer->priv;
g_array_free (jitterbuffer->priv->timers, TRUE);
g_mutex_clear (&jitterbuffer->priv->jbuf_lock);
g_cond_clear (&jitterbuffer->priv->jbuf_timer);
g_cond_clear (&jitterbuffer->priv->jbuf_event);
g_array_free (priv->timers, TRUE);
g_mutex_clear (&priv->jbuf_lock);
g_cond_clear (&priv->jbuf_timer);
g_cond_clear (&priv->jbuf_event);
g_object_unref (jitterbuffer->priv->jbuf);
rtp_jitter_buffer_flush (priv->jbuf, (GFunc) free_item, NULL);
g_object_unref (priv->jbuf);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -1034,7 +1051,7 @@ gst_rtp_jitter_buffer_flush_stop (GstRtpJitterBuffer * jitterbuffer)
priv->last_elapsed = 0;
priv->ext_timestamp = -1;
GST_DEBUG_OBJECT (jitterbuffer, "flush and reset jitterbuffer");
rtp_jitter_buffer_flush (priv->jbuf);
rtp_jitter_buffer_flush (priv->jbuf, (GFunc) free_item, NULL);
rtp_jitter_buffer_reset_skew (priv->jbuf);
remove_all_timers (jitterbuffer);
JBUF_UNLOCK (priv);
@ -1809,20 +1826,6 @@ calculate_expected (GstRtpJitterBuffer * jitterbuffer, guint32 expected,
}
}
static RTPJitterBufferItem *
alloc_item (void)
{
return g_slice_new (RTPJitterBufferItem);
}
static void
free_item (RTPJitterBufferItem * item)
{
if (item->data)
gst_mini_object_unref (item->data);
g_slice_free (RTPJitterBufferItem, item);
}
static GstFlowReturn
gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer)
@ -1952,7 +1955,7 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
}
if (G_UNLIKELY (reset)) {
GST_DEBUG_OBJECT (jitterbuffer, "flush and reset jitterbuffer");
rtp_jitter_buffer_flush (priv->jbuf);
rtp_jitter_buffer_flush (priv->jbuf, (GFunc) free_item, NULL);
rtp_jitter_buffer_reset_skew (priv->jbuf);
remove_all_timers (jitterbuffer);
priv->last_popped_seqnum = -1;

View file

@ -96,7 +96,6 @@ rtp_jitter_buffer_finalize (GObject * object)
jbuf = RTP_JITTER_BUFFER_CAST (object);
rtp_jitter_buffer_flush (jbuf);
g_queue_free (jbuf->packets);
G_OBJECT_CLASS (rtp_jitter_buffer_parent_class)->finalize (object);
@ -819,18 +818,22 @@ rtp_jitter_buffer_peek (RTPJitterBuffer * jbuf)
/**
* rtp_jitter_buffer_flush:
* @jbuf: an #RTPJitterBuffer
* @free_func: function to free each item
* @user_data: user data passed to @free_func
*
* Flush all packets from the jitterbuffer.
*/
void
rtp_jitter_buffer_flush (RTPJitterBuffer * jbuf)
rtp_jitter_buffer_flush (RTPJitterBuffer * jbuf, GFunc free_func,
gpointer user_data)
{
GstBuffer *buffer;
GList *item;
g_return_if_fail (jbuf != NULL);
g_return_if_fail (free_func != NULL);
while ((buffer = g_queue_pop_head (jbuf->packets)))
gst_buffer_unref (buffer);
while ((item = g_queue_pop_head_link (jbuf->packets)))
free_func ((RTPJitterBufferItem *) item, user_data);
}
/**

View file

@ -144,7 +144,8 @@ gboolean rtp_jitter_buffer_insert (RTPJitterBuffer *jbuf,
RTPJitterBufferItem * rtp_jitter_buffer_peek (RTPJitterBuffer *jbuf);
RTPJitterBufferItem * rtp_jitter_buffer_pop (RTPJitterBuffer *jbuf, gint *percent);
void rtp_jitter_buffer_flush (RTPJitterBuffer *jbuf);
void rtp_jitter_buffer_flush (RTPJitterBuffer *jbuf,
GFunc free_func, gpointer user_data);
gboolean rtp_jitter_buffer_is_buffering (RTPJitterBuffer * jbuf);
void rtp_jitter_buffer_set_buffering (RTPJitterBuffer * jbuf, gboolean buffering);