rtpjitterbuffer: Clear clock master before unreffing
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpjitterbuffer.c
index f1187e2..64d89a8 100644 (file)
@@ -103,8 +103,11 @@ rtp_jitter_buffer_finalize (GObject * object)
   if (jbuf->media_clock_synced_id)
     g_signal_handler_disconnect (jbuf->media_clock,
         jbuf->media_clock_synced_id);
-  if (jbuf->media_clock)
+  if (jbuf->media_clock) {
+    /* Make sure to clear any clock master before releasing the clock */
+    gst_clock_set_master (jbuf->media_clock, NULL);
     gst_object_unref (jbuf->media_clock);
+  }
 
   if (jbuf->pipeline_clock)
     gst_object_unref (jbuf->pipeline_clock);
@@ -1046,7 +1049,7 @@ duplicate:
  * @percent: the buffering percent
  *
  * Pops the oldest buffer from the packet queue of @jbuf. The popped buffer will
- * have its timestamp adjusted with the incomming running_time and the detected
+ * have its timestamp adjusted with the incoming running_time and the detected
  * clock skew.
  *
  * Returns: a #GstBuffer or %NULL when there was no packet in the queue.
@@ -1227,6 +1230,49 @@ rtp_jitter_buffer_get_ts_diff (RTPJitterBuffer * jbuf)
   return result;
 }
 
+
+/**
+ * rtp_jitter_buffer_get_seqnum_diff:
+ * @jbuf: an #RTPJitterBuffer
+ *
+ * Get the difference between the seqnum of first and last packet in the
+ * jitterbuffer.
+ *
+ * Returns: The difference expressed in seqnum.
+ */
+guint16
+rtp_jitter_buffer_get_seqnum_diff (RTPJitterBuffer * jbuf)
+{
+  guint32 high_seqnum, low_seqnum;
+  RTPJitterBufferItem *high_buf, *low_buf;
+  guint16 result;
+
+  g_return_val_if_fail (jbuf != NULL, 0);
+
+  high_buf = (RTPJitterBufferItem *) g_queue_peek_tail_link (jbuf->packets);
+  low_buf = (RTPJitterBufferItem *) g_queue_peek_head_link (jbuf->packets);
+
+  while (high_buf && high_buf->seqnum == -1)
+    high_buf = (RTPJitterBufferItem *) high_buf->prev;
+
+  while (low_buf && low_buf->seqnum == -1)
+    low_buf = (RTPJitterBufferItem *) low_buf->next;
+
+  if (!high_buf || !low_buf || high_buf == low_buf)
+    return 0;
+
+  high_seqnum = high_buf->seqnum;
+  low_seqnum = low_buf->seqnum;
+
+  /* it needs to work if ts wraps */
+  if (high_seqnum >= low_seqnum) {
+    result = (guint32) (high_seqnum - low_seqnum);
+  } else {
+    result = (guint32) (high_seqnum + G_MAXUINT16 + 1 - low_seqnum);
+  }
+  return result;
+}
+
 /**
  * rtp_jitter_buffer_get_sync:
  * @jbuf: an #RTPJitterBuffer