]> git.sesse.net Git - vlc/commitdiff
* Changed pf_read prototype and minor changes.
authorChristophe Massiot <massiot@videolan.org>
Thu, 27 Dec 2001 03:47:09 +0000 (03:47 +0000)
committerChristophe Massiot <massiot@videolan.org>
Thu, 27 Dec 2001 03:47:09 +0000 (03:47 +0000)
14 files changed:
include/config.h.in
include/input_ext-dec.h
include/input_ext-intf.h
include/input_ext-plugins.h
include/modules.h
plugins/dvd/input_dvd.c
plugins/mpeg_system/input_es.c
plugins/mpeg_system/input_es.h
plugins/mpeg_system/input_ps.c
plugins/mpeg_system/input_ps.h
plugins/mpeg_system/input_ts.c
plugins/mpeg_system/input_ts.h
plugins/vcd/input_vcd.c
src/input/input.c

index 133c1cabab983221105fc344b5b12c323d4ea219..7e45a95762998b872b7fa71b819a8220870e5f84 100644 (file)
 /* Environment variable containing the memcpy method */
 #define MEMCPY_METHOD_VAR               "vlc_memcpy"
 
-/*
- * Decoders FIFO configuration
- */
-
-/* Size of the FIFO. FIFO_SIZE+1 must be a power of 2 */
-#define FIFO_SIZE                       1023
-
 /*
  * Paths
  */
index f06b4b3a087fd8c7ed102f78577900c4040e670b..6d5952ff129f08b63a73ff3154836f1096c53a31 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * input_ext-dec.h: structures exported to the VideoLAN decoders
  *****************************************************************************
- * Copyright (C) 1999-2000 VideoLAN
- * $Id: input_ext-dec.h,v 1.46 2001/12/27 01:49:34 massiot Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: input_ext-dec.h,v 1.47 2001/12/27 03:47:08 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Michel Kaempf <maxx@via.ecp.fr>
index eb991d6b7864e79a4fa2452a44f2d04174ac2ee6..fef37410562cf0fa904e2ab99fbf6ea05346a770 100644 (file)
@@ -4,7 +4,7 @@
  * control the pace of reading. 
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-intf.h,v 1.53 2001/12/12 13:48:09 massiot Exp $
+ * $Id: input_ext-intf.h,v 1.54 2001/12/27 03:47:08 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -26,7 +26,6 @@
 /*
  * Communication input -> interface
  */
-#define INPUT_MAX_PLUGINS   1
 /* FIXME ! */
 #define REQUESTED_MPEG         1
 #define REQUESTED_AC3          2
@@ -94,6 +93,7 @@ typedef struct es_descriptor_s
 #define SPU_ES          0x02
 #define NAV_ES          0x03
 #define UNKNOWN_ES      0xFF
+
 /*****************************************************************************
  * pgrm_descriptor_t
  *****************************************************************************
@@ -262,7 +262,7 @@ typedef struct input_thread_s
 
     /* Read & Demultiplex */
     int                  (* pf_read)( struct input_thread_s *,
-                                      struct data_packet_s * pp_packets[] );
+                                      struct data_packet_s ** );
     void                 (* pf_demux)( struct input_thread_s *,
                                        struct data_packet_s * );
 
@@ -288,8 +288,6 @@ typedef struct input_thread_s
     int                     i_handle;           /* socket or file descriptor */
     FILE *                  p_stream;                       /* if applicable */
     void *                  p_handle;          /* if i_handle isn't suitable */
-    int                     i_read_once;        /* number of packet read by
-                                                 * pf_read once */
     void *                  p_method_data;     /* data of the packet manager */
     void *                  p_plugin_data;             /* data of the plugin */
 
index 5bce16317ce129d3ca74641d3e2e64764899bcec..2a3f65cb009e8383b317f6300fafe1f52a42a7b4 100644 (file)
@@ -3,7 +3,7 @@
  *                      but exported to plug-ins
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: input_ext-plugins.h,v 1.12 2001/12/27 01:49:34 massiot Exp $
+ * $Id: input_ext-plugins.h,v 1.13 2001/12/27 03:47:08 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
  */
 
 /* FIXME: you've gotta move this move this, you've gotta move this move this */
-#define INPUT_READ_ONCE     7   /* We live in a world dominated by Ethernet. *
-                                 * Ethernet MTU is 1500 bytes, so in a UDP   *
-                                 * packet we can put : 1500/188 = 7 TS       *
-                                 * packets. Have a nice day and merry Xmas.  */
 #define PADDING_PACKET_SIZE 188 /* Size of the NULL packet inserted in case
                                  * of data loss (this should be < 188).      */
 #define PADDING_PACKET_NUMBER 10 /* Number of padding packets top insert to
@@ -185,17 +181,16 @@ typedef struct input_buffers_s                                              \
     vlc_mutex_t lock;                                                       \
     PACKETS_LIFO( pes_packet_t, pes )                                       \
     PACKETS_LIFO( data_packet_t, data )                                     \
