- if( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
- {
- /* This is not the startcode of a packet. Read the stream
- * until we find one. */
-
- if( !U32_AT( p_buffer + i_index ) )
- {
- /* It is common for MPEG-1 streams to pad with zeros
- * (although it is forbidden by the recommendation), so
- * don't bother everybody in this case. */
- intf_WarnMsg( 3, "Garbage at input" );
- }
-
- while( ( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
- && ( i_index < BUFFER_SIZE - 4 ) )
- {
- i_index ++;
- }
-
- if ( i_index == BUFFER_SIZE - 4 )
- {
- b_no_packet = 1;
- }
- /* Packet found. */
- }
-
- if (b_no_packet)
- {
- b_no_packet = 0;
- intf_WarnMsg(3, "No packet found on sector %d\n",
- p_vcd->current_sector -1 );
- break; /* go to the next sector */
- }
-
-#ifdef DEBUG
- intf_DbgMsg("packet start code : %X\n",
- U32_AT(p_buffer + i_index));
-#endif
- /* 0x1B9 == SYSTEM_END_CODE, it is only 4 bytes long. */
- if( U32_AT(p_buffer + i_index) != 0x1B9 )
- {
- /* The packet is at least 6 bytes long. */
-
- if( U32_AT(p_buffer + i_index) != 0x1BA )
- {
- /* That's the case for all packets, except pack header. */
- i_packet_size = U16_AT((p_buffer + ( i_index + 4 )));
- }
- else
- {
- /* Pack header. */
- if( ( *( p_buffer + ( i_index + 4 ) ) & 0xC0) == 0x40 )
- {
- /* MPEG-2 */
- i_packet_size = 8;
- }
- else if( (*(p_buffer + ( i_index + 4 ) ) & 0xF0) == 0x20 )
- {
- /* MPEG-1 */
- i_packet_size = 6;
- }
- else
- {
- intf_ErrMsg( "Unable to determine stream type" );
- return( -1 );
- }
- }
- }
- else
- {
- /* System End Code */
- i_packet_size = -2;
- }
-#ifdef DEBUG
- intf_DbgMsg("i_index : %d\n", i_index);
- intf_DbgMsg("i_packet_size : %d\n", i_packet_size);
-#endif
- if ( i_index + i_packet_size > BUFFER_SIZE )
- {
- intf_ErrMsg( "Too long packet");
- continue;
- }