]> git.sesse.net Git - vlc/commitdiff
-New method using netlist to read packets on DVD device by sectors of
authorStéphane Borel <stef@videolan.org>
Thu, 8 Feb 2001 01:34:42 +0000 (01:34 +0000)
committerStéphane Borel <stef@videolan.org>
Thu, 8 Feb 2001 01:34:42 +0000 (01:34 +0000)
2048 bytes.
-Some modifications in netlist to make it work with DVD.
-Fixed � bug in mpeg_system.c

We use INPUT_READ_ONCE many times in the input code. I think that
we should replace it with a field in input_thread_t to give more
flexibility to modules. I have done it in DVD plugin but it can't work
if input.c is limited by INPUT_READ_ONCE.

The DVD method is slower than input_ps ; but there are things to
improve.
CSS descrambling is broken.

src/input/css_table.h
src/input/dvd_css.c
src/input/dvd_css.h
src/input/dvd_ifo.c
src/input/dvd_ifo.h
src/input/input_dvd.c
src/input/input_dvd.h
src/input/input_netlist.c
src/input/input_netlist.h
src/input/mpeg_system.c

index acd11cf7c8fef69fdf6118707b15fda850e8365c..47779ed403094aa1567fcd91d188729aa66a8941 100644 (file)
@@ -2,6 +2,7 @@
  * css_table.h : Various tables needed by css unencryption
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
+ * $Id: css_table.h,v 1.2 2001/02/08 01:34:41 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
index 6980945c873923e324e65b622778d42290b9fc8f..d8738dcf7ceacefcf50d767eedde7f71116f1316 100644 (file)
@@ -2,6 +2,7 @@
  * dvd_css.c: Functions for DVD authentification and unscrambling
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
+ * $Id: dvd_css.c,v 1.5 2001/02/08 01:34:41 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -46,6 +47,8 @@
 
 #include "intf_msg.h"
 #include "dvd_css.h"
+#include "dvd_ifo.h"
+#include "input_dvd.h"
 #include "css_table.h"
 
 /*****************************************************************************
@@ -658,6 +661,25 @@ static int CSScracker( int StartVal,
  * Authentication and keys
  */
 
+/*****************************************************************************
+ * CSSTest : check if the disc is encrypted or not
+ *****************************************************************************/
+int CSSTest( int i_fd )
+{
+    dvd_struct dvd;
+
+    dvd.type = DVD_STRUCT_COPYRIGHT;
+    dvd.copyright.layer_num = 0;
+
+    if( ioctl( i_fd, DVD_READ_STRUCT, &dvd ) < 0 )
+    {
+        intf_ErrMsg( "DVD ioctl error" );
+        return -1;
+    }
+
+    return dvd.copyright.cpst;
+}
+
 /*****************************************************************************
  * CSSInit : CSS Structure initialisation and DVD authentication.
  *****************************************************************************/
index f5f87e515e641138714441b169b188cc63b56670..43f747143981c6bd5908861652e796908a089a63 100644 (file)
@@ -2,6 +2,7 @@
  * dvd_css.h: Structures for DVD authentification and unscrambling
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
+ * $Id: dvd_css.h,v 1.5 2001/02/08 01:34:41 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -19,7 +20,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
-#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
 #define KEY_SIZE 5
 
 typedef u8 DVD_key_t[KEY_SIZE];
@@ -52,11 +52,3 @@ typedef struct css_s
     int             i_title_nb;
     title_key_t*    p_title_key;
 } css_t;
-
-/*****************************************************************************
- * Prototypes in dvd_css.c
- *****************************************************************************/
-struct css_s    CSSInit     ( int );
-int             CSSGetKeys  ( struct css_s* );
-int             CSSDescrambleSector( DVD_key_t , u8* );
-#endif
index 8330d7aa716f95d08f3e0c47e83d7643da46685c..7ed4e9e44aee3be00d5c31366d6b4ad14beee0f9 100644 (file)
@@ -2,6 +2,7 @@
  * dvd_ifo.c: Functions for ifo parsing
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
+ * $Id: dvd_ifo.c,v 1.7 2001/02/08 01:34:41 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -33,6 +34,7 @@
 
 #include "intf_msg.h"
 #include "dvd_ifo.h"
+#include "input_dvd.h"
 
 /*
  * IFO Management.
@@ -176,8 +178,7 @@ void IfoEnd( ifo_t* p_ifo )
 /*fprintf(stderr, "Pos : %lld Val : %llx\n",                                  \
                                 (long long)(p_ifo->i_pos - i_start),        \
                                 (long long)*(p_field) );    */                \
-        p_ifo->i_pos =                                                      \
-                   lseek64( p_ifo->i_fd, p_ifo->i_pos + (i_len), SEEK_SET );\
+        p_ifo->i_pos += i_len;                                              \
     }
 
 #define GETC( p_field )                                                     \
@@ -186,7 +187,7 @@ void IfoEnd( ifo_t* p_ifo )
 /*fprintf(stderr, "Pos : %lld Value : %d\n",                                  \
                                 (long long)(p_ifo->i_pos - i_start),        \
                                           *(p_field) );*/                     \
-        p_ifo->i_pos = lseek64( p_ifo->i_fd , p_ifo->i_pos + 1 , SEEK_SET );\
+        p_ifo->i_pos += 1;                                                  \
     }
 
 #define GETS( p_field )                                                     \
@@ -196,7 +197,7 @@ void IfoEnd( ifo_t* p_ifo )
 /*fprintf(stderr, "Pos : %lld Value : %d\n",                                  \
                                 (long long)(p_ifo->i_pos - i_start),        \
                                           *(p_field) );*/                     \
-        p_ifo->i_pos = lseek64( p_ifo->i_fd , p_ifo->i_pos + 2 , SEEK_SET );\
+        p_ifo->i_pos += 2;                                                  \
     }
 
 #define GETL( p_field )                                                     \
@@ -206,7 +207,7 @@ void IfoEnd( ifo_t* p_ifo )
 /*fprintf(stderr, "Pos : %lld Value : %d\n",                                  \
                                 (long long)(p_ifo->i_pos - i_start),        \
                                           *(p_field) );*/                     \
-        p_ifo->i_pos = lseek64( p_ifo->i_fd , p_ifo->i_pos + 4 , SEEK_SET );\
+        p_ifo->i_pos += 4;                                                  \
     }
 
 #define GETLL( p_field )                                                    \
@@ -216,7 +217,7 @@ void IfoEnd( ifo_t* p_ifo )
 /*fprintf(stderr, "Pos : %lld Value : %lld\n",                                \
                                 (long long)(p_ifo->i_pos - i_start),        \
                                             *(p_field) );*/                   \
-        p_ifo->i_pos = lseek64( p_ifo->i_fd , p_ifo->i_pos + 8 , SEEK_SET );\
+        p_ifo->i_pos += 8;                                                  \
     }
 
 #define FLUSH( i_len )                                                      \
@@ -246,9 +247,8 @@ void IfoEnd( ifo_t* p_ifo )
                                 (int)((p_com)->i_sub_cmd),                  \
                                 (int)((p_com)->i_v0),                       \
                                 (int)((p_com)->i_v2),                       \
-                                (int)((p_com)->i_v4) );*/                     \
-        p_ifo->i_pos =                                                      \
-                   lseek64( p_ifo->i_fd, p_ifo->i_pos + 8, SEEK_SET );      \
+                                (int)((p_com)->i_v4) );           */          \
+        p_ifo->i_pos += 8;                                                  \
     }
 
 static pgc_t ReadPGC( ifo_t* p_ifo )
@@ -1110,19 +1110,70 @@ void IfoRead( ifo_t* p_ifo )
 /*
  * IFO virtual machine : a set of commands that give the behaviour of the dvd
  */
-
+#if 0
 /*****************************************************************************
  * CommandRead : translates the command strings in ifo into command
  * structures.
  *****************************************************************************/
-ifo_command_t CommandRead( ifo_t* p_ifo )
+void CommandRead( ifo_command_t com )
 {
-    ifo_command_t   com;
+    u8*     pi_code = (u8*)(&com);
 
-    return com;
+    switch( com.i_type )
+    {
+        case 0:                                     /* Goto */
+            if( !pi_code[1] )
+            {
+                fprintf( stderr, "NOP\n" );
+            }
+            else if( cmd.i_cmp )
+            {
+                
+            }
+            break;
+        case 1:                                     /* Lnk */
+            break;
+        case 2:                                     /* SetSystem */
+            break;
+        case 3:                                     /* Set */
+            break;
+        case 4:                                     /* */
+            break;
+        case 5:                                     /* */
+            break;
+        case 6:                                     /* */
+            break;
+        default:
+            fprintf( stderr, "Unknown Command\n" );
+            break;
+    }
+
+    return;
 }
 
 /*****************************************************************************
- *
+ * IfoGoto
+ *****************************************************************************/
+static void IfoGoto( ifo_command_t cmd )
+{
+    
+
+    return;
+}
+
+/*****************************************************************************
+ * IfoLnk
  *****************************************************************************/
+static void IfoLnk( ifo_t* p_ifo )
+{
+    return;
+}
 
