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