Commit a3a150b9 authored by Ilkka Ollakka's avatar Ilkka Ollakka

trascode: reinit audio filters if audio format changes in midstream

parent 1036a0be
...@@ -52,6 +52,31 @@ static int audio_update_format( decoder_t *p_dec ) ...@@ -52,6 +52,31 @@ static int audio_update_format( decoder_t *p_dec )
return 0; return 0;
} }
static int transcode_audio_initialize_filters( sout_stream_t *p_stream, sout_stream_id_t *id, sout_stream_sys_t *p_sys, audio_sample_format_t *fmt_last )
{
/* Load user specified audio filters */
/* XXX: These variable names come kinda out of nowhere... */
var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
if( p_sys->psz_af )
var_SetString( p_stream, "audio-filter", p_sys->psz_af );
id->p_af_chain = aout_FiltersNew( p_stream, fmt_last,
&id->p_encoder->fmt_in.audio, NULL );
var_Destroy( p_stream, "audio-filter" );
var_Destroy( p_stream, "audio-time-stretch" );
if( id->p_af_chain == NULL )
{
msg_Err( p_stream, "Unable to initialize audio filters" );
module_unneed( id->p_encoder, id->p_encoder->p_module );
id->p_encoder->p_module = NULL;
module_unneed( id->p_decoder, id->p_decoder->p_module );
id->p_decoder->p_module = NULL;
return VLC_EGENERIC;
}
memcpy( fmt_last, &p_sys->fmt_audio, sizeof( audio_sample_format_t ) );
return VLC_SUCCESS;
}
int transcode_audio_new( sout_stream_t *p_stream, int transcode_audio_new( sout_stream_t *p_stream,
sout_stream_id_t *id ) sout_stream_id_t *id )
{ {
...@@ -128,25 +153,8 @@ int transcode_audio_new( sout_stream_t *p_stream, ...@@ -128,25 +153,8 @@ int transcode_audio_new( sout_stream_t *p_stream,
} }
aout_FormatPrepare( &id->p_encoder->fmt_in.audio ); aout_FormatPrepare( &id->p_encoder->fmt_in.audio );
/* Load user specified audio filters */ if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &fmt_last ) != VLC_SUCCESS ) )
/* XXX: These variable names come kinda out of nowhere... */
var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
if( p_sys->psz_af )
var_SetString( p_stream, "audio-filter", p_sys->psz_af );
id->p_af_chain = aout_FiltersNew( p_stream, &fmt_last,
&id->p_encoder->fmt_in.audio, NULL );
var_Destroy( p_stream, "audio-filter" );
var_Destroy( p_stream, "audio-time-stretch" );
if( id->p_af_chain == NULL )
{
msg_Err( p_stream, "cannot connect audio filters chain" );
module_unneed( id->p_encoder, id->p_encoder->p_module );
id->p_encoder->p_module = NULL;
module_unneed( id->p_decoder, id->p_decoder->p_module );
id->p_decoder->p_module = NULL;
return VLC_EGENERIC; return VLC_EGENERIC;
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -212,6 +220,17 @@ int transcode_audio_process( sout_stream_t *p_stream, ...@@ -212,6 +220,17 @@ int transcode_audio_process( sout_stream_t *p_stream,
p_audio_buf->i_dts = p_audio_buf->i_pts; p_audio_buf->i_dts = p_audio_buf->i_pts;
/* Check if audio format has changed, and filters need reinit */
if( unlikely( AOUT_FMTS_IDENTICAL( &id->p_decoder->fmt_out.audio, &p_sys->fmt_audio ) ) )
{
msg_Dbg( p_stream, "Audio changed, trying to reinitialize filters" );
if( id->p_af_chain != NULL )
aout_FiltersDelete( (vlc_object_t *)NULL, id->p_af_chain );
if( transcode_audio_initialize_filters( p_stream, id, p_sys, &id->p_decoder->fmt_out.audio ) != VLC_SUCCESS )
return VLC_EGENERIC;
}
/* Run filter chain */ /* Run filter chain */
p_audio_buf = aout_FiltersPlay( id->p_af_chain, p_audio_buf, p_audio_buf = aout_FiltersPlay( id->p_af_chain, p_audio_buf,
INPUT_RATE_DEFAULT ); INPUT_RATE_DEFAULT );
......
...@@ -25,6 +25,7 @@ struct sout_stream_sys_t ...@@ -25,6 +25,7 @@ struct sout_stream_sys_t
/* Audio */ /* Audio */
vlc_fourcc_t i_acodec; /* codec audio (0 if not transcode) */ vlc_fourcc_t i_acodec; /* codec audio (0 if not transcode) */
audio_sample_format_t fmt_audio;
char *psz_aenc; char *psz_aenc;
char *psz_alang; char *psz_alang;
config_chain_t *p_audio_cfg; config_chain_t *p_audio_cfg;
......
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