+/*****************************************************************************
+ * IfoJmp
+ *****************************************************************************/
+static void IfoJmp( ifo_t* p_ifo )
+{
+    return;
+}
+#endif
index cb4a8d79ac37ca2d753cd2b671dfa5ba36e4c02c..12295a5e1f39ec3f5505aa77e0940b188f38baf4 100644 (file)
@@ -2,6 +2,7 @@
  * dvd_ifo.h: Structures for ifo parsing
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
+ * $Id: dvd_ifo.h,v 1.7 2001/02/08 01:34:42 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#define DVD_LB_SIZE 2048
-
 /*****************************************************************************
  * Common structures for Video Management and Video Title sets
  *****************************************************************************/
@@ -481,9 +477,9 @@ typedef struct ifo_s
     /* File descriptor for the device */
     int             i_fd;
     /* Offset to video_ts.ifo on the device */
-    off64_t           i_off;
+    off64_t         i_off;
     /* Position of stream pointer */
-    off64_t           i_pos;
+    off64_t         i_pos;
     /* Error Management */
     boolean_t       b_error;
     /* Structure described in video_ts */
@@ -492,8 +488,3 @@ typedef struct ifo_s
     vts_t *         p_vts;
 } ifo_t;
 
-/*****************************************************************************
- * Prototypes in dvd_ifo.c
- *****************************************************************************/
-ifo_t   IfoInit( int );
-void    IfoRead( ifo_t* );
index fa7b418d7bde32f88a0481a47949ab68243d4cb6..b828d5408f50a34695bf4a8b3e6f879c5fed7130 100644 (file)
@@ -1,8 +1,16 @@
 /*****************************************************************************
- * input_dvd.c: DVD reading
+ * input_dvd.c: DVD raw reading plugin.
+ * ---
+ * This plugins should handle all the known specificities of the DVD format,
+ * especially the 2048 bytes logical block size.
+ * It depends on:
+ *  -input_netlist used to read packets
+ *  -dvd_ifo for ifo parsing and analyse
+ *  -dvd_css for unscrambling
+ *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.10 2001/01/30 19:19:02 massiot Exp $
+ * $Id: input_dvd.c,v 1.11 2001/02/08 01:34:42 stef Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
 
 #include <fcntl.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 
 #include <string.h>
 #include <errno.h>
 #include <malloc.h>
 
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_DVDIO_H
-# include <sys/dvdio.h>
-#endif
-#ifdef LINUX_DVD
-# include <linux/cdrom.h>
-#endif
-
 #include "config.h"
 #include "common.h"
 #include "threads.h"
@@ -60,6 +61,7 @@
 #include "input_ext-dec.h"
 
 #include "input.h"
+#include "input_netlist.h"
 
 #include "dvd_ifo.h"
 #include "dvd_css.h"
@@ -80,9 +82,6 @@ static void DVDEnd      ( struct input_thread_s * );
 /* FIXME : DVDSeek should be on 64 bits ? Is it possible in input ? */
 static int  DVDSeek     ( struct input_thread_s *, off_t );
 static int  DVDRewind   ( struct input_thread_s * );
-static struct data_packet_s * NewPacket ( void *, size_t );
-static void DeletePacket( void *, struct data_packet_s * );
-static void DeletePES   ( void *, struct pes_packet_s * );
 
 /*
  * Data reading functions
@@ -94,19 +93,11 @@ static void DeletePES   ( void *, struct pes_packet_s * );
 static int DVDProbe( input_thread_t * p_input )
 {
 #if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
-    dvd_struct dvd;
-
-    dvd.type = DVD_STRUCT_COPYRIGHT;
-    dvd.copyright.layer_num = 0;
-
-    if( ioctl( p_input->i_handle, DVD_READ_STRUCT, &dvd ) < 0 )
-    {
-        intf_ErrMsg( "DVD ioctl error" );
-        return -1;
-    }
-
-    return dvd.copyright.cpst;
+    return CSSTest( p_input->i_handle );
 #else
+    /* DVD ioctls unavailable.
+     * FIXME: Check the stream to see whether it is encrypted or not 
+     * to give and accurate error message */
     return 0;
 #endif
 }
@@ -130,16 +121,22 @@ static void DVDInit( input_thread_t * p_input )
     p_input->p_method_data = NULL;
 
     p_method->i_fd = p_input->i_handle;
+    /* FIXME: We assume that there are at most three data packets in a sector */
+    p_method->i_read_once = 1; 
+    p_method->i_title = 0;
 
 
     lseek64( p_input->i_handle, 0, SEEK_SET );
 