-    BUFFERS_LIFO( data_buffer_t, buffers[NB_LIFO] )                         \
+    BUFFERS_LIFO( _data_buffer_t, buffers[NB_LIFO] )                        \
     size_t i_allocated;                                                     \
 } input_buffers_t;
 
-typedef struct data_buffer_s
+typedef struct _data_buffer_s
 {
     int i_refcount;
     unsigned int i_size;
-    struct data_buffer_s * p_next;
-    byte_t payload_start;
-} data_buffer_t;
+    struct _data_buffer_s * p_next;
+} _data_buffer_t;
 
 
 /*****************************************************************************
@@ -282,8 +277,8 @@ static void * input_BuffersInit( void )                                     \
                                                                             \
     for( i = 0; i < NB_LIFO; i++ )                                          \
     {                                                                       \
-        data_buffer_t * p_next;                                             \
-        data_buffer_t * p_buf = p_buffers->buffers[i].p_stack;              \
+        _data_buffer_t * p_next;                                            \
+        _data_buffer_t * p_buf = p_buffers->buffers[i].p_stack;             \
         BUFFERS_END_BUFFERS_LOOP;                                           \
     }                                                                       \
 
@@ -479,7 +474,7 @@ static data_packet_t * input_NewPacket( void * _p_buffers, size_t i_size )  \
             BUFFERS_NEWPACKET_END )
 
 #define DECLARE_BUFFERS_NEWPACKET_SHARED( FLAGS, NB_LIFO )                  \
-    BUFFERS_NEWPACKET( FLAGS, NB_LIFO, data_buffer_t, buffers,              \
+    BUFFERS_NEWPACKET( FLAGS, NB_LIFO, _data_buffer_t, buffers,             \
             BUFFERS_NEWPACKET_EXTRA_DECLARATION_SHARED,                     \
             BUFFERS_NEWPACKET_EXTRA_SHARED, BUFFERS_NEWPACKET_END_SHARED )
 
@@ -490,7 +485,7 @@ static data_packet_t * input_NewPacket( void * _p_buffers, size_t i_size )  \
     data_packet_t * p_buf = p_data;
 
 #define BUFFERS_DELETEPACKET_EXTRA_SHARED( FLAGS, NB_LIFO, DATA_CACHE_SIZE )\
-    data_buffer_t * p_buf = (data_buffer_t *)p_data->p_buffer;              \
+    _data_buffer_t * p_buf = (_data_buffer_t *)p_data->p_buffer;            \
                                                                             \
     /* Get rid of the data packet */                                        \
     if( p_buffers->data.i_depth < DATA_CACHE_SIZE )                         \
@@ -577,7 +572,7 @@ static void input_DeletePacket( void * _p_buffers, data_packet_t * p_data ) \
 
 #define DECLARE_BUFFERS_DELETEPACKET_SHARED( FLAGS, NB_LIFO,                \
                                              DATA_CACHE_SIZE )              \
-    BUFFERS_DELETEPACKET( FLAGS, NB_LIFO, DATA_CACHE_SIZE, data_buffer_t,   \
+    BUFFERS_DELETEPACKET( FLAGS, NB_LIFO, DATA_CACHE_SIZE, _data_buffer_t,  \
                           buffers, BUFFERS_DELETEPACKET_EXTRA_SHARED )
 
 /*****************************************************************************
@@ -731,7 +726,7 @@ static data_packet_t * input_ShareBuffer( void * _p_buffers,                \
 {                                                                           \
     input_buffers_t *   p_buffers = (input_buffers_t *)_p_buffers;          \
     data_packet_t *     p_data;                                             \
-    data_buffer_t *     p_buf = (data_buffer_t *)p_shared_data->p_buffer;   \
+    _data_buffer_t *    p_buf = (_data_buffer_t *)p_shared_data->p_buffer;  \
                                                                             \
     vlc_mutex_lock( &p_buffers->lock );                                     \
                                                                             \
@@ -741,7 +736,7 @@ static data_packet_t * input_ShareBuffer( void * _p_buffers,                \
     /* Finish initialization of p_data */                                   \
     p_data->p_buffer = p_shared_data->p_buffer;                             \
     p_data->p_demux_start = p_data->p_payload_start                         \
-                = p_shared_data->p_buffer + sizeof( data_buffer_t );        \
+                = p_shared_data->p_buffer + sizeof( _data_buffer_t );       \
     p_data->p_payload_end = p_shared_data->p_buffer + p_buf->i_size;        \
                                                                             \
     /* Update refcount */                                                   \
index a7aad936767cfffeb2457c4baf6be76f57dc0736..7f3059eb849e70703c7df5ddee1ad751162751f5 100644 (file)
@@ -2,7 +2,7 @@
  * modules.h : Module management functions.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules.h,v 1.36 2001/12/09 17:01:35 sam Exp $
+ * $Id: modules.h,v 1.37 2001/12/27 03:47:08 massiot Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -125,8 +125,7 @@ typedef struct function_list_s
                                            void * );
 
             int  ( * pf_read ) ( struct input_thread_s *,
-                                 struct data_packet_s *
-                                        pp_packets[] );
+                                 struct data_packet_s ** );
             void ( * pf_demux )( struct input_thread_s *,
                                  struct data_packet_s * );
 
