/*****************************************************************************
* audio.c: audio decoder using ffmpeg library
*****************************************************************************
- * Copyright (C) 1999-2003 VideoLAN
+ * Copyright (C) 1999-2003 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
decoder_sys_t *p_sys;
vlc_value_t lockval;
- var_Get( p_dec->p_libvlc, "avcodec", &lockval );
+ var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
p_sys->p_context->channels = p_dec->fmt_in.audio.i_channels;
p_sys->p_context->block_align = p_dec->fmt_in.audio.i_blockalign;
p_sys->p_context->bit_rate = p_dec->fmt_in.i_bitrate;
+ p_sys->p_context->bits_per_sample = p_dec->fmt_in.audio.i_bitspersample;
if( ( p_sys->p_context->extradata_size = p_dec->fmt_in.i_extra ) > 0 )
{
+ int i_offset = 0;
+
+ if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'f', 'l', 'a', 'c' ) )
+ i_offset = 8;
+
+ p_sys->p_context->extradata_size -= i_offset;
p_sys->p_context->extradata =
- malloc( p_dec->fmt_in.i_extra + FF_INPUT_BUFFER_PADDING_SIZE );
+ malloc( p_sys->p_context->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE );
memcpy( p_sys->p_context->extradata,
- p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
- memset( (char*)p_sys->p_context->extradata + p_dec->fmt_in.i_extra, 0,
+ (char*)p_dec->fmt_in.p_extra + i_offset,
+ p_sys->p_context->extradata_size );
+ memset( (char*)p_sys->p_context->extradata +
+ p_sys->p_context->extradata_size, 0,
FF_INPUT_BUFFER_PADDING_SIZE );
}
msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
- p_sys->p_output = malloc( 3 * AVCODEC_MAX_AUDIO_FRAME_SIZE );
+ p_sys->p_output = malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE );
p_sys->p_samples = NULL;
p_sys->i_samples = 0;
return NULL;
}
- if( p_block->i_buffer <= 0 || p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
+ if( p_block->i_buffer <= 0 ||
+ (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) )
{
block_Release( p_block );
return NULL;
}
+ if( p_block->i_buffer > AVCODEC_MAX_AUDIO_FRAME_SIZE )
+ {
+ /* Grow output buffer if necessary (eg. for PCM data) */
+ p_sys->p_output = realloc(p_sys->p_output, p_block->i_buffer);
+ }
+
i_used = avcodec_decode_audio( p_sys->p_context,
(int16_t*)p_sys->p_output, &i_output,
p_block->p_buffer, p_block->i_buffer );
return NULL;
}
- if( p_dec->fmt_out.audio.i_rate != p_sys->p_context->sample_rate )
+ if( p_dec->fmt_out.audio.i_rate != (unsigned int)p_sys->p_context->sample_rate )
{
aout_DateInit( &p_sys->end_date, p_sys->p_context->sample_rate );
aout_DateSet( &p_sys->end_date, p_block->i_pts );