+    /* Reading structures initialisation */
+    input_NetlistInit( p_input, 4096, 4096, DVD_LB_SIZE,
+                       p_method->i_read_once ); 
+
     /* Ifo initialisation */
     p_method->ifo = IfoInit( p_input->i_handle );
     IfoRead( &(p_method->ifo) );
     intf_Msg( "Ifo: Initialized" );
 
-#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
     /* CSS authentication and keys */
     if( ( p_method->b_encrypted = DVDProbe( p_input ) ) )
     {
@@ -164,15 +161,15 @@ static void DVDInit( input_thread_t * p_input )
         CSSGetKeys( &(p_method->css) );
         intf_Msg( "CSS: Initialized" );
     }
-#endif
 
+    /* FIXME: Kludge beginning of vts_01_1.vob */
     i_start = p_method->ifo.p_vts[0].i_pos +
               p_method->ifo.p_vts[0].mat.i_tt_vobs_ssector *DVD_LB_SIZE;
 
     i_start = lseek64( p_input->i_handle, i_start, SEEK_SET );
     intf_Msg( "VOB start at : %lld", (long long)i_start );
 
-#if 1
+    /* Initialize ES structures */
     input_InitStream( p_input, sizeof( stream_ps_data_t ) );
     input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
 
@@ -210,7 +207,8 @@ static void DVDInit( input_thread_t * p_input )
             {
                 /* FIXME: use i_p_config_t */
                 input_ParsePS( p_input, pp_packets[i] );
-                DeletePacket( p_input->p_method_data, pp_packets[i] );
+                input_NetlistDeletePacket( p_input->p_method_data,
+                                           pp_packets[i] );
             }
 
             /* File too big. */
@@ -297,12 +295,12 @@ static void DVDInit( input_thread_t * p_input )
     }
     else
     {
-#endif
         /* The programs will be added when we read them. */
         vlc_mutex_lock( &p_input->stream.stream_lock );
         p_input->stream.pp_programs[0]->b_is_ok = 0;
         vlc_mutex_unlock( &p_input->stream.stream_lock );
     }
+
 }
 
 /*****************************************************************************
@@ -310,180 +308,116 @@ static void DVDInit( input_thread_t * p_input )
  *****************************************************************************/
 static void DVDEnd( input_thread_t * p_input )
 {
+    /* FIXME: check order of calls */
+//    CSSEnd( p_input );
+//    IfoEnd( (ifo_t*)(&p_input->p_plugin_data->ifo ) );
     free( p_input->stream.p_demux_data );
     free( p_input->p_plugin_data );
+    input_NetlistEnd( p_input );
 }
 
 /*****************************************************************************
- * SafeRead: reads a chunk of stream and correctly detects errors
- *****************************************************************************/
-static __inline__ int SafeRead( input_thread_t * p_input, byte_t * p_buffer,
-                                size_t i_len )
-{
-    // FIXME : aie aie ugly kludge for testing purposes :)
-    static byte_t       p_tmp[2048];
-
-
-    thread_dvd_data_t * p_method;
-    int                 i_nb;
-    off64_t             i_pos;
-
-    p_method = (thread_dvd_data_t *)p_input->p_plugin_data;
-    i_pos = lseek64( p_input->i_handle, 0, SEEK_CUR );
-    if( !p_method->b_encrypted )
-    {
-        i_nb = read( p_input->i_handle, p_buffer, i_len );
-    }
-    else
-    {
-        lseek64( p_input->i_handle, i_pos & ~0x7FF, SEEK_SET );
-        i_nb = read( p_input->i_handle, p_tmp, 0x800 );
-#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
-        CSSDescrambleSector( p_method->css.p_title_key[0].key, p_tmp );
-#endif
-        memcpy( p_buffer, p_tmp + (i_pos & 0x7FF ), i_len );
-    }
-    switch( i_nb )
-    {
-        case 0:
-            /* End of File */
-            return( 1 );
-        case -1:
-            intf_ErrMsg( "DVD: Read failed (%s)", strerror(errno) );
-            return( -1 );
-        default:
-            break;
-    }
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    p_input->stream.i_tell = 
-                lseek64( p_input->i_handle, i_pos+i_len, SEEK_SET );
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-    return( 0 );
-}
-
-/*****************************************************************************
- * DVDRead: reads data packets
+ * DVDRead: reads data packets into the netlist.
  *****************************************************************************
  * Returns -1 in case of error, 0 if everything went well, and 1 in case of
  * EOF.
  *****************************************************************************/
 static int DVDRead( input_thread_t * p_input,
-                   data_packet_t * pp_packets[INPUT_READ_ONCE] )
+                   data_packet_t ** pp_packets )
 {
-    byte_t              p_header[6];
-    data_packet_t *     p_data;
-    size_t              i_packet_size;
-    int                 i_packet, i_error;
-    thread_dvd_data_t * p_method;
+    thread_dvd_data_t *     p_method;
+    netlist_t *             p_netlist;
+    struct iovec *          p_vec;
+    struct data_packet_s *  p_data;
+    u8 *                    pi_cur;
+    int                     i_packet_size;
+    int                     i_packet;
+    int                     i_pos;
+    int                     i;
+    boolean_t               b_first_packet;
+
+    p_method = ( thread_dvd_data_t * ) p_input->p_plugin_data;
+    p_netlist = ( netlist_t * ) p_input->p_method_data;
+
+    /* Get an iovec pointer */
+    if( ( p_vec = input_NetlistGetiovec( p_netlist, &p_data ) ) == NULL )
+    {
+        intf_ErrMsg( "DVD: read error" );
+        return -1;
+    }
 
-    p_method = (thread_dvd_data_t *)p_input->p_plugin_data;
+    /* Reads from DVD */
+    readv( p_input->i_handle, p_vec, p_method->i_read_once );
+    input_NetlistMviovec( p_netlist, p_method->i_read_once );
 
-    memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) );
-    for( i_packet = 0; i_packet < INPUT_READ_ONCE; i_packet++ )
+    if( p_method->b_encrypted )
     {
-        /* Read what we believe to be a packet header. */
-        if( (i_error = SafeRead( p_input, p_header, 6 )) )
+        for( i=0 ; i<p_method->i_read_once ; i++ )
         {
-            return( i_error );
+            CSSDescrambleSector(
+                        p_method->css.p_title_key[p_method->i_title].key, 
+                        p_vec[i].iov_base );
         }
+    }
 
