Commit 75e39eac authored by Thomas Guillem's avatar Thomas Guillem

decoder: audio: don't update format when creating a buffer

Decoder modules are now responsible for calling decoder_UpdateAudioFormat()
before decoder_NewAudioBuffer().

In a lot of modules, decoder_UpdateAudioFormat() could be called in a better
place. Just after dec->fmt_out is updated for example.
parent 5b6d77b0
......@@ -317,6 +317,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{
block_t *p_out;
if( decoder_UpdateAudioFormat( p_dec ) )
goto drop;
p_out = decoder_NewAudioBuffer( p_dec, p_sys->i_samplesperblock );
if( p_out == NULL )
goto drop;
......
......@@ -146,6 +146,8 @@ static block_t *Decode( decoder_t *p_dec, block_t **pp_block )
if( !p_block )
return NULL;
if( decoder_UpdateAudioFormat( p_dec ) )
goto exit;
p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
if( p_aout_buffer == NULL )
goto exit;
......
......@@ -347,6 +347,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if( p_sys->decode != NULL )
{
if( decoder_UpdateAudioFormat( p_dec ) )
goto skip;
block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
if( p_out == NULL )
goto skip;
......
......@@ -972,6 +972,12 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
}
else
{
if( decoder_UpdateAudioFormat( p_dec ) )
{
p_out->vt->Release( (IUnknown *)p_out );
return NULL;
}
block_t *p_aout_buffer;
int i_samples = block_out.i_buffer /
( p_dec->fmt_out.audio.i_bitspersample *
......
......@@ -492,7 +492,10 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_dec->fmt_out.audio.i_physical_channels;
}
p_dec->fmt_out.audio.i_channels = nbChannels;
p_out = decoder_NewAudioBuffer( p_dec, frame.samples / nbChannels );
if( decoder_UpdateAudioFormat( p_dec ) )
p_out = NULL;
else
p_out = decoder_NewAudioBuffer( p_dec, frame.samples / nbChannels );
if( p_out == NULL )
{
p_sys->i_buffer = 0;
......
......@@ -180,6 +180,9 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
const unsigned char *pi_reorder = ppi_reorder[p_dec->fmt_out.audio.i_channels];
if( decoder_UpdateAudioFormat( p_dec ) )
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
p_sys->p_aout_buffer =
decoder_NewAudioBuffer( p_dec, frame->header.blocksize );
......
......@@ -297,6 +297,8 @@ static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
if (samples == 0)
goto drop;
if (decoder_UpdateAudioFormat (p_dec))
goto drop;
p_out = decoder_NewAudioBuffer (p_dec, samples);
if (p_out == NULL)
goto drop;
......
......@@ -263,6 +263,11 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( decoder_UpdateAudioFormat( p_dec ) )
{
block_Release( p_block );
return NULL;
}
block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
if( p_out == NULL )
{
......
......@@ -454,6 +454,8 @@ static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
/* */
block_t *p_aout_buffer;
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
if( !p_aout_buffer )
return NULL;
......
......@@ -688,6 +688,8 @@ static int ProcessOutputStream(decoder_t *p_dec, DWORD stream_id, void **result)
}
else
{
if (decoder_UpdateAudioFormat(p_dec))
goto error;
if (p_dec->fmt_out.audio.i_bitspersample == 0 || p_dec->fmt_out.audio.i_channels == 0)
goto error;
int samples = total_length / (p_dec->fmt_out.audio.i_bitspersample * p_dec->fmt_out.audio.i_channels / 8);
......
......@@ -563,6 +563,8 @@ static block_t *GetAoutBuffer( decoder_t *p_dec )
decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_buf;
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
p_buf = decoder_NewAudioBuffer( p_dec, p_sys->i_frame_length );
if( p_buf == NULL ) return NULL;
......
......@@ -176,6 +176,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
/* Request a new audio buffer */
if( decoder_UpdateAudioFormat( p_dec ) )
goto error;
block_t *p_out = decoder_NewAudioBuffer( p_dec, p_block->i_nb_samples );
if( unlikely( !p_out ) )
goto error;
......
......@@ -1706,6 +1706,8 @@ block_t *DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
i_samples = p_header->nFilledLen / p_sys->out.p_fmt->audio.i_channels / 2;
if(i_samples)
{
if( decoder_UpdateAudioFormat( p_dec ) )
break;
p_buffer = decoder_NewAudioBuffer( p_dec, i_samples );
if( !p_buffer ) break; /* No audio buffer available */
......
......@@ -436,6 +436,8 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
if(!i_nb_samples)
i_nb_samples = spp;
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
block_t *p_aout_buffer=decoder_NewAudioBuffer( p_dec, spp );
if ( !p_aout_buffer )
{
......
......@@ -732,8 +732,11 @@ static block_t *DecodeRtpSpeexPacket( decoder_t *p_dec, block_t **pp_block )
Ask for a new audio output buffer and make sure
we get one.
*/
p_aout_buffer = decoder_NewAudioBuffer( p_dec,
p_sys->p_header->frame_size );
if( decoder_UpdateAudioFormat( p_dec ) )
p_aout_buffer = NULL;
else
p_aout_buffer = decoder_NewAudioBuffer( p_dec,
p_sys->p_header->frame_size );
if ( !p_aout_buffer || p_aout_buffer->i_buffer == 0 )
{
msg_Err(p_dec, "Oops: No new buffer was returned!");
......@@ -795,6 +798,8 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
if( p_sys->p_header->frame_size == 0 )
return NULL;
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
p_aout_buffer =
decoder_NewAudioBuffer( p_dec, p_sys->p_header->frame_size );
if( !p_aout_buffer )
......
......@@ -97,6 +97,8 @@ static block_t *Decode(decoder_t *dec, block_t **block_ptr)
int sample_count = dv_get_audio_sample_count(&src[244], sys->is_pal);
if( decoder_UpdateAudioFormat(dec))
return NULL;
block_t *output = decoder_NewAudioBuffer(dec, sample_count);
if (!output)
return NULL;
......
......@@ -536,6 +536,7 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
block_t *p_aout_buffer;
if( decoder_UpdateAudioFormat( p_dec ) ) return NULL;
p_aout_buffer =
decoder_NewAudioBuffer( p_dec, i_samples );
......
......@@ -98,6 +98,8 @@ static block_t *SplitBuffer( decoder_t *p_dec )
if( i_samples == 0 ) return NULL;
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
if( !( p_buffer = decoder_NewAudioBuffer( p_dec, i_samples ) ) )
return NULL;
......
......@@ -594,9 +594,6 @@ static int DecoderGetDisplayRate( decoder_t *p_dec )
*****************************************************************************/
block_t *decoder_NewAudioBuffer( decoder_t *dec, int samples )
{
if( decoder_UpdateAudioFormat( dec ) )
return NULL;
size_t length = samples * dec->fmt_out.audio.i_bytes_per_frame
/ dec->fmt_out.audio.i_frame_length;
block_t *block = block_Alloc( length );
......
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