]> git.sesse.net Git - vlc/blobdiff - include/input_netlist.h
*initialization bugfixes in input_dvd
[vlc] / include / input_netlist.h
index a25b5fa2cb60757cfc09a85485c03b13abed640c..105af6088dfc145cbf7cb9eb8b9a3ed717e10991 100644 (file)
 /*****************************************************************************
- * input_netlist.h: netlist interface
- * (c)1998 VideoLAN
- *****************************************************************************
- * The netlists are an essential part of the input structure. We maintain a
- * list of free TS packets and free PES packets to avoid continuous malloc
- * and free.
+ * netlist_t: structure to manage a netlist
  *****************************************************************************/
-
-/*****************************************************************************
- * Prototypes
- *****************************************************************************/
-int     input_NetlistInit       ( input_thread_t *p_input );
-void    input_NetlistEnd        ( input_thread_t *p_input );
-
-static __inline__ void input_NetlistFreePES( input_thread_t *p_input, pes_packet_t *p_pes_packet );
-static __inline__ void input_NetlistFreeTS( input_thread_t *p_input, ts_packet_t *p_ts_packet );
-static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input );
-
-/*****************************************************************************
- * input_NetlistFreePES: add a PES packet to the netlist
- *****************************************************************************
- * Add a PES packet to the PES netlist, so that the packet can immediately be
- * reused by the demultiplexer. We put this function directly in the .h file,
- * because it is very frequently called.
- *****************************************************************************/
-static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
-                                  pes_packet_t *p_pes_packet )
+typedef struct netlist_s
 {
-    int             i_dummy;
-    ts_packet_t *   p_ts_packet;
-
-    ASSERT(p_pes_packet);
+    vlc_mutex_t             lock;
 
-    /* We will be playing with indexes, so we take a lock. */
-    vlc_mutex_lock( &p_input->netlist.lock );
+    size_t                  i_buffer_size;
 
-    /* Free all TS packets in this PES structure. */
-    p_ts_packet = p_pes_packet->p_first_ts;
-    for( i_dummy = 0; i_dummy < p_pes_packet->i_ts_packets; i_dummy++ )
-    {
-       ASSERT(p_ts_packet);
+    /* Buffers */
+    byte_t *                p_buffers;                 /* Big malloc'ed area */
+    data_packet_t *         p_data;                        /* malloc'ed area */
+    pes_packet_t *          p_pes;                         /* malloc'ed area */
 
-#ifdef INPUT_LIFO_TS_NETLIST
-        p_input->netlist.i_ts_index--;
-        p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
-                             = p_ts_packet;
-#else /* FIFO */
-        p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
-                             = p_ts_packet;
-        p_input->netlist.i_ts_end++;
-        p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
-#endif
-        p_ts_packet = p_ts_packet->p_next_ts;
-    }
+    /* FIFOs of free packets */
+    data_packet_t **        pp_free_data;
+    pes_packet_t **         pp_free_pes;
+    struct iovec *          p_free_iovec;
+    
+    /* FIFO size */
+    unsigned int            i_nb_pes;
+    unsigned int            i_nb_data;
 
-    /* Free the PES structure. */
-#ifdef INPUT_LIFO_PES_NETLIST
-    p_input->netlist.i_pes_index--;
-    p_input->netlist.p_pes_free[p_input->netlist.i_pes_index] = p_pes_packet;
-#else /* FIFO */
-    p_input->netlist.p_pes_free[p_input->netlist.i_pes_end] = p_pes_packet;
-    p_input->netlist.i_pes_end++;
-    p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
-#endif
+    /* Index */
+    unsigned int            i_data_start, i_data_end;
+    unsigned int            i_pes_start, i_pes_end;
 
-    vlc_mutex_unlock( &p_input->netlist.lock );
-}
+    /* Number of blocs read once by readv */
+    unsigned int            i_read_once;
+} netlist_t;
 
 /*****************************************************************************
- * input_NetlistFreeTS: add a TS packet to the netlist
- *****************************************************************************
- * Add a TS packet to the TS netlist, so that the packet can immediately be
- * reused by the demultiplexer. Shouldn't be called by other threads (they
- * should only use input_FreePES.
- *****************************************************************************/
-static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
-                                            ts_packet_t *p_ts_packet )
-{
-    ASSERT(p_ts_packet);
-
-    /* We will be playing with indexes, so we take a lock. */
-    vlc_mutex_lock( &p_input->netlist.lock );
-
-    /* Free the TS structure. */
-#ifdef INPUT_LIFO_TS_NETLIST
-    p_input->netlist.i_ts_index--;
-    p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base = p_ts_packet;
-#else /* FIFO */
-    p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base = p_ts_packet;
-    p_input->netlist.i_ts_end++;
-    p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
-#endif
-
-    vlc_mutex_unlock( &p_input->netlist.lock );
-}
-
-/*****************************************************************************
- * input_NetlistGetPES: remove a PES packet from the netlist
- *****************************************************************************
- * Add a TS packet to the TS netlist, so that the packet can immediately be
- * reused by the demultiplexer. Shouldn't be called by other threads (they
- * should only use input_FreePES.
+ * Prototypes
  *****************************************************************************/