index b995566364f128c66abc17947863d7581bfaa2ef..e571563aadaaff27220c9c55bbc34d8d150af30b 100644 (file)
@@ -9,7 +9,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.110 2001/12/27 01:49:34 massiot Exp $
+ * $Id: input_dvd.c,v 1.111 2001/12/27 03:47:08 massiot Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -92,7 +92,6 @@
 
 /* how many blocks DVDRead will read in each loop */
 #define DVD_BLOCK_READ_ONCE 64
-#define DVD_DATA_READ_ONCE  (4 * DVD_BLOCK_READ_ONCE)
 
 /*****************************************************************************
  * Local prototypes
@@ -221,11 +220,8 @@ static void DVDInit( input_thread_t * p_input )
         return;
     }
 
-    /* We read DVD_BLOCK_READ_ONCE in each loop, so the input will receive
-     * DVD_DATA_READ_ONCE at most */
+    /* We read DVD_BLOCK_READ_ONCE in each loop */
     p_dvd->i_block_once = DVD_BLOCK_READ_ONCE;
-    /* this value mustn't be modifed */
-    p_input->i_read_once = DVD_DATA_READ_ONCE;
 
     /* Ifo allocation & initialisation */
     if( IfoCreate( p_dvd ) < 0 )
@@ -832,14 +828,14 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 /*****************************************************************************
  * DVDRead: reads data packets into the netlist.
  *****************************************************************************
- * Returns -1 in case of error, 0 if everything went well, and 1 in case of
- * EOF.
+ * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
+ * packets.
  *****************************************************************************/
 static int DVDRead( input_thread_t * p_input,
-                    data_packet_t ** pp_packets )
+                    data_packet_t ** pp_data )
 {
     thread_dvd_data_t *     p_dvd;
-    struct iovec            p_vec[DVD_DATA_READ_ONCE];
+    struct iovec            p_vec[DVD_BLOCK_READ_ONCE];
     u8 *                    pi_cur;
     int                     i_block_once;
     int                     i_packet_size;
@@ -853,6 +849,8 @@ static int DVDRead( input_thread_t * p_input,
 
     p_dvd = (thread_dvd_data_t *)p_input->p_plugin_data;
 
+    *pp_data = NULL;
+
     b_eoc = 0;
     i_sector = p_dvd->i_title_start + p_dvd->i_sector;
     i_block_once = p_dvd->i_end_sector - p_dvd->i_sector + 1;
@@ -869,7 +867,6 @@ static int DVDRead( input_thread_t * p_input,
         /* Find cell index in adress map */
         if( DVDFindSector( p_dvd ) < 0 )
         {
-            pp_packets[0] = NULL;
             intf_ErrMsg( "dvd error: can't find next cell" );
             return 1;
         }
@@ -917,8 +914,8 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
 */
 
     /* Get iovecs */
-    p_data = input_BuffersToIO( p_input->p_method_data, p_vec,
-                                DVD_DATA_READ_ONCE );
+    *pp_data = p_data = input_BuffersToIO( p_input->p_method_data, p_vec,
+                                           DVD_BLOCK_READ_ONCE );
 
     if ( p_data == NULL )
     {
@@ -944,7 +941,7 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
         {
             pi_cur = (u8*)p_vec[i_iovec].iov_base + i_pos;
 
-            /*default header */
+            /* Default header */
             if( U32_AT( pi_cur ) != 0x1BA )
             {
                 /* That's the case for all packets, except pack header. */
@@ -958,30 +955,32 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
 
             if( i_pos != 0 )
             {
-                pp_packets[i_packet] = input_ShareBuffer( 
-                        p_input->p_method_data, p_current );
+                *pp_data = input_ShareBuffer( p_input->p_method_data,
+                                              p_current );
             }
             else
             {
-                pp_packets[i_packet] = p_data;
+                *pp_data = p_data;
                 p_data = p_data->p_next;
             }
 
-            pp_packets[i_packet]->p_payload_start =
-                    pp_packets[i_packet]->p_demux_start =
-                    pp_packets[i_packet]->p_demux_start + i_pos;
+            (*pp_data)->p_payload_start = (*pp_data)->p_demux_start =
+                    (*pp_data)->p_demux_start + i_pos;
 
-            pp_packets[i_packet]->p_payload_end =
-                    pp_packets[i_packet]->p_payload_start + i_packet_size + 6;
+            (*pp_data)->p_payload_end =
+                    (*pp_data)->p_payload_start + i_packet_size + 6;
 
             i_packet++;
             i_pos += i_packet_size + 6;
+            pp_data = &(*pp_data)->p_next;
         }
     }
 
-    pp_packets[i_packet] = NULL;
-
     p_input->pf_delete_packet( p_input->p_method_data, p_data );
+    if( i_packet != 0 )
+    {
+        (*pp_data)->p_next = NULL;
+    }
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
@@ -1002,7 +1001,7 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
         {
             /* EOF */
             vlc_mutex_unlock( &p_input->stream.stream_lock );
-            return 1;
+            return 0;
         }
 
         /* EOT */
@@ -1010,17 +1009,17 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
         p_dvd->i_title++;
         DVDSetArea( p_input, p_input->stream.pp_areas[p_dvd->i_title] );
         vlc_mutex_unlock( &p_input->stream.stream_lock );
-        return 0;
+        return( i_packet );
     }
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    if( i_read_blocks == i_block_once )
+    if( i_read_blocks != i_block_once )
     {
-        return 0;
+        return -1;
     }
 
-    return -1;
+    return( i_packet );
 }
 
 /*****************************************************************************
index 8f261b6fd85f6600d5a5779c0cd0dfb1b66b733c..a0cd6f5e17b85df629b389fb10eb009131d14f43 100644 (file)
@@ -2,7 +2,7 @@
  * input_es.c: Elementary Stream demux and packet management
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_es.c,v 1.7 2001/12/27 01:49:34 massiot Exp $
+ * $Id: input_es.c,v 1.8 2001/12/27 03:47:08 massiot Exp $
  *
  * Author: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -74,8 +74,7 @@
  * Local prototypes
  *****************************************************************************/
 static int  ESProbe     ( probedata_t * );
-static int  ESRead      ( struct input_thread_s *,
-                          data_packet_t * p_packets[INPUT_READ_ONCE] );
+static int  ESRead      ( struct input_thread_s *, data_packet_t ** );
 static void ESInit          ( struct input_thread_s * );
 static void ESEnd           ( struct input_thread_s * );
 static void ESSeek          ( struct input_thread_s *, off_t );
@@ -188,56 +187,53 @@ static void ESEnd( input_thread_t * p_input )
 /*****************************************************************************
  * ESRead: reads data packets
  *****************************************************************************
- * Returns -1 in case of error, 0 if everything went well, and 1 in case of
- * EOF.
+ * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
+ * packets.
  *****************************************************************************/
 static int ESRead( input_thread_t * p_input,
-                   data_packet_t * pp_packets[INPUT_READ_ONCE] )
+                   data_packet_t ** pp_data )
 {
-    int             i_read, i_loop;
-    struct iovec    p_iovec[INPUT_READ_ONCE];
+    int             i_read;
+    struct iovec    p_iovec[ES_READ_ONCE];
     data_packet_t * p_data;
 
     /* Get iovecs */
-    p_data = input_BuffersToIO( p_input->p_method_data, p_iovec,
-                                INPUT_READ_ONCE );
+    *pp_data = p_data = input_BuffersToIO( p_input->p_method_data, p_iovec,
+                                           ES_READ_ONCE );
 
     if ( p_data == NULL )
     {
         return( -1 );
     }
 
-    memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) );
-
-    i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+    i_read = readv( p_input->i_handle, p_iovec, ES_READ_ONCE );
     if( i_read == -1 )
     {
         intf_ErrMsg( "input error: ES readv error" );
+        p_input->pf_delete_packet( p_input->p_method_data, p_data );
         return( -1 );
     }
