mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
jitterbuffer: flesh out buffering mode some more
Add a buffering state to the jitterbuffer and wait until buffering ends before pushing out packets.
This commit is contained in:
parent
56b29c9a6b
commit
aeacbfed3e
3 changed files with 35 additions and 10 deletions
|
@ -1438,6 +1438,9 @@ again:
|
|||
id = NULL;
|
||||
/* always wait if we are blocked */
|
||||
if (G_LIKELY (!priv->blocked)) {
|
||||
/* we're buffering, wait */
|
||||
if (rtp_jitter_buffer_is_buffering (priv->jbuf))
|
||||
goto do_wait;
|
||||
/* if we have a packet, we can exit the loop and grab it */
|
||||
if (rtp_jitter_buffer_num_packets (priv->jbuf) > 0)
|
||||
break;
|
||||
|
@ -1460,6 +1463,7 @@ again:
|
|||
GST_OBJECT_UNLOCK (jitterbuffer);
|
||||
}
|
||||
}
|
||||
do_wait:
|
||||
/* now we wait */
|
||||
GST_DEBUG_OBJECT (jitterbuffer, "waiting");
|
||||
priv->waiting = TRUE;
|
||||
|
|
|
@ -125,6 +125,12 @@ void
|
|||
rtp_jitter_buffer_set_mode (RTPJitterBuffer * jbuf, RTPJitterBufferMode mode)
|
||||
{
|
||||
jbuf->mode = mode;
|
||||
|
||||
if (mode == RTP_JITTER_BUFFER_MODE_BUFFER) {
|
||||
/* when we're in buffering mode, always set our state to buffering, we'll
|
||||
* get out of it when we push the next buffer */
|
||||
jbuf->buffering = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -510,14 +516,19 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf,
|
|||
time = 0;
|
||||
else
|
||||
time = -1;
|
||||
|
||||
time = calculate_skew (jbuf, rtptime, time, clock_rate, max_delay);
|
||||
break;
|
||||
case RTP_JITTER_BUFFER_MODE_SLAVE:
|
||||
time = calculate_skew (jbuf, rtptime, time, clock_rate, max_delay);
|
||||
break;
|
||||
case RTP_JITTER_BUFFER_MODE_BUFFER:
|
||||
time = GST_BUFFER_TIMESTAMP (buf);
|
||||
/* send -1 for all timestamps except the first one. This will make the
|
||||
* timestamps increase according to the RTP timestamps. When in buffering
|
||||
* mode we will adjust the outgoing timestamps relative with how long we
|
||||
* buffered */
|
||||
if (jbuf->base_time != -1)
|
||||
time = -1;
|
||||
time = calculate_skew (jbuf, rtptime, time, clock_rate, max_delay);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -607,6 +618,21 @@ rtp_jitter_buffer_flush (RTPJitterBuffer * jbuf)
|
|||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_jitter_buffer_is_buffering:
|
||||
* @jbuf: an #RTPJitterBuffer
|
||||
*
|
||||
* Check if @jbuf is buffering currently. Users of the jitterbuffer should not
|
||||
* pop packets while in buffering mode.
|
||||
*
|
||||
* Returns: the buffering state of @jbuf
|
||||
*/
|
||||
gboolean
|
||||
rtp_jitter_buffer_is_buffering (RTPJitterBuffer * jbuf)
|
||||
{
|
||||
return jbuf->buffering;
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_jitter_buffer_num_packets:
|
||||
* @jbuf: an #RTPJitterBuffer
|
||||
|
@ -618,16 +644,9 @@ rtp_jitter_buffer_flush (RTPJitterBuffer * jbuf)
|
|||
guint
|
||||
rtp_jitter_buffer_num_packets (RTPJitterBuffer * jbuf)
|
||||
{
|
||||
guint result;
|
||||
|
||||
g_return_val_if_fail (jbuf != NULL, 0);
|
||||
|
||||
if (!jbuf->buffering)
|
||||
result = jbuf->packets->length;
|
||||
else
|
||||
result = 0;
|
||||
|
||||
return result;
|
||||
return jbuf->packets->length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -120,6 +120,8 @@ GstBuffer * rtp_jitter_buffer_pop (RTPJitterBuffer *jbuf)
|
|||
|
||||
void rtp_jitter_buffer_flush (RTPJitterBuffer *jbuf);
|
||||
|
||||
gboolean rtp_jitter_buffer_is_buffering (RTPJitterBuffer * jbuf);
|
||||
|
||||
guint rtp_jitter_buffer_num_packets (RTPJitterBuffer *jbuf);
|
||||
guint32 rtp_jitter_buffer_get_ts_diff (RTPJitterBuffer *jbuf);
|
||||
|
||||
|
|
Loading…
Reference in a new issue