-        if( (U32_AT(p_header) & 0xFFFFFF00) != 0x100L )
+    i_packet = 0;
+    /* Read headers to compute payload length */
+    for( i = 0 ; i < p_method->i_read_once ; i++ )
+    {
+        i_pos = 0;
+        b_first_packet = 1;
+        while( i_pos < p_netlist->i_buffer_size )
         {
-            /* This is not the startcode of a packet. Read the stream
-             * until we find one. */
-            u32         i_startcode = U32_AT(p_header);
-            int         i_nb;
-            byte_t      i_dummy;
-
-            if( i_startcode )
+            pi_cur = (u8*)(p_vec[i].iov_base + i_pos);
+            /*default header */
+            if( U32_AT( pi_cur ) != 0x1BA )
             {
-                /* It is common for MPEG-1 streams to pad with zeros
-                 * (although it is forbidden by the recommendation), so
-                 * don't bother everybody in this case. */
-                intf_WarnMsg( 1, "Garbage at input (%x)", i_startcode );
+                /* That's the case for all packets, except pack header. */
+                i_packet_size = U16_AT( pi_cur + 4 );
             }
-
-            while( (i_startcode & 0xFFFFFF00) != 0x100L )
+            else
             {
-                i_startcode <<= 8;
-                if( (i_nb = SafeRead( p_input, &i_dummy, 1 )) != 0 )
+                /* Pack header. */
+                if( ( pi_cur[4] & 0xC0 ) == 0x40 )
                 {
-                    i_startcode |= i_dummy;
+                    /* MPEG-2 */
+                    i_packet_size = 8;
+                }
+                else if( ( pi_cur[4] & 0xF0 ) == 0x20 )
+                {
+                    /* MPEG-1 */
+                    i_packet_size = 6;
                 }
                 else
                 {
-                    return( 1 );
+                    intf_ErrMsg( "Unable to determine stream type" );
+                    return( -1 );
                 }
             }
-
-            /* Packet found. */
-            *(u32 *)p_header = U32_AT(&i_startcode);
-            if( (i_error = SafeRead( p_input, p_header + 4, 2 )) )
-            {
-                return( i_error );
-            }
-        }
-
-        if( U32_AT(p_header) != 0x1BA )
-        {
-            /* That's the case for all packets, except pack header. */
-            i_packet_size = U16_AT(&p_header[4]);
-        }
-        else
-        {
-            /* Pack header. */
-            if( (p_header[4] & 0xC0) == 0x40 )
+            if( b_first_packet )
             {
-                /* MPEG-2 */
-                i_packet_size = 8;
-            }
-            else if( (p_header[4] & 0xF0) == 0x20 )
-            {
-                /* MPEG-1 */
-                i_packet_size = 6;
+                p_data->b_discard_payload = 0;
+                b_first_packet = 0;
             }
             else
-            {
-                intf_ErrMsg( "Unable to determine stream type" );
-                return( -1 );
+            { 
+                p_data = input_NetlistNewPacket( p_netlist ,
+                                                 i_packet_size + 6 );
+                memcpy( p_data->p_buffer,
+                        p_vec[i].iov_base + i_pos , i_packet_size + 6 );
             }
-        }
 
-        /* Fetch a packet of the appropriate size. */
-        if( (p_data = NewPacket( p_input, i_packet_size + 6 )) == NULL )
-        {
-            intf_ErrMsg( "Out of memory" );
-            return( -1 );
+            p_data->p_payload_end = p_data->p_payload_start + i_packet_size + 6;
+            pp_packets[i_packet] = p_data;
+            i_packet++;
+            i_pos += i_packet_size + 6;
         }
-
-        /* Copy the header we already read. */
-        memcpy( p_data->p_buffer, p_header, 6 );
-
-        /* Read the remaining of the packet. */
-        if( i_packet_size && (i_error =
-                SafeRead( p_input, p_data->p_buffer + 6, i_packet_size )) )
-        {
-            return( i_error );
-        }
-
-        /* In MPEG-2 pack headers we still have to read stuffing bytes. */
-        if( U32_AT(p_header) == 0x1BA )
-        {
-            if( i_packet_size == 8 && (p_data->p_buffer[13] & 0x7) != 0 )
-            {
-                /* MPEG-2 stuffing bytes */
-                byte_t      p_garbage[8];
-                if( (i_error = SafeRead( p_input, p_garbage,
-                                         p_data->p_buffer[13] & 0x7)) )
-                {
-                    return( i_error );
-                }
-            }
-        }
-
-        /* Give the packet to the other input stages. */
-        pp_packets[i_packet] = p_data;
     }
+    pp_packets[i_packet] = NULL;
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    p_input->stream.i_tell += p_method->i_read_once *DVD_LB_SIZE;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
 
     return( 0 );
 }
