[vlc-commits] avformat : fix overflow in timestamp computation

Sébastien Escudier git at videolan.org
Mon Feb 27 11:38:47 CET 2012


vlc | branch: master | Sébastien Escudier <sebastien-devel at celeos.eu> | Fri Feb 24 15:28:28 2012 +0100| [b19614ae62c2083ae7f5b34cd7b7a5d3ca7e250a] | committer: Sébastien Escudier

avformat : fix overflow in timestamp computation

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b19614ae62c2083ae7f5b34cd7b7a5d3ca7e250a
---

 modules/demux/avformat/demux.c |   42 +++++++++++++++++++++++++++++----------
 1 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 7356bfe..3264b11 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -609,17 +609,37 @@ static int Demux( demux_t *p_demux )
     if( pkt.flags & AV_PKT_FLAG_KEY )
         p_frame->i_flags |= BLOCK_FLAG_TYPE_I;
 
-    i_start_time = ( p_sys->ic->start_time != (int64_t)AV_NOPTS_VALUE ) ?
-        ( p_sys->ic->start_time * 1000000 / AV_TIME_BASE )  : 0;
-
-    p_frame->i_dts = ( pkt.dts == (int64_t)AV_NOPTS_VALUE ) ?
-        VLC_TS_INVALID : (pkt.dts) * 1000000 *
-        p_stream->time_base.num /
-        p_stream->time_base.den - i_start_time + VLC_TS_0;
-    p_frame->i_pts = ( pkt.pts == (int64_t)AV_NOPTS_VALUE ) ?
-        VLC_TS_INVALID : (pkt.pts) * 1000000 *
-        p_stream->time_base.num /
-        p_stream->time_base.den - i_start_time + VLC_TS_0;
+    /* Used to avoid timestamps overlow */
+    lldiv_t q;
+    if( p_sys->ic->start_time != (int64_t)AV_NOPTS_VALUE )
+    {
+        q = lldiv( p_sys->ic->start_time, AV_TIME_BASE);
+        i_start_time = q.quot * (int64_t)1000000 + q.rem * (int64_t)1000000 / AV_TIME_BASE;
+    }
+    else
+        i_start_time = 0;
+
+    if( pkt.dts == (int64_t)AV_NOPTS_VALUE )
+        p_frame->i_dts = VLC_TS_INVALID;
+    else
+    {
+        q = lldiv( pkt.dts, p_stream->time_base.den );
+        p_frame->i_dts = q.quot * (int64_t)1000000 *
+            p_stream->time_base.num + q.rem * (int64_t)1000000 *
+            p_stream->time_base.num /
+            p_stream->time_base.den - i_start_time + VLC_TS_0;
+    }
+
+    if( pkt.pts == (int64_t)AV_NOPTS_VALUE )
+        p_frame->i_pts = VLC_TS_INVALID;
+    else
+    {
+        q = lldiv( pkt.pts, p_stream->time_base.den );
+        p_frame->i_pts = q.quot * (int64_t)1000000 *
+            p_stream->time_base.num + q.rem * (int64_t)1000000 *
+            p_stream->time_base.num /
+            p_stream->time_base.den - i_start_time + VLC_TS_0;
+    }
     if( pkt.duration > 0 && p_frame->i_length <= 0 )
         p_frame->i_length = pkt.duration * 1000000 *
             p_stream->time_base.num /



More information about the vlc-commits mailing list