-static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
-{
-    pes_packet_t *          p_pes_packet;
-
-#ifdef INPUT_LIFO_PES_NETLIST
-    /* i_pes_index might be accessed by a decoder thread to give back a
-     * packet. */
-    vlc_mutex_lock( &p_input->netlist.lock );
-
-    /* Verify that we still have PES packet in the netlist */
-    if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
-    {
-        intf_ErrMsg("input error: PES netlist is empty !\n");
-        return( NULL );
-    }
-
-    /* Fetch a new PES packet */
-    p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
-    p_input->netlist.i_pes_index++;
-    vlc_mutex_unlock( &p_input->netlist.lock );
-
-#else /* FIFO */
-    /* No need to lock, since we are the only ones accessing i_pes_start. */
-
-    /* Verify that we still have PES packet in the netlist */
-    if( ((p_input->netlist.i_pes_end -1 - p_input->netlist.i_pes_start) & INPUT_MAX_PES) <= 1 )
-    {
-        intf_ErrMsg("input error: PES netlist is empty !\n");
-        return( NULL );
-    }
-
-    p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_start];
-    p_input->netlist.i_pes_start++;
-    p_input->netlist.i_pes_start &= INPUT_MAX_PES; /* loop */
-#endif /* netlist type */
-
-    /* Initialize PES flags. */
-    p_pes_packet->b_data_loss = 0;
-    p_pes_packet->b_data_alignment = 0;
-    p_pes_packet->b_has_pts = 0;
-    p_pes_packet->b_random_access = 0;
-    p_pes_packet->b_discard_payload = 0;
-    p_pes_packet->i_pes_size = 0;
-    p_pes_packet->i_ts_packets = 0;
-    p_pes_packet->p_first_ts = NULL;
-    p_pes_packet->p_last_ts = NULL;
+int                     input_NetlistInit( struct input_thread_s *,
+                                           int i_nb_data, int i_nb_pes,
+                                           size_t i_buffer_size,
+                                           int i_read_once );
+
+struct iovec * input_NetlistGetiovec( void * p_method_data );
+void input_NetlistMviovec( void * , size_t, struct data_packet_s **);
+struct data_packet_s *  input_NetlistNewPacket( void *, size_t );
+struct pes_packet_s *   input_NetlistNewPES( void * );
+void            input_NetlistDeletePacket( void *, struct data_packet_s * );
+void            input_NetlistDeletePES( void *, struct pes_packet_s * );
+void            input_NetlistEnd( struct input_thread_s * );
 
-    return( p_pes_packet );
-}