Commit fbfe10b4 authored by Ilkka Ollakka's avatar Ilkka Ollakka

transcode: initialize audio encoder properly when first packet arrives

parent 8f01bd1f
......@@ -78,45 +78,9 @@ static int transcode_audio_initialize_filters( sout_stream_t *p_stream, sout_str
return VLC_SUCCESS;
}
int transcode_audio_new( sout_stream_t *p_stream,
sout_stream_id_t *id )
static int transcode_audio_initialize_encoder( sout_stream_id_t *id, sout_stream_t *p_stream )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
audio_sample_format_t fmt_last;
/*
* Open decoder
*/
/* Initialization of decoder structures */
id->p_decoder->fmt_out = id->p_decoder->fmt_in;
id->p_decoder->fmt_out.i_extra = 0;
id->p_decoder->fmt_out.p_extra = 0;
id->p_decoder->pf_decode_audio = NULL;
id->p_decoder->pf_aout_format_update = audio_update_format;
/* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
id->p_decoder->p_module =
module_need( id->p_decoder, "decoder", "$codec", false );
if( !id->p_decoder->p_module )
{
msg_Err( p_stream, "cannot find audio decoder" );
return VLC_EGENERIC;
}
/* decoders don't set audio.i_format, but audio filters use it */
id->p_decoder->fmt_out.audio.i_format = id->p_decoder->fmt_out.i_codec;
aout_FormatPrepare( &id->p_decoder->fmt_out.audio );
fmt_last = id->p_decoder->fmt_out.audio;
/* Fix AAC SBR changing number of channels and sampling rate */
if( !(id->p_decoder->fmt_in.i_codec == VLC_CODEC_MP4A &&
fmt_last.i_rate != id->p_encoder->fmt_in.audio.i_rate &&
fmt_last.i_channels != id->p_encoder->fmt_in.audio.i_channels) )
fmt_last.i_rate = id->p_decoder->fmt_in.audio.i_rate;
/*
* Open encoder
*/
/* Initialization of encoder format structures */
es_format_Init( &id->p_encoder->fmt_in, id->p_decoder->fmt_in.i_cat,
id->p_decoder->fmt_out.i_codec );
......@@ -154,6 +118,50 @@ int transcode_audio_new( sout_stream_t *p_stream,
}
aout_FormatPrepare( &id->p_encoder->fmt_in.audio );
return VLC_SUCCESS;
}
int transcode_audio_new( sout_stream_t *p_stream,
sout_stream_id_t *id )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
audio_sample_format_t fmt_last;
/*
* Open decoder
*/
/* Initialization of decoder structures */
id->p_decoder->fmt_out = id->p_decoder->fmt_in;
id->p_decoder->fmt_out.i_extra = 0;
id->p_decoder->fmt_out.p_extra = 0;
id->p_decoder->pf_decode_audio = NULL;
id->p_decoder->pf_aout_format_update = audio_update_format;
/* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
id->p_decoder->p_module =
module_need( id->p_decoder, "decoder", "$codec", false );
if( !id->p_decoder->p_module )
{
msg_Err( p_stream, "cannot find audio decoder" );
return VLC_EGENERIC;
}
/* decoders don't set audio.i_format, but audio filters use it */
id->p_decoder->fmt_out.audio.i_format = id->p_decoder->fmt_out.i_codec;
aout_FormatPrepare( &id->p_decoder->fmt_out.audio );
fmt_last = id->p_decoder->fmt_out.audio;
/* Fix AAC SBR changing number of channels and sampling rate */
if( !(id->p_decoder->fmt_in.i_codec == VLC_CODEC_MP4A &&
fmt_last.i_rate != id->p_encoder->fmt_in.audio.i_rate &&
fmt_last.i_channels != id->p_encoder->fmt_in.audio.i_channels) )
fmt_last.i_rate = id->p_decoder->fmt_in.audio.i_rate;
/*
* Open encoder
*/
if( transcode_audio_initialize_encoder( id, p_stream ) == VLC_EGENERIC )
return VLC_EGENERIC;
if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &fmt_last ) != VLC_SUCCESS ) )
return VLC_EGENERIC;
......@@ -222,11 +230,13 @@ int transcode_audio_process( sout_stream_t *p_stream,
id->p_decoder->fmt_in.audio.i_physical_channels;
id->p_encoder->fmt_out.audio.i_physical_channels =
pi_channels_maps[id->p_encoder->fmt_out.audio.i_channels];
if( transcode_audio_new( p_stream, id ) )
if( transcode_audio_initialize_encoder( id, p_stream ) )
{
msg_Err( p_stream, "cannot create audio chain" );
return VLC_EGENERIC;
}
if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &id->p_decoder->fmt_out.audio ) != VLC_SUCCESS ) )
return VLC_EGENERIC;
date_Init( &id->interpolated_pts, id->p_decoder->fmt_out.audio.i_rate, 1 );
}
......
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