+    p_input->stream.p_selected_area->i_tell += i_read;
+    i_read /= ES_PACKET_SIZE;
 
-    for( i_loop = 0; i_loop * ES_PACKET_SIZE < i_read; i_loop++ )
-    {
-        pp_packets[i_loop] = p_data;
-        p_data = p_data->p_next;
-        pp_packets[i_loop]->p_next = NULL;
-    }
-    /* Delete remaining packets */
-    input_DeletePacket( p_input->p_method_data, p_data );
-    for( ; i_loop < INPUT_READ_ONCE ; i_loop++ )
+    if( i_read != ES_READ_ONCE )
     {
-        pp_packets[i_loop] = NULL;
-    }
+        /* We got fewer packets than wanted. Give remaining packets
+         * back to the buffer allocator. */
+        int i_loop;
 
-    /* EOF */
-    if( i_read == 0 && p_input->stream.b_seekable )
-    {
-        return( 1 );
+        for( i_loop = 0; i_loop + 1 < i_read; i_loop++ )
+        {
+            p_data = p_data->p_next;
+        }
+        p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next );
+        if( i_read != 0 )
+        {
+            p_data->p_next = NULL;
+        }
     }
 
-    p_input->stream.p_selected_area->i_tell += i_read;
-
-    return( 0 );
+    return( i_read );
 }
 
 /*****************************************************************************
index c306da27a4ded3425632d3f199d269c80803dd73..6d150577edc72f244c59726d1bed183a929cf48a 100644 (file)
@@ -2,9 +2,9 @@
  * input_es.h: thread structure of the ES plugin
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_es.h,v 1.2 2001/12/12 17:41:15 massiot Exp $
+ * $Id: input_es.h,v 1.3 2001/12/27 03:47:09 massiot Exp $
  *
- * Authors: 
+ * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,4 +22,5 @@
  *****************************************************************************/
 
 #define ES_PACKET_SIZE 2048
