- /* Has the reassembly of a section already began in a previous packet ? */
- if( p_psi->b_running_section )
- {
- /* Was data lost since the last TS packet ? */
- if( b_packet_lost )
- {
- /* Discard the section and wait for the begining of a new one to resynch */
- p_psi->b_running_section = 0;
- intf_DbgMsg( "Section discarded due to packet loss\n" );
- }
- else
- {
- /* The data that complete a previously began section are always at
- the beginning of the TS payload... */
- i_data_offset = p_ts_packet->i_payload_start;
- /* ...Unless there is a pointer field, that we have to bypass */
- if( b_unit_start )
- i_data_offset ++;
-// intf_DbgMsg( "New part of the section received at offset %d\n", i_data_offset );
- }
- }
- /* We are looking for the beginning of a new section */
- else
- {
- if( !b_unit_start )
- {
- /* Cannot do anything with those data: trash both PSI section and TS packet */
- p_psi->b_running_section = 0;
- break;
- }
- else
- {
- /* Get the offset at which the data for that section can be found */
- if( b_first_section )
- {
- /* The offset is stored in the pointer_field since we are interested in
- the first section of the TS packet. Note that the +1 is to bypass
- the pointer field */
- i_data_offset = p_ts_packet->i_payload_start +
- p_ts_packet->buffer[p_ts_packet->i_payload_start] + 1;
- }
- else
- {
- /* Since no gap is allowed between 2 sections in a TS packet, the
- offset is given by the end of the previous section. In fact, there
- is nothing to do, i_offset was set to the right value in the
- previous iteration */
- }
-// intf_DbgMsg( "New section beginning at offset %d in TS packet\n", i_data_offset );
-
- /* Read the length of that section */
- p_psi->i_length = (U16_AT(&p_ts_packet->buffer[i_data_offset+1]) & 0xFFF) + 3;
-// intf_DbgMsg( "Section length %d\n", p_psi->i_length );
- if( p_psi->i_length > PSI_SECTION_SIZE )
- {
- /* The TS packet is corrupted, stop here to avoid possible a seg fault */
- intf_DbgMsg( "Section size is too big, aborting its reception\n" );
- break;
- }
-
- /* Init the reassembly of that section */
- p_psi->b_running_section = 1;
- p_psi->i_current_position = 0;
- }
- }
-
- /* Compute the length of data related to the section in this TS packet */
- if( p_psi->i_length - p_psi->i_current_position > TS_PACKET_SIZE - i_data_offset)
- i_data_length = TS_PACKET_SIZE - i_data_offset;
- else
- i_data_length = p_psi->i_length - p_psi->i_current_position;