Commit 9d349e1c authored by Rafaël Carré's avatar Rafaël Carré

asf demuxer: fix header demuxing & use padding without confusing the user (refs #1404)

parent 689d893b
......@@ -89,7 +89,7 @@ struct demux_sys_t
asf_object_file_properties_t *p_fp;
unsigned int i_track;
asf_track_t *track[128];
asf_track_t *track[128]; /* track number is stored on 7 bits */
int64_t i_data_begin;
int64_t i_data_end;
......@@ -149,7 +149,11 @@ static int Demux( demux_t *p_demux )
mtime_t i_time_begin = GetMoviePTS( p_sys );
int i_result;
if( p_demux->b_die ) break;
if( p_demux->b_die )
break;
if( p_sys->i_data_end >= 0 &&
stream_Tell( p_demux->s ) >= p_sys->i_data_end )
return 0; /* EOF */
/* Check if we have concatenated files */
if( stream_Peek( p_demux->s, &p_peek, 16 ) == 16 )
......@@ -426,12 +430,16 @@ static int DemuxPacket( demux_t *p_demux )
GETVALUE2b( i_packet_flags >> 1, i_packet_sequence, 0 );
GETVALUE2b( i_packet_flags >> 3, i_packet_padding_length, 0 );
if( i_packet_padding_length > i_packet_length )
{
msg_Warn( p_demux, "Too large padding: %d", i_packet_padding_length );
goto loop_error_recovery;
}
i_packet_send_time = GetDWLE( p_peek + i_skip ); i_skip += 4;
i_packet_duration = GetWLE( p_peek + i_skip ); i_skip += 2;
// i_packet_size_left = i_packet_length; // XXX data really read
/* FIXME I have to do that for some file, I don't known why */
i_packet_size_left = i_data_packet_min;
i_packet_size_left = i_packet_length - i_packet_padding_length;
if( b_packet_multiple_payload )
{
......@@ -512,11 +520,10 @@ static int DemuxPacket( demux_t *p_demux )
}
else
{
i_payload_data_length = i_packet_length -
i_packet_padding_length - i_skip;
i_payload_data_length = i_packet_length - i_skip;
}
if( i_payload_data_length < 0 || i_skip + i_payload_data_length > i_packet_size_left )
if( i_payload_data_length < 0 || i_payload_data_length > i_packet_size_left )
{
break;
}
......@@ -616,14 +623,24 @@ static int DemuxPacket( demux_t *p_demux )
if( i_packet_size_left > 0 )
{
msg_Warn( p_demux, "Didn't read %d bytes in the packet",
i_packet_size_left );
if( stream_Read( p_demux->s, NULL, i_packet_size_left )
< i_packet_size_left )
{
msg_Warn( p_demux, "cannot skip data, EOF ?" );
msg_Err( p_demux, "cannot skip data, EOF ?" );
return 0;
}
}
if( i_packet_padding_length > 0 )
if( stream_Read( p_demux->s, NULL, i_packet_padding_length )
< i_packet_padding_length )
{
msg_Err( p_demux, "cannot skip padding data, EOF ?" );
return 0;
}
return 1;
loop_error_recovery:
......
......@@ -134,6 +134,7 @@ static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
static void ASF_FreeObject_Null( asf_object_t *pp_obj )
{
VLC_UNUSED(pp_obj);
return;
}
......@@ -270,7 +271,7 @@ static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
int i_peek;
const uint8_t *p_peek;
if( ( i_peek = stream_Peek( s, &p_peek, 104) ) < 104 )
if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 )
{
return VLC_EGENERIC;
}
......@@ -278,9 +279,10 @@ static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
p_fp->i_file_size = GetQWLE( p_peek + 40 );
p_fp->i_creation_date = GetQWLE( p_peek + 48 );
p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
p_fp->i_play_duration = GetQWLE( p_peek + 64 );
p_fp->i_send_duration = GetQWLE( p_peek + 72 );
p_fp->i_preroll = GetQWLE( p_peek + 80 );
p_fp->i_send_duration = GetQWLE( p_peek + 64 );
p_fp->i_play_duration = GetQWLE( p_peek + 72 );
p_fp->i_preroll = GetDWLE( p_peek + 80 );
p_fp->i_unknown = GetDWLE( p_peek + 84 );
p_fp->i_flags = GetDWLE( p_peek + 88 );
p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
......@@ -290,13 +292,13 @@ static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
msg_Dbg( s,
"read \"file properties object\" file_id:" GUID_FMT
" file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
"max_bitrate:%d",
I64Fd" send_duration:"I64Fd" play_duration:"I64Fd" preroll:%d"
"unknown:%d flags:%d min_data_packet_size:%d "
"max_data_packet_size:%d max_bitrate:%d",
GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
p_fp->i_creation_date, p_fp->i_data_packets_count,
p_fp->i_play_duration, p_fp->i_send_duration,
p_fp->i_preroll, p_fp->i_flags,
p_fp->i_send_duration, p_fp->i_play_duration,
p_fp->i_preroll, p_fp->i_unknown, p_fp->i_flags,
p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
p_fp->i_max_bitrate );
#endif
......
......@@ -198,9 +198,10 @@ typedef struct
uint64_t i_file_size;
uint64_t i_creation_date;
uint64_t i_data_packets_count;
uint64_t i_play_duration;
uint64_t i_send_duration;
uint64_t i_preroll;
uint64_t i_play_duration;
uint32_t i_preroll;
uint32_t i_unknown; /* ignored, usually 0 */
uint32_t i_flags;
uint32_t i_min_data_packet_size;
uint32_t i_max_data_packet_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment