jitterbuffer: avoid trying to buffer more than is available.

That is, in case of short (or near eos of) stream, deadlock (until timeout)
would occur trying to buffer more than is yet forthcoming.
This commit is contained in:
Mark Nauwelaerts 2011-03-07 16:56:18 +01:00
parent f84b8a69cb
commit 3c9a4239bf

View file

@ -1232,6 +1232,22 @@ parse_failed:
}
}
/* call with jbuf lock held */
static void
check_buffering_percent (GstRtpJitterBuffer * jitterbuffer, gint * percent)
{
GstRtpJitterBufferPrivate *priv = jitterbuffer->priv;
/* too short a stream, or too close to EOS will never really fill buffer */
if (*percent != -1 && priv->npt_stop != -1 &&
priv->npt_stop - priv->npt_start <=
rtp_jitter_buffer_get_delay (priv->jbuf)) {
GST_DEBUG_OBJECT (jitterbuffer, "short stream; faking full buffer");
rtp_jitter_buffer_set_buffering (priv->jbuf, FALSE);
*percent = 100;
}
}
static void
post_buffering_percent (GstRtpJitterBuffer * jitterbuffer, gint percent)
{
@ -1406,6 +1422,8 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstBuffer * buffer)
GST_DEBUG_OBJECT (jitterbuffer, "Pushed packet #%d, now %d packets, tail: %d",
seqnum, rtp_jitter_buffer_num_packets (priv->jbuf), tail);
check_buffering_percent (jitterbuffer, &percent);
finished:
JBUF_UNLOCK (priv);
@ -1836,6 +1854,8 @@ push_buffer:
/* when we get here we are ready to pop and push the buffer */
outbuf = rtp_jitter_buffer_pop (priv->jbuf, &percent);
check_buffering_percent (jitterbuffer, &percent);
if (G_UNLIKELY (discont || priv->discont)) {
/* set DISCONT flag when we missed a packet. We pushed the buffer writable
* into the jitterbuffer so we can modify now. */