@@ -507,102 +441,6 @@ static int DVDSeek( input_thread_t * p_input, off_t i_off )
     return( -1 );
 }
 
-/*
- * Packet management utilities
- */
-
-/*****************************************************************************
- * NewPacket: allocates a data packet
- *****************************************************************************/
-static struct data_packet_s * NewPacket( void * p_garbage,
-                                         size_t i_size )
-{
-    data_packet_t * p_data;
-
-    /* Safety check */
-    if( i_size > INPUT_MAX_PACKET_SIZE )
-    {
-        intf_ErrMsg( "Packet too big (%d)", i_size );
-        return NULL;
-    }
-
-    if( (p_data = (data_packet_t *)malloc( sizeof(data_packet_t) )) == NULL )
-    {
-        intf_DbgMsg( "Out of memory" );
-        return NULL;
-    }
-
-    if( (p_data->p_buffer = (byte_t *)malloc( i_size )) == NULL )
-    {
-        intf_DbgMsg( "Out of memory" );
-        free( p_data );
-        return NULL;
-    }
-
-    /* Initialize data */
-    p_data->p_next = NULL;
-    p_data->b_discard_payload = 0;
-
-    p_data->p_payload_start = p_data->p_buffer;
-    p_data->p_payload_end = p_data->p_buffer + i_size;
-
-    return( p_data );
-}
-
-/*****************************************************************************
- * NewPES: allocates a pes packet
- *****************************************************************************/
-static pes_packet_t * NewPES( void * p_garbage )
-{
-    pes_packet_t * p_pes;
-
-    if( (p_pes = (pes_packet_t *)malloc( sizeof(pes_packet_t) )) == NULL )
-    {
-        intf_DbgMsg( "Out of memory" );
-        return NULL;
-    }
-
-    p_pes->b_messed_up = p_pes->b_data_alignment = p_pes->b_discontinuity =
-        p_pes->i_pts = p_pes->i_dts = 0;
-    p_pes->i_pes_size = 0;
-    p_pes->p_first = NULL;
-
-    return( p_pes );
-}
-
-/*****************************************************************************
- * DeletePacket: deletes a data packet
- *****************************************************************************/
-static void DeletePacket( void * p_garbage,
-                          data_packet_t * p_data )
-{
-    ASSERT(p_data);
-    ASSERT(p_data->p_buffer);
-    free( p_data->p_buffer );
-    free( p_data );
-}
-
-/*****************************************************************************
- * DeletePES: deletes a PES packet and associated data packets
- *****************************************************************************/
-static void DeletePES( void * p_garbage, pes_packet_t * p_pes )
-{
-    data_packet_t *     p_data;
-    data_packet_t *     p_next;
-
-    p_data = p_pes->p_first;
-
-    while( p_data != NULL )
-    {
-        p_next = p_data->p_next;
-        free( p_data->p_buffer );
-        free( p_data );
-        p_data = p_next;
-    }
-
-    free( p_pes );
-}
-
 /*****************************************************************************
  * DVDKludge: fakes a DVD plugin (FIXME)
  *****************************************************************************/
