* input_netlist.c: netlist management
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_netlist.c,v 1.31 2001/02/14 15:58:29 henri Exp $
+ * $Id: input_netlist.c,v 1.32 2001/03/10 11:23:10 henri Exp $
*
* Authors: Henri Fallon <henri@videolan.org>
*
p_netlist->i_read_once = i_read_once;
+ /* In order to optimize netlist, we are taking i_nb_data a 2^i
+ * so that modulo is an "&".
+ * This is not changing i_nb data outside this function except in
+ * the netlist_t struct */
+ /* As i_loop is unsigned int, and i_ns_data int, this shouldn't be a
+ * problem */
+ for( i_loop=1; i_loop < i_nb_data; i_loop*=2 )
+ ;
+ intf_DbgMsg( "Netlist : Required %i byte, got %u",i_nb_data,i_loop );
+ i_nb_data = i_loop;
+
+ /* Same thing for i_nb_pes */
+ for( i_loop=1; i_loop < i_nb_data; i_loop*=2 )
+ ;
+ intf_DbgMsg( "Netlist : Required %i byte, got %u",i_nb_data,i_loop );
+ i_nb_data = i_loop;
+
/* allocate the buffers */
p_netlist->p_buffers =
(byte_t *) malloc(i_buffer_size* i_nb_data );
/* check */
if(
- (p_netlist->i_data_end - p_netlist->i_data_start + p_netlist->i_nb_data)
- %p_netlist->i_nb_data < p_netlist->i_read_once )
+ ( (p_netlist->i_data_end - p_netlist->i_data_start + p_netlist->i_nb_data)
+ & ( p_netlist->i_nb_data -1 ) ) < p_netlist->i_read_once )
{
intf_ErrMsg("Empty iovec FIFO. Unable to allocate memory");
return (NULL);
}
p_netlist->i_data_start += i_nb_iovec;
- p_netlist->i_data_start %= p_netlist->i_nb_data;
+ p_netlist->i_data_start &= ( p_netlist->i_nb_data - 1 );
/* unlock */
vlc_mutex_unlock (&p_netlist->lock);
p_return = (p_netlist->pp_free_data[p_netlist->i_data_start]);
p_netlist->i_data_start++;
- p_netlist->i_data_start %= p_netlist->i_nb_data;
+ p_netlist->i_data_start &= ( p_netlist->i_nb_data - 1 );
/* unlock */
vlc_mutex_unlock (&p_netlist->lock);
/* allocate */
p_return = p_netlist->pp_free_pes[p_netlist->i_pes_start];
p_netlist->i_pes_start++;
- p_netlist->i_pes_start %= p_netlist->i_nb_pes;
+ p_netlist->i_pes_start &= ( p_netlist->i_nb_pes - 1 );
/* unlock */
vlc_mutex_unlock (&p_netlist->lock);
/* Delete data_packet */
p_netlist->i_data_end ++;
- p_netlist->i_data_end %= p_netlist->i_nb_data;
+ p_netlist->i_data_end &= ( p_netlist->i_nb_data - 1 );
p_netlist->pp_free_data[p_netlist->i_data_end] = p_data;
p_netlist->p_free_iovec[p_netlist->i_data_end].iov_base = p_data->p_buffer;
/* copy of NetListDeletePacket, duplicate code avoid many locks */
p_netlist->i_data_end ++;
- p_netlist->i_data_end %= p_netlist->i_nb_data;
+ p_netlist->i_data_end &= ( p_netlist->i_nb_data - 1 );
/* re initialize*/
p_current_packet->p_payload_start = p_current_packet->p_buffer;
/* delete our current PES packet */
p_netlist->i_pes_end ++;
- p_netlist->i_pes_end %= p_netlist->i_nb_pes;
+ p_netlist->i_pes_end &= ( p_netlist->i_nb_pes - 1 );
p_netlist->pp_free_pes[p_netlist->i_pes_end] = p_pes;
/* unlock */