[vlc-commits] demux: ts: rework scrambling check

Francois Cartegnie git at videolan.org
Thu Dec 22 19:45:56 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Dec 22 16:12:14 2016 +0100| [b78a7ea1ad564f77b8067b1bd45bf3cbd7203ffc] | committer: Francois Cartegnie

demux: ts: rework scrambling check

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

 modules/demux/mpeg/ts.c | 45 ++++++++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index 8414819..10eb69f 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -636,13 +636,6 @@ static int Demux( demux_t *p_demux )
 
         /* Parse the TS packet */
         ts_pid_t *p_pid = GetPID( p_sys, PIDGet( p_pkt ) );
-
-        if( (p_pkt->p_buffer[1] & 0x40) && (p_pkt->p_buffer[3] & 0x10) &&
-            !SCRAMBLED(*p_pid) != !(p_pkt->p_buffer[3] & 0x80) )
-        {
-            UpdatePIDScrambledState( p_demux, p_pid, p_pkt->p_buffer[3] & 0x80 );
-        }
-
         if( !SEEN(p_pid) )
         {
             if( p_pid->type == TYPE_FREE )
@@ -657,17 +650,16 @@ static int Demux( demux_t *p_demux )
         if( !p_pkt )
             continue;
 
+        if( !SCRAMBLED(*p_pid) != !(p_pkt->i_flags & BLOCK_FLAG_SCRAMBLED) )
+        {
+            UpdatePIDScrambledState( p_demux, p_pid, p_pkt->i_flags & BLOCK_FLAG_SCRAMBLED );
+        }
+
         /* Adaptation field cannot be scrambled */
         mtime_t i_pcr = GetPCR( p_pkt );
         if( i_pcr > VLC_TS_INVALID )
             PCRHandle( p_demux, p_pid, i_pcr );
 
-        if ( SCRAMBLED(*p_pid) && !p_demux->p_sys->csa && p_sys->b_valid_scrambling )
-        {
-            block_Release( p_pkt );
-            continue;
-        }
-
         /* Probe streams to build PAT/PMT after MIN_PAT_INTERVAL in case we don't see any PAT */
         if( !SEEN( GetPID( p_sys, 0 ) ) &&
             (p_pid->probed.i_fourcc == 0 || p_pid->i_pid == p_sys->patfix.i_timesourcepid) &&
@@ -682,6 +674,7 @@ static int Demux( demux_t *p_demux )
         {
         case TYPE_PAT:
         case TYPE_PMT:
+            /* PAT and PMT are not allowed to be scrambled */
             ts_psi_Packet_Push( p_pid, p_pkt->p_buffer );
             block_Release( p_pkt );
             break;
@@ -719,12 +712,14 @@ static int Demux( demux_t *p_demux )
             break;
 
         case TYPE_SI:
-            ts_si_Packet_Push( p_pid, p_pkt->p_buffer );
+            if( (p_pkt->i_flags & (BLOCK_FLAG_SCRAMBLED|BLOCK_FLAG_CORRUPTED)) == 0 )
+                ts_si_Packet_Push( p_pid, p_pkt->p_buffer );
             block_Release( p_pkt );
             break;
 
         case TYPE_PSIP:
-            ts_psip_Packet_Push( p_pid, p_pkt->p_buffer );
+            if( (p_pkt->i_flags & (BLOCK_FLAG_SCRAMBLED|BLOCK_FLAG_CORRUPTED)) == 0 )
+                ts_psip_Packet_Push( p_pid, p_pkt->p_buffer );
             block_Release( p_pkt );
             break;
 
@@ -1342,12 +1337,6 @@ static void ParsePESDataChain( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
         return;
     }
 
-    if( (p_pes->i_flags & BLOCK_FLAG_SCRAMBLED) && p_demux->p_sys->b_valid_scrambling )
-    {
-        block_ChainRelease( p_pes );
-        return;
-    }
-
     if( header[0] != 0 || header[1] != 0 || header[2] != 1 )
     {
         if ( !(p_pes->i_flags & BLOCK_FLAG_SCRAMBLED) )
@@ -2359,6 +2348,7 @@ static block_t * ProcessTSPacket( demux_t *p_demux, ts_pid_t *pid, block_t *p_pk
     const uint8_t *p = p_pkt->p_buffer;
     const bool b_adaptation = p[3]&0x20;
     const bool b_payload    = p[3]&0x10;
+    const bool b_scrambled  = p[3]&0xc0;
     const int  i_cc         = p[3]&0x0f; /* continuity counter */
     bool       b_discontinuity = false;  /* discontinuity */
 
@@ -2375,7 +2365,7 @@ static block_t * ProcessTSPacket( demux_t *p_demux, ts_pid_t *pid, block_t *p_pk
      * TODO: handle Reed-Solomon 204,188 error correction */
     p_pkt->i_buffer = TS_PACKET_SIZE_188;
 
-    if( SCRAMBLED(*pid) )
+    if( b_scrambled )
     {
         if( p_demux->p_sys->csa )
         {
@@ -2383,10 +2373,8 @@ static block_t * ProcessTSPacket( demux_t *p_demux, ts_pid_t *pid, block_t *p_pk
             csa_Decrypt( p_demux->p_sys->csa, p_pkt->p_buffer, p_demux->p_sys->i_csa_pkt_size );
             vlc_mutex_unlock( &p_demux->p_sys->csa_lock );
         }
-        else if( p_demux->p_sys->b_valid_scrambling )
-        {
+        else
             p_pkt->i_flags |= BLOCK_FLAG_SCRAMBLED;
-        }
     }
 
     /* We don't have any adaptation_field, so payload starts
@@ -2552,6 +2540,13 @@ static bool GatherPESData( demux_t *p_demux, ts_pid_t *pid, block_t *p_pkt, size
 
     }
 
+    /* We'll cannot parse any pes data */
+    if( (p_pkt->i_flags & BLOCK_FLAG_SCRAMBLED) && p_demux->p_sys->b_valid_scrambling )
+    {
+        block_Release( p_pkt );
+        return PushPESBlock( p_demux, pid, NULL, true );
+    }
+
     /* Data discontinuity, we need to drop or output currently
      * gathered data as it can't match the target size or can
      * have dropped next sync code */



More information about the vlc-commits mailing list