* input_ext-dec.h: structures exported to the VideoLAN decoders
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-dec.h,v 1.43 2001/12/12 11:18:38 massiot Exp $
+ * $Id: input_ext-dec.h,v 1.44 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Kaempf <maxx@via.ecp.fr>
p_next fields of the data_packet_t struct) */
data_packet_t * p_first; /* The first packet contained by this
* PES (used by decoders). */
+ data_packet_t * p_last; /* The last packet contained by this
+ PES (used by the buffer allocator) */
+ int i_nb_data;
/* Chained list used by the input buffers manager */
struct pes_packet_s * p_next;
* control the pace of reading.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-intf.h,v 1.52 2001/12/10 04:53:10 sam Exp $
+ * $Id: input_ext-intf.h,v 1.53 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
/* PES parser information */
struct pes_packet_s * p_pes; /* Current PES */
- struct data_packet_s * p_last; /* The last packet gathered at present */
int i_pes_real_size; /* as indicated by the header */
/* Decoder information */
* but exported to plug-ins
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: input_ext-plugins.h,v 1.9 2001/12/12 11:18:38 massiot Exp $
+ * $Id: input_ext-plugins.h,v 1.10 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
if( p_pes != NULL )
{
p_pes->b_discontinuity = 1;
- p_es->p_last->p_next = p_pad_data;
- p_es->p_last = p_pad_data;
+ p_pes->p_last->p_next = p_pad_data;
+ p_pes->p_last = p_pad_data;
+ p_pes->i_nb_data++;
}
else
{
}
p_pes->i_rate = p_input->stream.control.i_rate;
- p_pes->p_first = p_pad_data;
+ p_pes->p_first = p_pes->p_last = p_pad_data;
+ p_pes->i_nb_data = 1;
p_pes->b_discontinuity = 1;
input_DecodePES( p_es->p_decoder_fifo, p_pes );
}
/* Flags */
#define BUFFERS_NOFLAGS 0
#define BUFFERS_SHARED 1
-#define BUFFERS_UNIQUE_SIZE 2
+#define BUFFERS_UNIQUE_SIZE 2 /* Only with NB_LIFO == 1 */
/*****************************************************************************
* input_buffers_t: defines a LIFO per data type to keep
if( p_main->b_stats ) \
{ \
int i; \
+ intf_StatMsg( "input buffers stats: pes: %d packets", \
+ p_buffers->pes.i_depth ); \
for( i = 0; i < NB_LIFO; i++ ) \
{ \
intf_StatMsg( \
* input_NewPacket: return a pointer to a data packet of the appropriate size
*****************************************************************************/
#define DECLARE_BUFFERS_NEWPACKET( FLAGS, NB_LIFO ) \
-static data_packet_t * input_NewPacket( void * _p_buffers, size_t i_size ) \
+static __inline__ data_packet_t * _input_NewPacket( void * _p_buffers, \
+ size_t i_size ) \
{ \
input_buffers_t * p_buffers = (input_buffers_t *)_p_buffers; \
int i_select; \
data_packet_t * p_data; \
\
- /* Safety checks */ \
- if( i_size > INPUT_MAX_PACKET_SIZE ) \
- { \
- intf_ErrMsg( "Packet too big (%d)", i_size ); \
- return NULL; \
- } \
- \
- vlc_mutex_lock( &p_buffers->lock ); \
- \
+ /* Safety check */ \
if( p_buffers->i_allocated > INPUT_MAX_ALLOCATION ) \
{ \
vlc_mutex_unlock( &p_buffers->lock ); \
p_buffers->data[i_select].i_depth--; \
\
/* Reallocate the packet if it is too small or too large */ \
- if( p_data->p_buffer_end - p_data->p_buffer < i_size || \
- p_data->p_buffer_end - p_data->p_buffer > 3 * i_size ) \
+ if( !(FLAGS & BUFFERS_UNIQUE_SIZE) && \
+ (p_data->p_buffer_end - p_data->p_buffer < i_size || \
+ p_data->p_buffer_end - p_data->p_buffer > 3 * i_size) ) \
{ \
p_buffers->i_allocated -= p_data->p_buffer_end \
- p_data->p_buffer; \
p_buffers->i_allocated += i_size; \
} \
\
- vlc_mutex_unlock( &p_buffers->lock ); \
- \
/* Initialize data */ \
p_data->p_next = NULL; \
p_data->b_discard_payload = 0; \
p_data->p_payload_end = p_data->p_buffer + i_size; \
\
return( p_data ); \
+} \
+ \
+static data_packet_t * input_NewPacket( void * _p_buffers, size_t i_size ) \
+{ \
+ input_buffers_t * p_buffers = (input_buffers_t *)_p_buffers; \
+ data_packet_t * p_data; \
+ \
+ /* Safety check */ \
+ if( !(FLAGS & BUFFERS_UNIQUE_SIZE) && i_size > INPUT_MAX_PACKET_SIZE ) \
+ { \
+ intf_ErrMsg( "Packet too big (%d)", i_size ); \
+ return NULL; \
+ } \
+ \
+ vlc_mutex_lock( &p_buffers->lock ); \
+ p_data = _input_NewPacket( _p_buffers, i_size ); \
+ vlc_mutex_unlock( &p_buffers->lock ); \
+ return( p_data ); \
}
/*****************************************************************************
p_buffers->data[i_select].p_stack = p_data; \
p_buffers->data[i_select].i_depth++; \
\
- /* Update Bresenham mean (very approximative) */ \
- p_buffers->data[i_select].i_average_size = ( i_size \
- + p_buffers->data[i_select].i_average_size \
- * (INPUT_BRESENHAM_NB - 1) ) \
- / INPUT_BRESENHAM_NB; \
+ if( !(FLAGS & BUFFERS_UNIQUE_SIZE) ) \
+ { \
+ /* Update Bresenham mean (very approximative) */ \
+ p_buffers->data[i_select].i_average_size = ( i_size \
+ + p_buffers->data[i_select].i_average_size \
+ * (INPUT_BRESENHAM_NB - 1) ) \
+ / INPUT_BRESENHAM_NB; \
+ } \
} \
else \
{ \
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; \
+ p_pes->p_first = p_pes->p_last = NULL; \
+ p_pes->i_nb_data = 0; \
\
return( p_pes ); \
}
/*****************************************************************************
* input_DeletePES: put a pes and all data packets back into the cache
*****************************************************************************/
-#define DECLARE_BUFFERS_DELETEPES( FLAGS, NB_LIFO, PES_CACHE_SIZE ) \
+#define DECLARE_BUFFERS_DELETEPES( FLAGS, NB_LIFO, DATA_CACHE_SIZE, \
+ PES_CACHE_SIZE ) \
static void input_DeletePES( void * _p_buffers, pes_packet_t * p_pes ) \
{ \
input_buffers_t * p_buffers = (input_buffers_t *)_p_buffers; \
- data_packet_t * p_data; \
\
vlc_mutex_lock( &p_buffers->lock ); \
\
- p_data = p_pes->p_first; \
- while( p_data != NULL ) \
+ if( !(FLAGS & BUFFERS_UNIQUE_SIZE) \
+ || p_buffers->data[0].i_depth > DATA_CACHE_SIZE ) \
+ /* This is a little inaccurate but who cares if we have too many \
+ * packets in the cache ? */ \
{ \
- data_packet_t * p_next = p_data->p_next; \
- _input_DeletePacket( _p_buffers, p_data ); \
- p_data = p_next; \
+ data_packet_t * p_data = p_pes->p_first; \
+ while( p_data != NULL ) \
+ { \
+ data_packet_t * p_next = p_data->p_next; \
+ _input_DeletePacket( _p_buffers, p_data ); \
+ p_data = p_next; \
+ } \
+ } \
+ else \
+ { \
+ /* NB_LIFO == 1 and we can keep all data packets */ \
+ p_pes->p_last->p_next = p_buffers->data[0].p_stack; \
+ p_buffers->data[0].p_stack = p_pes->p_first; \
+ p_buffers->data[0].i_depth += p_pes->i_nb_data; \
} \
\
if( p_buffers->pes.i_depth < PES_CACHE_SIZE ) \
vlc_mutex_unlock( &p_buffers->lock ); \
}
+/*****************************************************************************
+ * input_BuffersToIO: return an io vector (only with BUFFERS_UNIQUE_SIZE)
+ *****************************************************************************/
+#define DECLARE_BUFFERS_TOIO( FLAGS, BUFFER_SIZE ) \
+static data_packet_t * input_BuffersToIO( void * _p_buffers, \
+ struct iovec * p_iovec, int i_nb ) \
+{ \
+ input_buffers_t * p_buffers = (input_buffers_t *)_p_buffers; \
+ data_packet_t * p_data = NULL; \
+ int i; \
+ \
+ vlc_mutex_lock( &p_buffers->lock ); \
+ \
+ for( i = i_nb - 1; i >= 0; i-- ) \
+ { \
+ data_packet_t * p_next = _input_NewPacket( _p_buffers, \
+ BUFFER_SIZE /* UNIQUE_SIZE */ ); \
+ if( p_next == NULL ) \
+ { \
+ while( p_data != NULL ) \
+ { \
+ p_next = p_data->p_next; \
+ _input_DeletePacket( _p_buffers, p_data ); \
+ p_data = p_next; \
+ } \
+ return( NULL ); \
+ } \
+ \
+ p_iovec[i].iov_base = p_next->p_payload_start; \
+ p_iovec[i].iov_len = BUFFER_SIZE; \
+ p_next->p_next = p_data; \
+ p_data = p_next; \
+ } \
+ \
+ vlc_mutex_unlock( &p_buffers->lock ); \
+ \
+ return( p_data ); \
+}
+
/*
* Optional MPEG demultiplexing
* input_ps.c: PS demux and packet management
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ps.c,v 1.3 2001/12/12 11:18:38 massiot Exp $
+ * $Id: input_ps.c,v 1.4 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Cyril Deguet <asmax@via.ecp.fr>
DECLARE_BUFFERS_NEWPACKET( FLAGS, NB_LIFO );
DECLARE_BUFFERS_DELETEPACKET( FLAGS, NB_LIFO, 150 );
DECLARE_BUFFERS_NEWPES( FLAGS, NB_LIFO );
-DECLARE_BUFFERS_DELETEPES( FLAGS, NB_LIFO, 150 );
+DECLARE_BUFFERS_DELETEPES( FLAGS, NB_LIFO, 150, 150 );
/*****************************************************************************
* input_ts.c: TS demux and netlist management
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ts.c,v 1.2 2001/12/10 04:53:11 sam Exp $
+ * $Id: input_ts.c,v 1.3 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Henri Fallon <henri@videolan.org>
*
static int TSRead ( struct input_thread_s *,
data_packet_t * p_packets[INPUT_READ_ONCE] );
+/*****************************************************************************
+ * Declare a buffer manager
+ *****************************************************************************/
+#define FLAGS BUFFERS_UNIQUE_SIZE
+#define NB_LIFO 1
+DECLARE_BUFFERS_EMBEDDED( FLAGS, NB_LIFO );
+DECLARE_BUFFERS_INIT( FLAGS, NB_LIFO );
+DECLARE_BUFFERS_END( FLAGS, NB_LIFO );
+DECLARE_BUFFERS_NEWPACKET( FLAGS, NB_LIFO );
+DECLARE_BUFFERS_DELETEPACKET( FLAGS, NB_LIFO, 1000 );
+DECLARE_BUFFERS_NEWPES( FLAGS, NB_LIFO );
+DECLARE_BUFFERS_DELETEPES( FLAGS, NB_LIFO, 1000, 150 );
+DECLARE_BUFFERS_TOIO( FLAGS, TS_PACKET_SIZE );
+
/*****************************************************************************
* Functions exported as capabilities. They are declared as static so that
* we don't pollute the namespace too much.
input.pf_set_program = input_SetProgram;
input.pf_read = TSRead;
input.pf_demux = input_DemuxTS;
- input.pf_new_packet = input_NetlistNewPacket;
- input.pf_new_pes = input_NetlistNewPES;
- input.pf_delete_packet = input_NetlistDeletePacket;
- input.pf_delete_pes = input_NetlistDeletePES;
+ input.pf_new_packet = input_NewPacket;
+ input.pf_new_pes = input_NewPES;
+ input.pf_delete_packet = input_DeletePacket;
+ input.pf_delete_pes = input_DeletePES;
input.pf_rewind = NULL;
input.pf_seek = NULL;
#undef input
*****************************************************************************/
static void TSInit( input_thread_t * p_input )
{
- /* Initialize netlist and TS structures */
thread_ts_data_t * p_method;
es_descriptor_t * p_pat_es;
es_ts_data_t * p_demux_data;
p_input->p_method_data = NULL;
- /* Initialize netlist */
- if( input_NetlistInit( p_input, NB_DATA, NB_DATA, NB_PES, TS_PACKET_SIZE,
- INPUT_READ_ONCE ) )
+ if( (p_input->p_method_data = input_BuffersInit()) == NULL )
{
- intf_ErrMsg( "TS input : Could not initialize netlist" );
+ p_input->b_error = 1;
return;
}
input_DelES( p_input, p_pat_es );
free(p_input->p_plugin_data);
- input_NetlistEnd( p_input );
+ input_BuffersEnd( p_input->p_method_data );
}
/*****************************************************************************
unsigned int i_loop;
int i_read;
int i_data = 1;
- struct iovec * p_iovec;
+ struct iovec p_iovec[INPUT_READ_ONCE];
+ data_packet_t * p_data;
struct timeval timeout;
/* Init */
if( i_data )
{
/* Get iovecs */
- p_iovec = input_NetlistGetiovec( p_input->p_method_data );
+ p_data = input_BuffersToIO( p_input->p_method_data, p_iovec,
+ INPUT_READ_ONCE );
if ( p_iovec == NULL )
{
- return( -1 ); /* empty netlist */
+ return( -1 );
}
#if defined( WIN32 )
i_read = 0;
}
#endif
- if( i_read == -1 )
- {
- intf_ErrMsg( "input error: TS readv error" );
- return( -1 );
- }
-
- /* EOF */
- if( i_read == 0 && p_input->stream.b_seekable )
- {
- return( 1 );
- }
-
- input_NetlistMviovec( p_input->p_method_data,
- (int)(((i_read-1)/TS_PACKET_SIZE)+1) , pp_packets );
-
/* 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_buffer[0] != 0x47 )
intf_ErrMsg( "input error: bad TS packet (starts with "
"0x%.2x, should be 0x47)",
}
for( ; i_loop < INPUT_READ_ONCE ; i_loop++ )
{
+ data_packet_t * p_next = p_data->p_next;
+ input_DeletePacket( p_input->p_method_data, p_data );
+ p_data = p_next;
pp_packets[i_loop] = NULL;
}
+ /* Error */
+ if( i_read == -1 )
+ {
+ intf_ErrMsg( "input error: TS readv error" );
+ return( -1 );
+ }
+
+ /* EOF */
+ if( i_read == 0 && p_input->stream.b_seekable )
+ {
+ return( 1 );
+ }
+
+
p_input->stream.p_selected_area->i_tell += i_read;
}
return 0;
* mpeg_system.c: TS, PS and PES management
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: mpeg_system.c,v 1.71 2001/12/11 13:55:55 massiot Exp $
+ * $Id: mpeg_system.c,v 1.72 2001/12/12 13:48:09 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
else
{
/* Update the relations between the data packets */
- p_es->p_last->p_next = p_data;
+ p_pes->p_last->p_next = p_data;
}
- p_es->p_last = p_data;
+ p_pes->p_last = p_data;
+ p_pes->i_nb_data++;
/* Size of the payload carried in the data packet */
p_pes->i_pes_size += (p_data->p_payload_end