[vlc-commits] demux: ts: improve PCRCheckDTS()

Petri Hintukainen git at videolan.org
Mon Apr 25 13:04:19 CEST 2016


vlc | branch: master | Petri Hintukainen <phintuka at gmail.com> | Sat Apr  9 14:55:42 2016 +0300| [735b1b1aede668fe7fcb16d7feb35b69159aec8b] | committer: Petri Hintukainen

demux: ts: improve PCRCheckDTS()

Limit test to MPEG, H.264 and VC-1 video.
Check for video sequence end code.

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

 modules/demux/mpeg/ts.c |   36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index 2d50734..f59dfc5 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -2052,6 +2052,28 @@ static void ProgramSetPCR( demux_t *p_demux, ts_pmt_t *p_pmt, mtime_t i_pcr )
     }
 }
 
+static int IsVideoEnd( ts_pid_t *p_pid )
+{
+    /* jump to near end of PES packet */
+    block_t *p = p_pid->u.p_pes->p_data;
+    if( !p || !p->p_next )
+        return 0;
+    while( p->p_next->p_next )
+        p = p->p_next;
+    if( p->p_next->i_buffer > 4)
+        p = p->p_next;
+
+    /* extract last bytes */
+    uint8_t tail[ 188 ];
+    const int i_tail = block_ChainExtract( p, tail, sizeof( tail ) );
+    if( i_tail < 4 )
+        return 0;
+
+    /* check for start code at end */
+    return ( tail[ i_tail - 4 ] == 0 && tail[ i_tail - 3 ] == 0 && tail[ i_tail - 2 ] == 1 &&
+             ( tail[ i_tail - 1 ] == 0xb7 ||  tail[ i_tail - 1 ] == 0x0a ) );
+}
+
 static void PCRCheckDTS( demux_t *p_demux, ts_pmt_t *p_pmt, mtime_t i_pcr)
 {
     for( int i=0; i<p_pmt->e_streams.i_size; i++ )
@@ -2066,6 +2088,13 @@ static void PCRCheckDTS( demux_t *p_demux, ts_pmt_t *p_pmt, mtime_t i_pcr)
         if( p_pid->u.p_pes->i_data_size != 0 )
             continue;
 
+        /* check only MPEG2, H.264 and VC-1 */
+        ts_pes_es_t *p_es = p_pid->u.p_pes->p_es;
+        if( p_es->fmt.i_codec != VLC_CODEC_MPGV &&
+            p_es->fmt.i_codec != VLC_CODEC_H264 &&
+            p_es->fmt.i_codec != VLC_CODEC_VC1 )
+            continue;
+
         uint8_t header[34];
         const int i_max = block_ChainExtract( p_pid->u.p_pes->p_data, header, 34 );
 
@@ -2096,7 +2125,12 @@ static void PCRCheckDTS( demux_t *p_demux, ts_pmt_t *p_pmt, mtime_t i_pcr)
         if(( i_dts > VLC_TS_INVALID && i_dts <= i_pcr ) ||
            ( i_pts > VLC_TS_INVALID && i_pts <= i_pcr ))
         {
-            ParsePESDataChain( p_demux, p_pid );
+            if( IsVideoEnd( p_pid ) )
+            {
+                msg_Warn( p_demux, "send queued data for pid %d: TS %"PRId64" <= PCR %"PRId64"\n",
+                          p_pid->i_pid, i_dts > VLC_TS_INVALID ? i_dts : i_pts, i_pcr);
+                ParsePESDataChain( p_demux, p_pid );
+            }
         }
     }
 }



More information about the vlc-commits mailing list