[vlc-commits] [Git][videolan/vlc][master] 3 commits: rtp: fix timestamp sign expansion

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Tue Nov 9 18:01:36 UTC 2021



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
0656521a by Rémi Denis-Courmont at 2021-11-09T17:44:39+00:00
rtp: fix timestamp sign expansion

Pointed-out-by: François Cartégnie

- - - - -
3a0fd782 by Rémi Denis-Courmont at 2021-11-09T17:44:39+00:00
rtp: fix sequence signed overflow

- - - - -
a8613e9b by Rémi Denis-Courmont at 2021-11-09T17:44:39+00:00
rtp: optimise negation out

Perform the misordering comparison in unsigned space.

- - - - -


2 changed files:

- modules/access/rtp/rtp.c
- modules/access/rtp/session.c


Changes:

=====================================
modules/access/rtp/rtp.c
=====================================
@@ -301,7 +301,7 @@ static int OpenSDP(vlc_object_t *obj)
     sys->max_src = var_InheritInteger(obj, "rtp-max-src");
     sys->timeout = vlc_tick_from_sec(var_InheritInteger(obj, "rtp-timeout"));
     sys->max_dropout  = var_InheritInteger(obj, "rtp-max-dropout");
-    sys->max_misorder = var_InheritInteger(obj, "rtp-max-misorder");
+    sys->max_misorder = -var_InheritInteger(obj, "rtp-max-misorder");
     sys->autodetect = true;
 
     demux->pf_demux = NULL;
@@ -443,7 +443,7 @@ static int OpenURL(vlc_object_t *obj)
     p_sys->max_src      = var_CreateGetInteger (obj, "rtp-max-src");
     p_sys->timeout      = vlc_tick_from_sec( var_CreateGetInteger (obj, "rtp-timeout") );
     p_sys->max_dropout  = var_CreateGetInteger (obj, "rtp-max-dropout");
-    p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder");
+    p_sys->max_misorder = -var_CreateGetInteger (obj, "rtp-max-misorder");
     p_sys->autodetect   = true;
 
     demux->pf_demux   = NULL;


=====================================
modules/access/rtp/session.c
=====================================
@@ -326,9 +326,13 @@ rtp_queue (demux_t *demux, rtp_session_t *session, block_t *block)
     /* Check sequence number */
     /* NOTE: the sequence number is per-source,
      * but is independent from the payload type. */
-    int16_t delta_seq = seq - src->max_seq;
-    if ((delta_seq > 0) ? (delta_seq > p_sys->max_dropout)
-                        : (-delta_seq > p_sys->max_misorder))
+    union {
+        uint16_t u;
+        int16_t s;
+    } delta_seq = { .u = seq - src->max_seq };
+
+    if ((delta_seq.s > 0) ? (delta_seq.u > p_sys->max_dropout)
+                          : (delta_seq.u < p_sys->max_misorder))
     {
         msg_Dbg (demux, "sequence discontinuity"
                  " (got: %"PRIu16", expected: %"PRIu16")", seq, src->max_seq);
@@ -347,7 +351,7 @@ rtp_queue (demux_t *demux, rtp_session_t *session, block_t *block)
         }
     }
     else
-    if (delta_seq >= 0)
+    if (delta_seq.s >= 0)
         src->max_seq = seq + 1;
 
     /* Queues the block in sequence order,
@@ -355,10 +359,10 @@ rtp_queue (demux_t *demux, rtp_session_t *session, block_t *block)
     block_t **pp = &src->blocks;
     for (block_t *prev = *pp; prev != NULL; prev = *pp)
     {
-        delta_seq = seq - rtp_seq (prev);
-        if (delta_seq < 0)
+        delta_seq.u = seq - rtp_seq (prev);
+        if (delta_seq.s < 0)
             break;
-        if (delta_seq == 0)
+        if (delta_seq.s == 0)
         {
             msg_Dbg (demux, "duplicate packet (sequence: %"PRIu16")", seq);
             goto drop; /* duplicate */
@@ -506,8 +510,13 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src)
      * format, a single source MUST only use payloads of a chosen frequency.
      * Otherwise it would be impossible to compute consistent timestamps. */
     const uint32_t timestamp = rtp_timestamp (block);
-    block->i_pts = src->ref_ntp
-       + vlc_tick_from_samples(timestamp - src->ref_rtp, pt->frequency);
+    union {
+        uint32_t u;
+        int32_t s;
+    } ts_delta = { .u = timestamp - src->ref_rtp };
+    vlc_tick_t ticks = vlc_tick_from_samples(ts_delta.s, pt->frequency);
+
+    block->i_pts = src->ref_ntp + ticks;
     /* TODO: proper inter-medias/sessions sync (using RTCP-SR) */
     src->ref_ntp = block->i_pts;
     src->ref_rtp = timestamp;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2f5d21d6d82167882a255e7e52e3be7a04285780...a8613e9b92db9a29b87ca81ef2ec12d8ec1f345a

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2f5d21d6d82167882a255e7e52e3be7a04285780...a8613e9b92db9a29b87ca81ef2ec12d8ec1f345a
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list