-#define MAX_PACKETS_IN_FIFO 14
+#define ES_READ_ONCE 50
+#define MAX_PACKETS_IN_FIFO 50
index b9b359fc38533a7961bf7778f5b3ebe6ebccf8c7..02ff0b48e836abef51e4cbc35740b94d27088682 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ps.c,v 1.7 2001/12/27 01:49:34 massiot Exp $
+ * $Id: input_ps.c,v 1.8 2001/12/27 03:47:09 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
@@ -85,8 +85,7 @@ static __inline__ off_t fseeko( FILE *p_file, off_t i_offset, int i_pos )
  * Local prototypes
  *****************************************************************************/
 static int  PSProbe         ( probedata_t * );
-static int  PSRead          ( struct input_thread_s *,
-                             data_packet_t * p_packets[INPUT_READ_ONCE] );
+static int  PSRead          ( struct input_thread_s *, data_packet_t ** );
 static void PSInit          ( struct input_thread_s * );
 static void PSEnd           ( struct input_thread_s * );
 static int  PSSetProgram    ( struct input_thread_s * , pgrm_descriptor_t * );
@@ -210,12 +209,22 @@ static void PSInit( input_thread_t * p_input )
         while( !p_input->b_die && !p_input->b_error
                 && !p_demux_data->b_has_PSM )
         {
-            int                 i_result, i;
-            data_packet_t *     pp_packets[INPUT_READ_ONCE];
+            int                 i_result;
+            data_packet_t *     p_data;
+            data_packet_t *     p_saved_data;
 
-            i_result = PSRead( p_input, pp_packets );
+            i_result = PSRead( p_input, &p_data );
+            p_saved_data = p_data;
 
-            if( i_result == 1 )
+            while( p_data != NULL )
+            {
+                input_ParsePS( p_input, p_data );
+                p_data = p_data->p_next;
+            }
+
+            p_input->pf_delete_packet( p_input->p_method_data, p_saved_data );
+
+            if( i_result == 0 )
             {
                 /* EOF */
                 vlc_mutex_lock( &p_input->stream.stream_lock );
@@ -229,13 +238,6 @@ static void PSInit( input_thread_t * p_input )
                 break;
             }
 
-            for( i = 0; i < INPUT_READ_ONCE && pp_packets[i] != NULL; i++ )
-            {
-                /* FIXME: use i_p_config_t */
-                input_ParsePS( p_input, pp_packets[i] );
-                p_input->pf_delete_packet( p_input->p_method_data, pp_packets[i] );
-            }
-
             /* File too big. */
             if( p_input->stream.p_selected_area->i_tell >
                                                     INPUT_PREPARSE_LENGTH )
@@ -361,7 +363,7 @@ static __inline__ int SafeRead( input_thread_t * p_input, byte_t * p_buffer,
     {
         if( feof( p_input->p_stream ) )
         {
-            return( 1 );
+            return( 0 );
         }
 
         if( (i_error = ferror( p_input->p_stream )) )
@@ -373,28 +375,29 @@ static __inline__ int SafeRead( input_thread_t * p_input, byte_t * p_buffer,
     vlc_mutex_lock( &p_input->stream.stream_lock );
     p_input->stream.p_selected_area->i_tell += i_len;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
-    return( 0 );
+    return( i_len );
 }
 
 /*****************************************************************************
  * PSRead: reads data packets
  *****************************************************************************
- * Returns -1 in case of error, 0 if everything went well, and 1 in case of
- * EOF.
+ * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
+ * packets.
  *****************************************************************************/
 static int PSRead( input_thread_t * p_input,
-                   data_packet_t * pp_packets[INPUT_READ_ONCE] )
+                   data_packet_t ** pp_data )
 {
     byte_t              p_header[6];
     data_packet_t *     p_data;
     size_t              i_packet_size;
     int                 i_packet, i_error;
 
-    memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) );
-    for( i_packet = 0; i_packet < INPUT_READ_ONCE; i_packet++ )
+    *pp_data = NULL;
+
+    for( i_packet = 0; i_packet < PS_READ_ONCE; i_packet++ )
     {
         /* Read what we believe to be a packet header. */
-        if( (i_error = SafeRead( p_input, p_header, 4 )) )
+        if( (i_error = SafeRead( p_input, p_header, 4 )) <= 0 )
         {
             return( i_error );
         }
@@ -423,7 +426,7 @@ static int PSRead( input_thread_t * p_input,
                 }
                 else
                 {
-                    return( 1 );
+                    return( 0 );
                 }
             }
             /* Packet found. */
@@ -434,7 +437,7 @@ static int PSRead( input_thread_t * p_input,
         if( U32_AT(p_header) != 0x1B9 )
         {
             /* The packet is at least 6 bytes long. */
-            if( (i_error = SafeRead( p_input, p_header + 4, 2 )) )
+            if( (i_error = SafeRead( p_input, p_header + 4, 2 )) <= 0 )
             {
                 return( i_error );
             }
@@ -486,8 +489,10 @@ static int PSRead( input_thread_t * p_input,
 
             /* Read the remaining of the packet. */
             if( i_packet_size && (i_error =
-                    SafeRead( p_input, p_data->p_demux_start + 6, i_packet_size )) )
+                    SafeRead( p_input, p_data->p_demux_start + 6,
+                              i_packet_size )) <= 0 )
             {
+                p_input->pf_delete_packet( p_input->p_method_data, p_data );
                 return( i_error );
             }
 
@@ -499,8 +504,10 @@ static int PSRead( input_thread_t * p_input,
                     /* MPEG-2 stuffing bytes */
                     byte_t      p_garbage[8];
                     if( (i_error = SafeRead( p_input, p_garbage,
-                                             p_data->p_demux_start[13] & 0x7)) )
+                                     p_data->p_demux_start[13] & 0x7)) <= 0 )
                     {
+                        p_input->pf_delete_packet( p_input->p_method_data,
+                                                   p_data );
                         return( i_error );
                     }
                 }
