- msg_Warn( p_demux, "cannot peek while getting new packet, EOF ?" );
- return 0;
- }
- unsigned int i_skip = 0;
-
- /* *** parse error correction if present *** */
- if( p_peek[0]&0x80 )
- {
- unsigned int i_error_correction_data_length = p_peek[0] & 0x0f;
- unsigned int i_opaque_data_present = ( p_peek[0] >> 4 )& 0x01;
- unsigned int i_error_correction_length_type = ( p_peek[0] >> 5 ) & 0x03;
- i_skip += 1; // skip error correction flags
-
- if( i_error_correction_length_type != 0x00 ||
- i_opaque_data_present != 0 ||
- i_error_correction_data_length != 0x02 )
- {
- goto loop_error_recovery;
- }
-
- i_skip += i_error_correction_data_length;
- }
- else
- msg_Warn( p_demux, "no error correction" );
-
- /* sanity check */
- if( i_skip + 2 >= i_data_packet_min )
- goto loop_error_recovery;
-
- struct asf_packet_t pkt;
- int i_packet_flags = p_peek[i_skip]; i_skip++;
- pkt.property = p_peek[i_skip]; i_skip++;
- pkt.multiple = !!(i_packet_flags&0x01);
-
- pkt.length = i_data_packet_min;
- pkt.padding_length = 0;
-
- if (GetValue2b(&pkt.length, p_peek, &i_skip, i_data_packet_min - i_skip, i_packet_flags >> 5) < 0)
- goto loop_error_recovery;
- uint32_t i_packet_sequence;
- if (GetValue2b(&i_packet_sequence, p_peek, &i_skip, i_data_packet_min - i_skip, i_packet_flags >> 1) < 0)
- goto loop_error_recovery;
- if (GetValue2b(&pkt.padding_length, p_peek, &i_skip, i_data_packet_min - i_skip, i_packet_flags >> 3) < 0)
- goto loop_error_recovery;
-
- if( pkt.padding_length > pkt.length )
- {
- msg_Warn( p_demux, "Too large padding: %d", pkt.padding_length );
- goto loop_error_recovery;
- }
-
- if( pkt.length < i_data_packet_min )
- {
- /* if packet length too short, there is extra padding */
- pkt.padding_length += i_data_packet_min - pkt.length;
- pkt.length = i_data_packet_min;
- }
-
- pkt.send_time = GetDWLE( p_peek + i_skip ); i_skip += 4;
- /* uint16_t i_packet_duration = GetWLE( p_peek + i_skip ); */ i_skip += 2;
-
- i_return = stream_Peek( p_demux->s, &p_peek, pkt.length );
- if( i_return <= 0 || pkt.length == 0 || (unsigned int)i_return < pkt.length )
- {
- msg_Warn( p_demux, "cannot peek, EOF ?" );
- return 0;
- }
-
- int i_payload_count = 1;
- pkt.length_type = 0x02; //unused
- if( pkt.multiple )
- {
- i_payload_count = p_peek[i_skip] & 0x3f;
- pkt.length_type = ( p_peek[i_skip] >> 6 )&0x03;
- i_skip++;
- }
-