@@ -616,10 +454,10 @@ input_capabilities_t * DVDKludge( void )
     p_plugin->pf_end = DVDEnd;
     p_plugin->pf_read = DVDRead;
     p_plugin->pf_demux = input_DemuxPS; /* FIXME: use i_p_config_t ! */
-    p_plugin->pf_new_packet = NewPacket;
-    p_plugin->pf_new_pes = NewPES;
-    p_plugin->pf_delete_packet = DeletePacket;
-    p_plugin->pf_delete_pes = DeletePES;
+    p_plugin->pf_new_packet = input_NetlistNewPacket;
+    p_plugin->pf_new_pes = input_NetlistNewPES;
+    p_plugin->pf_delete_packet = input_NetlistDeletePacket;
+    p_plugin->pf_delete_pes = input_NetlistDeletePES;
     p_plugin->pf_rewind = DVDRewind;
     p_plugin->pf_seek = DVDSeek;
 
index c0b492093f59a727b009f9aa8299ec002cca147e..3f15d7f48feac421a11ea8db3af23d9bbff3b866 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#define DVD_LB_SIZE 2048
+
 /*****************************************************************************
  * thread_dvd_data_t: extension of input_thread_t for DVD specificity
  *****************************************************************************/
 typedef struct thread_dvd_data_s
 {
-    int                     i_fd;
-    boolean_t               b_encrypted;
-#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
+    int                     i_fd;               // File descriptor of device
+    boolean_t               b_encrypted;        // CSS encryption
+    int                     i_read_once;        // NB of bytes read by DVDRead
+    int                     i_title;            // Current Title
     /* Scrambling Information */
+#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
     struct css_s            css;
 #endif
     /* Structure that contains all information of the DVD */
     struct ifo_s            ifo;
 } thread_dvd_data_t;
 
+/*****************************************************************************
+ * Prototypes in dvd_ifo.c
+ *****************************************************************************/
+struct ifo_s    IfoInit( int );
+void            IfoRead( struct ifo_s * );
+void            IfoEnd( ifo_t * );
+
+/*****************************************************************************
+ * Prototypes in dvd_css.c
+ *****************************************************************************/
+#if defined( HAVE_SYS_DVDIO_H ) || defined( LINUX_DVD )
+int             CSSTest     ( int );
+struct css_s    CSSInit     ( int );
+int             CSSGetKeys  ( struct css_s * );
+int             CSSDescrambleSector( u8 * , u8 * );
 
+#endif
index fc8dc0d09d476968023891e4012f94eed4b72931..5865ae536c038fd2e365898cd20761e371f65a4c 100644 (file)
@@ -2,7 +2,7 @@
  * input_netlist.c: netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_netlist.c,v 1.28 2001/01/07 03:56:40 henri Exp $
+ * $Id: input_netlist.c,v 1.29 2001/02/08 01:34:42 stef Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -52,7 +52,7 @@
  * input_NetlistInit: allocates netlist buffers and init indexes
  *****************************************************************************/
 int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
-                       size_t i_buffer_size )
+                       size_t i_buffer_size, int i_read_once )
 {
     unsigned int i_loop;
     netlist_t * p_netlist;
@@ -155,13 +155,16 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
     p_netlist->i_nb_pes = i_nb_pes;
     p_netlist->i_buffer_size = i_buffer_size;
 
+    p_netlist->i_read_once = i_read_once;
+
     return (0); /* Everything went all right */
 }
 
 /*****************************************************************************
  * input_NetlistGetiovec: returns an iovec pointer for a readv() operation
  *****************************************************************************/
