mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
jitterbuffer: configure clock-rate on jitterbuffer
Add a get and setter to configure the clock-rate in the jitterbuffer instead of passing it as an argument to the insert method.
This commit is contained in:
parent
a71014518c
commit
5051f51f0a
3 changed files with 51 additions and 25 deletions
|
@ -937,6 +937,8 @@ gst_jitter_buffer_sink_parse_caps (GstRtpJitterBuffer * jitterbuffer,
|
|||
|
||||
GST_DEBUG_OBJECT (jitterbuffer, "got clock-rate %d", priv->clock_rate);
|
||||
|
||||
rtp_jitter_buffer_set_clock_rate (priv->jbuf, priv->clock_rate);
|
||||
|
||||
/* The clock base is the RTP timestamp corrsponding to the npt-start value. We
|
||||
* can use this to track the amount of time elapsed on the sender. */
|
||||
if (gst_structure_get_uint (caps_struct, "clock-base", &val))
|
||||
|
@ -1995,7 +1997,7 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
|
|||
* FALSE if a packet with the same seqnum was already in the queue, meaning we
|
||||
* have a duplicate. */
|
||||
if (G_UNLIKELY (!rtp_jitter_buffer_insert (priv->jbuf, buffer, dts,
|
||||
priv->clock_rate, &tail, &percent)))
|
||||
&tail, &percent)))
|
||||
goto duplicate;
|
||||
|
||||
/* update timers */
|
||||
|
|
|
@ -166,6 +166,44 @@ rtp_jitter_buffer_set_delay (RTPJitterBuffer * jbuf, GstClockTime delay)
|
|||
GST_TIME_ARGS (jbuf->low_level), GST_TIME_ARGS (jbuf->high_level));
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_jitter_buffer_set_clock_rate:
|
||||
* @jbuf: an #RTPJitterBuffer
|
||||
*
|
||||
* Set the clock rate in the jitterbuffer.
|
||||
*/
|
||||
void
|
||||
rtp_jitter_buffer_set_clock_rate (RTPJitterBuffer * jbuf, guint32 clock_rate)
|
||||
{
|
||||
if (jbuf->clock_rate != clock_rate) {
|
||||
if (jbuf->clock_rate == -1) {
|
||||
GST_DEBUG ("Clock rate changed from %" G_GUINT32_FORMAT " to %"
|
||||
G_GUINT32_FORMAT, jbuf->clock_rate, clock_rate);
|
||||
} else {
|
||||
GST_WARNING ("Clock rate changed from %" G_GUINT32_FORMAT " to %"
|
||||
G_GUINT32_FORMAT, jbuf->clock_rate, clock_rate);
|
||||
}
|
||||
jbuf->base_time = -1;
|
||||
jbuf->base_rtptime = -1;
|
||||
jbuf->clock_rate = clock_rate;
|
||||
jbuf->prev_out_time = -1;
|
||||
jbuf->prev_send_diff = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_jitter_buffer_get_clock_rate:
|
||||
* @jbuf: an #RTPJitterBuffer
|
||||
*
|
||||
* Get the currently configure clock rate in @jbuf.
|
||||
*
|
||||
* Returns: the current clock-rate
|
||||
*/
|
||||
guint32
|
||||
rtp_jitter_buffer_get_clock_rate (RTPJitterBuffer * jbuf)
|
||||
{
|
||||
return jbuf->clock_rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_jitter_buffer_reset_skew:
|
||||
|
@ -360,8 +398,7 @@ update_buffer_level (RTPJitterBuffer * jbuf, gint * percent)
|
|||
* Returns: @time adjusted with the clock skew.
|
||||
*/
|
||||
static GstClockTime
|
||||
calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time,
|
||||
guint32 clock_rate)
|
||||
calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time)
|
||||
{
|
||||
guint64 ext_rtptime;
|
||||
guint64 send_diff, recv_diff;
|
||||
|
@ -376,26 +413,12 @@ calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time,
|
|||
if (jbuf->last_rtptime != -1 && ext_rtptime == jbuf->last_rtptime)
|
||||
return jbuf->prev_out_time;
|
||||
|
||||
gstrtptime = gst_util_uint64_scale_int (ext_rtptime, GST_SECOND, clock_rate);
|
||||
gstrtptime =
|
||||
gst_util_uint64_scale_int (ext_rtptime, GST_SECOND, jbuf->clock_rate);
|
||||
|
||||
/* keep track of the last extended rtptime */
|
||||
jbuf->last_rtptime = ext_rtptime;
|
||||
|
||||
if (jbuf->clock_rate != clock_rate) {
|
||||
if (jbuf->clock_rate == -1) {
|
||||
GST_DEBUG ("Clock rate changed from %" G_GUINT32_FORMAT " to %"
|
||||
G_GUINT32_FORMAT, jbuf->clock_rate, clock_rate);
|
||||
} else {
|
||||
GST_WARNING ("Clock rate changed from %" G_GUINT32_FORMAT " to %"
|
||||
G_GUINT32_FORMAT, jbuf->clock_rate, clock_rate);
|
||||
}
|
||||
jbuf->base_time = -1;
|
||||
jbuf->base_rtptime = -1;
|
||||
jbuf->clock_rate = clock_rate;
|
||||
jbuf->prev_out_time = -1;
|
||||
jbuf->prev_send_diff = -1;
|
||||
}
|
||||
|
||||
/* first time, lock on to time and gstrtptime */
|
||||
if (G_UNLIKELY (jbuf->base_time == -1)) {
|
||||
jbuf->base_time = time;
|
||||
|
@ -593,7 +616,6 @@ no_skew:
|
|||
* @jbuf: an #RTPJitterBuffer
|
||||
* @buf: a buffer
|
||||
* @time: a running_time when this buffer was received in nanoseconds
|
||||
* @clock_rate: the clock-rate of the payload of @buf
|
||||
* @max_delay: the maximum lateness of @buf
|
||||
* @tail: TRUE when the tail element changed.
|
||||
*
|
||||
|
@ -606,7 +628,7 @@ no_skew:
|
|||
*/
|
||||
gboolean
|
||||
rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf,
|
||||
GstClockTime time, guint32 clock_rate, gboolean * tail, gint * percent)
|
||||
GstClockTime time, gboolean * tail, gint * percent)
|
||||
{
|
||||
GList *list;
|
||||
guint32 rtptime;
|
||||
|
@ -654,8 +676,8 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf,
|
|||
GstClockTime ext_rtptime = jbuf->ext_rtptime;
|
||||
|
||||
ext_rtptime = gst_rtp_buffer_ext_timestamp (&ext_rtptime, rtptime);
|
||||
if (ext_rtptime > jbuf->last_rtptime + 3 * clock_rate ||
|
||||
ext_rtptime + 3 * clock_rate < jbuf->last_rtptime) {
|
||||
if (ext_rtptime > jbuf->last_rtptime + 3 * jbuf->clock_rate ||
|
||||
ext_rtptime + 3 * jbuf->clock_rate < jbuf->last_rtptime) {
|
||||
/* reset even if we don't have valid incoming time;
|
||||
* still better than producing possibly very bogus output timestamp */
|
||||
GST_WARNING ("rtp delta too big, reset skew");
|
||||
|
@ -682,7 +704,7 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf,
|
|||
/* do skew calculation by measuring the difference between rtptime and the
|
||||
* receive time, this function will retimestamp @buf with the skew corrected
|
||||
* running time. */
|
||||
time = calculate_skew (jbuf, rtptime, time, clock_rate);
|
||||
time = calculate_skew (jbuf, rtptime, time);
|
||||
GST_BUFFER_PTS (buf) = time;
|
||||
|
||||
/* It's more likely that the packet was inserted in the front of the buffer */
|
||||
|
|
|
@ -110,11 +110,13 @@ void rtp_jitter_buffer_set_mode (RTPJitterBuffer *jbuf,
|
|||
GstClockTime rtp_jitter_buffer_get_delay (RTPJitterBuffer *jbuf);
|
||||
void rtp_jitter_buffer_set_delay (RTPJitterBuffer *jbuf, GstClockTime delay);
|
||||
|
||||
void rtp_jitter_buffer_set_clock_rate (RTPJitterBuffer *jbuf, guint32 clock_rate);
|
||||
guint32 rtp_jitter_buffer_get_clock_rate (RTPJitterBuffer *jbuf);
|
||||
|
||||
void rtp_jitter_buffer_reset_skew (RTPJitterBuffer *jbuf);
|
||||
|
||||
gboolean rtp_jitter_buffer_insert (RTPJitterBuffer *jbuf, GstBuffer *buf,
|
||||
GstClockTime time,
|
||||
guint32 clock_rate,
|
||||
gboolean *tail, gint *percent);
|
||||
GstBuffer * rtp_jitter_buffer_peek (RTPJitterBuffer *jbuf);
|
||||
GstBuffer * rtp_jitter_buffer_pop (RTPJitterBuffer *jbuf, gint *percent);
|
||||
|
|
Loading…
Reference in a new issue