]> git.sesse.net Git - vlc/blobdiff - modules/demux/rtpsession.c
cdda/info: fix memleaks.
[vlc] / modules / demux / rtpsession.c
index 4e1008123b06beefb17b57cf507c3bf0a2af63f3..ccad2841a4a1cf045daea351b631f628a2cb36cb 100644 (file)
@@ -141,6 +141,7 @@ struct rtp_source_t
     uint16_t bad_seq; /* tentatively next expected sequence for resync */
     uint16_t max_seq; /* next expected sequence */
 
+    uint16_t last_seq; /* sequence of the last dequeued packet */
     block_t *blocks; /* re-ordered blocks queue */
     void    *opaque[0]; /* Per-source private payload data */
 };
@@ -160,6 +161,7 @@ rtp_source_create (demux_t *demux, const rtp_session_t *session,
 
     source->ssrc = ssrc;
     source->max_seq = source->bad_seq = init_seq;
+    source->last_seq = init_seq - 1;
     source->blocks = NULL;
 
     /* Initializes all payload */
@@ -266,6 +268,13 @@ rtp_receive (demux_t *demux, rtp_session_t *session, block_t *block)
         tab[session->srcc++] = src;
     }
 
+    /* Be optimistic for the first packet. Certain codec, such as Vorbis
+     * do not like loosing the first packet(s), so we cannot just wait
+     * for proper sequence synchronization. And we don't want to assume that
+     * the sender starts at seq=0 either. */
+    if (src->blocks == NULL)
+        src->max_seq = seq - p_sys->max_dropout;
+
     /* Check sequence number */
     /* NOTE: the sequence number is per-source,
      * but is independent from the payload type. */
@@ -297,7 +306,7 @@ rtp_receive (demux_t *demux, rtp_session_t *session, block_t *block)
     block_t **pp = &src->blocks;
     for (block_t *prev = *pp; prev != NULL; prev = *pp)
     {
-        if ((int16_t)(seq - rtp_seq (*pp)) >= 0)
+        if ((int16_t)(seq - rtp_seq (*pp)) < 0)
             break;
         pp = &prev->p_next;
     }
@@ -324,6 +333,11 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src)
     src->blocks = block->p_next;
     block->p_next = NULL;
 
+    /* Discontinuity detection */
+    if (((src->last_seq + 1) & 0xffff) != rtp_seq (block))
+        block->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+    src->last_seq = rtp_seq (block);
+
     /* Match the payload type */
     const rtp_pt_t *pt = NULL;
     void *pt_data = NULL;