Commit e34f42f7 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

avcodec audio decoder: remove SplitBuffer()

Manual backport of 160e651e28805cfe4d1f2d4295a58e5c4e1b7370

Close #8260
parent a481fd69
......@@ -67,12 +67,6 @@ struct decoder_sys_t
audio_sample_format_t aout_format;
date_t end_date;
/*
*
*/
uint8_t *p_samples;
int i_samples;
/* */
int i_reject_count;
......@@ -239,8 +233,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
msg_Dbg( p_dec, "Using %d bytes output buffer", p_sys->i_output_max );
p_sys->p_output = av_malloc( p_sys->i_output_max );
p_sys->p_samples = NULL;
p_sys->i_samples = 0;
p_sys->i_reject_count = 0;
p_sys->b_extract = false;
p_sys->i_previous_channels = 0;
......@@ -260,49 +252,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
return VLC_SUCCESS;
}
/*****************************************************************************
* SplitBuffer: Needed because aout really doesn't like big audio chunk and
* wma produces easily > 30000 samples...
*****************************************************************************/
static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
int i_samples = __MIN( p_sys->i_samples, 4096 );
int sample_planar=0;
aout_buffer_t *p_buffer;
if( i_samples == 0 ) return NULL;
if( ( p_buffer = decoder_NewAudioBuffer( p_dec, i_samples ) ) == NULL )
return NULL;
p_buffer->i_pts = date_Get( &p_sys->end_date );
p_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
- p_buffer->i_pts;
sample_planar = av_sample_fmt_is_planar( p_sys->p_context->sample_fmt );
if( sample_planar )
Interleave( p_buffer->p_buffer, p_sys->p_samples, i_samples, p_sys->p_context->channels, p_dec->fmt_out.audio.i_format );
if( p_sys->b_extract )
{
if( sample_planar )
memcpy( p_sys->p_samples, p_buffer->p_buffer, p_buffer->i_buffer );
aout_ChannelExtract( p_buffer->p_buffer, p_dec->fmt_out.audio.i_channels,
p_sys->p_samples, p_sys->p_context->channels, i_samples,
p_sys->pi_extraction, p_dec->fmt_out.audio.i_bitspersample );
}
else if (!sample_planar)
memcpy( p_buffer->p_buffer, p_sys->p_samples, p_buffer->i_buffer );
p_sys->p_samples += i_samples * p_sys->p_context->channels * ( p_dec->fmt_out.audio.i_bitspersample / 8 );
p_sys->i_samples -= i_samples;
return p_buffer;
}
/*****************************************************************************
* DecodeAudio: Called to decode one frame
*****************************************************************************/
......@@ -310,13 +259,12 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
int i_used, i_output;
aout_buffer_t *p_buffer;
block_t *p_block;
AVPacket pkt;
if( !pp_block || !*pp_block ) return NULL;
p_block = *pp_block;
block_t *p_block = *pp_block;
pp_block = NULL;
if( !p_sys->p_context->extradata_size && p_dec->fmt_in.i_extra &&
p_sys->b_delayed_open)
......@@ -327,15 +275,14 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
}
if( p_sys->b_delayed_open )
{
block_Release( p_block );
//block_Release( p_block );
return NULL;
}
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
block_Release( p_block );
//block_Release( p_block );
avcodec_flush_buffers( p_sys->p_context );
p_sys->i_samples = 0;
date_Set( &p_sys->end_date, 0 );
if( p_sys->i_codec_id == CODEC_ID_MP2 || p_sys->i_codec_id == CODEC_ID_MP3 )
......@@ -343,30 +290,22 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( p_sys->i_samples > 0 )
{
/* More data */
p_buffer = SplitBuffer( p_dec );
if( !p_buffer ) block_Release( p_block );
return p_buffer;
}
if( !date_Get( &p_sys->end_date ) && !p_block->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( p_block );
//block_Release( p_block );
return NULL;
}
if( p_block->i_buffer <= 0 )
{
block_Release( p_block );
//block_Release( p_block );
return NULL;
}
if( (p_block->i_flags & BLOCK_FLAG_PRIVATE_REALLOCATED) == 0 )
{
*pp_block = p_block = block_Realloc( p_block, 0, p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE );
p_block = block_Realloc( p_block, 0, p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE );
if( !p_block )
return NULL;
p_block->i_buffer -= FF_INPUT_BUFFER_PADDING_SIZE;
......@@ -397,7 +336,7 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
msg_Warn( p_dec, "cannot decode one frame (%zu bytes)",
p_block->i_buffer );
block_Release( p_block );
// block_Release( p_block );
return NULL;
}
else if( (size_t)i_used > p_block->i_buffer )
......@@ -415,29 +354,22 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
{
msg_Warn( p_dec, "invalid audio properties channels count %d, sample rate %d",
p_sys->p_context->channels, p_sys->p_context->sample_rate );
block_Release( p_block );
//block_Release( p_block );
return NULL;
}
if( p_dec->fmt_out.audio.i_rate != (unsigned int)p_sys->p_context->sample_rate )
{
date_Init( &p_sys->end_date, p_sys->p_context->sample_rate, 1 );
date_Set( &p_sys->end_date, p_block->i_pts );
}
/* **** Set audio output parameters **** */
SetupOutputFormat( p_dec, true );
if( p_block->i_pts != 0 &&
p_block->i_pts != date_Get( &p_sys->end_date ) )
{
date_Set( &p_sys->end_date, p_block->i_pts );
}
p_block->i_pts = 0;
/* **** Now we can output these samples **** */
p_sys->i_samples = i_output / (p_dec->fmt_out.audio.i_bitspersample / 8) / p_sys->p_context->channels;
p_sys->p_samples = p_sys->p_output;
//block_Release( p_block );
SetupOutputFormat( p_dec, true );
/* Silent unwanted samples */
if( p_sys->i_reject_count > 0 )
......@@ -446,8 +378,29 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
p_sys->i_reject_count--;
}
p_buffer = SplitBuffer( p_dec );
if( !p_buffer ) block_Release( p_block );
int i_samples = i_output / (p_dec->fmt_out.audio.i_bitspersample / 8) / p_sys->p_context->channels;
if (i_samples == 0)
return NULL;
block_t *p_buffer = decoder_NewAudioBuffer( p_dec, i_samples );
if (!p_buffer)
return NULL;
p_buffer->i_pts = date_Get( &p_sys->end_date );
p_buffer->i_length = date_Increment( &p_sys->end_date, i_samples ) - p_buffer->i_pts;
int sample_planar = av_sample_fmt_is_planar( p_sys->p_context->sample_fmt );
if( sample_planar )
Interleave( p_buffer->p_buffer, p_sys->p_output, i_samples, p_sys->p_context->channels, p_dec->fmt_out.audio.i_format );
if( p_sys->b_extract == !!sample_planar )
memcpy( p_sys->p_output, p_buffer->p_buffer, p_buffer->i_buffer );
if (p_sys->b_extract)
aout_ChannelExtract( p_buffer->p_buffer, p_dec->fmt_out.audio.i_channels,
p_sys->p_output, p_sys->p_context->channels, i_samples,
p_sys->pi_extraction, p_dec->fmt_out.audio.i_bitspersample );
return p_buffer;
}
......
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