- /* Verify that we still have packets in the TS netlist */
- if( (INPUT_MAX_TS + INPUT_TS_READ_ONCE - 1 - p_input->netlist.i_ts_index) <= INPUT_TS_READ_ONCE )
- {
- intf_ErrMsg("input error: TS netlist is empty !\n");
- return( -1 );
- }
-
-#else /* FIFO netlist */
- i_base_index = p_input->netlist.i_ts_start;
- if( p_input->netlist.i_ts_start + INPUT_TS_READ_ONCE -1 > INPUT_MAX_TS )
- {
- /* The netlist is splitted in 2 parts. We must gather them to consolidate
- the FIFO (we make the loop easily in having the same iovec at the far
- end and in the beginning of netlist_free).
- That's why the netlist is (INPUT_MAX_TS +1) + (INPUT_TS_READ_ONCE -1)
- large. */
- memcpy( p_input->netlist.p_ts_free + INPUT_MAX_TS + 1,
- p_input->netlist.p_ts_free,
- (p_input->netlist.i_ts_start + INPUT_TS_READ_ONCE - 1 - INPUT_MAX_TS)
- * sizeof(struct iovec) );
- }
-
- /* Verify that we still have packets in the TS netlist */
- if( ((p_input->netlist.i_ts_end -1 - p_input->netlist.i_ts_start) & INPUT_MAX_TS) <= INPUT_TS_READ_ONCE )
- {
- intf_ErrMsg("input error: TS netlist is empty !\n");
- return( -1 );
- }
-#endif /* FIFO netlist */
-
- /* Scatter read the buffer. */
- i_packet_size = (*p_input->p_Read)( p_input,
- &p_input->netlist.p_ts_free[i_base_index],
- INPUT_TS_READ_ONCE );
- if( i_packet_size == (-1) )
- {
-#if 0
- intf_DbgMsg("Read packet %d %p %d %d\n", i_base_index,
- &p_input->netlist.p_ts_free[i_base_index],
- p_input->netlist.i_ts_start,
- p_input->netlist.i_ts_end);
-#endif
- intf_ErrMsg("input error: readv() failed (%s)\n", strerror(errno));
- return( -1 );
- }
-
- if( i_packet_size == 0 )
- {
- /* No packet has been received, so stop here. */
- return( 0 );
- }
-
- /* Demultiplex the TS packets (1..INPUT_TS_READ_ONCE) received. */
- for( i_current_index = i_base_index;
- (i_packet_size -= TS_PACKET_SIZE) >= 0;
- i_current_index++ )
- {
- /* BTW, something REALLY bad could happen if we receive packets with
- a wrong size. */
- p_ts_packet = (ts_packet_t*)(p_input->netlist.p_ts_free[i_current_index].iov_base);
- /* Don't cry :-), we are allowed to do that cast, because initially,
- our buffer was malloc'ed with sizeof(ts_packet_t) */
-
- /* Find out if we need this packet and demultiplex. */
- input_SortPacket( p_input /* for current PIDs and netlist */,
- p_ts_packet);
- }
-
- if( i_packet_size > 0 )
- {
- intf_ErrMsg("input error: wrong size\n");
- return( -1 );
- }