Commit 48d16c43 authored by Gildas Bazin's avatar Gildas Bazin

* include/vlc_block_helper.h: fixed an idiotically stupid bug in block_PeekOffsetBytes().

* modules/codec/mpeg_audio.c, modules/codec/a52.c, modules/packetizer/mpeg4audio.c: fixed a couple of issues.
parent 3fa2bee8
......@@ -2,7 +2,7 @@
* vlc_block_helper.h: Helper functions for data blocks management.
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: vlc_block_helper.h,v 1.3 2003/10/05 00:50:05 gbazin Exp $
* $Id: vlc_block_helper.h,v 1.4 2003/10/23 20:51:20 gbazin Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -321,13 +321,14 @@ static inline int block_PeekOffsetBytes( block_bytestream_t *p_bytestream,
{
i_copy = __MIN( i_size, p_block->i_buffer - i_offset );
i_size -= i_copy;
i_offset = 0;
if( !i_size ) break;
i_offset = 0;
}
/* Copy the data */
i_offset = i_copy;
i_offset += i_copy;
i_size = i_data;
i_copy = 0;
for( ; p_block != NULL; p_block = p_block->p_next )
......
......@@ -2,7 +2,7 @@
* a52.c: A/52 basic parser
*****************************************************************************
* Copyright (C) 2001-2002 VideoLAN
* $Id: a52.c,v 1.27 2003/10/08 21:03:36 gbazin Exp $
* $Id: a52.c,v 1.28 2003/10/23 20:51:20 gbazin Exp $
*
* Authors: Stphane Borel <stef@via.ecp.fr>
* Christophe Massiot <massiot@via.ecp.fr>
......@@ -53,7 +53,6 @@ struct decoder_sys_t
* Input properties
*/
int i_state;
vlc_bool_t b_synchro;
block_t *p_chain;
block_bytestream_t bytestream;
......@@ -170,7 +169,6 @@ static int OpenPacketizer( vlc_object_t *p_this )
static int InitDecoder( decoder_t *p_dec )
{
p_dec->p_sys->i_state = STATE_NOSYNC;
p_dec->p_sys->b_synchro = VLC_FALSE;
p_dec->p_sys->p_out_buffer = NULL;
aout_DateSet( &p_dec->p_sys->end_date, 0 );
......@@ -207,6 +205,11 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
return VLC_SUCCESS;
}
if( p_block->b_discontinuity )
{
p_sys->i_state = STATE_SYNC;
}
if( p_sys->p_chain )
{
block_ChainAppend( &p_sys->p_chain, p_block );
......@@ -232,10 +235,16 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
break;
}
block_SkipByte( &p_sys->bytestream );
p_sys->b_synchro = VLC_FALSE;
}
if( p_sys->i_state != STATE_SYNC )
{
if( block_PeekByte( &p_sys->bytestream, p_header )
== VLC_SUCCESS && p_header[0] == 0x0b )
{
/* Start of a sync word, need more data */
return VLC_SUCCESS;
}
block_ChainRelease( p_sys->p_chain );
p_sys->p_chain = NULL;
......@@ -274,7 +283,6 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
msg_Dbg( p_dec, "emulated sync word" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_FALSE;
break;
}
p_sys->i_state = STATE_DATA;
......@@ -283,26 +291,22 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
/* TODO: If p_block == NULL, flush the buffer without checking the
* next sync word */
if( !p_sys->b_synchro )
{
/* Check if next expected frame contains the sync word */
if( block_PeekOffsetBytes( &p_sys->bytestream,
p_sys->i_frame_size, p_header, 2 )
!= VLC_SUCCESS )
{
/* Need more data */
return VLC_SUCCESS;
}
if( p_header[0] != 0x0b || p_header[1] != 0x77 )
{
msg_Dbg( p_dec, "emulated sync word "
"(no sync on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
p_sys->b_synchro = VLC_FALSE;
break;
}
/* Check if next expected frame contains the sync word */
if( block_PeekOffsetBytes( &p_sys->bytestream,
p_sys->i_frame_size, p_header, 2 )
!= VLC_SUCCESS )
{
/* Need more data */
return VLC_SUCCESS;
}
if( p_header[0] != 0x0b || p_header[1] != 0x77 )
{
msg_Dbg( p_dec, "emulated sync word "
"(no sync on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
break;
}
if( !p_sys->p_out_buffer )
......@@ -323,7 +327,6 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
SendOutBuffer( p_dec );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_TRUE;
/* Make sure we don't reuse the same pts twice */
if( p_sys->pts == p_sys->bytestream.p_block->i_pts )
......
......@@ -2,7 +2,7 @@
* mpeg_audio.c: parse MPEG audio sync info and packetize the stream
*****************************************************************************
* Copyright (C) 2001-2003 VideoLAN
* $Id: mpeg_audio.c,v 1.19 2003/10/05 00:50:05 gbazin Exp $
* $Id: mpeg_audio.c,v 1.20 2003/10/23 20:51:20 gbazin Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -50,7 +50,6 @@ struct decoder_sys_t
* Input properties
*/
int i_state;
vlc_bool_t b_synchro;
block_t *p_chain;
block_bytestream_t bytestream;
......@@ -183,7 +182,6 @@ static int OpenPacketizer( vlc_object_t *p_this )
static int InitDecoder( decoder_t *p_dec )
{
p_dec->p_sys->i_state = STATE_NOSYNC;
p_dec->p_sys->b_synchro = VLC_FALSE;
p_dec->p_sys->p_out_buffer = NULL;
aout_DateSet( &p_dec->p_sys->end_date, 0 );
......@@ -217,15 +215,18 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
uint8_t p_header[MAD_BUFFER_GUARD];
uint32_t i_header;
if( (!aout_DateGet( &p_sys->end_date ) && !p_block->i_pts)
|| p_block->b_discontinuity )
if( !aout_DateGet( &p_sys->end_date ) && !p_block->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( p_block );
p_sys->b_synchro = VLC_FALSE;
return VLC_SUCCESS;
}
if( p_block->b_discontinuity )
{
p_sys->i_state = STATE_SYNC;
}
if( p_sys->p_chain )
{
block_ChainAppend( &p_sys->p_chain, p_block );
......@@ -252,10 +253,16 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
break;
}
block_SkipByte( &p_sys->bytestream );
p_sys->b_synchro = VLC_FALSE;
}
if( p_sys->i_state != STATE_SYNC )
{
if( block_PeekByte( &p_sys->bytestream, p_header )
== VLC_SUCCESS && p_header[0] == 0xff )
{
/* Start of a sync word, need more data */
return VLC_SUCCESS;
}
block_ChainRelease( p_sys->p_chain );
p_sys->p_chain = NULL;
......@@ -269,6 +276,8 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
if( p_sys->pts != 0 &&
p_sys->pts != aout_DateGet( &p_sys->end_date ) )
{
msg_Err( p_dec, "set PTS: %lli old: %lli", p_sys->pts,
aout_DateGet( &p_sys->end_date ) );
aout_DateSet( &p_sys->end_date, p_sys->pts );
}
p_sys->i_state = STATE_HEADER;
......@@ -302,7 +311,6 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
msg_Dbg( p_dec, "emulated start code" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_FALSE;
break;
}
......@@ -400,7 +408,6 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
"(emulated startcode ?)" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_FALSE;
break;
}
}
......@@ -413,14 +420,11 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
break;
}
if( !p_sys->b_synchro )
{
msg_Dbg( p_dec, "emulated startcode "
"(no startcode on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
break;
}
msg_Dbg( p_dec, "emulated startcode "
"(no startcode on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
break;
}
if( GetOutBuffer( p_dec, &p_sys->p_out_buffer ) != VLC_SUCCESS )
......@@ -456,7 +460,6 @@ static int RunDecoder( decoder_t *p_dec, block_t *p_block )
SendOutBuffer( p_dec );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_TRUE;
/* Make sure we don't reuse the same pts twice */
if( p_sys->pts == p_sys->bytestream.p_block->i_pts )
......@@ -717,7 +720,7 @@ static int SyncInfo( uint32_t i_header, unsigned int * pi_channels,
};
int i_version, i_mode, i_emphasis;
vlc_bool_t b_padding, b_mpeg_2_5;
vlc_bool_t b_padding, b_mpeg_2_5, b_crc;
int i_frame_size = 0;
int i_bitrate_index, i_samplerate_index;
int i_max_bit_rate;
......@@ -725,7 +728,7 @@ static int SyncInfo( uint32_t i_header, unsigned int * pi_channels,
b_mpeg_2_5 = 1 - ((i_header & 0x100000) >> 20);
i_version = 1 - ((i_header & 0x80000) >> 19);
*pi_layer = 4 - ((i_header & 0x60000) >> 17);
/* CRC */
b_crc = !((i_header >> 16) & 0x01);
i_bitrate_index = (i_header & 0xf000) >> 12;
i_samplerate_index = (i_header & 0xc00) >> 10;
b_padding = (i_header & 0x200) >> 9;
......
......@@ -2,7 +2,7 @@
* mpeg4audio.c: parse and packetize an MPEG 4 audio stream
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: mpeg4audio.c,v 1.9 2003/10/05 18:09:36 gbazin Exp $
* $Id: mpeg4audio.c,v 1.10 2003/10/23 20:51:20 gbazin Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
......@@ -59,7 +59,6 @@ struct decoder_sys_t
* Input properties
*/
int i_state;
vlc_bool_t b_synchro;
block_t *p_chain;
block_bytestream_t bytestream;
......@@ -160,7 +159,6 @@ static int InitPacketizer( decoder_t *p_dec )
WAVEFORMATEX *p_wf;
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_FALSE;
aout_DateSet( &p_sys->end_date, 0 );
......@@ -255,15 +253,18 @@ static int RunADTSPacketizer( decoder_t *p_dec, block_t *p_block )
decoder_sys_t *p_sys = p_dec->p_sys;
uint8_t p_header[ADTS_HEADER_SIZE];
if( (!aout_DateGet( &p_sys->end_date ) && !p_block->i_pts)
|| p_block->b_discontinuity )
if( !aout_DateGet( &p_sys->end_date ) && !p_block->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( p_block );
p_sys->b_synchro = VLC_FALSE;
return VLC_SUCCESS;
}
if( p_block->b_discontinuity )
{
p_sys->i_state = STATE_SYNC;
}
if( p_sys->p_chain )
{
block_ChainAppend( &p_sys->p_chain, p_block );
......@@ -290,10 +291,16 @@ static int RunADTSPacketizer( decoder_t *p_dec, block_t *p_block )
break;
}
block_SkipByte( &p_sys->bytestream );
p_sys->b_synchro = VLC_FALSE;
}
if( p_sys->i_state != STATE_SYNC )
{
if( block_PeekByte( &p_sys->bytestream, p_header )
== VLC_SUCCESS && p_header[0] == 0xff )
{
/* Start of a sync word, need more data */
return VLC_SUCCESS;
}
block_ChainRelease( p_sys->p_chain );
p_sys->p_chain = NULL;
......@@ -332,7 +339,6 @@ static int RunADTSPacketizer( decoder_t *p_dec, block_t *p_block )
msg_Dbg( p_dec, "emulated sync word" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_synchro = VLC_FALSE;
break;
}
......@@ -342,26 +348,22 @@ static int RunADTSPacketizer( decoder_t *p_dec, block_t *p_block )
/* TODO: If p_block == NULL, flush the buffer without checking the
* next sync word */
if( !p_sys->b_synchro )
/* Check if next expected frame contains the sync word */
if( block_PeekOffsetBytes( &p_sys->bytestream,
p_sys->i_frame_size, p_header, 2 )
!= VLC_SUCCESS )
{
/* Check if next expected frame contains the sync word */
if( block_PeekOffsetBytes( &p_sys->bytestream,
p_sys->i_frame_size, p_header, 2 )
!= VLC_SUCCESS )
{
/* Need more data */
return VLC_SUCCESS;
}
/* Need more data */
return VLC_SUCCESS;
}
if( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 )
{
msg_Dbg( p_dec, "emulated sync word "
"(no sync on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
p_sys->b_synchro = VLC_FALSE;
break;
}
if( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 )
{
msg_Dbg( p_dec, "emulated sync word "
"(no sync on following frame)" );
p_sys->i_state = STATE_NOSYNC;
block_SkipByte( &p_sys->bytestream );
break;
}
if( !p_sys->p_sout_buffer )
......@@ -385,7 +387,6 @@ static int RunADTSPacketizer( decoder_t *p_dec, block_t *p_block )
p_sys->i_state = STATE_NOSYNC;
p_sys->p_sout_buffer = NULL;
p_sys->b_synchro = VLC_TRUE;
/* Make sure we don't reuse the same pts twice */
if( p_sys->pts == p_sys->bytestream.p_block->i_pts )
......
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