@@ -513,10 +520,11 @@ static int PSRead( input_thread_t * p_input,
         }
 
         /* Give the packet to the other input stages. */
-        pp_packets[i_packet] = p_data;
+        *pp_data = p_data;
+        pp_data = &p_data->p_next;
     }
 
-    return( 0 );
+    return( i_packet + 1 );
 }
 
 /*****************************************************************************
index 0420cc354798f58df87e7aaeff24777bd4f67bc5..bc1108e56af05e7cc8b95e79401ece193c2cb62d 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.h: thread structure of the PS plugin
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ps.h,v 1.1 2001/12/09 17:01:36 sam Exp $
+ * $Id: input_ps.h,v 1.2 2001/12/27 03:47:09 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#define DATA_CACHE_SIZE 150
-#define PES_CACHE_SIZE 150
-#define SMALL_CACHE_SIZE 150
-#define LARGE_CACHE_SIZE 150
-#define MAX_SMALL_SIZE 50     // frontier between small and large packets
-
-typedef struct
-{
-    data_packet_t **        p_stack;
-    long                    l_index;
-} data_packet_cache_t;
-
-
-typedef struct
-{
-    pes_packet_t **         p_stack;
-    long                    l_index;
-} pes_packet_cache_t;
-
-
-typedef struct
-{
-    byte_t *                p_data;
-    long                    l_size;
-} packet_buffer_t;
-
-
-typedef struct
-{
-    packet_buffer_t *       p_stack;
-    long                    l_index;
-} small_buffer_cache_t;
-
-
-typedef struct
-{
-    packet_buffer_t *       p_stack;
-    long                    l_index;
-} large_buffer_cache_t;
-
-
-typedef struct
-{
-    vlc_mutex_t             lock;
-    data_packet_cache_t     data;
-    pes_packet_cache_t      pes;
-    small_buffer_cache_t    smallbuffer;
-    large_buffer_cache_t    largebuffer;
-} packet_cache_t;
-
-
+#define PS_READ_ONCE 50
index 2056f3b25a1e15fa9936aefb34aa2d52baef8ed5..c92ef16ecb38c3b60ec56685093b3fd1708310ae 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ts.c,v 1.6 2001/12/27 01:49:34 massiot Exp $
+ * $Id: input_ts.c,v 1.7 2001/12/27 03:47:09 massiot Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -88,8 +88,7 @@
 static int  TSProbe     ( probedata_t * );
 static void TSInit      ( struct input_thread_s * );
 static void TSEnd       ( struct input_thread_s * );
-static int  TSRead      ( struct input_thread_s *,
-                          data_packet_t * p_packets[INPUT_READ_ONCE] );
+static int  TSRead      ( struct input_thread_s *, data_packet_t ** );
 
 /*****************************************************************************
  * Declare a buffer manager
@@ -244,17 +243,16 @@ static void TSEnd( input_thread_t * p_input )
 /*****************************************************************************
  * TSRead: reads data packets
  *****************************************************************************
- * Returns -1 in case of error, 0 if everything went well, and 1 in case of
- * EOF.
+ * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
+ * packets.
  *****************************************************************************/
 static int TSRead( input_thread_t * p_input,
-                   data_packet_t * pp_packets[INPUT_READ_ONCE] )
+                   data_packet_t ** pp_data )
 {
     thread_ts_data_t    * p_method;
-    unsigned int    i_loop;
-    int             i_read;
+    int             i_read = 0, i_loop;
     int             i_data = 1;
-    struct iovec    p_iovec[INPUT_READ_ONCE];
+    struct iovec    p_iovec[TS_READ_ONCE];
     data_packet_t * p_data;
     struct timeval  timeout;
 
@@ -269,9 +267,6 @@ static int TSRead( input_thread_t * p_input,
     timeout.tv_sec = 0;
     timeout.tv_usec = 500000;
 
-    /* Reset pointer table */
-    memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) );
-
     /* Fill if some data is available */
 #if defined( WIN32 )
     if ( ! p_input->stream.b_pace_control ) 
@@ -290,8 +285,8 @@ static int TSRead( input_thread_t * p_input,
     if( i_data )
     {
         /* Get iovecs */
-        p_data = input_BuffersToIO( p_input->p_method_data, p_iovec,
-                                    INPUT_READ_ONCE );
+        *pp_data = p_data = input_BuffersToIO( p_input->p_method_data, p_iovec,
+                                               TS_READ_ONCE );
 
         if ( p_data == NULL )
         {
@@ -301,15 +296,15 @@ static int TSRead( input_thread_t * p_input,
 #if defined( WIN32 )
         if( p_input->stream.b_pace_control )
         {
-            i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+            i_read = readv( p_input->i_handle, p_iovec, TS_READ_ONCE );
         }
         else
         {
             i_read = readv_network( p_input->i_handle, p_iovec,
-                                    INPUT_READ_ONCE, p_method );
+                                    TS_READ_ONCE, p_method );
         }
 #else
-        i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+        i_read = readv( p_input->i_handle, p_iovec, TS_READ_ONCE );
 
         /* Shouldn't happen, but it does - at least under Linux */
         if( (i_read == -1) && ( (errno == EAGAIN) || (errno = EWOULDBLOCK) ) )
@@ -319,41 +314,46 @@ static int TSRead( input_thread_t * p_input,
             i_read = 0;
         }
 #endif
-        /* check correct TS header */
-        for( i_loop=0; i_loop * TS_PACKET_SIZE < i_read; i_loop++ )
-        {
-            pp_packets[i_loop] = p_data;
-            p_data = p_data->p_next;
-            pp_packets[i_loop]->p_next = NULL;
-
-            if( pp_packets[i_loop]->p_demux_start[0] != 0x47 )
-                intf_ErrMsg( "input error: bad TS packet (starts with "
-                             "0x%.2x, should be 0x47)",
-                             pp_packets[i_loop]->p_demux_start[0] );
-        }
-       /* Delete remaining packets */
-        input_DeletePacket( p_input->p_method_data, p_data );
-        for( ; i_loop < INPUT_READ_ONCE ; i_loop++ )
-        {
-            pp_packets[i_loop] = NULL;
-        }
-
         /* Error */
         if( i_read == -1 )
         {
             intf_ErrMsg( "input error: TS readv error" );
+            p_input->pf_delete_packet( p_input->p_method_data, p_data );
             return( -1 );
         }
+        p_input->stream.p_selected_area->i_tell += i_read;
+        i_read /= TS_PACKET_SIZE;
 
-        /* EOF */
-        if( i_read == 0 && p_input->stream.b_seekable )
+        /* Check correct TS header */
+        for( i_loop = 0; i_loop + 1 < i_read; i_loop++ )
         {
-            return( 1 );
+            if( p_data->p_demux_start[0] != 0x47 )
+            {
+                intf_ErrMsg( "input error: bad TS packet (starts with "
+                             "0x%.2x, should be 0x47)",
+                             p_data->p_demux_start[0] );
+            }
+            p_data = p_data->p_next;
         }
 
+        /* Last packet */
+        if( p_data->p_demux_start[0] != 0x47 )
+        {
+            intf_ErrMsg( "input error: bad TS packet (starts with "
+                         "0x%.2x, should be 0x47)",
+                         p_data->p_demux_start[0] );
+        }
 
-        p_input->stream.p_selected_area->i_tell += i_read;
+        if( i_read != TS_READ_ONCE )
+        {
+            /* Delete remaining packets */
+            p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next );
+            if( i_read != 0 )
+            {
+                p_data->p_next = NULL;
+            }
+        }
     }
-    return 0;
+    return( i_read );
 }
 
index 2ad4657765a20f3ff0c2006c415327077cc4115d..6dccf501485ee91240805dc5155736861110935a 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.h: structures of the input not exported to other modules
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ts.h,v 1.3 2001/12/12 17:41:15 massiot Exp $
+ * $Id: input_ts.h,v 1.4 2001/12/27 03:47:09 massiot Exp $
  *
  * Authors: Henri Fallon <henri@via.ecp.fr>
  *          Boris Dorès <babal@via.ecp.fr>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#define BUFFER_SIZE (7 * TS_PACKET_SIZE)
+/* UDP packets contain 1500 bytes, that is 7 TS packets */
+#define TS_READ_ONCE 7
+
+#ifdef WIN32
+#   define BUFFER_SIZE (7 * TS_PACKET_SIZE)
+#endif
 
 /*****************************************************************************
  * thread_ts_data_t: private input data
index cb084c1c5f37fed9afb18d792823d0e4f3bf5534..135a3b5b0ea5505c93ffba02d40aad5e0860b69e 100644 (file)
@@ -243,8 +243,6 @@ static void VCDInit( input_thread_t * p_input )
         intf_ErrMsg( "vcd error: could not read TOC" );
     }
 
-    p_input->i_read_once = VCD_DATA_ONCE;
-
     /* Set stream and area data */
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
@@ -396,10 +394,10 @@ static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
 /*****************************************************************************
  * VCDRead: reads from the VCD into PES packets.
  *****************************************************************************
- * Returns -1 in case of error, 0 if everything went well, and 1 in case of
- * EOF.
+ * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
+ * packets.
  *****************************************************************************/
