>From 13d1145ca9a58621a168698caec2cb78526f879c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20G=C3=BCntner?= <fatbull@web.de>
Date: Tue, 16 Aug 2011 21:23:35 +0000
Subject: [PATCH 2/3] Ignore invalid timestamps

---
 modules/demux/ps.c |    9 +++++----
 modules/demux/ps.h |    4 ++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/modules/demux/ps.c b/modules/demux/ps.c
index dd4f729..fd1621b 100644
--- a/modules/demux/ps.c
+++ b/modules/demux/ps.c
@@ -218,13 +218,13 @@ static int Demux2( demux_t *p_demux, bool b_end )
     if( (i_id = ps_pkt_id( p_pkt )) >= 0xc0 )
     {
         ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
-        if( !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
+        if( !ps_pkt_parse_pes( p_pkt, tk->i_skip ) && p_pkt->i_pts != VLC_TS_INVALID )
         {
             if( b_end && p_pkt->i_pts > tk->i_last_pts )
             {
                 tk->i_last_pts = p_pkt->i_pts;
             }
-            else if ( tk->i_first_pts == -1 )
+            else if ( tk->i_first_pts == VLC_TS_INVALID )
             {
                 tk->i_first_pts = p_pkt->i_pts;
             }
@@ -264,10 +264,11 @@ static void FindLength( demux_t *p_demux )
     for( int i = 0; i < PS_TK_COUNT; i++ )
     {
         ps_track_t *tk = &p_sys->tk[i];
-        if( tk->i_first_pts >= 0 && tk->i_last_pts > 0 &&
-            tk->i_last_pts > tk->i_first_pts )
+        if( tk->i_first_pts >= VLC_TS_0 && tk->i_last_pts >= VLC_TS_0 )
         {
             int64_t i_length = (int64_t)tk->i_last_pts - tk->i_first_pts;
+
+            assert( p_sys->i_length >= 0 );
             if( i_length > p_sys->i_length )
             {
                 p_sys->i_length = i_length;
diff --git a/modules/demux/ps.h b/modules/demux/ps.h
index 674c365..755e3db 100644
--- a/modules/demux/ps.h
+++ b/modules/demux/ps.h
@@ -71,8 +71,8 @@ static inline void ps_track_init( ps_track_t tk[PS_TK_COUNT] )
         tk[i].i_skip = 0;
         tk[i].i_id   = 0;
         tk[i].es     = NULL;
-        tk[i].i_first_pts = -1;
-        tk[i].i_last_pts = -1;
+        tk[i].i_first_pts = VLC_TS_INVALID;
+        tk[i].i_last_pts = VLC_TS_INVALID;
         es_format_Init( &tk[i].fmt, UNKNOWN_ES, 0 );
     }
 }
-- 
1.7.0.4