-struct iovec * input_NetlistGetiovec( void * p_method_data )
+struct iovec * input_NetlistGetiovec( void * p_method_data,
+                                      struct data_packet_s ** pp_data )
 {
     netlist_t * p_netlist;
 
@@ -169,9 +172,9 @@ struct iovec * input_NetlistGetiovec( void * p_method_data )
     p_netlist = ( netlist_t * ) p_method_data;
     
     /* check */
-    if 
+    if( 
      (p_netlist->i_data_end - p_netlist->i_data_start + p_netlist->i_nb_data)
-     %p_netlist->i_nb_data < INPUT_READ_ONCE )
+     %p_netlist->i_nb_data < p_netlist->i_read_once )
     {
         intf_ErrMsg("Empty iovec FIFO. Unable to allocate memory");
         return (NULL);
@@ -181,13 +184,21 @@ struct iovec * input_NetlistGetiovec( void * p_method_data )
      * so, as a solution, we chose to have a FIFO a bit longer
      * than i_nb_data, and copy the begining of the FIFO to its end
      * if the readv needs to go after the end */
-    if( p_netlist->i_nb_data - p_netlist->i_data_start < INPUT_READ_ONCE )
+    if( p_netlist->i_nb_data - p_netlist->i_data_start <
+                                                    p_netlist->i_read_once )
+    {
         memcpy( &p_netlist->p_free_iovec[p_netlist->i_nb_data], 
                 p_netlist->p_free_iovec, 
-                INPUT_READ_ONCE-(p_netlist->i_nb_data-p_netlist->i_data_start)
-                * sizeof(struct iovec *)
+                (p_netlist->i_read_once-
+                    (p_netlist->i_nb_data-p_netlist->i_data_start))
+                    * sizeof(struct iovec*)
               );
+
+    }
  
+    /* Gives a pointer to the data_packet struct associated with io_vec */
+    *pp_data = p_netlist->pp_free_data[p_netlist->i_data_start];
+
     /* Initialize payload start and end */
     p_netlist->pp_free_data[p_netlist->i_data_start]->p_payload_start 
         = p_netlist->pp_free_data[p_netlist->i_data_start]->p_buffer;
@@ -259,10 +270,6 @@ struct data_packet_s * input_NetlistNewPacket( void * p_method_data,
     /* unlock */
     vlc_mutex_unlock (&p_netlist->lock);
 
-    if (i_buffer_size < p_netlist->i_buffer_size) 
-    {
-        p_return->p_payload_end = p_return->p_payload_start + i_buffer_size;
-    }
    
     /* initialize data */
     p_return->p_next = NULL;
@@ -363,7 +370,7 @@ void input_NetlistDeletePES( void * p_method_data, pes_packet_t * p_pes )
         p_netlist->pp_free_data[p_netlist->i_data_end] = p_current_packet;
         
         p_netlist->p_free_iovec[p_netlist->i_data_end].iov_base 
-            = p_netlist->p_data->p_buffer;
+            = p_current_packet->p_buffer;
     
         p_current_packet = p_current_packet->p_next;
     }
@@ -375,6 +382,7 @@ void input_NetlistDeletePES( void * p_method_data, pes_packet_t * p_pes )
     
     /* unlock */
     vlc_mutex_unlock (&p_netlist->lock);
+
 }
 
 /*****************************************************************************
index 3bb606f3bc15f528f58b6b11f0f8a5a807f7a76c..301d5e1c259254cc43fa5341d76b8bca83d6082f 100644 (file)
@@ -24,6 +24,9 @@ typedef struct netlist_s
     /* Index */
     unsigned int            i_data_start, i_data_end;
     unsigned int            i_pes_start, i_pes_end;
+
+    /* Number of blocs read once by readv */
+    unsigned int            i_read_once;
 } netlist_t;
 
 /*****************************************************************************
@@ -31,8 +34,9 @@ typedef struct netlist_s
  *****************************************************************************/
 int                     input_NetlistInit( struct input_thread_s *,
                                            int i_nb_data, int i_nb_pes,
-                                           size_t i_buffer_size );
-struct iovec *          input_NetlistGetiovec( void * );
+                                           size_t i_buffer_size,
+                                           int i_read_once );
+struct iovec *          input_NetlistGetiovec( void *, struct data_packet_s** );
 void                    input_NetlistMviovec( void *, size_t );
 struct data_packet_s *  input_NetlistNewPacket( void *, size_t );
 struct pes_packet_s *   input_NetlistNewPES( void * );
index 188023d5bd878a08b04388813cf131c76aa8d2a8..0c2ad92297e21e182150a8acfdbdd2f595117333 100644 (file)
@@ -2,7 +2,7 @@
  * mpeg_system.c: TS, PS and PES management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: mpeg_system.c,v 1.30 2001/02/07 17:44:52 massiot Exp $
+ * $Id: mpeg_system.c,v 1.31 2001/02/08 01:34:42 stef Exp $
  *
  * Authors: 
  *
@@ -396,6 +396,7 @@ void input_ParsePES( input_thread_t * p_input, es_descriptor_t * p_es )
         p_pes = NULL;
     }
 #undef p_pes
+
 }
 
 /*****************************************************************************
@@ -858,7 +859,7 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
     /* Trash the packet if it has no payload or if it isn't selected */
     if( b_trash )
     {
-        p_input->p_plugin->pf_delete_packet( p_input, p_data );
+        p_input->p_plugin->pf_delete_packet( p_input->p_method_data, p_data );
 #ifdef STATS
         p_input->c_packets_trashed++;
 #endif