-static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
+static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data )
 {
     thread_vcd_data_t *     p_vcd;
     data_packet_t *         p_data;
@@ -413,6 +411,7 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
     p_vcd = (thread_vcd_data_t *)p_input->p_plugin_data;
 
     i_packet = 0;
+    *pp_data = NULL;
 
     while( i_packet < VCD_DATA_ONCE
             && !p_vcd->b_end_of_track )
@@ -489,10 +488,8 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
                     break;
             }
 
-#ifdef DEBUG
             intf_DbgMsg("i_index : %d\n", i_index);
             intf_DbgMsg("i_packet_size : %d\n", i_packet_size);
-#endif
 
             if ( i_index + i_packet_size > BUFFER_SIZE )
             {
@@ -525,13 +522,11 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
             }
 
             /* Give the packet to the other input stages. */
-            pp_packets[i_packet] = p_data;
-            i_packet++;
+            *pp_data = p_data;
+            pp_data = &p_data->p_next;
         }
     }
 
-    pp_packets[i_packet] = NULL;
-
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
     p_input->stream.p_selected_area->i_tell =
@@ -553,7 +548,7 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
         if( p_vcd->i_track >= p_vcd->nb_tracks - 1 )
         {
             vlc_mutex_unlock( &p_input->stream.stream_lock );
-            return 1;
+            return 0;
         }
 
         intf_WarnMsg( 4, "vcd info: new title" );
@@ -569,7 +564,7 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_packets )
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    return 0;
+    return( i_packet + 1 );
 }
 
 /*****************************************************************************
index 219f4f98c7a6f00ea0fe0633966e28a67b64b1f1..51ee2d0bb55839639926c26c13c62329f3a6ed46 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input.c,v 1.165 2001/12/12 02:13:50 sam Exp $
+ * $Id: input.c,v 1.166 2001/12/27 03:47:09 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -120,9 +120,6 @@ input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
         return( NULL );
     }
 
-    /* Packets read once */
-    p_input->i_read_once = INPUT_READ_ONCE;
-
     /* Initialize thread properties */
     p_input->b_die              = 0;
     p_input->b_error            = 0;
@@ -229,9 +226,6 @@ void input_DestroyThread( input_thread_t *p_input, int *pi_status )
  *****************************************************************************/
 static void RunThread( input_thread_t *p_input )
 {
-    int                     i_error, i;
-    data_packet_t **        pp_packets;
-
     if( InitThread( p_input ) )
     {
         /* If we failed, wait before we are killed, and exit */
@@ -242,22 +236,16 @@ static void RunThread( input_thread_t *p_input )
         return;
     }
 
-    /* initialization is completed */
+    /* initialization is complete */
     vlc_mutex_lock( &p_input->stream.stream_lock );
     p_input->stream.b_changed = 1;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    pp_packets = (data_packet_t **) malloc( p_input->i_read_once *
-                                        sizeof( data_packet_t * ) );
-    if( pp_packets == NULL )
-    {
-        intf_ErrMsg( "input error: out of memory" );
-        free( pp_packets );
-        p_input->b_error = 1;
-    }
-
     while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
     {
+        data_packet_t * p_data;
+        int i_count, i;
+
         p_input->c_loops++;
 
         vlc_mutex_lock( &p_input->stream.stream_lock );
@@ -357,33 +345,33 @@ static void RunThread( input_thread_t *p_input )
 
         vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-        i_error = p_input->pf_read( p_input, pp_packets );
+        i_count = p_input->pf_read( p_input, &p_data );
 
         /* Demultiplex read packets. */
-        for( i = 0; i < p_input->i_read_once && pp_packets[i] != NULL; i++ )
+        while( p_data != NULL )
         {
+            data_packet_t * p_next = p_data->p_next;
+            p_data->p_next = NULL;
+
             p_input->stream.c_packets_read++;
-            p_input->pf_demux( p_input, pp_packets[i] );
+            p_input->pf_demux( p_input, p_data );
+
+            p_data = p_next;
         }
 
-        if( i_error )
+        if( i_count == 0 && p_input->stream.b_seekable )
         {
-            if( i_error == 1 )
-            {
-                /* End of file - we do not set b_die because only the
-                 * interface is allowed to do so. */
-                intf_WarnMsg( 3, "input: EOF reached" );
-                p_input->b_eof = 1;
-            }
-            else
-            {
-                p_input->b_error = 1;
-            }
+            /* End of file - we do not set b_die because only the
+             * interface is allowed to do so. */
+            intf_WarnMsg( 3, "input: EOF reached" );
+            p_input->b_eof = 1;
+        }
+        else if( i_count < 0 )
+        {
+            p_input->b_error = 1;
         }
     }
 
-    free( pp_packets );
-
     if( p_input->b_error || p_input->b_eof )
     {
         ErrorThread( p_input );